:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --card-2: #f0f0f4;
  --text: #14141a;
  --muted: #6b6b78;
  --border: #e2e2ea;
  --accent: #6d5cff;
  --accent-2: #8b7dff;
  --danger: #ff4757;
  --ok: #22c07a;
  --shadow: 0 6px 24px rgba(20,20,40,.08);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0f;
    --card: #17171f;
    --card-2: #1f1f2a;
    --text: #f2f2f7;
    --muted: #9a9aa8;
    --border: #2a2a36;
    --accent: #8b7dff;
    --accent-2: #a99bff;
    --shadow: 0 6px 28px rgba(0,0,0,.4);
  }
}
:root[data-theme="light"] {
  --bg:#f5f5f7;--card:#fff;--card-2:#f0f0f4;--text:#14141a;--muted:#6b6b78;--border:#e2e2ea;--accent:#6d5cff;--accent-2:#8b7dff;--shadow:0 6px 24px rgba(20,20,40,.08);
}
:root[data-theme="dark"] {
  --bg:#0b0b0f;--card:#17171f;--card-2:#1f1f2a;--text:#f2f2f7;--muted:#9a9aa8;--border:#2a2a36;--accent:#8b7dff;--accent-2:#a99bff;--shadow:0 6px 28px rgba(0,0,0,.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); }
.err { color: var(--danger); font-size: 14px; margin: 8px 0 0; text-align: center; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
/* Safari/WebKit: an explicit display value overrides the [hidden] attribute,
   so force hidden elements to actually hide. */
[hidden] { display: none !important; }

/* ---- Gate ---- */
#gate { align-items: center; justify-content: center; padding: 24px; position: relative; }
.gate-card { width: 100%; max-width: 360px; text-align: center; }
.brand-mark { font-size: 44px; }
.brand h1 { margin: 6px 0 2px; font-size: 26px; letter-spacing: -.02em; }
#gate-form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

/* ---- Cards / inputs ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--accent); }
button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  padding: 13px 16px;
  background: var(--accent);
  color: #fff;
  transition: transform .05s, opacity .15s, background .15s;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.theme-toggle {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  width: 40px; height: 40px; padding: 0; font-size: 18px; border-radius: 50%;
}
#gate .theme-toggle { position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar-title { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions .ghost { padding: 9px 14px; font-size: 14px; }

.content { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 18px; }
.foot { text-align: center; font-size: 12px; padding: 12px 18px max(18px, env(safe-area-inset-bottom)); }

.field { display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 600; }
.field + .field { margin-top: 12px; }
.field span small { font-weight: 400; }
.mode-row .field { margin: 0; }
.adv { margin-top: 14px; }
.adv summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.adv[open] summary { margin-bottom: 12px; }

/* ---- Record ---- */
.record-card { text-align: center; }
.rec-btn {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--accent); display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(109,92,255,.4);
}
.rec-btn .rec-dot { width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: all .2s; }
.rec-btn.recording { background: var(--danger); box-shadow: 0 0 0 0 rgba(255,71,87,.5); animation: pulse 1.4s infinite; }
.rec-btn.recording .rec-dot { border-radius: 3px; width: 14px; height: 14px; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(255,71,87,.45)} 70%{box-shadow:0 0 0 18px rgba(255,71,87,0)} 100%{box-shadow:0 0 0 0 rgba(255,71,87,0)} }
.timer { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; margin: 14px 0 4px; }
.hint { font-size: 13px; }

/* ---- Upload ---- */
.upload { display: block; cursor: pointer; }
.upload-inner {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 22px; border: 2px dashed var(--border); border-radius: 14px;
  background: var(--card-2); transition: border-color .15s;
}
.upload-inner:hover { border-color: var(--accent); }
.upload-ic { font-size: 26px; }
#player { width: 100%; margin-top: 14px; }

/* ---- Result ---- */
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.result-head h2 { margin: 0; font-size: 18px; }
.result-meta { font-size: 12px; color: var(--muted); text-align: right; }
.transcript {
  background: var(--card-2); border-radius: 12px; padding: 16px;
  font-size: 16px; line-height: 1.6; white-space: pre-wrap; min-height: 40px;
}
.transcript .spk { display: block; margin-top: 14px; }
.transcript .spk:first-child { margin-top: 0; }
.transcript .spk-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.transcript .spk-head b { color: var(--accent); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.transcript .ts { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.transcript .spk-text { display: block; }
.result-actions { display: flex; gap: 10px; margin-top: 12px; }
.result-actions .ghost { flex: 1; padding: 11px; font-size: 14px; }

/* ---- Status / toast ---- */
.status {
  text-align: center; padding: 14px; border-radius: 12px; font-size: 14px;
  background: var(--card-2); border: 1px solid var(--border); margin-bottom: 16px;
}
.status.loading { color: var(--accent); }
.status.error { color: var(--danger); border-color: var(--danger); }
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 50; box-shadow: var(--shadow);
}

/* ---- Live / batch switch ---- */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 16px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 14px;
}
.seg-btn {
  flex: 1; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; padding: 10px 8px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, color .15s;
}
.seg-btn small { font-weight: 400; opacity: .75; }
.seg-btn.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---- Live streaming ---- */
.rec-btn.listening { background: var(--danger); box-shadow: 0 0 0 0 rgba(255,71,87,.5); animation: pulse 1.4s infinite; }
.rec-btn.listening .rec-dot { border-radius: 3px; width: 14px; height: 14px; }
.rec-btn.connecting { background: var(--muted); }

/* Uncommitted words: still being revised by the model. */
.transcript .partial .spk-text { color: var(--muted); font-style: italic; }
.transcript .spk.partial .spk-head b { opacity: .6; }
.transcript .caret {
  display: inline-block; width: 2px; height: 1em; margin-left: 2px;
  background: var(--accent); vertical-align: -2px; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.transcript .placeholder { color: var(--muted); font-style: italic; }

/* Live status line with a soft "connected" dot */
.status.live { color: var(--ok); border-color: var(--ok); }
.status .live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); margin-right: 8px; vertical-align: 0px;
  animation: blink 1.6s ease-in-out infinite;
}
