/* TimeProof site styles. Values come from tokens.css; rules are explained in identity.md. */

* { box-sizing: border-box; }

/* Desktop: slim rail on the left, content on the right; the mock banner spans both. */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  grid-auto-rows: auto;
  align-content: start;
  min-height: 100vh;
}
body > * { grid-column: 2; }
body > header.site { grid-column: 1; grid-row: 1 / span 20; }

a { color: var(--link); font-weight: 600; text-decoration-thickness: 1px; text-underline-offset: 3px; }

h1, h2, h3 { font-family: var(--font-serif); font-weight: 700; line-height: var(--lh-tight); letter-spacing: -0.01em; }
h1 { font-size: var(--fs-h1); margin: 0 0 16px; }
h2 { font-size: var(--fs-h2); margin: 48px 0 16px; }
h2 span, h1 .two-tone { color: var(--brand-text); }
h3 { font-size: var(--fs-h3); margin: 0 0 6px; }

.wrap, main, footer.site .inner {
  max-width: var(--container);
  margin: 0 auto;
  padding-left: calc(var(--gutter) * 2);
  padding-right: calc(var(--gutter) * 2);
}
main { width: 100%; padding-top: 40px; padding-bottom: 24px; }

/* ---------- Banner ---------- */

.mock-banner {
  /* Never shown on the deployed site; local mock screenshots must stay identifiable. A strip at the
     top of the content (not a fixed corner badge) so it never hides a button or a line of text. */
  justify-self: end;
  margin: 12px 16px 0;
  background: var(--rail);
  color: var(--rail-text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-button);
  box-shadow: var(--shadow);
}

/* ---------- Rail ---------- */

header.site {
  background: var(--rail);
  color: var(--rail-text);
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  z-index: 2;
}
header.site .inner { display: flex; flex-direction: column; align-items: stretch; padding: 16px 0; gap: 20px; }

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: var(--radius-card);
  background: var(--brand);
  color: var(--on-brand);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.03em;
  text-decoration: none;
}

nav { display: flex; flex-direction: column; gap: 4px; }
nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  color: var(--rail-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.25;
  text-align: center;
  border-left: 3px solid transparent;
}
nav a svg { width: 22px; height: 22px; }
nav a:hover { color: var(--rail-text); }
nav a.active { color: var(--rail-text); border-left-color: var(--brand-text); background: rgba(255, 255, 255, 0.05); }

/* ---------- Footer ---------- */

footer.site { background: var(--surface-2); margin-top: var(--section); border-top: 1px solid var(--line); }
footer.site .inner { padding-top: 20px; padding-bottom: 28px; font-size: var(--fs-small); color: var(--text-2); }
footer.site p { margin: 0 0 6px; max-width: 760px; }
footer.site .wordmark { font-family: var(--font-serif); font-weight: 700; color: var(--text); }
footer.site .wordmark span { color: var(--brand-text); }

/* ---------- Shared bits ---------- */

.lead { color: var(--text-2); font-size: 18px; margin: 0 0 28px; max-width: 680px; }

.label-small {
  font-size: var(--fs-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin: 0 0 8px;
}

.meta { font-size: var(--fs-small); color: var(--text-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }

.tag {
  display: inline-block;
  font-size: var(--fs-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: var(--radius-button);
  border: 1px solid currentColor;
}
.tag.flag { background: var(--signal); border-color: var(--signal); color: var(--bg); }

.pill {
  display: inline-block;
  background: var(--button);
  color: var(--on-brand);
  font-size: var(--fs-small);
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--radius-button);
  text-decoration: none;
}
.pill:hover { background: var(--button-hover); }

.card { border-top: 1px solid var(--line); padding: 24px 0; }

/* --signal is kept for evidence only: an error is not evidence. */
.error { color: var(--warning); font-weight: 600; }
.empty { color: var(--text-2); }
.more-link { display: inline-block; margin-top: 24px; }

/* ---------- Blue hero band ---------- */

.hero-blue { background: var(--brand); color: var(--on-brand); }
.hero-blue a { color: var(--on-brand); }
.hero-blue .lead, .hero-blue .label-small, .hero-blue .meta { color: var(--on-brand-muted); }
.hero-blue .tag { color: var(--on-brand); }
.hero-blue .tag.flag { color: var(--bg); }

.hero { padding: var(--section) 0; }
.hero .display {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: var(--fs-display);
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  margin: 0 0 20px;
  max-width: 820px;
}
.hero .display em { font-weight: 400; font-style: italic; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 24px;
  margin-top: 36px;
  border-top: 1px solid rgba(255, 255, 255, 0.3);
  padding-top: 24px;
}
.stat .value { font-family: var(--font-serif); font-size: 36px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--on-brand-muted); font-size: var(--fs-small); margin-top: 4px; }

/* ---------- Case rows ---------- */

.case-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  font-weight: 400;
}
.case-item.has-image { grid-template-columns: minmax(0, 1fr) 240px; }
.case-item.has-image figure { order: 2; }
/* Alternating sides only makes sense with images, which need a credit to be shown. */
.case-item.has-image:nth-child(even) { grid-template-columns: 240px minmax(0, 1fr); }
.case-item.has-image:nth-child(even) figure { order: -1; }
.case-item img { width: 100%; height: 160px; object-fit: cover; border-radius: var(--radius-card); background: var(--surface-2); }
.case-item figcaption { font-size: 11px; margin-top: 4px; }
.case-item h3 { font-size: 22px; }
.case-item p { margin: 0 0 12px; color: var(--text-2); max-width: 660px; }
.case-item .readers { color: var(--text); font-weight: 600; }
.case-item .row-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }

