/* Colour and type tokens live in assets/tokens.css, loaded before this file
   and shared with the narrative front door. Only layout tokens are local. */
:root {
  --header-height: 60px;
  --sidebar-width: 250px;
  --content-max: 760px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  padding: 0.6em 1em;
  z-index: 100;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* ---------- Header ---------- */

/* The deep bar. Same panel as the narrative page's hero and CTA, so every
   page in the project opens with the same dark band. Fixed across themes. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  background: var(--color-deep);
  border-bottom: 1px solid var(--color-deep-border);
}

.site-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  overflow: hidden;
}

.portal-name {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-accent-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.current-tab {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-deep-text);
}

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

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  width: 38px;
  height: 34px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--color-deep-text);
  position: relative;
}
.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
}
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

/* ---------- Layout ---------- */

.layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
  align-items: flex-start;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-raised);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0;
}

.nav-item {
  display: block;
  padding: 0.55rem 1.25rem;
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}

/* Its own column rather than display:contents, which some browsers have
   dropped from the accessibility tree along with the role and its label. */
.nav-group {
  display: flex;
  flex-direction: column;
}

.nav-group-label {
  margin: 1.1rem 0 0.3rem;
  padding: 0 1.25rem;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--color-text-muted);
}

/* The way back to the narrative, set apart from the portal's own sections. */
.nav-return {
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--color-border);
}

.nav-arrow {
  display: inline-block;
  width: 1.15em;
  margin-right: 0.2em;
}

.nav-letter {
  display: inline-block;
  width: 1.15em;
  margin-right: 0.2em;
  color: var(--color-text-muted);
  font-weight: 600;
}

.nav-item.active .nav-letter {
  color: var(--color-accent);
}

.nav-item:hover {
  background: var(--color-bg);
}

.nav-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.nav-item.active {
  border-left-color: var(--color-accent);
  background: var(--color-bg);
  font-weight: 600;
  color: var(--color-accent);
}

.nav-scrim {
  display: none;
}

.nav-toggle-checkbox:focus-visible ~ .site-header .nav-toggle {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 1.5rem 5rem;
}

.main-content:focus {
  outline: none;
}

/* ---------- Tab header / question callout ---------- */

.tab-header {
  max-width: var(--content-max);
}

/* Display serif on headings only — body copy stays on the system sans. This
   is the second thing tying the two surfaces together; the prose density and
   restraint below are unchanged. */
.tab-header h1,
.tab-body h1 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.75rem;
  line-height: 1.2;
}

.tab-body h2,
.tier-panel h2 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.005em;
}

.question-callout {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: 4px;
  padding: 0.85rem 1rem;
  margin: 0 0 1.25rem;
  font-size: 0.98rem;
}

.tab-body,
.tab-header > p {
  max-width: var(--content-max);
}

/* --- Findings by module: the overview's router into A–G ------------------
   Cards rather than a bulleted list, so seven long paragraphs can be scanned
   and each one is a way in. The letter badge matches .nav-letter's treatment
   so the same module reads the same way in the sidebar and here. */
.findings {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 0.9rem;
}

.finding {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1rem 1.15rem 1.1rem;
}

.finding-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  text-decoration: none;
  color: var(--color-text);
}

.finding-head:hover .finding-title {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.finding-letter {
  flex: none;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--color-accent);
}

.finding-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
}

.finding-body {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--color-text-muted);
}

/* Source links inside prose. Scoped with :not([class]) so the navigation
   and skip links, which all carry a class, keep their own treatment. */
.main-content a:not([class]) {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: var(--color-border-strong);
}

.main-content a:not([class]):hover {
  text-decoration-color: var(--color-link);
}

.main-content a:not([class]):focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Tier controls ---------- */

.tab-controls {
  position: sticky;
  top: var(--header-height);
  z-index: 20;
  background: var(--color-bg);
  padding: 0.6rem 0;
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  max-width: var(--content-max);
}

.tier-switcher {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: 999px;
  overflow: hidden;
}

/*
 * The tier switcher and the "copy for an LLM" affordance are driven by
 * plain radio inputs (the classic checkbox/radio hack) rather than JS:
 * `.tier-radio` sits before `.tab-controls`/`.tab-body` as a sibling inside
 * `.tier-block`, so `:checked` can select the matching label and panel with
 * no script involved. See scripts/build.js for the generated markup.
 */
.tier-radio {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tier-block .tier-panel {
  display: none;
}

#tier-30s:checked ~ .tab-body [data-tier="30s"],
#tier-5min:checked ~ .tab-body [data-tier="5min"],
#tier-full:checked ~ .tab-body [data-tier="full"] {
  display: block;
}

