/* Gemini Live Translate — shared design system (light + dark) */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --soft: #f3f5fa;
  --line: #e3e7ee;
  --ink: #1f1f1f;
  --muted: #5f6368;
  --dim: #a0a5ad;
  --accent: #1a73e8;
  --accent-strong: #1a73e8;
  --accent-soft: #e8f0fe;
  --accent-line: #c6dafc;
  --red: #d93025;
  --red-soft: #fce8e6;
  --amber: #b06000;
  --amber-soft: #fef7e0;
  --green: #188038;
  --shadow: 0 1px 2px rgba(60,64,67,.08), 0 4px 16px rgba(60,64,67,.06);
  --radius: 20px;
  color-scheme: light;
  font-family: "Google Sans", "Google Sans Text", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  color: var(--ink);
  background: var(--bg);
}
:root[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #141821;
  --soft: #1b2030;
  --line: #262c3a;
  --ink: #eef1f6;
  --muted: #9aa3b2;
  --dim: #6c7588;
  --accent: #8ab4f8;
  --accent-strong: #4c8df6;
  --accent-soft: rgba(138,180,248,.13);
  --accent-line: rgba(138,180,248,.35);
  --red: #f28b82;
  --red-soft: rgba(242,139,130,.14);
  --amber: #fdd663;
  --amber-soft: rgba(253,214,99,.12);
  --green: #81c995;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); transition: background .25s, color .25s; }
body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ---------- Header ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand > div { min-width: 0; }
.title { font-weight: 600; font-size: 16px; letter-spacing: .1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark {
  width: 26px; height: 26px; flex: none;
  background: conic-gradient(from 200deg, #4285f4, #9b72cb, #d96570, #f9ab00, #34a853, #4285f4);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
}
.bar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted); padding: 0;
}
.icon-btn:active { transform: scale(.94); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 7px 12px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; font-weight: 500; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.live.on { background: var(--red-soft); color: var(--red); font-weight: 600; }
.live.on .dot { background: var(--red); animation: blink 1.4s infinite; }
.live.warn { background: var(--amber-soft); color: var(--amber); }
.live.warn .dot { background: var(--amber); }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- Layout ---------- */
.wrap { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right)) 18px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
select, input {
  font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 38px; }
.primary { background: var(--accent-strong); color: #fff; border: 0; border-radius: 999px; padding: 14px 24px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.primary:active { transform: scale(.98); }
.primary.big { width: 100%; font-size: 17px; padding: 16px 24px; min-height: 54px; }
.pill { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pill.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.pill .ic { width: 18px; height: 18px; }
.tag { flex: none; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 2px 6px; letter-spacing: .3px; }
.err { color: var(--red); font-size: 13px; line-height: 1.5; }
.err:empty { display: none; }

/* ---------- Listener: setup ---------- */
.setup h1 { font-size: 26px; line-height: 1.25; margin: 2px 0 6px; font-weight: 600; }
.setup p { margin: 0 0 18px; font-size: 15px; line-height: 1.5; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 12px 14px; text-align: left;
  display: flex; flex-direction: column; gap: 2px; transition: border-color .15s, background .15s; min-height: 62px; position: relative;
}
.chip b { font-size: 16px; font-weight: 600; }
.chip small { color: var(--muted); font-size: 12px; }
.chip.sel { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.chip.sel::after { content: ""; position: absolute; top: 12px; right: 12px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent-strong) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.2 4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z'/%3E%3C/svg%3E") center/14px no-repeat; }
.more { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.start-wrap { position: sticky; bottom: 0; padding: 12px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--surface) 70%, transparent); margin: 0 -2px; }
.start-wrap .tiny { text-align: center; margin-top: 8px; }

/* ---------- Listener: player ---------- */
#player { display: flex; flex-direction: column; flex: 1; gap: 12px; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.captions {
  flex: 1; min-height: 50vh; overflow-y: auto; padding: 6px 2px 28px; scroll-behavior: smooth;
  display: flex; flex-direction: column; gap: 16px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 40px); mask-image: linear-gradient(to bottom, transparent 0, #000 40px);
}
.captions .placeholder { color: var(--muted); font-size: 17px; margin: auto 0; text-align: center; line-height: 1.6; }
.line { font-size: var(--cap, clamp(24px, 6.4vw, 36px)); line-height: 1.45; font-weight: 500; color: var(--dim); transition: color .3s; overflow-wrap: anywhere; }
.line.prev { color: var(--muted); }
.line.cur { color: var(--ink); }
body[data-size="s"] { --cap: clamp(19px, 5vw, 28px); }
body[data-size="l"] { --cap: clamp(30px, 8.4vw, 46px); }
.source { display: flex; gap: 10px; align-items: flex-start; background: var(--soft); border-radius: 16px; padding: 12px 14px; font-size: 15px; line-height: 1.5; max-height: 4.9em; overflow: hidden; color: var(--muted); }
.meter { height: 3px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: linear-gradient(90deg, #4285f4, #9b72cb, #34a853); transition: width .1s; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 40; animation: fade .15s; }
.sheet-card { background: var(--surface); width: 100%; max-width: 560px; max-height: 82vh; border-radius: 22px 22px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; animation: up .2s ease-out; }
.sheet-grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 4px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-list { overflow-y: auto; display: flex; flex-direction: column; -webkit-overflow-scrolling: touch; }
.sheet-list button { text-align: left; border: 0; background: transparent; padding: 14px 6px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; font-size: 16px; }
.sheet-list button small { color: var(--muted); }
.sheet-list button.sel { color: var(--accent); font-weight: 600; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }

.foot { text-align: center; font-size: 12px; color: var(--dim); padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }

/* ---------- Speaker console ---------- */
.speaker .wrap { max-width: 1180px; }
.grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel h3 .grow { flex: 1; }
.panel h3 select { font-size: 14px; padding: 7px 34px 7px 12px; border-radius: 999px; width: auto; max-width: 170px; }
.transcript { min-height: 120px; max-height: 32vh; overflow-y: auto; font-size: 19px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.transcript:empty::before { content: attr(data-empty); color: var(--dim); font-size: 15px; }
.transcript.tgt { font-size: 21px; }

.console { display: flex; align-items: center; gap: 22px; }
.console-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.mic-label { font-size: 18px; font-weight: 600; }
.timer { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.mic {
  --lvl: 0;
  position: relative; width: 104px; height: 104px; border-radius: 50%; border: 0; flex: none; padding: 0;
  background: linear-gradient(145deg, #4c8df6, #1a73e8 60%, #1558b0); color: #fff;
  box-shadow: 0 10px 28px rgba(26,115,232,.38), inset 0 1px 0 rgba(255,255,255,.25);
  display: inline-flex; align-items: center; justify-content: center; transition: transform .15s, background .25s, box-shadow .25s;
}
.mic:active { transform: scale(.95); }
.mic svg { width: 44px; height: 44px; fill: currentColor; position: relative; z-index: 1; }
.mic .ic-stop { display: none; width: 34px; height: 34px; }
.mic .ring, .mic .ring2 { position: absolute; inset: 0; border-radius: 50%; pointer-events: none; }
.mic.on { background: linear-gradient(145deg, #ff6b5e, #e53935 60%, #b3261e); box-shadow: 0 10px 28px rgba(229,57,53,.4), inset 0 1px 0 rgba(255,255,255,.25); }
.mic.on .ic-mic { display: none; }
.mic.on .ic-stop { display: block; }
.mic.on .ring { background: rgba(229,57,53,.22); transform: scale(calc(1.06 + var(--lvl) * .3)); transition: transform .09s linear; }
.mic.on .ring2 { border: 2px solid rgba(229,57,53,.45); animation: ripple 1.8s ease-out infinite; }
.mic.busy { opacity: .7; pointer-events: none; }
@keyframes ripple { from { transform: scale(1); opacity: .9; } to { transform: scale(1.38); opacity: 0; } }
.level { height: 6px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.level > div { height: 100%; width: 0; background: linear-gradient(90deg, #34a853, #f9ab00, #ea4335); transition: width .08s; }
#micSelect { font-size: 14px; padding: 9px 36px 9px 12px; border-radius: 12px; }

.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat { background: var(--soft); border-radius: 999px; padding: 7px 12px; font-size: 14px; }
.stat b { color: var(--accent); }
.qr { display: flex; gap: 16px; align-items: center; }
.qr img { width: 140px; height: 140px; border-radius: 14px; border: 1px solid var(--line); background: #fff; flex: none; }
.qr-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.qr a { color: var(--accent); word-break: break-all; font-size: 14px; }
.big-qr { position: fixed; inset: 0; background: #fff; color: #1f1f1f; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; padding: 24px; }
.big-qr img { width: min(66vh, 82vw); height: min(66vh, 82vw); }
.big-qr h2 { font-size: clamp(24px, 4vw, 44px); margin: 0; }
.big-qr p { margin: 0; color: #5f6368; font-size: clamp(15px, 2vw, 22px); }
.big-qr .pill { background: #fff; color: #1f1f1f; border-color: #e3e7ee; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .wrap { padding-top: 12px; padding-bottom: 12px; }
  .sub { display: none; }
  .title { font-size: 15px; }
  .live { padding: 6px 10px; font-size: 12px; }
  .card { padding: 16px; border-radius: 18px; }
  .listen .setup { border: 0; box-shadow: none; padding: 4px 2px 0; background: transparent; }
  .listen .start-wrap { background: linear-gradient(to top, var(--bg) 70%, transparent); }
  .setup h1 { font-size: 23px; }
  .chips { grid-template-columns: 1fr 1fr; gap: 8px; }
  .chip { padding: 10px 12px; min-height: 58px; border-radius: 14px; }
  .chip b { font-size: 15px; }
  .toolbar .pill { padding: 8px 12px; }
  .captions { min-height: 54vh; }
  .speaker .grid, .speaker .stack { gap: 12px; }
  .console { flex-direction: column; text-align: center; gap: 22px; padding: 18px 0 2px; }
  .console-info { width: 100%; align-items: stretch; }
  .mic { width: 108px; height: 108px; }
  .panel h3 .grow { display: none; }
  #monBtn { margin-left: auto; }
  .transcript { font-size: 17px; max-height: 26vh; min-height: 90px; }
  .transcript.tgt { font-size: 19px; }
  .qr { flex-direction: column; align-items: stretch; text-align: center; }
  .qr img { width: 180px; height: 180px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