/* ---------- Case page ---------- */

.case-hero { display: grid; gap: 32px; align-items: start; padding: 32px; border-radius: var(--radius-card); margin-bottom: 24px; }
.case-hero.has-image { grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); }
.case-hero.has-image figure { order: 2; }
.case-hero h1 { margin-top: 14px; color: var(--on-brand); }
.case-hero .lead { font-family: var(--font-serif); font-size: var(--fs-read); color: var(--on-brand); margin-bottom: 0; }
.case-hero figcaption { color: var(--on-brand-muted); }

figure { margin: 0; }
figure img { width: 100%; height: auto; border-radius: var(--radius-card); display: block; background: var(--surface-2); }
figcaption { font-size: var(--fs-small); color: var(--text-2); margin-top: 8px; }

.band { background: var(--rail); color: var(--rail-text); }
.band .label-small, .band .meta { color: var(--rail-muted); }
.exposure-band { padding: 28px 32px; border-radius: var(--radius-card); margin: 0 0 16px; }
.exposure-band .exposure { font-family: var(--font-serif); font-weight: 700; font-size: clamp(24px, 3.5vw, 32px); line-height: 1.2; margin: 4px 0 10px; }
.exposure-band .meta { margin: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.caption-old { text-decoration: line-through; color: var(--text-2); font-family: var(--font-serif); font-size: var(--fs-read); margin: 0; }
.caption-new { font-family: var(--font-serif); font-size: var(--fs-read); margin: 0; }
.diff-removed, .diff-added { padding: 12px 14px; border-radius: var(--radius-card); white-space: pre-wrap; font-family: var(--font-serif); font-size: 17px; }
.diff-removed { background: var(--removed); color: var(--removed-text); }
.diff-added { background: var(--added); color: var(--added-text); }

.report { font-family: var(--font-serif); font-size: var(--fs-read); margin: 0 0 12px; max-width: 720px; }
ul.plain { margin: 8px 0 0; padding-left: 18px; }
ul.plain li { margin-bottom: 4px; }

/* ---------- Time machine ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; margin-bottom: 24px; }
.controls label { display: flex; flex-direction: column; font-size: var(--fs-small); color: var(--text-2); gap: 6px; font-weight: 500; min-width: 0; max-width: 100%; }
/* Long article titles must not push the page wider than a phone screen. */
.controls select { max-width: 100%; }
select, input[type="date"], input[type="search"] {
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
}
button {
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 600;
  padding: 9px 20px;
  border-radius: var(--radius-button);
  border: 0;
  background: var(--button);
  color: var(--on-brand);
  cursor: pointer;
}
button:hover { background: var(--button-hover); }

/* Key figures above the chart */
.tm-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px 24px; margin: 0 0 24px; }
.tm-stat .value { font-family: var(--font-serif); font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tm-stat .label { font-size: var(--fs-small); color: var(--text-2); margin-top: 4px; }

/* Chart: y axis on the left, bars with grid lines, year labels below */
.tm-chart { margin: 0 0 28px; }
.tm-axis-title { font-size: var(--fs-label); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); margin: 0 0 8px; }
.tm-x-title { text-align: center; margin: 22px 0 0; }
.tm-plot { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; }
.tm-y { display: flex; flex-direction: column; justify-content: space-between; height: 160px; font-size: 12px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.tm-y span { line-height: 0; }
.timeline { position: relative; display: flex; align-items: flex-end; gap: 1px; height: 160px; border-bottom: 1px solid var(--text); border-left: 1px solid var(--line); }
.tm-grid { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.tm-grid i { display: block; border-top: 1px dashed var(--line); }
.timeline .bar { flex: 1; background: var(--brand-text); min-height: 1px; position: relative; cursor: pointer; }
.timeline .bar:hover, .timeline .bar:focus-visible { opacity: 0.75; outline: none; }
.timeline .bar .rev { position: absolute; bottom: 0; left: 0; right: 0; background: var(--warning); }
.timeline .bar.selected { outline: 2px solid var(--text); outline-offset: 1px; }
/* A published case is evidence: its month gets the signal colour. */
.timeline .case-mark { position: absolute; left: 50%; top: -12px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 2px var(--bg); }
.tm-x { position: relative; height: 16px; margin-top: 6px; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.tm-x span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.tm-readout { margin: 12px 0 4px; font-size: var(--fs-small); color: var(--text); min-height: 1.6em; font-variant-numeric: tabular-nums; }
.legend { font-size: var(--fs-small); color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin: 0 4px 0 14px; vertical-align: middle; }
.legend i:first-child { margin-left: 0; }
.legend i.legend-case { border-radius: 50%; background: var(--signal); }

/* ---------- Home: search and filters ---------- */

#sort-name { color: inherit; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 16px; align-items: end; margin: 8px 0 12px; }
.filters label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-small); color: var(--text-2); font-weight: 500; min-width: 0; }
.filters label.search { grid-column: 1 / -1; }
.filters select, .filters input { width: 100%; min-width: 0; }
.filters .years { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 0; }
.filters button { justify-self: start; }
.pill.secondary, button.secondary { background: transparent; color: var(--brand-text); border: 1px solid var(--brand-text); }
.pill.secondary:hover, button.secondary:hover { background: var(--brand-soft); }
.case-count { margin: 0 0 4px; }

.article-text { white-space: pre-wrap; font-family: var(--font-serif); font-size: var(--fs-read); line-height: 1.7; max-width: 720px; max-height: 560px; overflow-y: auto; }

/* ---------- Detection quality ---------- */

.quality-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 40px; }
.quality-grid .value { font-family: var(--font-serif); font-size: 48px; font-weight: 700; line-height: 1.1; color: var(--link); font-variant-numeric: tabular-nums; }
.quality-grid p { margin: 8px 0 0; color: var(--text-2); }

