:root {
  --bg: #f6f7f9; --panel: #fff; --fg: #1d2127; --muted: #6b7280; --line: #e3e6ea; --accent: #2563eb;
  --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --panel: #1a1e24; --fg: #e5e7eb; --muted: #9ca3af; --line: #2b313a; --accent: #60a5fa;
          --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--fg); }
header { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 2px; }
h3 { font-size: 14px; margin: 22px 0 8px; }
nav button { background: none; border: 0; padding: 6px 10px; color: var(--muted); font: inherit; cursor: pointer; border-radius: 6px; }
nav button.active { color: var(--fg); background: var(--bg); font-weight: 600; }
#auth { margin-left: auto; font-size: 12px; cursor: pointer; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); }
#auth.bad { color: var(--bad); border-color: var(--bad); }
main { padding: 0; }
.tab { display: none; }
.tab.active { display: flex; }
#tab-people.active, #tab-training.active { display: block; padding: 20px; max-width: 1100px; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: normal; }
.mono { font-family: ui-monospace, monospace; }
.grow { flex: 1; }
button, select, input, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; }
button { cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

#library { width: 340px; flex: none; height: calc(100vh - 53px); overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
.filters { display: flex; gap: 6px; padding: 10px; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.filters input { flex: 1; min-width: 0; }
#rec-list { list-style: none; margin: 0; padding: 0; }
#rec-list li { padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
#rec-list li:hover { background: var(--bg); }
#rec-list li.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); }
#rec-list .l1 { display: flex; gap: 6px; align-items: baseline; }
#rec-list .l2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 9px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.tag.lab { color: var(--ok); border-color: var(--ok); }
.tag.test { color: var(--warn); border-color: var(--warn); }

#player { flex: 1; min-width: 0; padding: 18px 24px; height: calc(100vh - 53px); overflow: auto; }
.empty { color: var(--muted); padding: 60px; text-align: center; }
.rec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.now { margin: 14px 0; padding: 14px 18px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.now-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.now-name { font-size: 28px; font-weight: 650; min-height: 40px; }
.now-name.unknown { color: var(--muted); }
#waveform { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
#lanes { position: relative; margin-top: 4px; }
.lane { position: relative; height: 18px; margin-bottom: 3px; background: var(--panel); border-radius: 4px; }
.lane span.seg { position: absolute; top: 2px; bottom: 2px; border-radius: 3px; cursor: pointer; }
.lane .lane-name { position: absolute; left: 4px; top: 0; font-size: 11px; line-height: 18px; z-index: 1; pointer-events: none; text-shadow: 0 0 3px var(--panel); }
.lane .cursor { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--fg); }
.transport { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.job { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.job .bar { width: 220px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.job .bar div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

table.grid { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table.grid th, table.grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.score.ok { color: var(--ok); } .score.low { color: var(--muted); } .score.bad { color: var(--bad); }
.labels { display: flex; flex-wrap: wrap; gap: 6px; }
.labels .chip { font-size: 12px; padding: 3px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }

.train-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.version { margin-top: 16px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.version h4 { margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; font-size: 13px; }
.confusion td.diag { font-weight: 700; color: var(--ok); }
.confusion td.off { color: var(--bad); }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--fg); width: min(480px, 92vw); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog input, dialog textarea { width: 100%; }
#picker-results { list-style: none; padding: 0; margin: 8px 0; max-height: 300px; overflow: auto; }
#picker-results li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; }
#picker-results li:hover, #picker-results li.hint { background: var(--bg); }
.picker-special { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

#sx-library { width: 300px; flex: none; height: calc(100vh - 53px); overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
#sx-list { list-style: none; margin: 0; padding: 0; }
#sx-list li { padding: 7px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 6px; align-items: baseline; }
#sx-list li:hover { background: var(--bg); }
#sx-list li.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); }
#sx-body { flex: 1; min-width: 0; padding: 18px 24px; height: calc(100vh - 53px); overflow: auto; }
#sx-wave { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-top: 14px; }
.sx-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.sx-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.sx-card .big { font-size: 26px; font-weight: 650; }
.sx-card table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.sx-card td, .sx-card th { padding: 2px 6px; text-align: left; border-bottom: 1px solid var(--line); }
.sx-words { line-height: 2.1; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.sx-words .w { cursor: pointer; padding: 1px 2px; border-radius: 3px; border-bottom: 3px solid transparent; }
.sx-words .w.now { outline: 2px solid var(--accent); }
.sx-words .turn { display: block; margin-top: 6px; }
.sx-words .who { font-size: 11px; color: var(--muted); margin-right: 6px; }
.w.s-bad { background: color-mix(in srgb, var(--bad) 22%, transparent); }
.w.p-bad { border-bottom-color: var(--warn); }
.w.dim { opacity: .35; }
.legend { font-size: 12px; color: var(--muted); margin: 6px 0; }
.legend .w { padding: 0 4px; }
.lanes .lane { margin-bottom: 3px; }

.login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 10; }
.login-card { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; display: grid; gap: 10px; }
.login-card > div { display: grid; gap: 8px; }
.login-card input, .login-card select { width: 100%; }
.err { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 13px; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; }
[hidden] { display: none !important; }
