/* Viral Song Atlas — one typeface (Archivo, width axis used for display),
   cool paper and ink neutrals, validated categorical hues for archetypes. */

:root {
  color-scheme: light;
  --paper: #eef1f4;
  --panel: #ffffff;
  --ink: #131a23;
  --ink-2: #465261;
  --ink-3: #5a6573;
  --rule: #d3d9e0;
  --rule-strong: #b4bdc7;
  --compare: #b9c1ca;
  --focus: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-0: #9ba3ad;
  --tier-a: #1c5cab;
  --tier-b: #465261;
  --tier-c: #8a4b0a;

  --font: "Archivo", system-ui, sans-serif;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: 2.4414rem;
  --step-4: 3.4rem;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 72px;
  --radius-s: 4px;
  --radius-m: 8px;
  --measure: 72ch;
  --wrap: 1240px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --paper: #10151c;
    --panel: #171d25;
    --ink: #eef1f5;
    --ink-2: #b6bfca;
    --ink-3: #98a2ae;
    --rule: #2a323d;
    --rule-strong: #3d4653;
    --compare: #47515c;
    --focus: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-0: #7d8691;
    --tier-a: #86b6ef;
    --tier-b: #b6bfca;
    --tier-c: #f0a35c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #10151c;
  --panel: #171d25;
  --ink: #eef1f5;
  --ink-2: #b6bfca;
  --ink-3: #98a2ae;
  --rule: #2a323d;
  --rule-strong: #3d4653;
  --compare: #47515c;
  --focus: #6da7ec;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-0: #7d8691;
  --tier-a: #86b6ef;
  --tier-b: #b6bfca;
  --tier-c: #f0a35c;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }

.skip {
  position: absolute; left: var(--space-4); top: -100px;
  background: var(--ink); color: var(--paper); padding: var(--space-2) var(--space-3);
  z-index: 10;
}
.skip:focus { top: var(--space-2); }

/* Masthead */
.masthead {
  display: flex; align-items: center; gap: var(--space-5);
  max-width: var(--wrap); margin: 0 auto; padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--rule);
}
.wordmark {
  font-weight: 800; font-stretch: 112%; font-size: var(--step-1);
  text-decoration: none; letter-spacing: -0.01em; white-space: nowrap;
}
.masthead nav { display: flex; gap: var(--space-1); flex-wrap: wrap; flex: 1; }
.masthead nav a {
  text-decoration: none; color: var(--ink-2); font-weight: 500;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-s);
  min-height: 44px; display: inline-flex; align-items: center;
}
.masthead nav a:hover { color: var(--ink); background: var(--panel); }
.masthead nav a[aria-current="page"] { color: var(--paper); background: var(--ink); }
.theme-toggle {
  background: none; border: 1px solid var(--rule-strong); color: var(--ink);
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  display: inline-grid; place-items: center;
}
.theme-toggle:hover { background: var(--panel); }

main { max-width: var(--wrap); margin: 0 auto; padding: var(--space-6) var(--space-5) var(--space-8); }
main:focus { outline: none; }
.loading, .error { color: var(--ink-2); }
.error { border-left: 3px solid var(--series-2); padding-left: var(--space-4); }

/* Type */
h1, h2, h3 { line-height: 1.15; margin: 0; font-weight: 700; }
h1 {
  font-size: var(--step-4); font-stretch: 118%; font-weight: 850;
  letter-spacing: -0.025em; max-width: 18ch;
}
h2 { font-size: var(--step-2); font-stretch: 108%; font-weight: 750; letter-spacing: -0.01em; }
h3 { font-size: var(--step-1); font-weight: 650; }
.lede { font-size: var(--step-1); color: var(--ink-2); max-width: 60ch; margin: var(--space-4) 0 0; line-height: 1.45; }
.muted { color: var(--ink-3); }
.small { font-size: var(--step--1); }
p { max-width: var(--measure); }