/* ---------- Lens page ---------- */

.lens-steps { padding-left: 20px; max-width: 680px; }
.lens-steps li { margin-bottom: 8px; }
.lens-drag { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin: 28px 0; }
.lens-button { font-size: 16px; padding: 12px 24px; cursor: grab; }
.lens-mock { display: inline-block; background: var(--brand-soft); color: var(--text); border-left: 3px solid var(--brand-text); font-weight: 500; padding: 10px 14px; border-radius: var(--radius-card); }

/* ---------- Below 900px: the rail becomes a top bar ---------- */

@media (max-width: 900px) {
  body { display: block; }
  header.site { position: sticky; top: 0; height: auto; }
  header.site .inner { flex-direction: row; align-items: center; justify-content: space-between; padding: 8px 12px; gap: 12px; }
  .brand-mark { width: 44px; height: 44px; font-size: 19px; margin: 0; }
  nav { flex-direction: row; gap: 0; }
  nav a { padding: 6px 8px; border-left: 0; border-bottom: 3px solid transparent; min-width: 44px; min-height: 44px; justify-content: center; }
  nav a.active { border-bottom-color: var(--brand-text); background: transparent; }
  nav a svg { width: 20px; height: 20px; }
}

@media (max-width: 720px) {
  :root { --section: 40px; }
  .wrap, main, footer.site .inner { padding-left: var(--gutter); padding-right: var(--gutter); }
  main { padding-top: 28px; }
  .case-item.has-image, .case-item.has-image:nth-child(even) { grid-template-columns: 1fr; }
  .case-item.has-image:nth-child(even) figure { order: 0; }
  .case-hero.has-image, .grid2 { grid-template-columns: 1fr; }
  .case-hero { padding: 24px 20px; gap: 20px; }
  .exposure-band { padding: 24px 20px; }
  .timeline { gap: 0; }
}


/* ================= Accessibility and ergonomics (WCAG 2.2 AA) ================= */

/* Skip link: first thing a keyboard user reaches, visible only when focused. */
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--button); color: var(--on-brand);
  padding: 10px 16px; border-radius: var(--radius-card); font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 8px; }
body > .skip-link { grid-column: 1 / -1; }

/* One visible focus ring everywhere; never removed without a replacement. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.hero-blue :focus-visible, .band :focus-visible, header.site :focus-visible, .pill:focus-visible, button:focus-visible { outline-color: var(--on-brand); box-shadow: 0 0 0 4px var(--focus); }
main:focus { outline: none; }

/* Touch targets: 44 x 44 px in the rail and top bar, 24 px minimum elsewhere. */
nav a { min-height: 44px; }
.pill, button { min-height: 32px; }

