:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1b1c1f;
  --muted: #6b6e76;
  --line: #e3e3de;
  --accent: #2f6fed;
  --rec: #e5484d;
  --star: #d99a00;
  --note-bg: #fff6d6;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #e9eaee;
    --muted: #8b909b;
    --line: #2a2e36;
    --accent: #6c9bff;
    --rec: #ff5c61;
    --star: #f5c04a;
    --note-bg: #2d2714;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #181b21; --text: #e9eaee; --muted: #8b909b; --line: #2a2e36;
  --accent: #6c9bff; --rec: #ff5c61; --star: #f5c04a; --note-bg: #2d2714; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang HK", "Noto Sans HK", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.view { display: flex; flex-direction: column; height: 100dvh; }
.view[hidden] { display: none; }
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.bar h1 { flex: 1; margin: 0; font-size: 20px; }
.scroll { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }

.icon-btn { background: none; border: 0; font-size: 24px; width: 40px; height: 40px; border-radius: 10px; }
.title-input {
  flex: 1; min-width: 0; border: 0; background: none; font-size: 17px; font-weight: 600;
  padding: 6px 4px; border-radius: 8px;
}
.title-input:focus { outline: 2px solid var(--accent); }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }

.primary, .secondary {
  border-radius: 12px; padding: 10px 16px; border: 1px solid transparent;
}
.primary { background: var(--accent); color: #fff; }
.secondary { background: var(--surface); border-color: var(--line); }
.big { width: 100%; padding: 16px; font-size: 18px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; }
.gap { gap: 8px; margin-top: 16px; }
.end { justify-content: flex-end; }

.list { list-style: none; padding: 0; margin: 16px 0 0; }
.list li {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px;
}
.list li .info { flex: 1; min-width: 0; }
.list li .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li .del { background: none; border: 0; color: var(--muted); font-size: 18px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }
.badge.done { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; background: none; border: 0; padding: 10px 0; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); vertical-align: middle; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .25; } }

.md { overflow-wrap: anywhere; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; margin-top: 1.2em; } .md h3 { font-size: 15px; }
.md ul { padding-left: 1.2em; } .md li { margin: 3px 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; }

.transcript { list-style: none; padding: 0; margin: 0; }
.transcript li { display: flex; gap: 10px; padding: 6px 0; }
.transcript .ts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 3px; min-width: 38px; }
.transcript li.mark { background: var(--note-bg); border-radius: 10px; padding: 6px 8px; }
.transcript li.mark .txt { color: var(--star); font-weight: 600; }
.transcript li.pending .txt { color: var(--muted); font-style: italic; }

.status-line { font-size: 12px; color: var(--muted); text-align: center; min-height: 18px; padding: 2px 16px; }
.controls {
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.ctrl {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center;
  font-size: 22px; width: 56px; padding: 4px 0; border-radius: 12px;
}
.ctrl small { font-size: 11px; color: var(--muted); }
.ctrl:disabled { opacity: .35; }
.rec-wrap { position: relative; width: 72px; height: 72px; }
.rec {
  position: relative; z-index: 1; width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid var(--rec); background: var(--surface); color: var(--rec); font-size: 30px;
  overflow: hidden;
}
.rec.on { background: var(--rec); color: #fff; }
.rec .level { position: absolute; inset: 0; border-radius: 50%; background: #fff; opacity: 0; transform: scale(.4); transition: transform 80ms, opacity 80ms; }
.rec span#recIcon { position: relative; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(92vw, 420px); padding: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
dialog textarea, dialog input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg);
}

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 110px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 99px; font-size: 14px;
  max-width: calc(100vw - 32px);
}
.advanced { margin-top: 14px; }
.advanced summary { color: var(--muted); font-size: 14px; cursor: pointer; margin-bottom: 8px; }
.dlg-title { margin: 0 0 8px; font-size: 18px; }
.dlg-section { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.dlg-section h3 { margin: 0 0 10px; font-size: 15px; }
#providerFields label, #aiForm > label { margin-top: 10px; }
dialog select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); color: var(--text);
}
.key-link { display: inline-block; margin-top: 8px; color: var(--accent); }
.ok { color: #2e9e5b; } .err { color: var(--rec); }
.wrap { flex-wrap: wrap; }
dialog { max-height: 90dvh; overflow-y: auto; }
.token-row { justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0 0; min-height: 20px; }
.link-btn { background: none; border: 0; color: var(--accent); padding: 0; }

/* Voice activity: scrolling level bars above the controls */
.voice-viz {
  display: flex; align-items: center; justify-content: center; gap: 3px;
  height: 0; overflow: hidden; padding: 0 16px; transition: height 200ms ease;
}
.voice-viz.active { height: 34px; }
.voice-viz i {
  display: block; width: 4px; height: 28px; border-radius: 2px;
  background: var(--muted); opacity: .45; transform: scaleY(.08); transform-origin: center;
  transition: transform 70ms linear, background-color 200ms, opacity 200ms;
}
.voice-viz.speaking i { background: var(--accent); opacity: 1; }

/* Ripples around the record button while speech is detected */
.ripple {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--rec);
  opacity: 0; pointer-events: none;
}
.rec-wrap.speaking .ripple { animation: ripple 1.4s ease-out infinite; }
.rec-wrap.speaking .ripple.r2 { animation-delay: .7s; }
@keyframes ripple {
  from { transform: scale(1); opacity: .55; }
  to { transform: scale(1.7); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .rec-wrap.speaking .ripple { animation: none; opacity: .5; transform: scale(1.15); }
  .voice-viz i { transition: none; }
}
.version {
  text-align: center; font-size: 11px; color: var(--muted); opacity: .7;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 8px);
}
.upload-btn { margin-top: 10px; font-size: 16px; padding: 12px; font-weight: 500; }
.transcript li.seg { cursor: pointer; border-radius: 10px; padding: 6px 8px; margin: 0 -8px; }
.transcript li.seg:active { background: var(--line); }
.transcript li.seg.playing { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.transcript li.seg.playing .ts::before { content: "▶ "; color: var(--accent); }
.badge.processing { background: color-mix(in srgb, var(--star) 22%, transparent); color: var(--star); }
.badge.error { background: color-mix(in srgb, var(--rec) 18%, transparent); color: var(--rec); }
