/* =============================================================================
   Three Body Orbits — design system
   Scarlet light in a dark, finely constructed space.
   ============================================================================= */

@layer reset, tokens, base, layout, components, views, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body { margin: 0; }
  h1, h2, h3, h4, p, ul, ol, figure, dl, dd { margin: 0; }
  ul, ol { padding: 0; list-style: none; }
  img, canvas, svg { display: block; max-width: 100%; }
  button, input, select { font: inherit; color: inherit; }
  button { background: none; border: 0; padding: 0; cursor: pointer; }
  a { color: inherit; }
  [hidden] { display: none !important; }
}

@layer tokens {
  :root {
    color-scheme: dark;
    --carbon: #100d0c;
    --smoke: #1b1513;
    --depth: #291a17;
    --scarlet: #ff3b3b;
    --coral: #ff7868;
    --blush: #ffd2c8;
    --white: #fff4f0;
    --mineral: #cbb4ac;
    --rule: #65433d;
    --rule-soft: rgb(101 67 61 / 0.45);
    --rule-faint: rgb(101 67 61 / 0.22);
    --scarlet-band: rgb(255 59 59 / 0.16);

    --sans: 'Archivo', 'Helvetica Neue', Arial, system-ui, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

    --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
    --s7: 48px; --s8: 64px; --s9: 96px; --s10: 144px;

    --margin: clamp(16px, 5vw, 96px);
    --gutter: clamp(16px, 2vw, 32px);
    --max: 1600px;
    --measure: 62ch;

    --t-fast: 110ms;
    --t-hover: 200ms;
    --t-assemble: 360ms;
    --t-major: 720ms;
    --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.25, 1);

    --topbar-h: 60px;
  }
}

@layer base {
  html { background: var(--carbon); scroll-behavior: smooth; }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

  body {
    min-height: 100dvh;
    background: var(--carbon);
    color: var(--white);
    font-family: var(--sans);
    font-size: 1.0625rem;
    line-height: 1.55;
    font-stretch: 100%;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
  }

  /* Fine grain over the deepest layer. */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.032;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 0.9 0 0 0 0 0.85 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 180px 180px;
    mix-blend-mode: screen;
  }

  ::selection { background: var(--scarlet); color: var(--carbon); }

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

  a { text-decoration: none; }
  p a, li a.text { color: var(--blush); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 0.18em; }
  p a:hover, li a.text:hover { text-decoration-color: var(--coral); }

  .mono {
    font-family: var(--mono);
    font-size: 0.8125rem;
    line-height: 1.35;
    letter-spacing: 0.02em;
    font-feature-settings: 'tnum' 1, 'zero' 1;
  }

  .display {
    font-stretch: 112%;
    font-weight: 760;
    line-height: 0.98;
    letter-spacing: -0.012em;
    font-size: clamp(2.5rem, 5.1vw, 6.25rem);
    text-wrap: balance;
  }

  h1.major,
  h2.major {
    font-stretch: 106%;
    font-weight: 660;
    line-height: 1.08;
    letter-spacing: -0.008em;
    font-size: clamp(1.9rem, 3.4vw, 3.6rem);
    text-wrap: balance;
  }

  h3.secondary {
    font-stretch: 102%;
    font-weight: 560;
    line-height: 1.2;
    font-size: clamp(1.25rem, 1.8vw, 1.75rem);
  }

  .lede {
    font-size: clamp(1.0625rem, 1.25vw, 1.25rem);
    line-height: 1.55;
    color: var(--mineral);
    max-width: var(--measure);
  }
  .lede strong { color: var(--white); font-weight: 560; }

  .skip {
    position: absolute; left: 8px; top: -60px; z-index: 100;
    padding: 8px 12px; background: var(--scarlet); color: var(--carbon); font-weight: 600;
  }
  .skip:focus { top: 8px; }

  /* Keep chrome above the grain. */
  .topbar, main, .foot { position: relative; z-index: 1; }
}

/* =============================================================================
   Layout
   ============================================================================= */
@layer layout {
  .wrap {
    width: min(100% - 2 * var(--margin), var(--max));
    margin-inline: auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--topbar-h);
    background: color-mix(in srgb, var(--carbon) 86%, transparent);
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    border-bottom: 1px solid var(--rule-soft);
  }
  .topbar .wrap {
    height: 100%;
    display: flex;
    align-items: center;
    gap: var(--s6);
  }
  .wordmark {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-stretch: 112%;
    font-weight: 720;
    font-size: 0.8125rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--white);
    white-space: nowrap;
  }
  .wordmark .mark {
    width: 9px; height: 9px; background: var(--scarlet); flex: none;
    box-shadow: 0 0 10px 1px rgb(255 59 59 / 0.55);
  }
  .nav {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: clamp(12px, 2vw, 28px);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--mineral);
  }
  .nav a { padding: 8px 2px; position: relative; }
  .nav a:hover { color: var(--white); }
  .nav a[aria-current='page'] { color: var(--white); }
  .nav a[aria-current='page']::after {
    content: ''; position: absolute; left: 2px; right: 2px; bottom: 2px; height: 2px; background: var(--scarlet);
  }
  .nav .personal {
    color: var(--white);
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 10px 6px 12px;
    border: 1px solid var(--rule);
    transition: border-color var(--t-hover) var(--ease-out);
  }
  .nav .personal::after { content: ''; width: 6px; height: 6px; background: var(--coral); }
  .nav .personal:hover { border-color: var(--coral); }

  main { min-height: calc(100dvh - var(--topbar-h)); }

  .foot {
    margin-top: var(--s10);
    border-top: 1px solid var(--rule-soft);
    padding: var(--s7) 0 var(--s8);
    color: var(--mineral);
    font-size: 0.9375rem;
  }
  .foot .wrap { display: grid; grid-template-columns: 1fr auto; gap: var(--s5) var(--s7); align-items: start; }
  .foot nav { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s5); }
  .foot a:hover { color: var(--white); }
  .foot .colophon { max-width: 60ch; }
  @media (max-width: 960px) {
    .foot .wrap { grid-template-columns: 1fr; }
    .topbar .wrap { gap: var(--s3); }
    .wordmark { font-size: 0.6875rem; letter-spacing: 0.04em; gap: 8px; }
    .nav { gap: 10px; font-size: 0.8125rem; }
    .nav .about-link, .nav a[data-route='atlas'] { display: none; }
    .nav .personal { padding: 5px 8px 5px 10px; white-space: nowrap; }
  }
  @media (max-width: 480px) {
    .wordmark { font-size: 0.625rem; letter-spacing: 0.03em; }
    .nav .personal { padding: 5px 9px; }
    .nav .personal::after { display: none; }
  }
}

