:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #66706b;
  --line: #dfe5e0;
  --line-strong: #c7d0c9;
  --paper: #fbfcfa;
  --panel: #ffffff;
  --wash: #f2f5f1;
  --accent: #1e6b50;
  --accent-soft: #e5f1eb;
  --amber: #9a5b16;
  --amber-soft: #fbf0df;
  --red: #a43b3b;
  --red-soft: #f9e8e6;
  --blue: #2e5e91;
  --blue-soft: #e8eff7;
  --radius: 10px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
button, input, select { font: inherit; }
button, .button { -webkit-tap-highlight-color: transparent; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 8px;
  z-index: 100;
  transform: translateY(-160%);
  background: var(--ink);
  color: white;
  border-radius: 6px;
  padding: 8px 12px;
  transition: transform 160ms var(--ease-out);
}
.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 70px;
  display: grid;
  grid-template-columns: 228px minmax(260px, 640px) 1fr;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.1;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--ink);
  color: white;
  font-family: Georgia, serif;
  font-size: 20px;
}
.brand strong { display: block; letter-spacing: -0.015em; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }

.search-wrap { position: relative; }
.search-wrap input {
  width: 100%;
  height: 40px;
  padding: 0 44px 0 38px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%2366706b' stroke-width='1.6'%3E%3Ccircle cx='8' cy='8' r='5.5'/%3E%3Cpath d='m12 12 4 4'/%3E%3C/svg%3E") no-repeat 12px center;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap kbd {
  position: absolute;
  right: 10px;
  top: 9px;
  min-width: 23px;
  height: 22px;
  border: 1px solid var(--line);
  border-bottom-color: var(--line-strong);
  border-radius: 5px;
  background: var(--wash);
  color: var(--muted);
  text-align: center;
  font: 12px/20px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.load-state { justify-self: end; color: var(--muted); font-size: 12px; }
.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: calc(100vh - 70px); }