section + section { margin-top: var(--space-8); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.section-head p { margin: 0; color: var(--ink-2); }

/* Overview hero: the three-step story, each step a link. */
.hero h1 { max-width: 22ch; }
.hero h1 span { display: block; color: var(--series-1); }
.eyebrow { margin: 0 0 var(--space-3); font-size: var(--step--1); font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.steps { list-style: none; padding: 0; margin: var(--space-6) 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.steps a {
  display: grid; gap: var(--space-2); height: 100%; box-sizing: border-box;
  padding: var(--space-5); background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m);
  text-decoration: none; color: var(--ink-2);
}
.steps a:hover { border-color: var(--ink); }
.steps strong { color: var(--ink); font-size: var(--step-1); font-stretch: 108%; font-weight: 750; }
.step-n { font-size: var(--step--1); font-weight: 700; color: var(--series-1); letter-spacing: 0.06em; }
.steps li:last-child a { border-color: var(--series-1); }
.hero-cta { margin: var(--space-5) 0 0; }
.button {
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 var(--space-5);
  background: var(--series-1); color: #fff; border-radius: 999px; font-weight: 700; text-decoration: none;
}
.button:hover { background: var(--ink); color: var(--paper); }
.hero-more a { white-space: nowrap; }
.hero-more { max-width: none; margin: var(--space-4) 0 0; color: var(--ink-3); font-size: var(--step--1); }

/* Song grid: the one bold element. One square per song, a row per group. */
.atlas-wrap { margin-top: var(--space-7); }
.atlas-wrap .section-head p { max-width: 72ch; }
.atlas { background: var(--panel); border-radius: var(--radius-m); padding: var(--space-5); display: grid; gap: var(--space-4); }
.atlas-row { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.atlas-label { margin: 0; display: grid; grid-template-columns: 14px 1fr; gap: var(--space-2); font-size: var(--step--1); color: var(--ink-2); }
.atlas-label .sw { width: 14px; height: 14px; border-radius: 3px; margin-top: 3px; background: var(--c); }
.atlas-label strong { display: block; font-size: var(--step-0); font-weight: 650; color: var(--ink); }
.atlas-label .muted { display: block; }
.atlas-cells { display: flex; flex-wrap: wrap; gap: 3px; padding-top: 3px; }
.cell { width: 11px; height: 11px; border-radius: 2px; box-shadow: inset 0 0 0 1.5px var(--c); }
.cell.in { background: var(--c); }
.cell:hover { outline: 2px solid var(--ink); outline-offset: 1px; }
.cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.key-in, .key-out { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 2px 0 4px; vertical-align: baseline; }
.key-in { background: var(--ink-2); }
.key-out { box-shadow: inset 0 0 0 1.5px var(--ink-2); }

/* Key numbers */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-5); margin: var(--space-7) 0 0; padding: var(--space-5) 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.facts div { margin: 0; }
.facts dt { color: var(--ink-2); font-size: var(--step--1); }
.facts dd { margin: var(--space-1) 0 0; font-size: var(--step-3); font-weight: 750; font-stretch: 110%; letter-spacing: -0.02em; line-height: 1; }
.facts dd span { font-size: var(--step-0); font-weight: 500; font-stretch: 100%; color: var(--ink-2); letter-spacing: 0; }

/* Layout grids */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: var(--space-7); }
.panel { background: var(--panel); border-radius: var(--radius-m); padding: var(--space-5); }

/* Bars */
.bars { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr 6.5em; gap: var(--space-3); align-items: center; border-radius: var(--radius-s); }
.bar-row:hover { background: color-mix(in srgb, var(--rule) 45%, transparent); }
.bar-label { font-size: var(--step--1); color: var(--ink); overflow-wrap: anywhere; line-height: 1.3; }
.bar-track { display: grid; gap: 3px; padding: var(--space-1) 0; }
.bar { height: 10px; border-radius: 0 4px 4px 0; min-width: 2px; }
.bar.primary { background: var(--series-1); }
.bar.compare { background: var(--compare); height: 6px; }
.bar-value { text-align: right; font-size: var(--step--1); color: var(--ink); white-space: nowrap; }
.bar-value .muted { display: block; }
.bar-value .diff { display: block; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.key { display: flex; gap: var(--space-5); flex-wrap: wrap; font-size: var(--step--1); color: var(--ink-2); margin: 0 0 var(--space-4); }
.key span { display: inline-flex; align-items: center; gap: var(--space-2); }
.key i { display: inline-block; width: 18px; height: 8px; border-radius: 2px; }

/* Notes and caveats */
.note { border-left: 3px solid var(--rule-strong); padding: var(--space-1) 0 var(--space-1) var(--space-4); color: var(--ink-2); max-width: var(--measure); }
.caveats { margin: 0; padding-left: 1.2em; display: grid; gap: var(--space-2); max-width: var(--measure); }

/* Tier badges */
.tier { display: inline-flex; align-items: center; gap: 6px; font-size: var(--step--1); font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.tier.A { color: var(--tier-a); }
.tier.B { color: var(--tier-b); }
.tier.C { color: var(--tier-c); }

/* Controls */
.intro { margin-bottom: var(--space-6); }
.controls { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: end; margin-bottom: var(--space-5); }
.field { display: grid; gap: var(--space-1); font-size: var(--step--1); color: var(--ink-2); }
select, input[type="search"] {
  font: inherit; font-size: var(--step-0); color: var(--ink); background: var(--panel);
  border: 1px solid var(--rule-strong); border-radius: var(--radius-s);
  min-height: 44px; padding: 0 var(--space-3);
}
input[type="search"] { min-width: min(320px, 100%); }
input::placeholder { color: var(--ink-3); opacity: 1; }
.lede, .caveats li, .prose p, .prose li { text-wrap: pretty; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; color: var(--ink); font-size: var(--step-0); }
.check input { width: 18px; height: 18px; accent-color: var(--series-1); }
.segmented { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); overflow: hidden; flex-wrap: wrap; }
.segmented button { font: inherit; background: var(--panel); color: var(--ink-2); border: 0; border-right: 1px solid var(--rule); min-height: 44px; padding: 0 var(--space-4); cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.linkish { font: inherit; background: none; border: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: var(--space-2) 0; min-height: 44px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius-m); }
table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
th, td { text-align: left; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 650; color: var(--ink-2); position: sticky; top: 0; background: var(--panel); }
th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
th[aria-sort="ascending"] button::after { content: " ▲"; }
th[aria-sort="descending"] button::after { content: " ▼"; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: color-mix(in srgb, var(--rule) 40%, transparent); }
.song-cell a { font-weight: 600; text-decoration: none; }
.song-cell a:hover { text-decoration: underline; }
.song-cell span { display: block; color: var(--ink-3); }
.arch { display: inline-flex; align-items: center; gap: var(--space-2); }
.arch i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.count { color: var(--ink-2); margin: 0 0 var(--space-3); }

/* Recipe page */
.recipe-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); gap: var(--space-7); align-items: start; }
.lane-panel { position: sticky; top: var(--space-4); max-height: calc(100vh - 32px); overflow: auto; }
.lane-panel h2 { font-size: var(--step-1); }
.lane-tabs { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-4) 0; }
.lane-tabs button { font: inherit; font-size: var(--step--1); border: 1px solid var(--rule-strong); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 0 var(--space-3); min-height: 36px; cursor: pointer; display: inline-flex; align-items: center; gap: var(--space-2); }
.lane-tabs button i { width: 10px; height: 10px; border-radius: 2px; }
.lane-tabs button[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 650; }
.lane-field { margin-top: var(--space-5); }
.lane-field header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.lane-field h3 { font-size: var(--step-0); }
.lane-panel .bar-row { grid-template-columns: minmax(90px, 40%) 1fr 4.5em; }
.exemplars { padding-left: 1.2em; margin: var(--space-2) 0 0; font-size: var(--step--1); display: grid; gap: var(--space-1); }

