:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --line: #e2ddd2;
  --text: #1c1d1f;
  --muted: #6b6a66;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --accent-soft: #fde8db;
  --ok: #2b8a3e;
  --ok-soft: #e3f4e6;
  --warn: #b7791f;
  --warn-soft: #fdf1d8;
  --bad: #c92a2a;
  --bad-soft: #fde4e4;
  --kz: #1c7ed6;
  --kz-soft: #e1effc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 25, 15, .05), 0 4px 16px rgba(30, 25, 15, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b; --surface: #1f2226; --surface-2: #272b30; --line: #33383e;
    --text: #ecebe8; --muted: #9a9a96; --accent: #ff7a2e; --accent-ink: #1a1007; --accent-soft: #3a2416;
    --ok: #51cf66; --ok-soft: #1b3322; --warn: #f2b84b; --warn-soft: #3a2f17; --bad: #ff6b6b; --bad-soft: #3d1e1e;
    --kz: #5aa9f0; --kz-soft: #182c40; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181b; --surface: #1f2226; --surface-2: #272b30; --line: #33383e;
  --text: #ecebe8; --muted: #9a9a96; --accent: #ff7a2e; --accent-ink: #1a1007; --accent-soft: #3a2416;
  --ok: #51cf66; --ok-soft: #1b3322; --warn: #f2b84b; --warn-soft: #3a2f17; --bad: #ff6b6b; --bad-soft: #3d1e1e;
  --kz: #5aa9f0; --kz-soft: #182c40; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  max-width: 1120px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px; background: var(--accent); flex: none;
  display: grid; place-items: center;
}
.brand-mark svg { width: 24px; height: 24px; fill: #fff; stroke: #fff; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { font-size: 13px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-muted { background: var(--surface-2); color: var(--muted); }
.pill-muted::before { display: none; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }

/* Tabs */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  max-width: 1120px; margin: 0 auto; padding: 0 16px 10px;
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 15px; white-space: nowrap;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.count { font-size: 12px; color: var(--accent); }

main { max-width: 1120px; margin: 0 auto; padding: 0 16px 32px; }
.tab { display: none; }
.tab.active { display: block; }

.grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .grid { grid-template-columns: 1.05fr 1fr; align-items: start; } }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.col .card { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Segmented */
.seg { display: flex; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; cursor: pointer;
  font-weight: 600; color: var(--muted); font-size: 15px;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button:disabled { opacity: .5; cursor: not-allowed; }

/* Mic */
.mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 26px 0 12px; }
.mic {
  position: relative; width: 112px; height: 112px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); display: grid; place-items: center; touch-action: manipulation;
  box-shadow: 0 8px 24px rgba(232, 89, 12, .3); transition: transform .12s ease;
}
.mic:active { transform: scale(.96); }
.mic svg { width: 46px; height: 46px; fill: var(--accent-ink); stroke: var(--accent-ink); position: relative; z-index: 1; }
.mic .ico-stop { display: none; }
.mic.rec { background: var(--bad); box-shadow: 0 8px 24px rgba(201, 42, 42, .3); }
.mic.rec .ico-mic { display: none; }
.mic.rec .ico-stop { display: block; fill: #fff; }
.mic.busy { opacity: .6; pointer-events: none; }
.mic-ring {
  position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--bad); opacity: 0;
  transform: scale(1); transition: transform .08s linear, opacity .2s;
}
.mic.rec .mic-ring { opacity: .45; }
.mic-meta { text-align: center; }
.mic-state { font-weight: 600; }
.mic-timer { font-family: var(--mono); color: var(--muted); font-size: 14px; }

.file-drop {
  width: 100%; border: 2px dashed var(--line); border-radius: var(--radius); padding: 24px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s;
}
.file-drop:hover, .file-drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.file-drop input { display: none; }
.file-drop svg { width: 34px; height: 34px; stroke: var(--accent); }
.file-drop span { font-weight: 600; }
.file-drop small { color: var(--muted); }

.opts { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; font-size: 14px; color: var(--muted); }
.check { display: inline-flex; gap: 7px; align-items: center; cursor: pointer; }
.check input { accent-color: var(--accent); width: 17px; height: 17px; }