/* =============================================================================
   Components
   ============================================================================= */
@layer components {
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 44px; padding: 0 20px;
    border: 1px solid var(--rule);
    background: var(--smoke);
    color: var(--white);
    font-weight: 560;
    font-size: 0.9375rem;
    letter-spacing: 0.005em;
    white-space: nowrap;
    transition: border-color var(--t-hover) var(--ease-out), background-color var(--t-hover) var(--ease-out), transform var(--t-fast) var(--ease-out);
  }
  .btn:hover { border-color: var(--coral); background: var(--depth); }
  .btn:active { transform: translateY(1px); }
  .btn-primary { background: var(--scarlet); border-color: var(--scarlet); color: var(--carbon); }
  .btn-primary:hover { background: var(--coral); border-color: var(--coral); }
  .btn-quiet { background: transparent; }
  .btn[disabled] { opacity: 0.5; pointer-events: none; }

  .icon-btn {
    width: 44px; height: 44px; display: inline-grid; place-items: center;
    border: 1px solid var(--rule); background: var(--smoke); color: var(--white);
    transition: border-color var(--t-hover) var(--ease-out);
  }
  .icon-btn:hover { border-color: var(--coral); }
  .icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

  .field {
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 40px; padding: 0 10px 0 12px;
    border: 1px solid var(--rule); background: var(--smoke); color: var(--white);
  }
  .field select, .field input {
    background: transparent; border: 0; outline: 0; color: var(--white);
    min-width: 0; height: 38px; font-size: 0.9375rem;
  }
  .field select { padding-right: 4px; cursor: pointer; }
  .field select option { background: var(--smoke); color: var(--white); }
  .field > span { color: var(--mineral); font-size: 0.8125rem; white-space: nowrap; }
  .field:focus-within { border-color: var(--mineral); }
  .field input::placeholder { color: rgb(203 180 172 / 0.62); opacity: 1; }

  .chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .chip {
    min-height: 36px; padding: 0 14px;
    border: 1px solid var(--rule-soft); color: var(--mineral);
    font-size: 0.875rem; font-weight: 500;
    transition: color var(--t-hover), border-color var(--t-hover), background-color var(--t-hover);
  }
  .chip:hover { color: var(--white); border-color: var(--rule); }
  .chip[aria-pressed='true'] { color: var(--carbon); background: var(--blush); border-color: var(--blush); font-weight: 600; }

  .toggle {
    display: inline-flex; align-items: center; gap: 10px; min-height: 40px; color: var(--mineral); font-size: 0.9375rem; cursor: pointer;
    padding: 0 4px;
  }
  .toggle input { appearance: none; width: 34px; height: 18px; border: 1px solid var(--rule); background: var(--smoke); position: relative; margin: 0; cursor: pointer; }
  .toggle input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 10px; height: 10px; background: var(--mineral); transition: transform var(--t-hover) var(--ease-out), background-color var(--t-hover); }
  .toggle input:checked { border-color: var(--scarlet); }
  .toggle input:checked::after { transform: translateX(16px); background: var(--scarlet); }
  .toggle:hover { color: var(--white); }

  /* Framed area with open corner brackets. */
  .frame { position: relative; }
  .frame::before, .frame::after, .frame > .bk::before, .frame > .bk::after {
    content: ''; position: absolute; width: var(--bk, 28px); height: var(--bk, 28px);
    border: 0 solid var(--mineral); pointer-events: none;
    transition: width var(--t-hover) var(--ease-out), height var(--t-hover) var(--ease-out), border-color var(--t-hover);
  }
  .frame::before { top: -1px; left: -1px; border-top-width: 1px; border-left-width: 1px; }
  .frame::after { top: -1px; right: -1px; border-top-width: 1px; border-right-width: 1px; }
  .frame > .bk::before { bottom: -1px; left: -1px; border-bottom-width: 1px; border-left-width: 1px; }
  .frame > .bk::after { bottom: -1px; right: -1px; border-bottom-width: 1px; border-right-width: 1px; }

  .rule-line { height: 1px; background: var(--rule-soft); }
  .rule-line.marked { position: relative; }
  .rule-line.marked::after { content: ''; position: absolute; right: 0; top: -2px; width: 5px; height: 5px; background: var(--mineral); }

  /* Rating control: five small squares. */
  .rating { display: inline-flex; align-items: center; gap: 14px; }
  .rating-squares { display: inline-flex; gap: 6px; }
  .rating-squares button {
    width: 30px; height: 30px; display: grid; place-items: center;
    color: var(--rule);
    transition: color var(--t-fast);
  }
  .rating-squares button::before {
    content: ''; width: 14px; height: 14px; border: 1px solid currentColor; transition: background-color var(--t-fast), transform var(--t-fast) var(--ease-out);
  }
  .rating-squares button.on { color: var(--scarlet); }
  .rating-squares button.on::before { background: currentColor; box-shadow: 0 0 10px rgb(255 59 59 / 0.5); }
  .rating-squares button.preview { color: var(--coral); }
  .rating-squares button.preview::before { background: currentColor; }
  .rating-squares button:active::before { transform: scale(0.85); }
  .rating-text { color: var(--mineral); font-size: 0.9375rem; }
  .rating-text strong { color: var(--white); font-weight: 600; }

  .note { color: var(--mineral); font-size: 0.9375rem; }
  .note.err { color: var(--coral); }
  .note.approx { padding: 10px 12px; border-left: 2px solid var(--coral); background: var(--smoke); font-size: 0.875rem; }

  .kbd { font-family: var(--mono); font-size: 0.75rem; padding: 1px 6px; border: 1px solid var(--rule); color: var(--mineral); }

  .data-table { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: var(--s5); row-gap: 7px; align-items: baseline; }
  .data-table dt { color: var(--mineral); font-size: 0.875rem; }
  .data-table dd { font-family: var(--mono); font-size: 0.8125rem; letter-spacing: 0.02em; font-feature-settings: 'tnum' 1, 'zero' 1; color: var(--white); text-align: right; white-space: normal; overflow-wrap: anywhere; }
  .data-table dd .unit { color: var(--mineral); display: inline-block; }
  .data-table dd .unit:only-child, .data-table dd .unit:not(:first-child) { display: block; margin-top: 2px; }
  .data-table dd.stable { color: var(--blush); }
  .data-table.stale { opacity: 0.45; }
  .stale-note { display: none; }
  .data-table.stale + .stale-note { display: block; }

  .range {
    appearance: none; width: 100%; height: 2px; background: var(--rule); margin: 0; cursor: pointer; flex: 1; min-width: 120px;
  }
  .range::-webkit-slider-runnable-track { height: 2px; background: transparent; }
  .range::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -6px; background: var(--scarlet); border: 0; box-shadow: 0 0 8px rgb(255 59 59 / 0.5); }
  .range::-moz-range-track { height: 2px; background: var(--rule); }
  .range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 0; background: var(--scarlet); border: 0; }
  .range:hover::-webkit-slider-thumb { background: var(--coral); }
  .range-field { gap: 12px; padding-right: 12px; }
  .range-field .kick-value { min-width: 5ch; text-align: right; color: var(--white); }
  .nudge .actions { align-items: center; }
  .nudge-status { font-size: 0.75rem; }

  .tag { display: inline-block; padding: 2px 8px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
  .tag.band { background: var(--scarlet); color: var(--carbon); }
  .tag.soft { background: var(--scarlet-band); color: var(--blush); }
}