/* Section titles of the case and quality pages are real h2s, styled as small labels. */
h2.label-small, h3.label-small { font-family: var(--font-sans); font-size: var(--fs-label); line-height: 1.4; letter-spacing: 0.08em; margin: 0 0 8px; }

/* Comfortable reading: 70 characters per line at most. */
.lead, .report, .case-item p, .article-text, .quality-grid p { max-width: 70ch; }

/* Upper bound marker: explained on hover, on keyboard focus and on tap (tapping focuses it). */
abbr.approx { text-decoration: underline dotted; cursor: help; position: relative; }
abbr.approx:hover::after, abbr.approx:focus::after {
  content: attr(data-tip); position: absolute; left: 0; top: 1.6em; z-index: 20; width: max-content; max-width: 260px;
  background: var(--rail); color: var(--rail-text); font: 400 12px/1.45 var(--font-sans); letter-spacing: 0; text-transform: none;
  padding: 8px 10px; border-radius: var(--radius-card); box-shadow: var(--shadow); white-space: normal; }

/* Loading skeletons: grey bars with a slow pulse, then the real content. */
.skeleton { display: grid; gap: 12px; padding: 8px 0; }
.skeleton i { display: block; height: 14px; border-radius: var(--radius-card); background: var(--surface-2); animation: tp-pulse 1.4s ease-in-out infinite; }
.skeleton i:nth-child(1) { width: 40%; height: 20px; } .skeleton i:nth-child(2) { width: 90%; } .skeleton i:nth-child(3) { width: 75%; }
@keyframes tp-pulse { 50% { opacity: 0.45; } }

/* Errors and empty states say what to do next. */
.error-box, .empty-box { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 0; }
.error-box p, .empty-box p { margin: 0; }

/* Case page: three lines that answer what, how long, how many, before the detail. */
.glance { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 4px; font-size: 15px; color: var(--on-brand); }
.glance li { display: grid; grid-template-columns: 6.5em minmax(0, 1fr); gap: 8px; }
.glance strong { font-weight: 600; }
.diff-label::before { font-weight: 700; margin-right: 4px; }
.diff-label.minus::before { content: "\2212"; }
.diff-label.plus::before { content: "+"; }

/* Time machine chart: one keyboard stop (arrows move, Enter opens), the current month outlined. */
.timeline:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.timeline .bar.current { outline: 2px solid var(--text); outline-offset: 1px; z-index: 1; }
.tm-table { margin-top: 12px; font-size: var(--fs-small); }
.tm-table summary { cursor: pointer; color: var(--link); font-weight: 600; min-height: 24px; }
.tm-table table { border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.tm-table th, .tm-table td { text-align: right; padding: 4px 12px; border-bottom: 1px solid var(--line); }
.tm-table th:first-child, .tm-table td:first-child { text-align: left; }

/* Light / dark switch in the rail. */
.theme-toggle { background: transparent; color: var(--rail-muted); border: 1px solid var(--rail-muted); border-radius: var(--radius-button);
  min-width: 44px; min-height: 44px; padding: 0; margin: 0 auto; display: flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: rgba(255, 255, 255, 0.08); color: var(--rail-text); }
.theme-toggle svg { width: 20px; height: 20px; }
@media (max-width: 900px) { .theme-toggle { margin: 0; } }

/* Keep the footer below the fold while the content loads, so it does not jump (layout shift). */
main { min-height: 100vh; }
/* The case image's height is unknown until it loads: reserve a fixed frame so nothing moves. */
.case-hero figure img { aspect-ratio: 4 / 3; object-fit: contain; background: rgba(255, 255, 255, 0.08); }

/* Visually hidden, still read by screen readers. */
.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; }

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

/* Printing a case: no rail, no buttons, black on white, link addresses written out. */
@media print {
  body { display: block; background: #fff; color: #000; }
  header.site, footer.site, .skip-link, .mock-banner, .theme-toggle, .filters, .controls, button, .pill, .more-link { display: none !important; }
  main { max-width: none; padding: 0; min-height: 0; }
  .hero-blue, .band, .case-hero, .exposure-band { background: none !important; color: #000 !important; padding: 0 0 12px; }
  .hero-blue *, .band *, .glance { color: #000 !important; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-weight: 400; word-break: break-all; }
  .card { break-inside: avoid; }
}

/* Reserve the final height of blocks filled after the data arrives, so nothing below them jumps
   (measured on the live site at 1280 px and 375 px). */
#stats { min-height: 110px; }
#case-filters { min-height: 191px; }
#timeline { min-height: 443px; }
@media (max-width: 720px) {
  #stats { min-height: 287px; }
  #case-filters { min-height: 496px; }
  #timeline { min-height: 670px; }
}
