:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f0ece2;
  --ink: #1d2422;
  --ink-2: #4a5451;
  --muted: #7a827f;
  --line: #e2ddd1;
  --accent: #1f5f5b;
  --accent-ink: #f6f1e7;
  --accent-soft: #dcebe7;
  --warm: #c2702a;
  --warm-soft: #f6e6d5;
  --danger: #b23a3a;
  --danger-soft: #f7e0de;
  --ok: #2f7a4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 36, 34, .05), 0 6px 24px rgba(29, 36, 34, .05);
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Noto Sans Mono CJK SC", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615; --surface: #1a201e; --surface-2: #222a28; --ink: #e9ece8; --ink-2: #bfc6c2;
    --muted: #8b9490; --line: #2d3532; --accent: #6fb5a9; --accent-ink: #0f1514; --accent-soft: #1f3431;
    --warm: #e2a265; --warm-soft: #3a2c1f; --danger: #ec8b84; --danger-soft: #3b2322; --ok: #7fcf9d;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --surface: #1a201e; --surface-2: #222a28; --ink: #e9ece8; --ink-2: #bfc6c2;
  --muted: #8b9490; --line: #2d3532; --accent: #6fb5a9; --accent-ink: #0f1514; --accent-soft: #1f3431;
  --warm: #e2a265; --warm-soft: #3a2c1f; --danger: #ec8b84; --danger-soft: #3b2322; --ok: #7fcf9d;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 15px; line-height: 1.6; min-height: 100vh;
}
[hidden] { display: none !important; }
h2, h3 { margin: 0; font-weight: 650; letter-spacing: .01em; }
h2 { font-size: 17px; display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
h3 { font-size: 15px; margin-bottom: 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { font-size: 12px; color: var(--muted); letter-spacing: .04em; margin-bottom: 4px; }
audio { width: 100%; height: 40px; }

/* brand & top bar */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-lg { font-size: 22px; margin-bottom: 8px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none; background: var(--accent) no-repeat center / 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 18v-4M11 22V10M15 25V7M19 20v-8M23 23V9M27 17v-2' stroke='%23f6f1e7' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 12px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.page { max-width: 820px; margin: 0 auto; padding: 20px 16px 24px; display: grid; gap: 16px; }
.foot { text-align: center; padding: 8px 16px 32px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); scroll-margin-top: 72px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.step {
  width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px;
  background: var(--accent); color: var(--accent-ink); font-variant-numeric: tabular-nums;
}
.empty { padding: 16px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); text-align: center; }
.note { background: var(--warm-soft); color: var(--ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; }

/* forms */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--ink-2); }
input[type="text"], input:not([type]), input[inputmode], select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, .dropzone:focus-within {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 14px; }
.form-error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* buttons */
.btn {
  font: inherit; font-size: 14px; font-weight: 600; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); padding: 9px 16px; min-height: 40px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-lg { min-height: 48px; padding: 12px 28px; font-size: 16px; }
.btn-block { width: 100%; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login-card p { margin: 0 0 18px; font-size: 14px; }
#invite-code { letter-spacing: .12em; font-family: var(--mono); text-transform: uppercase; }

/* reference list */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ref-tip { margin: -6px 0 12px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.kbd-play { display: inline-block; width: 0; height: 0; border-style: solid; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent var(--accent); margin: 0 2px; }
.ref-filter { display: block; margin-bottom: 10px; }
.ref-filter input { font: inherit; width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.ref-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ref-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s;
}
.ref-item:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.ref-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ref-item[aria-checked="true"] {
  border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
  box-shadow: inset 3px 0 0 var(--accent);
}
.ref-main { min-width: 0; }
.ref-title { display: flex; align-items: baseline; gap: 8px; font-weight: 650; }
.ref-title .muted { font-weight: 400; font-size: 13px; font-variant-numeric: tabular-nums; }
.ref-text { margin: 4px 0 0; font-size: 15px; line-height: 1.6; color: var(--ink-2); overflow-wrap: anywhere; }
.ref-text.none { color: var(--muted); font-size: 13px; }
.ref-side { align-self: center; }
.ref-check { white-space: nowrap; display: none; }
.ref-item[aria-checked="true"] .ref-check { display: inline-flex; }
.ref-item[aria-checked="true"] .ref-pick { display: none; }
.ref-pick { font-size: 12px; color: var(--muted); white-space: nowrap; }
.progress-line { height: 3px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 8px; opacity: 0; transition: opacity .2s; }
.progress-line.on { opacity: 1; }
.progress-line span { display: block; height: 100%; width: 0; background: var(--accent); }

/* round play button (shared by list and target panel) */
.play-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--accent); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; flex: none; color: var(--accent); padding: 0;
}
.play-btn:hover { background: var(--accent-soft); }
.play-btn.playing { background: var(--accent); color: var(--accent-ink); }
.play-lg { width: 48px; height: 48px; }
.icon-play { width: 0; height: 0; border-style: solid; border-width: 7px 0 7px 11px; border-color: transparent transparent transparent currentColor; margin-left: 3px; }
.playing .icon-play { width: 11px; height: 13px; border: 0; margin: 0; border-left: 4px solid currentColor; border-right: 4px solid currentColor; }

/* imitation target */
.target { display: flex; gap: 14px; align-items: flex-start; padding: 14px; border-radius: 12px; background: var(--surface-2); margin-bottom: 14px; }
.target-body { flex: 1; min-width: 0; }
.target-label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.target-text { margin: 6px 0 0; font-size: 18px; line-height: 1.6; color: var(--ink); overflow-wrap: anywhere; }
#target-none { margin-bottom: 14px; }
.admin-box { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.admin-box summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-2); padding: 4px 0; }
.admin-box form { margin-top: 12px; }
.pending-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.pending-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }

/* segmented */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.segmented button {
  font: inherit; font-size: 14px; border: 0; background: transparent; color: var(--ink-2);
  padding: 7px 16px; border-radius: 8px; cursor: pointer; min-height: 36px;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* upload */
.dropzone {
  position: relative; display: grid; place-items: center; gap: 2px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 28px 16px; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dz-title { font-weight: 600; }
.dz-sub { font-size: 13px; color: var(--muted); }
.progress { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.asset-chip { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; margin-top: 14px; padding: 12px; border-radius: 12px; border: 1px solid var(--accent-soft); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.asset-chip audio { grid-column: 1 / -1; }
.asset-chip .btn { grid-row: 1; grid-column: 2; }
.asset-meta { display: grid; min-width: 0; }
.asset-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* recorder */
.recorder { display: flex; align-items: center; gap: 16px; padding: 8px 0; }
.rec-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.rec-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--danger); transition: border-radius .2s, width .2s, height .2s; }
.rec-btn.recording { border-color: var(--danger); animation: pulse 1.4s ease-in-out infinite; }
.rec-btn.recording .rec-dot { width: 22px; height: 22px; border-radius: 5px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--danger) 18%, transparent); } }
@media (prefers-reduced-motion: reduce) { .rec-btn.recording { animation: none; } }
.rec-info { flex: 1; min-width: 0; }
.rec-time { font-family: var(--mono); font-size: 22px; font-variant-numeric: tabular-nums; display: flex; gap: 6px; align-items: baseline; }
.rec-time .muted { font-size: 14px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 6px 0 4px; }
.meter span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .08s linear; }
.rec-preview { display: grid; gap: 10px; margin-top: 8px; }