/* =============================================================================
   Views
   ============================================================================= */
@layer views {
  /* ---- Hero ------------------------------------------------------------- */
  .hero {
    position: relative;
    padding: clamp(40px, 6vh, 80px) 0 clamp(48px, 7vh, 96px);
    min-height: calc(100dvh - var(--topbar-h));
    display: grid;
    align-items: center;
  }
  .hero .wrap {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: var(--s7) var(--s8);
    align-items: center;
  }
  /* The stage comes first in the DOM (so focus order matches the phone layout)
     and is placed in the second column on wide screens. */
  .hero-copy { display: grid; gap: var(--s5); max-width: 40rem; grid-column: 1; grid-row: 1; }
  .hero-copy .display { margin-bottom: var(--s2); }
  .hero-actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s2); }

  .hero-stage {
    position: relative;
    aspect-ratio: 1;
    width: min(100%, calc(100dvh - var(--topbar-h) - 220px), 760px);
    justify-self: end;
    grid-column: 2; grid-row: 1;
    --bk: 36px;
  }
  .hero-stage .stage { position: absolute; inset: 0; width: 100%; height: 100%; }
  .hero-stage .frame-line {
    position: absolute; left: -1px; top: -1px; height: 1px; width: 0; background: var(--mineral);
  }
  .hero-stage .seam {
    position: absolute; left: -1px; top: -1px; width: 7px; height: 7px; background: var(--scarlet);
    box-shadow: 0 0 12px 2px rgb(255 59 59 / 0.55);
    opacity: 0;
  }
  .hero-stage.assembled .seam { opacity: 1; transition: opacity var(--t-fast) ease-out; }
  .hero-stage.assembled .frame-line { width: calc(100% + 2px); transition: width var(--t-assemble) var(--ease-out) 80ms; }
  .hero-stage::before, .hero-stage::after, .hero-stage > .bk::before, .hero-stage > .bk::after { opacity: 0; }
  .hero-stage.assembled::before, .hero-stage.assembled::after, .hero-stage.assembled > .bk::before, .hero-stage.assembled > .bk::after {
    opacity: 1; transition: opacity var(--t-assemble) var(--ease-out) 260ms;
  }
  /* The final, nearly imperceptible adjustment. */
  .hero-stage.assembled > .bk::after { animation: settle 420ms var(--ease-in-out) 1200ms both; }
  @keyframes settle { 0% { width: var(--bk); } 50% { width: calc(var(--bk) + 3px); } 100% { width: var(--bk); } }

  .hero-caption {
    position: absolute; left: 0; right: 0; top: calc(100% + 14px);
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px;
    color: var(--mineral);
  }
  .hero-caption .name { color: var(--white); font-weight: 600; font-size: 0.9375rem; font-family: var(--sans); letter-spacing: 0; }
  .hero-caption a.open { margin-left: auto; color: var(--blush); font-family: var(--sans); font-weight: 560; font-size: 0.9375rem; letter-spacing: 0; }
  .hero-caption a.open:hover { color: var(--coral); }
  .hero-caption button { color: var(--mineral); font-family: var(--sans); font-size: 0.9375rem; letter-spacing: 0; }
  .hero-caption button:hover { color: var(--white); }

  /* A construction line that continues beyond the hero into the atlas. */
  .hero-rule {
    position: absolute; top: 0; bottom: 0; width: 1px; background: var(--rule-faint);
    left: calc(var(--margin) + (min(100vw - 2 * var(--margin), var(--max)) - 11 * var(--gutter)) / 12 * 5 + 5 * var(--gutter) - var(--s6));
    pointer-events: none;
  }

  @media (max-width: 1000px) {
    .hero { min-height: 0; padding-top: var(--s6); }
    .hero .wrap { grid-template-columns: 1fr; gap: var(--s7); }
    .hero-copy, .hero-stage { grid-column: 1; grid-row: auto; }
    .hero-stage { justify-self: center; width: min(100%, 70dvh, 560px); margin-bottom: 56px; --bk: 22px; }
    .hero-rule { display: none; }
    .hero-caption { gap: 4px 14px; font-size: 0.8125rem; }
    .hero-caption .name, .hero-caption a.open, .hero-caption button { font-size: 0.875rem; }
  }

  /* ---- Atlas map -------------------------------------------------------- */
  .atlas { padding-top: var(--s8); }
  .atlas-frame { scroll-margin-top: var(--topbar-h); }
  .atlas-head { display: grid; gap: var(--s4); margin-bottom: var(--s6); }
  .atlas-head .lede { max-width: 70ch; }
  .touch-only { display: none; }
  @media (hover: none) { .touch-only { display: inline; } .desktop-only { display: none; } }

  .atlas-frame {
    position: relative;
    width: 100%;
    height: calc(100dvh - var(--topbar-h));
    min-height: 520px;
    max-height: 1100px;
    background: var(--carbon);
    border-top: 1px solid var(--rule-soft);
    border-bottom: 1px solid var(--rule-soft);
    overflow: hidden;
  }
  .atlas-stage { position: absolute; inset: 0; }
  .atlas-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; outline-offset: -4px; }
  .atlas-canvas:active { cursor: grabbing; }
  @media (hover: hover) { .atlas-canvas { touch-action: none; } }
  .atlas-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
  .atlas-label {
    position: absolute; left: 0; top: 0; display: grid; justify-items: center; gap: 2px;
    text-align: center; white-space: nowrap; color: var(--white);
    font-stretch: 112%; font-weight: 720; letter-spacing: 0.06em; text-transform: uppercase; line-height: 1;
    text-shadow: 0 0 18px rgb(16 13 12), 0 0 6px rgb(16 13 12);
    will-change: transform, opacity;
  }
  .atlas-label[data-lod='far'] .small { display: none; }
  .atlas-label .small { font-family: var(--mono); font-size: 0.42em; font-weight: 400; font-stretch: 100%; letter-spacing: 0.04em; text-transform: none; color: var(--mineral); }
  .atlas-tip {
    position: absolute; left: 0; top: 0; z-index: 3; display: flex; gap: 12px; align-items: center; width: 300px;
    padding: 8px; background: color-mix(in srgb, var(--smoke) 92%, transparent); border: 1px solid var(--rule);
    color: var(--white); pointer-events: none; will-change: transform;
  }
  .atlas-tip img { width: 72px; height: 72px; flex: none; border: 1px solid var(--rule-faint); background: var(--carbon); }
  .atlas-tip .tip-text { display: grid; gap: 3px; min-width: 0; }
  .atlas-tip .name { font-weight: 600; font-size: 0.9375rem; }
  .atlas-tip .qual { color: var(--blush); font-size: 0.8125rem; }
  .atlas-tip .mono { color: var(--mineral); white-space: pre; font-size: 0.75rem; }

  .atlas-ui { position: absolute; inset: 0; pointer-events: none; }
  .atlas-ui > * { pointer-events: none; }
  .atlas-ui .ui-corner { position: absolute; display: grid; gap: 10px; }
  .atlas-ui .ui-corner > * { pointer-events: auto; }
  .atlas-ui .tl { left: var(--margin); top: var(--s5); width: min(360px, calc(100% - 2 * var(--margin))); }
  .atlas-ui .tr { right: var(--margin); top: var(--s5); }
  .atlas-ui .bl { left: var(--margin); bottom: var(--s5); justify-items: start; }
  .atlas-ui .br { right: var(--margin); bottom: var(--s5); justify-items: end; }
  .atlas-search { width: 100%; background: color-mix(in srgb, var(--smoke) 90%, transparent); }
  .atlas-search input { width: 100%; }
  .atlas-results {
    position: absolute; left: 0; right: 0; top: 46px; z-index: 4; display: grid;
    background: var(--smoke); border: 1px solid var(--rule); max-height: 60vh; overflow: auto;
  }
  .atlas-results li { display: grid; grid-template-columns: 40px 1fr; gap: 2px 12px; align-items: center; padding: 8px 10px; cursor: pointer; border-top: 1px solid var(--rule-faint); }
  .atlas-results li:first-child { border-top: 0; }
  .atlas-results li.active, .atlas-results li:hover { background: var(--depth); }
  .atlas-results img { grid-row: 1 / span 2; border: 1px solid var(--rule-faint); background: var(--carbon); }
  .atlas-results .r-name { font-weight: 600; font-size: 0.9375rem; }
  .atlas-results .r-qual { color: var(--blush); font-weight: 400; }
  .atlas-results .r-meta { color: var(--mineral); white-space: pre; }
  .atlas-random { background: color-mix(in srgb, var(--smoke) 90%, transparent); }
  .atlas-projections { display: flex; flex-wrap: wrap; gap: 4px 14px; }
  .atlas-word {
    color: var(--mineral); font-size: 0.9375rem; font-weight: 500; padding: 6px 0; position: relative;
    text-shadow: 0 0 12px rgb(16 13 12);
  }
  .atlas-word::after { content: ''; position: absolute; left: 0; right: 0; bottom: 2px; height: 2px; background: var(--scarlet); transform: scaleX(0); transform-origin: left; transition: transform var(--t-hover) var(--ease-out); }
  .atlas-word:hover { color: var(--white); }
  .atlas-word[aria-pressed='true'] { color: var(--white); }
  .atlas-word[aria-pressed='true']::after { transform: scaleX(1); }
  .zoom-buttons { display: flex; gap: 6px; }
  .zoom-buttons .icon-btn { width: 40px; height: 40px; font-size: 1.125rem; background: color-mix(in srgb, var(--smoke) 90%, transparent); }
  .atlas-minimap { width: 180px; height: 150px; border: 1px solid var(--rule); background: color-mix(in srgb, var(--carbon) 88%, transparent); cursor: crosshair; }
  .atlas-loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
  .atlas-status { min-height: 1.4em; padding: var(--s3) 0 0; color: var(--mineral); white-space: pre-wrap; }

  @media (max-width: 720px) {
    .atlas-frame { height: calc(100dvh - var(--topbar-h)); min-height: 480px; }
    /* Dark bands behind the controls so the map reads as continuing underneath. */
    .atlas-ui::before, .atlas-ui::after {
      content: ''; position: absolute; left: 0; right: 0; height: 120px; pointer-events: none;
      background: linear-gradient(to bottom, rgb(16 13 12 / 0.9), rgb(16 13 12 / 0));
    }
    .atlas-ui::before { top: 0; }
    .atlas-ui::after { bottom: 0; background: linear-gradient(to top, rgb(16 13 12 / 0.9), rgb(16 13 12 / 0)); }
    .atlas-ui .tl { width: calc(100% - 2 * var(--margin) - 150px); }
    .atlas-ui .bl { width: calc(100% - 2 * var(--margin) - 150px); }
    .atlas-ui .tr .btn { padding: 0 12px; min-height: 40px; font-size: 0.875rem; }
    .atlas-ui .bl { bottom: var(--s4); }
    .atlas-ui .br { bottom: var(--s4); }
    .atlas-minimap { display: none; }
    .atlas-projections { gap: 2px 12px; }
    .atlas-word { font-size: 0.875rem; }
    .atlas-label { letter-spacing: 0.04em; }
  }

  /* ---- Detail ----------------------------------------------------------- */
  .detail { padding-top: var(--s5); }
  .detail-bar { display: flex; align-items: center; gap: var(--s4); margin-bottom: var(--s5); color: var(--mineral); font-size: 0.9375rem; }
  .detail-bar .back { display: inline-flex; align-items: center; gap: 8px; color: var(--mineral); }
  .detail-bar .back:hover { color: var(--white); }
  .detail-bar .back svg { width: 16px; height: 16px; fill: currentColor; }
  .detail-bar .pos { margin-left: auto; font-family: var(--mono); font-size: 0.8125rem; letter-spacing: 0.02em; }
  .detail-bar .pager { display: inline-flex; gap: 6px; }

  .detail-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
    gap: var(--s7) var(--s8);
    align-items: start;
  }
  .stage-wrap { display: grid; gap: var(--s4); }
  .stage-frame {
    position: relative; aspect-ratio: 1; width: 100%;
    max-height: calc(100dvh - var(--topbar-h) - 140px);
    margin-inline: auto;
    border: 1px solid var(--rule-soft);
    --bk: 32px;
  }
  .stage-frame .stage { position: absolute; inset: 0; width: 100%; height: 100%; }
  .stage-frame .stage-poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
  .stage-frame .progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 100%; transform: scaleX(0); transform-origin: left center; background: var(--scarlet); box-shadow: 0 0 8px rgb(255 59 59 / 0.6); pointer-events: none; }
  .stage-frame .scrub {
    position: absolute; left: 0; right: 0; bottom: -10px; height: 20px; width: 100%; margin: 0;
    appearance: none; background: transparent; cursor: ew-resize; opacity: 0; transition: opacity var(--t-hover);
  }
  .stage-frame .scrub::-webkit-slider-runnable-track { height: 2px; background: transparent; }
  .stage-frame .scrub::-webkit-slider-thumb { appearance: none; width: 10px; height: 10px; margin-top: -4px; background: var(--white); border: 0; box-shadow: 0 0 8px rgb(255 244 240 / 0.7); }
  .stage-frame .scrub::-moz-range-track { height: 2px; background: transparent; }
  .stage-frame .scrub::-moz-range-thumb { width: 10px; height: 10px; border-radius: 0; background: var(--white); border: 0; }
  .stage-frame:hover .scrub, .stage-frame .scrub:focus-visible, .stage-frame .scrub:active { opacity: 1; }
  .stage-frame .scrub:focus-visible { outline-offset: 6px; }
  .stage-frame .live-tag {
    position: absolute; left: 14px; top: 12px; padding: 4px 8px;
    background: var(--scarlet); color: var(--carbon); font-weight: 600; letter-spacing: 0.04em;
  }
  .stage-frame .hint {
    position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
    padding: 6px 10px; background: color-mix(in srgb, var(--carbon) 80%, transparent);
    color: var(--mineral); font-size: 0.8125rem; white-space: nowrap; pointer-events: none;
    opacity: 0; transition: opacity var(--t-hover);
  }
  .stage-frame .hint.show { opacity: 1; }

  .controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
  .controls .time { font-family: var(--mono); font-size: 0.8125rem; letter-spacing: 0.02em; color: var(--mineral); font-feature-settings: 'tnum' 1; min-width: 12ch; }
  .controls .time strong { color: var(--white); font-weight: 500; }
  .controls .spacer { flex: 1; }
  .controls .icon-btn.playing svg.play { display: none; }
  .controls .icon-btn:not(.playing) svg.pause { display: none; }
  .controls .field { min-height: 40px; }
  .controls .field select { height: 36px; }

  /* The look row: colour scheme, line thickness and trail intensity. */
  .controls.look { margin-top: calc(-1 * var(--s2)); }
  .controls.look .range-field { flex: 1 1 200px; max-width: 320px; }
  .controls.look .range { min-width: 80px; }
  .range-field .range-value { min-width: 4.5ch; text-align: right; color: var(--white); font-size: 0.8125rem; }
  .linkish {
    min-height: 40px; padding: 0 4px; color: var(--mineral); font-size: 0.8125rem; text-decoration: underline; text-underline-offset: 3px;
  }
  .linkish:hover { color: var(--white); }

  .keys { display: flex; flex-wrap: wrap; gap: 8px 20px; color: var(--mineral); font-size: 0.8125rem; }
  @media (hover: none) { .keys { display: none; } }

  /* ---- Touch targets (44 px) ------------------------------------------------ */
  @media (hover: none) {
    .hero-caption a.open, .hero-caption button { padding: 12px 6px; margin: -12px -6px; }
    .nav a { padding: 12px 2px; }
    .atlas-word { padding: 12px 0; }
    .zoom-buttons .icon-btn { width: 44px; height: 44px; }
    .rating { flex-wrap: wrap; }
    .rating-squares { gap: 2px; }
    .rating-squares button { width: 40px; height: 40px; }
    .detail-bar .back { padding: 10px 0; }
    details.ic summary { padding: 10px 0; }
    .foot nav a { display: inline-block; padding: 10px 0; }
    .stage-frame .scrub { opacity: 1; height: 32px; bottom: -16px; }
    .stage-frame .scrub::-webkit-slider-thumb { width: 16px; height: 16px; margin-top: -7px; }
    .stage-frame .scrub::-moz-range-thumb { width: 16px; height: 16px; }
    .data-table dd, .controls .time { font-size: 0.875rem; }
    .related .cap, .nudge-status { font-size: 0.8125rem; }
    .rating-squares button { color: #8a5f57; }
  }
  .panel { display: grid; gap: var(--s5); position: sticky; top: calc(var(--topbar-h) + var(--s5)); min-width: 0; }
  .stage-wrap { min-width: 0; }
  .panel section, .panel details, .panel pre { min-width: 0; max-width: 100%; }
  .panel-head { display: grid; gap: 6px; }
  .panel-head .family { color: var(--mineral); font-size: 0.9375rem; }
  .panel-head .name { font-stretch: 106%; font-weight: 660; font-size: clamp(1.75rem, 2.4vw, 2.5rem); line-height: 1.04; letter-spacing: -0.01em; }
  .panel-head .qual { color: var(--blush); font-family: var(--mono); font-size: 0.875rem; }
  .panel-head .source { color: var(--mineral); font-size: 0.875rem; line-height: 1.4; }
  .panel-head .source a { color: var(--mineral); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 0.18em; }
  .panel-head .source a:hover { color: var(--white); }
  .panel .blurb { color: var(--mineral); font-size: 0.9375rem; line-height: 1.5; }

  .panel section { display: grid; gap: var(--s3); padding-top: var(--s5); border-top: 1px solid var(--rule-soft); }
  .panel section h3 { font-size: 0.875rem; font-weight: 600; color: var(--white); letter-spacing: 0.01em; }
  .panel .rank { color: var(--mineral); font-size: 0.9375rem; }
  .panel .rank strong { color: var(--white); }
  .panel .actions { display: flex; flex-wrap: wrap; gap: var(--s2); }

  details.ic summary { cursor: pointer; color: var(--mineral); font-size: 0.9375rem; list-style: none; display: flex; align-items: center; gap: 10px; }
  details.ic summary::-webkit-details-marker { display: none; }
  details.ic summary::before { content: ''; width: 6px; height: 6px; background: var(--mineral); transition: transform var(--t-hover); }
  details.ic[open] summary::before { transform: rotate(45deg); }
  details.ic summary:hover { color: var(--white); }
  details.ic pre { margin: var(--s3) 0 0; padding: var(--s3) var(--s4); background: var(--smoke); border: 1px solid var(--rule-faint); font-family: var(--mono); font-size: 0.75rem; line-height: 1.5; overflow-x: auto; color: var(--mineral); }
  details.ic pre b { color: var(--white); font-weight: 500; }

  .related { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .related a { display: block; border: 1px solid var(--rule-faint); background: var(--carbon); transition: border-color var(--t-hover); }
  .related a:hover { border-color: var(--coral); }
  .related img { width: 100%; aspect-ratio: 1; object-fit: cover; }
  .related .cap { padding: 6px 6px 8px; font-size: 0.75rem; color: var(--mineral); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  @media (max-width: 1000px) {
    .detail-body { grid-template-columns: 1fr; gap: var(--s6); }
    .stage-frame { max-height: none; width: min(100%, calc(100dvh - var(--topbar-h) - 120px)); }
    .panel { position: static; }
    .stage-frame { --bk: 22px; }
  }
  @media (max-width: 1000px) and (max-height: 520px) {
    /* Landscape phone: keep the stage beside the panel instead of a screen-tall square. */
    .detail-body { grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); gap: var(--s5); }
    .stage-frame { width: min(100%, calc(100dvh - var(--topbar-h) - 40px)); }
  }
  @media (max-height: 520px) {
    .atlas-frame { min-height: 0; height: calc(100dvh - var(--topbar-h)); }
    .atlas-minimap { display: none; }
  }

  /* ---- Battle ------------------------------------------------------------ */
  .battle { padding-top: var(--s7); }
  .duel-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: var(--s5); align-items: center; }
  .duel { display: grid; gap: var(--s3); min-width: 0; transition: opacity var(--t-hover); }
  .duel-frame { position: relative; aspect-ratio: 1; width: 100%; max-height: calc(100dvh - var(--topbar-h) - 220px); margin-inline: auto; border: 1px solid var(--rule-soft); --bk: 24px; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
  .duel-frame .stage { position: absolute; inset: 0; width: 100%; height: 100%; }
  .duel.won .duel-frame { border-color: var(--scarlet); box-shadow: 0 0 28px rgb(255 59 59 / 0.35); }
  .duel.lost { opacity: 0.4; }
  .duel-meta { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
  .duel-meta .who { display: grid; gap: 2px; min-width: 0; }
  .duel-meta .name { color: var(--white); font-weight: 600; }
  .duel-meta .fam { font-size: 0.875rem; color: var(--mineral); }
  .duel-or { color: var(--mineral); font-size: 0.875rem; }
  .duel-actions { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; margin-top: var(--s6); }
  .duel-status { margin-left: auto; color: var(--mineral); font-size: 0.8125rem; }
  .duel-note { margin-top: var(--s4); }
  .board-tabs { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center; }
  .board-cta { margin-left: auto; }
  .battle-line { margin-top: 2px; }
  @media (max-width: 720px) {
    .duel-grid { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
    .duel-or { display: none; }
    .duel-frame { max-height: 60dvh; }
    .board-cta { margin-left: 0; }
  }

  /* ---- Leaderboard ------------------------------------------------------ */
  .board { padding-top: var(--s7); }
  .board-head { display: grid; gap: var(--s4); margin-bottom: var(--s7); max-width: 60rem; }
  .board-list { display: grid; gap: 2px; grid-template-columns: minmax(0, 1fr); }
  .board-list > li { min-width: 0; }
  .board-row {
    display: grid; grid-template-columns: 56px 96px minmax(0, 1fr) minmax(120px, 220px) 110px;
    align-items: center; gap: var(--s4);
    padding: 10px 12px 10px 0;
    border-top: 1px solid var(--rule-faint);
    color: var(--mineral);
    transition: background-color var(--t-hover);
  }
  .board-row:hover { background: var(--smoke); }
  .board-row .rank { font-family: var(--mono); font-size: 0.875rem; text-align: center; color: var(--white); }
  .board-row:first-child { border-top-color: var(--rule-soft); }
  .board-row.top .rank { background: var(--scarlet); color: var(--carbon); font-weight: 600; padding: 4px 0; }
  .board-row img { width: 96px; aspect-ratio: 1; border: 1px solid var(--rule-faint); }
  .board-row .who { display: grid; gap: 2px; min-width: 0; }
  .board-row .who .name { color: var(--white); font-weight: 600; font-size: 1.0625rem; }
  .board-row .who .fam { font-size: 0.875rem; }
  .board-row .bar { height: 6px; background: var(--depth); position: relative; }
  .board-row .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--scarlet); box-shadow: 0 0 8px rgb(255 59 59 / 0.5); }
  .board-row .score { font-family: var(--mono); font-size: 0.8125rem; text-align: right; }
  .board-row .score strong { color: var(--white); font-weight: 500; font-size: 1rem; }
  .board-empty { padding: var(--s7) 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); color: var(--mineral); }
  .board-empty p { max-width: 60ch; }
  .board-empty .related { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-width: 1000px; min-width: 0; }
  @media (max-width: 720px) {
    .board-row { grid-template-columns: 40px 64px minmax(0, 1fr) 80px; }
    .board-row .bar { display: none; }
    .board-row img { width: 64px; }
  }
  @media (max-width: 480px) {
    .board-row { grid-template-columns: 28px 56px minmax(0, 1fr) 72px; gap: 10px; padding-right: 0; }
    .board-row img { width: 56px; }
    .board-row .who .name { font-size: 0.9375rem; }
  }

  /* ---- About ------------------------------------------------------------ */
  .about { padding-top: var(--s7); display: grid; gap: var(--s8); }
  .about .intro { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--s7) var(--s8); align-items: end; }
  .about .intro .quiet { align-self: end; }
  .prose { max-width: var(--measure); display: grid; gap: var(--s4); color: var(--mineral); font-size: 1.0625rem; line-height: 1.6; }
  .prose h2 { color: var(--white); }
  .prose h3 { color: var(--white); font-size: 1.125rem; font-weight: 600; margin-top: var(--s3); }
  .prose strong { color: var(--white); font-weight: 560; }
  .prose ol { list-style: decimal; padding-left: 1.4em; display: grid; gap: 6px; }
  .prose ul { display: grid; gap: 8px; }
  .prose li { padding-left: 0; }
  .prose .cite { display: grid; gap: 2px; padding-left: 16px; border-left: 1px solid var(--rule); }
  .prose .cite .t { color: var(--white); }
  .prose .cite .v { font-size: 0.9375rem; }
  .about-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s7) var(--s8); align-items: start; }
  .method-figure { display: grid; gap: 8px; }
  .method-figure .row { display: grid; grid-template-columns: 1fr auto; gap: var(--s4); align-items: baseline; padding: 8px 0; border-top: 1px solid var(--rule-faint); color: var(--mineral); font-size: 0.9375rem; }
  .method-figure .row .v { font-family: var(--mono); font-size: 0.8125rem; color: var(--white); }
  @media (max-width: 900px) { .about .intro { grid-template-columns: 1fr; } }

  /* ---- Families: the index and one family's page ------------------------ */
  .family-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .family-card { display: grid; align-content: start; border: 1px solid var(--rule-faint); background: var(--carbon); color: var(--mineral); transition: border-color var(--t-hover); }
  .family-card:hover { border-color: var(--coral); }
  .family-card img { width: 100%; aspect-ratio: 1; object-fit: cover; }
  .family-card .cap { display: grid; gap: 2px; padding: 8px 8px 10px; font-size: 0.8125rem; line-height: 1.3; }
  .family-card .cap strong { color: var(--white); font-weight: 600; }
  .family-card .cap .mono { font-size: 0.75rem; }
  .family-card .blurb { padding: 0 8px 10px; font-size: 0.8125rem; line-height: 1.4; }
  .families-page, .family-page { padding: var(--s7) 0 var(--s9); }
  .families-page .wrap, .family-page .wrap { display: grid; gap: var(--s6); }
  .families-page .prose .lede, .family-page .prose .lede { max-width: 70ch; }
  .family-group { display: grid; gap: var(--s4); }
  .family-group h2, .family-page h2 { font-size: 1.25rem; font-weight: 600; color: var(--white); }
  .family-head .prose { display: grid; gap: var(--s3); max-width: 78ch; }
  .family-head .family { color: var(--mineral); font-size: 0.875rem; }
  .family-head .family a { color: var(--blush); }
  .orbit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .orbit-card { display: grid; align-content: start; border: 1px solid var(--rule-faint); background: var(--carbon); color: var(--mineral); transition: border-color var(--t-hover); }
  .orbit-card:hover { border-color: var(--coral); }
  .orbit-card img { width: 100%; aspect-ratio: 1; object-fit: cover; }
  .orbit-card .cap { padding: 8px 8px 0; font-size: 0.8125rem; color: var(--white); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .orbit-card .qual { color: var(--mineral); }
  .orbit-card .meta { padding: 2px 8px 10px; font-size: 0.75rem; }
  .orbit-card .stable { color: var(--blush); }
  .prerender-note { color: var(--mineral); font-size: 0.875rem; }

  /* ---- Not found / loading --------------------------------------------- */
  .status { padding: var(--s9) 0; display: grid; gap: var(--s4); max-width: 50ch; color: var(--mineral); }
  .loading { padding: var(--s8) 0; color: var(--mineral); display: flex; align-items: center; gap: 12px; }
  .loading::before { content: ''; width: 8px; height: 8px; background: var(--scarlet); animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
}

/* =============================================================================
   Motion and utilities
   ============================================================================= */
@layer utilities {
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: 260ms; }
  ::view-transition-group(*) { animation-duration: 420ms; animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1); }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  }
}