.tier-btn {
  display: inline-block;
  border: none;
  background: var(--color-bg-raised);
  color: var(--color-text);
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-right: 1px solid var(--color-border);
  font-family: var(--font);
  user-select: none;
}
.tier-btn:last-child { border-right: none; }

#tier-30s:checked ~ .tab-controls .tier-switcher label[for="tier-30s"],
#tier-5min:checked ~ .tab-controls .tier-switcher label[for="tier-5min"],
#tier-full:checked ~ .tab-controls .tier-switcher label[for="tier-full"] {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  font-weight: 600;
}

#tier-30s:focus-visible ~ .tab-controls .tier-switcher label[for="tier-30s"],
#tier-5min:focus-visible ~ .tab-controls .tier-switcher label[for="tier-5min"],
#tier-full:focus-visible ~ .tab-controls .tier-switcher label[for="tier-full"] {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Copy-for-LLM only makes sense while the full report is the one on screen.
   flex-basis: 100% forces it onto its own line under the switcher instead of
   fighting the switcher for space in the same centered flex row. */
.copy-details {
  display: none;
  flex-basis: 100%;
}
#tier-full:checked ~ .tab-controls .copy-details {
  display: block;
}

.copy-details summary {
  font-family: var(--font);
  font-size: 0.82rem;
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-raised);
  color: var(--color-text);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  display: inline-block;
  list-style: none;
}
.copy-details summary::-webkit-details-marker { display: none; }
.copy-details summary:hover { border-color: var(--color-accent); }
.copy-details[open] summary {
  border-radius: 6px 6px 0 0;
  margin-bottom: 0.4rem;
}

.copy-textarea {
  display: block;
  width: 100%;
  max-width: 640px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--color-text-muted);
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  resize: vertical;
}

.copy-btn {
  font-family: var(--font);
  font-size: 0.82rem;
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-raised);
  color: var(--color-text);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

/* ---------- Landing prompt CTA (Overview page only) ---------- */

.landing-prompt {
  margin: 1.5rem 0 2rem;
  max-width: var(--content-max);
}

.landing-prompt-details {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: 4px;
  padding: 0.85rem 1rem;
}

.landing-prompt-summary {
  font-family: var(--font);
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}
.landing-prompt-summary:hover { color: var(--color-accent); }
.landing-prompt-summary:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.landing-prompt-details[open] .landing-prompt-summary {
  margin-bottom: 0.75rem;
}
.landing-prompt-summary.copied {
  color: var(--color-accent);
}

.landing-prompt-hint {
  color: var(--color-text-muted);
  font-size: 0.88rem;
  margin: 0 0 0.65rem;
}
.landing-prompt-hint code {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0.05em 0.35em;
  font-size: 0.92em;
}

.landing-prompt-textarea {
  max-width: 100%;
}

.landing-prompt-details .copy-btn {
  font-size: 0.88rem;
  padding: 0.5rem 0.9rem;
  margin-bottom: 0.6rem;
}
.copy-btn[hidden] { display: none; }
.copy-btn:hover { border-color: var(--color-accent); }
.copy-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.copy-btn.copied {
  background: var(--color-safe-bg);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ---------- Prose ---------- */

.tier-panel h2 {
  font-size: 1.25rem;
  margin: 1.6rem 0 0.6rem;
}

.tier-panel h3 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.tier-panel h3 .copy-section-btn {
  opacity: 0;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  transition: opacity 0.1s ease;
}
.tier-panel h3:hover .copy-section-btn,
.tier-panel h3:focus-within .copy-section-btn,
.tier-panel h3 .copy-section-btn:focus-visible {
  opacity: 1;
}

.tier-panel p {
  margin: 0 0 1rem;
  max-width: var(--content-max);
}

.tier-panel ul,
.tier-panel ol {
  max-width: var(--content-max);
  padding-left: 1.4rem;
  margin: 0 0 1rem;
}

.tier-panel li {
  margin-bottom: 0.4rem;
}

.tier-panel blockquote {
  border-left: 4px solid var(--color-border-strong);
  background: var(--color-bg-raised);
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  max-width: var(--content-max);
  color: var(--color-text-muted);
}

.tier-panel blockquote strong:first-child {
  color: var(--color-text);
}

.tier-panel code {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0.05em 0.35em;
  font-size: 0.9em;
}

.tier-panel hr {
  border: none;
  border-top: 1px solid var(--color-border);
  max-width: var(--content-max);
  margin: 1.75rem 0;
}

.table-scroll {
  overflow-x: auto;
  margin: 0 0 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.tier-panel table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
  font-size: 0.9rem;
}

.tier-panel th,
.tier-panel td {
  border: 1px solid var(--color-border);
  padding: 0.5rem 0.65rem;
  text-align: left;
  vertical-align: top;
}

.tier-panel th {
  background: var(--color-bg-raised);
  font-weight: 600;
}

.load-error {
  color: var(--color-red-text);
}

/* ---------- Figure Ledger ---------- */

.ledger-intro {
  color: var(--color-text-muted);
}

.ledger-data-link {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.ledger-legend {
  max-width: var(--content-max);
  margin-bottom: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-raised);
  padding: 0.6rem 1rem;
}

.ledger-legend summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 0.75rem;
}

