:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1f1e1b;
  --muted: #6d6a62;
  --border: #e2dfd6;
  --accent: #2f6fdf;
  --accent-soft: #e6eefc;
  --you: #c2410c;
  --you-soft: #fff1e8;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --mark: #fde68a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.04);
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171716;
    --surface: #212120;
    --surface-2: #2a2a28;
    --text: #ecebe6;
    --muted: #a3a097;
    --border: #3a3936;
    --accent: #6e9df2;
    --accent-soft: #1f2b44;
    --you: #fb923c;
    --you-soft: #3a2416;
    --danger-soft: #3b1d1d;
    --mark: #6b5a12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-rows: auto 1fr auto;
  font-size: 15px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary.danger { background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }
select, input[type='text'], input:not([type]), input[type='number'], textarea {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 10px;
}
textarea { width: 100%; resize: vertical; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.logo { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, var(--accent), var(--you)); }
.tag { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }
.controls { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }
.file-pick { position: relative; border: 1px dashed var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 48px; }
.status { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.status[data-state='listening']::before { background: var(--ok); animation: blink 1.4s infinite; }
.status[data-state='connecting']::before, .status[data-state='warning']::before { background: var(--warn); }
.status[data-state='error']::before { background: var(--danger); }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 390px; min-height: 0; }
.transcript-pane { position: relative; min-height: 0; display: flex; }
.transcript { flex: 1; overflow-y: auto; padding: 20px 28px 40px; }
.sidebar {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

/* ---------- transcript ---------- */
.empty { max-width: 560px; margin: 8vh auto; color: var(--muted); }
.empty h2 { color: var(--text); font-weight: 600; margin: 0 0 8px; }
.empty li { margin: 6px 0; }
.seg { display: grid; grid-template-columns: 56px minmax(0, 1fr); column-gap: 10px; padding: 3px 6px; border-radius: 6px; font-size: 16.5px; line-height: 1.6; }
.seg .ts { grid-row: span 2; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 4px; }
.seg .spk { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 8px; }
.seg .spk:empty { display: none; }
.seg .txt { grid-column: 2; }
.seg.interim .txt { color: var(--muted); }
.seg.asked { background: var(--accent-soft); }
.seg.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--mark); } 100% { background: transparent; } }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }
.jump-live { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); border: none; border-radius: 999px; background: var(--text); color: var(--bg); padding: 7px 14px; cursor: pointer; box-shadow: var(--shadow); }

/* ---------- sidebar ---------- */
.called {
  border: 2px solid var(--you);
  background: var(--you-soft);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.called strong { color: var(--you); font-size: 16px; }
.called span { font-size: 13px; }
.called.pulse { animation: pulse 0.9s ease 3; }
@keyframes pulse { 50% { transform: scale(1.025); box-shadow: 0 0 0 6px color-mix(in srgb, var(--you) 25%, transparent); } }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; font-weight: 600; }
.placeholder { color: var(--muted); font-size: 13px; margin: 0; list-style: none; }
.cards { display: flex; flex-direction: column; gap: 10px; }

.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); padding: 12px; box-shadow: var(--shadow); }
.card.to-you { border: 2px solid var(--you); background: var(--you-soft); }
.card-head { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.to-you .badge { color: var(--you); }
.catchup .badge { color: var(--ok); }
.meta { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.x { border: none; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
.question-text { font-weight: 600; margin: 6px 0 4px; font-size: 15.5px; }
.points { margin: 6px 0; padding-left: 20px; }
.points li { margin: 3px 0; }
.short, .recap { margin: 8px 0 0; font-size: 14px; }
.recap { color: var(--muted); }
.label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.conf { font-size: 12px; color: var(--muted); }
.conf-low { color: var(--warn); }
.card.old { padding: 8px 12px; box-shadow: none; cursor: pointer; opacity: 0.85; }
.card.old:not(.open) .card-body { display: none; }
.card.old .question-text { font-size: 14px; font-weight: 500; margin: 4px 0 0; }

.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.topic { position: relative; padding: 2px 0 10px 14px; }
.topic::before { content: ''; position: absolute; left: -6px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border); }
.topic.current::before { background: var(--accent); border-color: var(--accent); }
.topic-btn { display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left; border: none; background: none; padding: 0; cursor: pointer; }
.topic-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 40px; }
.topic-title { font-weight: 600; font-size: 14px; }
.topic-btn:hover .topic-title { color: var(--accent); }
.now { margin-left: auto; font-size: 10.5px; font-weight: 600; color: #fff; background: var(--accent); border-radius: 999px; padding: 0 7px; }
.gist { margin: 2px 0 0 48px; font-size: 13px; color: var(--muted); }

.spinner { width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- stats bar ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 7px 16px; border-top: 1px solid var(--border); background: var(--surface); font-size: 12.5px; color: var(--muted); }
.stats b { color: var(--text); font-weight: 600; margin-right: 3px; }
.stats b.err { color: var(--danger); }

/* ---------- settings dialog ---------- */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(680px, 94vw); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog form { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; max-height: 88vh; overflow-y: auto; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; font-weight: 500; }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 12px; }
.checks { display: flex; flex-direction: column; gap: 6px; }
details summary { cursor: pointer; font-size: 13.5px; font-weight: 500; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- full-screen overlays: notes, lectures ---------- */
.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; z-index: 20; }
.overlay-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }
.spacer { flex: 1; }
.lectures-wrap { overflow-y: auto; padding: 20px max(16px, calc((100vw - 820px) / 2)) 60px; }
.lectures { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lecture { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.lec-main { flex: 1; min-width: 0; }
.lec-title { font-weight: 600; }
.lec-meta { font-size: 13px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 600; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 0 7px; margin-left: 6px; vertical-align: middle; }
.danger-text { color: var(--danger) !important; border-color: var(--danger) !important; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; place-items: center; padding: 20px; }
.login-box { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.login-box input { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 9px 11px; font-size: 16px; }
.login-error { margin: 0; color: var(--danger); font-size: 14px; }
.dialog-actions .left { margin-right: auto; }
.notes { overflow-y: auto; padding: 28px max(24px, calc((100vw - 780px) / 2)) 60px; line-height: 1.65; }
.notes h1 { font-size: 28px; margin: 0 0 12px; }
.notes h2 { font-size: 19px; margin: 28px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.notes h3 { font-size: 16px; margin: 18px 0 6px; }
.notes ul, .notes ol { padding-left: 22px; }
.notes li { margin: 3px 0; }
.notes blockquote { margin: 10px 0; padding: 6px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.notes table { border-collapse: collapse; margin: 10px 0; }
.notes th, .notes td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.notes pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); margin-top: 10vh; justify-content: center; }
.error-box { border: 1px solid var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 14px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 52px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: 420px; }
.toast { background: var(--text); color: var(--bg); padding: 9px 13px; border-radius: 8px; font-size: 13.5px; box-shadow: var(--shadow); transition: opacity 0.5s, transform 0.5s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(6px); }

/* ---------- narrow screens (phone) ---------- */
@media (max-width: 900px) {
  html, body { height: auto; }
  body { min-height: 100%; grid-template-rows: auto auto auto; }
  .topbar { position: sticky; top: 0; z-index: 5; gap: 10px; }
  .layout { grid-template-columns: 1fr; min-height: auto; }
  .transcript-pane { border-top: 1px solid var(--border); }
  .transcript { height: 55vh; padding: 14px 12px 30px; }
  .sidebar { border-left: none; order: -1; overflow: visible; min-height: auto; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .seg { grid-template-columns: 44px minmax(0, 1fr); font-size: 15.5px; }
}