.sidebar {
  position: sticky;
  top: 70px;
  height: calc(100vh - 70px);
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #f8faf7;
}
.sidebar > a {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 4px;
  padding: 9px 11px;
  border-radius: 7px;
  color: #44504a;
  text-decoration: none;
  font-size: 14px;
}
.sidebar > a span { width: 18px; color: var(--muted); text-align: center; font-size: 17px; }
.sidebar > a[aria-current="page"] { background: var(--accent-soft); color: #174f3c; font-weight: 650; }
.sidebar-note {
  position: absolute;
  right: 20px;
  bottom: 22px;
  left: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}
.sidebar-note strong { display: block; margin-bottom: 4px; color: var(--ink); }

main { min-width: 0; padding: 44px clamp(28px, 5vw, 78px) 80px; }
main:focus { outline: none; }
.page { max-width: 1180px; margin: 0 auto; }
.page.narrow { max-width: 880px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .1em;
  text-transform: uppercase;
}
h1, h2, h3 { margin-top: 0; line-height: 1.18; letter-spacing: -0.025em; }
h1 { max-width: 960px; margin-bottom: 14px; font-size: clamp(30px, 4vw, 48px); font-weight: 680; }
h2 { margin-bottom: 14px; font-size: 22px; }
h3 { margin-bottom: 8px; font-size: 16px; }
.lede { max-width: 750px; margin: 0 0 30px; color: #4f5b55; font-size: 17px; line-height: 1.65; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.breadcrumb { margin-bottom: 23px; color: var(--muted); font-size: 12px; }
.breadcrumb a { color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 28px 0 42px; }
.stat {
  min-height: 108px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.stat strong { display: block; margin-bottom: 5px; font-size: 27px; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; line-height: 1.35; }

.section { margin-top: 42px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.section-head h2, .section-head p { margin-bottom: 0; }
.surface { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.padded { padding: 22px; }

.waterfall { padding: 6px 22px 8px; }
.waterfall-row { display: grid; grid-template-columns: minmax(220px, 1fr) 100px 2fr; gap: 16px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.waterfall-row:last-child { border-bottom: 0; }
.waterfall-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; overflow: hidden; border-radius: 99px; background: var(--wash); }
.bar { height: 100%; border-radius: inherit; background: var(--accent); }

.callout { display: grid; grid-template-columns: auto 1fr; gap: 13px; padding: 18px 20px; border: 1px solid #cddbd2; border-radius: var(--radius); background: #f0f7f3; }
.callout .symbol { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: white; font-weight: 700; }
.callout p { margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 22px 0 14px; }
.toolbar input, .toolbar select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  padding: 0 11px;
  outline: none;
}
.toolbar input { flex: 1; min-width: 240px; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.result-count { margin-left: auto; color: var(--muted); font-size: 12px; }
.list { border-top: 1px solid var(--line); }
.list-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; padding: 17px 3px; border-bottom: 1px solid var(--line); }
.list-item h3 { margin: 0 0 6px; font-size: 15px; line-height: 1.4; letter-spacing: -.008em; }
.list-item h3 a { color: var(--ink); text-decoration: none; }
.list-item h3 a:hover { color: var(--accent); text-decoration: underline; }
.list-item p { margin: 0; color: var(--muted); font-size: 12px; }
.list-meta { white-space: nowrap; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.pill { display: inline-flex; align-items: center; min-height: 23px; padding: 2px 8px; border-radius: 99px; background: var(--wash); color: #53605a; font-size: 11px; font-weight: 600; }
.pill.green { background: var(--accent-soft); color: #176044; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }

.pagination { display: flex; justify-content: space-between; align-items: center; padding-top: 18px; color: var(--muted); font-size: 12px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: transform 140ms var(--ease-out), border-color 140ms ease, background-color 140ms ease;
}
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button:disabled { cursor: default; opacity: .45; }
.button:active:not(:disabled) { transform: scale(.97); }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(240px, .8fr); gap: 38px; align-items: start; }
.quote { margin: 26px 0; padding: 22px 24px; border-left: 3px solid var(--accent); background: #f3f6f2; color: #344039; font-family: Georgia, "Times New Roman", serif; font-size: 19px; line-height: 1.55; }
.quote footer { margin-top: 12px; color: var(--muted); font-family: inherit; font-size: 12px; }
.meta-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.meta-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 12px; }
.meta-row:last-child { border-bottom: 0; }
.meta-row dt { color: var(--muted); }
.meta-row dd { margin: 0; overflow-wrap: anywhere; text-align: right; font-weight: 600; }
.prose { max-width: 780px; }
.prose p { color: #3e4944; }

.match { padding: 18px 0; border-bottom: 1px solid var(--line); }
.match:last-child { border-bottom: 0; }
.match h3 { margin-bottom: 7px; line-height: 1.4; }
.match h3 a { color: var(--ink); }
.match p { margin: 8px 0 0; color: #4f5b55; font-size: 13px; }
.match .match-rationale { padding: 10px 12px; border-radius: 6px; background: var(--wash); }

.transcript-actions { display: flex; flex-wrap: wrap; gap: 9px; margin: 20px 0; }
.transcript { max-height: 70vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.cue { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 18px; padding: 9px 15px; border-bottom: 1px solid #eef1ee; }
.cue time { color: var(--muted); font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.cue p { margin: 0; }
.cue.target { background: #fff4cf; box-shadow: inset 3px 0 #d89b16; }

.chart-wrap { margin-top: 16px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.chart { display: block; width: 100%; height: 260px; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .point { fill: var(--panel); stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart text { fill: var(--muted); font: 11px ui-sans-serif, sans-serif; }

.failure-table { width: 100%; border-collapse: collapse; }
.failure-table th, .failure-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
.failure-table th { color: var(--muted); font-weight: 600; }
.failure-table td:last-child, .failure-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.empty, .page-state { padding: 56px 20px; color: var(--muted); text-align: center; }
.page-state { min-height: 50vh; display: grid; place-content: center; }
.spinner { display: block; width: 20px; height: 20px; margin: auto; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto minmax(180px, 1fr); padding: 0 18px; }
  .load-state { display: none; }
  .shell { display: block; }
  .sidebar { position: sticky; top: 70px; z-index: 15; display: flex; gap: 4px; width: 100%; height: auto; overflow-x: auto; padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar > a { flex: 0 0 auto; margin: 0; }
  .sidebar-note { display: none; }
  main { padding: 34px 22px 70px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .meta-panel { order: -1; }
}

@media (max-width: 560px) {
  .topbar { height: auto; min-height: 70px; grid-template-columns: 1fr; gap: 9px; padding: 10px 14px; }
  .brand small, .search-wrap kbd { display: none; }
  .shell { min-height: calc(100vh - 112px); }
  .sidebar { top: 112px; }
  .sidebar > a span { display: none; }
  main { padding: 28px 16px 60px; }
  h1 { font-size: 31px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { min-height: 94px; padding: 14px; }
  .stat strong { font-size: 22px; }
  .waterfall-row { grid-template-columns: 1fr auto; }
  .waterfall-row .bar-track { grid-column: 1 / -1; }
  .list-item { grid-template-columns: 1fr; gap: 6px; }
  .list-meta { text-align: left; }
  .cue { grid-template-columns: 66px 1fr; gap: 9px; padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