/* job status */
.job-status { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.status-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.chip { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.chip.running, .chip.queued, .chip.pending_enqueue { background: var(--accent-soft); color: var(--accent); }
.chip.succeeded { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); color: var(--ok); }
.chip.failed, .chip.timed_out { background: var(--danger-soft); color: var(--danger); }
.stages { list-style: none; display: flex; gap: 0; padding: 0; margin: 0 0 12px; counter-reset: s; }
.stages li {
  flex: 1; position: relative; font-size: 13px; color: var(--muted); padding-top: 18px; text-align: center;
}
.stages li::before {
  content: ""; position: absolute; top: 4px; left: 50%; width: 10px; height: 10px; margin-left: -5px;
  border-radius: 50%; background: var(--line); z-index: 1;
}
.stages li::after { content: ""; position: absolute; top: 8px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.stages li:first-child::after { display: none; }
.stages li.done { color: var(--ink-2); }
.stages li.done::before, .stages li.done::after, .stages li.active::after { background: var(--accent); }
.stages li.active { color: var(--accent); font-weight: 600; }
.stages li.active::before { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.timers { display: flex; gap: 18px; font-size: 14px; color: var(--ink-2); margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.error-box { background: var(--danger-soft); color: var(--ink); border-radius: 10px; padding: 12px; font-size: 14px; }
.error-box pre { white-space: pre-wrap; font-size: 12px; max-height: 240px; overflow: auto; margin: 8px 0 0; }

/* result */
.result-top { display: grid; grid-template-columns: 168px 1fr; gap: 24px; align-items: center; }
.score-ring { position: relative; width: 168px; height: 168px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .8s ease; }
.score-num { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.score-num strong { font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.score-num span { font-size: 12px; color: var(--muted); margin-top: 4px; }
.parts { display: grid; gap: 12px; }
.part-row { display: grid; grid-template-columns: 72px 1fr 64px; gap: 10px; align-items: center; font-size: 14px; }
.part-bar { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.part-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 8px; transition: width .6s ease; }
.part-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.part-val.na { color: var(--muted); font-weight: 400; font-size: 13px; }
.grade { margin: 14px 0 0; font-size: 14px; color: var(--ink-2); }
.grade strong { color: var(--accent); font-size: 16px; }
.warning { background: var(--warm-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.advice { margin-top: 18px; }
.advice ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.metrics { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 16px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.metrics strong { color: var(--ink-2); font-weight: 600; }
.playback { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.charts { display: grid; gap: 12px; margin-bottom: 16px; }
.charts figure { margin: 0; background: #fff; border-radius: 10px; border: 1px solid var(--line); overflow: hidden; }
.charts img { display: block; width: 100%; height: auto; }
.charts figcaption { font-size: 12px; color: #6b7370; padding: 6px 10px; background: #fafaf7; }
.report {
  margin: 14px 0 0; padding: 14px; background: var(--surface-2); border-radius: 10px; font-family: var(--mono);
  font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; max-height: 560px; overflow: auto;
}

/* history */
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history li { margin: 0; }
.history button {
  width: 100%; font: inherit; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; cursor: pointer; color: var(--ink);
}
.history button:hover, .history button.current { border-color: var(--accent); }
.h-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-score { grid-row: span 2; align-self: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.h-sub { font-size: 12px; color: var(--muted); }

/* invites (admin) */
.step-admin { background: var(--warm); font-size: 12px; }
.invite-form { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.invite-form .field { margin: 0; flex: 1 1 240px; }
.invite-form .check { margin: 0; min-height: 44px; }
.invite-form .btn { min-height: 44px; }
.invite-result { margin-top: 14px; padding: 14px; border-radius: 12px; border: 1px solid var(--warm); background: var(--warm-soft); display: grid; gap: 10px; }
.invite-result p { margin: 0; }
.invite-code { font-family: var(--mono); font-size: 26px; font-weight: 700; letter-spacing: .12em; user-select: all; overflow-wrap: anywhere; }
.user-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.user-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.user-row.off { opacity: .6; }
.user-name { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.user-sub { font-size: 12px; color: var(--muted); }
.user-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-warn { background: var(--danger-soft); color: var(--danger); }

/* transcription provider (admin) */
.asr-tip { margin: 0 0 12px; }
.asr-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.asr-option {
  font: inherit; color: var(--ink); text-align: left; cursor: pointer; display: grid; gap: 4px;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); min-height: 64px;
}
.asr-option:hover:not(:disabled) { border-color: var(--accent); }
.asr-option[aria-checked="true"] { border: 2px solid var(--accent); padding: 11px 13px; background: var(--accent-soft); cursor: default; }
.asr-option:disabled { cursor: not-allowed; opacity: .65; }
.asr-name { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.asr-state { font-size: 12px; color: var(--muted); }
.asr-state.ok { color: var(--ok); }
.asr-state.bad { color: var(--danger); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 600px) {
  .card { padding: 16px; }
  .result-top { grid-template-columns: 1fr; justify-items: center; }
  .parts { width: 100%; }
  .playback { grid-template-columns: 1fr; }
  .part-row { grid-template-columns: 64px 1fr 56px; }
  .btn-lg { width: 100%; }
  .ref-item { grid-template-columns: auto 1fr; }
  .ref-side { grid-column: 2; align-self: start; }
  .ref-item:not([aria-checked="true"]) .ref-side { display: none; }
  .target-text { font-size: 17px; }
  .who #user-name { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