.legend-grid h2 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin: 0 0 0.4rem;
}

.legend-grid dl {
  margin: 0;
  font-size: 0.85rem;
}
.legend-grid dt {
  font-weight: 600;
  margin-top: 0.4rem;
}
.legend-grid dd {
  margin: 0 0 0.2rem;
  color: var(--color-text-muted);
}

.ledger-controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  min-width: 4.5rem;
}

.toggle-group {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.toggle-btn {
  font-family: var(--font);
  font-size: 0.82rem;
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-raised);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
}
.toggle-btn.active {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  border-color: var(--color-accent);
}
.toggle-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.flag-row {
  gap: 1.25rem;
}
.flag-toggle {
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.ledger-search {
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  width: 100%;
  max-width: 320px;
}

.ledger-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.ledger-table-scroll {
  max-width: 100%;
}

.ledger-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.ledger-table th,
.ledger-table td {
  border: 1px solid var(--color-border);
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.ledger-table thead th {
  background: var(--color-bg-raised);
  position: sticky;
  top: 0;
}

.sort-btn {
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  color: var(--color-text);
  white-space: nowrap;
}

.col-claim { min-width: 220px; }
.col-source { min-width: 160px; }
.col-flags { min-width: 140px; }

.ledger-table tbody tr.row-stale {
  border-left: 3px solid var(--color-amber-border);
}
.ledger-table tbody tr.row-stale td:first-child {
  box-shadow: inset 3px 0 0 var(--color-amber-border);
}

.chip {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  margin: 0 0.25rem 0.25rem 0;
  white-space: nowrap;
  border: 1px solid transparent;
}

.tier-chip.tier-safe { background: var(--color-safe-bg); color: var(--color-safe-text); }
.tier-chip.tier-neutral { background: var(--color-neutral-bg); color: var(--color-neutral-text); }
.tier-chip.tier-warn { background: var(--color-amber-bg); color: var(--color-amber-text); border-color: var(--color-amber-border); }

.flag-chip { background: var(--color-neutral-bg); color: var(--color-neutral-text); }
.flag-chip.flag-warn { background: var(--color-amber-bg); color: var(--color-amber-text); border-color: var(--color-amber-border); }
.flag-chip.flag-unverified {
  background: var(--color-red-bg);
  color: var(--color-red-text);
  border-color: var(--color-red-border);
  font-weight: 700;
}

.flag-stale {
  background: var(--color-amber-bg);
  color: var(--color-amber-text);
  border-color: var(--color-amber-border);
  font-weight: 600;
}

.ledger-table tbody tr.row-unverified {
  background: linear-gradient(0deg, var(--color-red-bg), var(--color-red-bg));
  background-blend-mode: multiply;
}

/* ---------- Responsive ---------- */

@media (max-width: 800px) {
  .nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    width: 78vw;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.15s ease;
    z-index: 50;
  }

  #nav-toggle-checkbox:checked ~ .layout .sidebar {
    transform: translateX(0);
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  #nav-toggle-checkbox:checked ~ .layout .nav-scrim {
    display: block;
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(0,0,0,0.3);
    z-index: 45;
  }

  .main-content {
    padding: 1.25rem 1rem 4rem;
  }

  .legend-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Print ---------- */

@media print {
  .site-header,
  .sidebar,
  .nav-scrim,
  .nav-toggle,
  .nav-toggle-checkbox,
  .tab-controls,
  .copy-btn,
  .landing-prompt,
  .skip-link {
    display: none !important;
  }

  .layout {
    display: block;
  }

  .main-content {
    padding: 0;
  }

  body {
    background: #fff;
  }

  a { color: inherit; text-decoration: none; }

  .main-content a:not([class])::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    word-break: break-all;
  }
}

/* Targeted figure row: arrived via a citation link from the narrative page
   (ledger.html#fig-N). .row-targeted is set by focusHashRow() after the
   interactive table replaces the static one. */
.ledger-table tbody tr:target,
.ledger-table tbody tr.row-targeted {
  box-shadow: inset 4px 0 0 var(--color-accent);
}