/* Rendered Markdown */
.prose { max-width: var(--measure); min-width: 0; overflow-wrap: break-word; }
.prose code { overflow-wrap: anywhere; }
.prose h1 { font-size: var(--step-3); max-width: none; }
.prose h2 { margin-top: var(--space-7); margin-bottom: var(--space-3); }
.prose h3 { margin-top: var(--space-6); margin-bottom: var(--space-2); }
.prose h4 { margin-top: var(--space-5); }
.prose table { display: block; overflow-x: auto; background: var(--panel); border-radius: var(--radius-m); margin: var(--space-4) 0; }
.prose code { font-size: 0.92em; background: color-mix(in srgb, var(--rule) 60%, transparent); padding: 1px 4px; border-radius: 3px; }
.prose pre { background: var(--panel); padding: var(--space-4); border-radius: var(--radius-m); overflow-x: auto; font-size: var(--step--1); line-height: 1.5; border-left: 3px solid var(--series-1); }
.prose pre code { background: none; padding: 0; }
.prose li + li { margin-top: var(--space-1); }
.prose blockquote { margin: 0; border-left: 3px solid var(--rule-strong); padding-left: var(--space-4); color: var(--ink-2); }

/* Song page */
.back { display: inline-flex; min-height: 44px; align-items: center; color: var(--ink-2); }
.song-head h1 { font-size: var(--step-3); max-width: none; }
.song-head p { margin: var(--space-2) 0 0; color: var(--ink-2); font-size: var(--step-1); }
.profile { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-4) var(--space-6); margin: var(--space-6) 0; padding: var(--space-5); background: var(--panel); border-radius: var(--radius-m); }
.profile div { margin: 0; }
.profile dt { font-size: var(--step--1); color: var(--ink-3); }
.profile dd { margin: 2px 0 0; }
.flag-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.flag { font-size: var(--step--1); border: 1px solid var(--rule-strong); border-radius: 999px; padding: 1px 8px; }

details.full { margin-top: var(--space-5); }
details.full summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--ink); color: var(--paper); border-radius: var(--radius-s);
  padding: var(--space-2) var(--space-3); font-size: var(--step--1); line-height: 1.4;
  max-width: 280px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.18);
}
.tooltip strong { display: block; font-weight: 650; }

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

@media (max-width: 900px) {
  .steps { grid-template-columns: 1fr; }
  .recipe-layout { grid-template-columns: 1fr; }
  .lane-panel { position: static; max-height: none; }
}

@media (max-width: 640px) {
  .masthead { flex-wrap: wrap; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
  .masthead nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .masthead nav a { white-space: nowrap; }
  .atlas { padding: var(--space-4); }
  .atlas-row { grid-template-columns: 1fr; gap: var(--space-2); }
  .atlas-cells { gap: 2px; }
  .cell { width: 9px; height: 9px; }
  .theme-toggle { margin-left: auto; }
  main { padding: var(--space-5) var(--space-4) var(--space-7); }
  h1 { font-size: 2.35rem; }
  .hero h1 { font-size: clamp(2rem, 9vw, 2.6rem); }
  .bar-row { grid-template-columns: 1fr 5.5em; }
  .bar-row .bar-label { grid-column: 1 / -1; }
  th, td { padding: var(--space-2) var(--space-3); }
  .hide-sm { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .bar { transition: width 220ms ease-out; }
}