/* Transcript */
.transcript {
  min-height: 110px; padding: 12px 14px; background: var(--surface-2); border-radius: 10px;
  font-size: 17px; line-height: 1.7; overflow-wrap: anywhere;
}
.transcript.empty { color: var(--muted); font-size: 15px; line-height: 1.5; }
.transcript .seg-line { display: block; }
.transcript .seg-line + .seg-line { margin-top: 4px; }
.transcript .seg-line.fresh { animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.w { border-radius: 4px; padding: 0 1px; }
.w.kz { color: var(--kz); }
.w.low { text-decoration: underline wavy var(--warn); text-underline-offset: 4px; text-decoration-thickness: 1.5px; }
.w.term { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.transcript .pending { color: var(--muted); font-style: italic; }
.transcript-edit {
  width: 100%; min-height: 110px; padding: 12px 14px; border-radius: 10px; border: 1.5px solid var(--accent);
  background: var(--surface); font-size: 17px; resize: vertical;
}

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.metric span { display: block; font-size: 12px; color: var(--muted); }
.metric b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric b.good { color: var(--ok); } .metric b.bad { color: var(--bad); }
@media (max-width: 420px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
.lg-kz { background: var(--kz); }
.lg-low { border-bottom: 2px dotted var(--warn); height: 6px; border-radius: 0; }
.lg-term { background: var(--accent-soft); outline: 1px solid var(--accent); }

/* Buttons */
.btn-primary {
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer;
  padding: 11px 18px; border-radius: 11px; min-height: 44px;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
  padding: 7px 12px; border-radius: 9px; color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-link { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 13px; font-weight: 600; padding: 0; margin-left: 6px; }

/* Form */
.field { display: block; margin-bottom: 12px; }
.field-label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea, .boost-add input, .boost-add select, dialog input {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; min-height: 46px; font-size: 16px; outline: none; transition: border-color .15s, background .3s;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .boost-add input:focus { border-color: var(--accent); }
.field .filled { background: var(--accent-soft); }
.src { font-style: normal; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; }
.src:empty { display: none; }
.src.auto { background: var(--accent-soft); color: var(--accent); }
.src.explicit { background: var(--ok-soft); color: var(--ok); }
.alts { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.alts button { border: 1px dashed var(--line); background: transparent; border-radius: 8px; padding: 3px 9px; font-size: 13px; cursor: pointer; color: var(--muted); }
.alts button:hover { border-color: var(--accent); color: var(--accent); }
.terms { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.terms .t { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.hint { font-size: 13.5px; color: var(--muted); margin: 12px 0 0; }
.card > .hint:first-of-type { margin-top: 0; margin-bottom: 12px; }

/* Log */
.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.log-item .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.log-item .type { font-weight: 700; }
.log-item .time { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.log-item dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0 0; font-size: 14.5px; }
.log-item dt { color: var(--muted); }
.log-item dd { margin: 0; overflow-wrap: anywhere; }
.log-item .del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 0 0; }
.log-item .del:hover { color: var(--bad); }
.empty-note { color: var(--muted); text-align: center; padding: 28px 8px; }

/* Dict */
.boost-add { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-bottom: 12px; }
@media (max-width: 520px) { .boost-add { grid-template-columns: 1fr auto; } .boost-add .btn-primary { grid-column: 1 / -1; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 6px 4px 11px; font-size: 14px; background: var(--surface);
}
.chip b { font-size: 11.5px; color: var(--accent); }
.chip button { border: 0; background: var(--surface-2); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; line-height: 1; color: var(--muted); }
.chip button:hover { background: var(--bad-soft); color: var(--bad); }
.dict { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.dict-cat { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.dict-cat h3 { font-size: 14.5px; margin: 0; }
.dict-cat .kz { font-size: 12.5px; color: var(--kz); margin-bottom: 8px; }
.dict-cat .chips button {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 13px; cursor: pointer;
}
.dict-cat .chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* WER */
.wer-out { margin-top: 16px; }
.wer-score { display: flex; align-items: baseline; gap: 12px; }
.wer-score b { font-size: 40px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.wer-align { margin-top: 12px; line-height: 2; font-size: 15.5px; }
.wer-align span { padding: 1px 4px; border-radius: 4px; }
.wer-align .sub { background: var(--warn-soft); }
.wer-align .sub s { color: var(--muted); margin-right: 4px; }
.wer-align .del { background: var(--bad-soft); text-decoration: line-through; }
.wer-align .ins { background: var(--kz-soft); }

/* Docs */
.doc h3 { font-size: 14.5px; margin: 20px 0 8px; }
.doc p { margin: 6px 0; color: var(--muted); }
pre { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.55; margin: 0; }
code { font-family: var(--mono); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14.5px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #fff; }

dialog { border: 0; border-radius: var(--radius); padding: 20px; background: var(--surface); color: var(--text); width: min(360px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog input { margin: 14px 0; }
