:root {
  color-scheme: light dark;
  --page: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --text-primary: #14140f;
  --text-secondary: #4d4c46;
  --text-muted: #86847c;
  --border: rgba(20, 20, 15, 0.09);
  --accent: #2a6df5;
  --accent-wash: #e4edfe;
  --good: #1a9c4c;
  --good-wash: #e3f6ea;
  --warn: #b7791e;
  --warn-wash: #fdf1dc;
  --bad: #d13b30;
  --bad-wash: #fce8e6;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 8px 24px -12px rgba(20, 20, 15, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    --page: #101012;
    --surface: #18181b;
    --surface-2: #1f1f23;
    --text-primary: #f4f4f2;
    --text-secondary: #b8b7b1;
    --text-muted: #817f78;
    --border: rgba(255, 255, 255, 0.09);
    --accent: #5b93ff;
    --accent-wash: #1c2b4d;
    --good: #38c777;
    --good-wash: #103a22;
    --warn: #e0a539;
    --warn-wash: #3d2d0c;
    --bad: #ec5c50;
    --bad-wash: #3f1714;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  --page: #101012;
  --surface: #18181b;
  --surface-2: #1f1f23;
  --text-primary: #f4f4f2;
  --text-secondary: #b8b7b1;
  --text-muted: #817f78;
  --border: rgba(255, 255, 255, 0.09);
  --accent: #5b93ff;
  --accent-wash: #1c2b4d;
  --good: #38c777;
  --good-wash: #103a22;
  --warn: #e0a539;
  --warn-wash: #3d2d0c;
  --bad: #ec5c50;
  --bad-wash: #3f1714;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  margin: 0;
  line-height: 1.5;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.brand .mark {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.brand .mark .dot { color: var(--accent); }
.brand .file {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.topbar nav a:hover { color: var(--accent); }

/* ---------- layout primitives ---------- */
.stack { display: flex; flex-direction: column; gap: 1rem; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem 1.4rem;
  margin-bottom: 1rem;
}
.card:last-child { margin-bottom: 0; }
.card > h2 {
  margin: 0 0 0.9rem;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: space-between;
}
.card > h2 .hint { text-transform: none; letter-spacing: normal; font-weight: 400; font-size: 0.78rem; }

/* ---------- hero: pulse score ---------- */
.hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.75rem;
  align-items: center;
}
@media (max-width: 560px) {
  .hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}

.gauge { position: relative; width: 132px; height: 132px; flex: 0 0 auto; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge circle { fill: none; stroke-width: 11; }
.gauge .track { stroke: var(--surface-2); }
.gauge .value-ring { stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.gauge .value-ring.good { stroke: var(--good); }
.gauge .value-ring.warn { stroke: var(--warn); }
.gauge .value-ring.bad { stroke: var(--bad); }
.gauge .readout {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gauge .readout .num { font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.gauge .readout .lbl { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-top: 0.2rem; }

.sub-score-bars { display: flex; flex-direction: column; gap: 0.55rem; width: 100%; }
.sub-score-bar { display: grid; grid-template-columns: 5.5rem 1fr 2.4rem; align-items: center; gap: 0.6rem; }
.sub-score-bar .lbl { font-size: 0.78rem; color: var(--text-secondary); font-weight: 600; }
.sub-score-bar .track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.sub-score-bar .fill { height: 100%; border-radius: 999px; }
.sub-score-bar .fill.good { background: var(--good); }
.sub-score-bar .fill.warn { background: var(--warn); }
.sub-score-bar .fill.bad { background: var(--bad); }
.sub-score-bar .val { font-size: 0.8rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

.score-note { font-size: 0.82rem; color: var(--text-secondary); margin: 1.1rem 0 0; padding-top: 0.9rem; border-top: 1px solid var(--border); }
.score-note dt { font-weight: 700; color: var(--text-primary); display: inline; }
.score-note dd { display: inline; margin: 0; }
.score-note .row + .row { margin-top: 0.35rem; }

/* ---------- video + timeline ---------- */
video { width: 100%; border-radius: 10px; background: #000; display: block; }
#timeline { width: 100%; height: 56px; cursor: pointer; border-radius: 6px; margin-top: 0.6rem; }
.timeline-legend { display: flex; gap: 1rem; font-size: 0.74rem; color: var(--text-muted); margin-top: 0.5rem; }
.timeline-legend .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 0.35rem; }

/* ---------- findings ---------- */
.finding {
  border-left: 3px solid var(--warn);
  padding: 0.6rem 0.9rem;
  border-radius: 0 8px 8px 0;
  background: var(--surface-2);
  cursor: pointer;
  transition: background 0.12s ease;
}
.finding:hover { background: var(--accent-wash); }
.finding + .finding { margin-top: 0.55rem; }
.finding .ts { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 0.76rem; font-weight: 600; }
.finding .diagnosis { font-weight: 600; margin: 0.2rem 0; font-size: 0.92rem; }
.finding .fix { color: var(--text-secondary); font-size: 0.87rem; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--accent-wash);
  color: var(--accent);
  margin: 0 0.35rem 0.35rem 0;
}
.pill.status-good { background: var(--good-wash); color: var(--good); }
.pill.status-warn { background: var(--warn-wash); color: var(--warn); }
.pill.status-bad { background: var(--bad-wash); color: var(--bad); }

.beats { list-style: none; margin: 0; padding: 0; }
.beats li {
  display: flex; gap: 0.75rem; align-items: baseline;
  padding: 0.4rem 0; border-bottom: 1px solid var(--border);
}
.beats li:last-child { border-bottom: none; }
.beats a { color: var(--accent); text-decoration: none; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.82rem; flex: 0 0 auto; }
.beats a:hover { text-decoration: underline; }

.tech-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.tech-list li { font-size: 0.85rem; color: var(--text-secondary); }
.tech-list strong { color: var(--text-primary); }

details.transcript summary {
  cursor: pointer; font-weight: 600; font-size: 0.85rem; color: var(--accent);
  list-style: none;
}
details.transcript summary::-webkit-details-marker { display: none; }
details.transcript summary::before { content: "▸ "; }
details.transcript[open] summary::before { content: "▾ "; }
details.transcript p { white-space: pre-wrap; font-size: 0.88rem; color: var(--text-secondary); margin-top: 0.8rem; max-height: 360px; overflow-y: auto; }

/* ---------- upload form ---------- */
.upload-form { display: flex; flex-direction: column; gap: 1.1rem; max-width: 480px; width: 100%; }
.upload-form label { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); display: flex; flex-direction: column; gap: 0.4rem; }
.upload-form input[type="file"], .upload-form input[type="text"] {
  padding: 0.65rem 0.75rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); font: inherit;
  width: 100%; box-sizing: border-box;
}
.upload-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.or-divider { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); font-size: 0.78rem; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.upload-form button {
  padding: 0.75rem; border-radius: 8px; border: none; background: var(--accent); color: white;
  font-weight: 700; cursor: pointer; font-size: 0.92rem;
}
.upload-form button:hover { filter: brightness(1.08); }
#status { margin-top: 1rem; color: var(--text-secondary); font-size: 0.85rem; white-space: pre-line; }

/* ---------- recent analyses (upload page) ---------- */
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
  gap: 1rem;
}
.recent-card {
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.recent-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px -4px rgba(0,0,0,0.25); }
.recent-card.pending { cursor: default; }
.recent-score {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 2rem;
  color: white;
}
.recent-score.good { background: var(--good); }
.recent-score.warn { background: var(--warn); }
.recent-score.bad { background: var(--bad); }
.recent-score.pending { background: var(--text-muted); }
.recent-body { padding: 0.65rem 0.75rem 0.75rem; border-top: 1px solid var(--border); }
.recent-title {
  font-size: 0.82rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent-meta { font-size: 0.7rem; color: var(--text-muted); text-transform: capitalize; margin-top: 0.2rem; }

@media (max-width: 640px) {
  .page { padding: 1.1rem 1rem 3rem; }
  .card { padding: 1rem 1.1rem 1.2rem; }
  .sub-score-bar { grid-template-columns: 4.4rem 1fr 2.1rem; }
}
