/* Warming World — "Gray Card" (ART.md). Every chrome token is an exact gray (OKLCh chroma 0), so a hue
   on screen is always a departure from 1951–1980. One face, Archivo, one variable file. No shadow,
   blur, glow or gradient in the chrome. tools/check.mjs asserts the grays' chroma. */

@font-face {
  font-family: Archivo;
  src: url(fonts/archivo-ww.woff2) format('woff2');
  font-weight: 400 700;
  font-stretch: 87.5% 100%;
  font-display: block;
}

:root {
  --page: #f5f5f5;
  --card: #bebebe;
  --sheet: #f5f5f5;
  --ink: #161616;
  --ink-2: #4f4f4f;
  --ink-3: #666666;
  --card-ink: #121212;
  --card-ink-2: #333333;
  --line: #d9d9d9;
  --line-strong: #8a8a8a;
  --turn: cubic-bezier(0.45, 0, 0.2, 1);
  --settle: cubic-bezier(0.2, 0, 0, 1);
  --gutter: 16px;
  /* the side gutters: never under the sensor housing in landscape (viewport-fit=cover) */
  --gl: max(var(--gutter), env(safe-area-inset-left));
  --gr: max(var(--gutter), env(safe-area-inset-right));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #1f1f1f;
    --card: #303030;
    --sheet: #262626;
    --ink: #ededed;
    --ink-2: #ababab;
    --ink-3: #8e8e8e;
    --card-ink: #f0f0f0;
    --card-ink-2: #c4c4c4;
    --line: #393939;
    --line-strong: #6b6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--ink); overflow: hidden; }
body {
  font: 400 12px/1.4 Archivo, system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums lining-nums;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.panel :focus-visible { outline-color: var(--card-ink); }

/* ── the screen (DESIGN §3): one column, the page never scrolls ── */
.app {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: calc(44px + env(safe-area-inset-top)) minmax(0, 1fr) 56px 64px calc(48px + env(safe-area-inset-bottom));
  grid-template-areas: "top" "panel" "year" "track" "controls";
}

.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; padding: env(safe-area-inset-top) var(--gr) 0 var(--gl); }
.name { margin: 0; font-size: 14px; font-weight: 650; font-stretch: 87.5%; letter-spacing: 0.005em; }
.top-r { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stamp { position: relative; min-height: 44px; display: flex; align-items: center; padding: 0 2px; font-size: 10.5px; line-height: 1.3; font-stretch: 87.5%; white-space: nowrap; color: var(--ink-2); min-width: 0; }
.textkey { position: relative; font-size: 12px; font-stretch: 87.5%; min-height: 44px; min-width: 44px; padding: 0 2px; color: var(--ink-2); }
.iconkey { width: 44px; height: 44px; display: inline-grid; place-items: center; }
.iconkey svg { display: block; }

/* ── the Earth panel: the gray card in both themes ── */
.panel { grid-area: panel; position: relative; overflow: hidden; background: var(--card); color: var(--card-ink); }
.earth { position: absolute; inset: 0; touch-action: none; }
.earth canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.strip { position: absolute; left: 0; right: 0; top: 0; height: 44px; padding: 0 var(--gr) 0 var(--gl); display: flex; align-items: center; justify-content: space-between; pointer-events: none; z-index: 2;
  background: var(--card); }   /* its own ground (review R-2): a zoomed Earth passes under it, never through its keys */
.strip > * { pointer-events: auto; }
.keys { display: flex; align-items: center; gap: 8px; }
.panel .textkey { color: var(--card-ink-2); }
.pole { position: relative; }
.pole-g { display: none; }
.pole[aria-pressed="true"] { color: var(--card-ink); font-weight: 650; }
.pole[aria-pressed="true"]::after { content: ''; position: absolute; left: 2px; right: 2px; bottom: 9px; height: 2px; background: currentColor; }

/* the underline switch (ART "Designed objects"): no box, a base rule, the chosen option's stretch of
   the rule thickened to 2 px of ink */
.seg { position: relative; display: inline-flex; gap: 14px; border-bottom: 1px solid var(--line-strong); font-size: 12px; font-stretch: 87.5%; }
.panel .seg { border-bottom-color: color-mix(in srgb, currentColor 35%, transparent); }
.seg button { position: relative; height: 32px; min-width: 30px; padding: 0; color: var(--ink-2); white-space: nowrap; }
.panel .seg button { color: var(--card-ink-2); }
.seg button::before { content: ''; position: absolute; left: -7px; right: -7px; top: -6px; bottom: -6px; }
.seg button[aria-checked="true"] { color: var(--ink); font-weight: 650; }
.panel .seg button[aria-checked="true"] { color: var(--card-ink); }
.seg .mark { position: absolute; bottom: -1px; left: 0; height: 2px; width: 1px; background: currentColor; transform: scaleX(0); transform-origin: 0 0; transition: transform 140ms var(--settle); pointer-events: none; }
.seg button:focus-visible { outline-offset: 1px; }

/* notices (ART): one line on a sheet chip, never amber or red */
.chips { position: absolute; left: 0; right: 0; top: 48px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 var(--gr) 0 var(--gl); z-index: 3; pointer-events: none; }
.notices { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 100%; }
.chip { margin: 0; max-width: 100%; background: var(--sheet); color: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 5px 9px; font-size: 12px; font-stretch: 87.5%; line-height: 1.35; text-align: center; }
.notice { max-width: 100%; background: var(--sheet); color: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 5px 9px; font-size: 12px; font-stretch: 87.5%; line-height: 1.35; text-align: center; opacity: 0; transition: opacity 200ms linear; }
.notice.in { opacity: 1; transition-duration: 160ms; }

.error { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); width: min(300px, calc(100% - 32px)); margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--card-ink); text-align: center; z-index: 2; }

/* the legend: the panel's foot, the printed ±4 °C scale */
.legend { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px var(--gr) 5px var(--gl); background: var(--card); z-index: 2; }
.legend canvas { display: block; width: 100%; height: 30px; }
.legend p, .legend-caption { margin: 0; font-size: 10.5px; line-height: 1.3; font-stretch: 87.5%; color: var(--card-ink-2); }
.legend-caption { display: block; width: 100%; text-align: left; position: relative; cursor: help; }
.legend-caption::before { content: ''; position: absolute; left: 0; right: 0; top: -25px; bottom: -6px; }
/* plan 0012 3.3: Difference | Absolute and the baseline key, the legend's first row (hidden in focus mode) */
.lg-row { display: flex; align-items: center; justify-content: space-between; height: 40px; margin: -3px 0 -1px; }
.lg-row .seg button { height: 28px; }
.lg-row .seg button::before { top: -8px; bottom: -8px; }
.lg-row .textkey { min-height: 40px; }
.lg-row .textkey::after { content: ''; position: absolute; left: 0; right: 0; top: -2px; bottom: -2px; }
.focus .lg-row { display: none; }
.basecard .c-head { margin-bottom: 0; }
#base-title { font-size: 11.5px; color: var(--ink-2); min-width: 0; }
/* plan 0012 D22: four presets (a radio group in the underline switch's dress) and a two-thumb year slider */
.basecard .seg { display: flex; justify-content: space-between; gap: 6px; margin-top: 2px; border-bottom-color: var(--line-strong); }
.basecard .seg button { color: var(--ink-2); }
.basecard .seg button[aria-checked="true"] { color: var(--ink); }
.b-span { margin-top: 10px !important; font-size: 20px; line-height: 24px; font-weight: 600; font-stretch: 87.5%; }
.b-slider { position: relative; height: 44px; margin: -4px 0 0; touch-action: none; --p0: 0; --p1: 1; --w: calc(100% - 22px); }
.b-slider::before, .b-run { content: ''; position: absolute; top: 21px; height: 2px; pointer-events: none; }
.b-slider::before { left: 11px; right: 11px; background: var(--line-strong); }
.b-run { left: calc(11px + var(--p0) * var(--w)); width: calc((var(--p1) - var(--p0)) * var(--w)); top: 20px; height: 4px; background: var(--ink); }
.b-thumb { position: absolute; top: 0; left: calc(var(--p) * var(--w) - 11px); width: 44px; height: 44px; margin: 0; opacity: 0; pointer-events: none; }
#b0, #b0 + .b-dot { --p: var(--p0); } #b1, #b1 + .b-dot { --p: var(--p1); }
.b-dot { position: absolute; top: 13px; left: calc(var(--p) * var(--w) + 2px); width: 18px; height: 18px; border-radius: 50%; background: var(--ink); border: 2px solid var(--sheet); pointer-events: none; }
.b-thumb:focus-visible + .b-dot { outline: 2px solid var(--ink); outline-offset: 2px; }
.b-ends { display: flex; justify-content: space-between; margin: -8px 0 0 !important; font-size: 10.5px; line-height: 14px; color: var(--ink-3); }

/* the tap card (DESIGN §8, ART): paper with a hairline edge; no shadow, no blur */
.tapcard { position: absolute; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: var(--card-bottom, 52px); max-height: calc(100% - 52px - var(--card-bottom, 52px)); overflow: auto; overscroll-behavior: contain; z-index: 4;
  background: var(--sheet); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 3px; padding: 6px 12px 8px;
  opacity: 0; transform: translateY(6px); transition: opacity 120ms var(--settle), transform 160ms var(--settle); }
.tapcard.in { opacity: 1; transform: none; transition-duration: 160ms; }
.tapcard p { margin: 0; }
.c-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -10px 0 0; }
#c-place { font-size: 11.5px; color: var(--ink-2); min-width: 0; }
.c-val { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 7px; margin-top: -6px !important; }
#c-value { font-size: 22px; line-height: 1.15; font-weight: 600; font-stretch: 87.5%; white-space: nowrap; }
#c-when { font-size: 12px; color: var(--ink); }
.none #c-when { font-size: 13.5px; padding: 4px 0 0; }
.c-note { font-size: 12px; color: var(--ink-2); }
#c-chart, #c-months { display: block; width: 100%; margin-top: 6px; touch-action: manipulation; }
#c-chart { height: 124px; cursor: ew-resize; touch-action: pan-y; }
#c-months { height: 40px; }
.c-foot { font-size: 10.5px; line-height: 1.3; color: var(--ink-3); margin-top: 4px !important; }

/* the ghost key that brings the controls back (focus mode, DESIGN §10) */
.iconkey.ghost { position: absolute; top: 4px; right: max(4px, env(safe-area-inset-right)); z-index: 5; opacity: 0.72; transition: opacity 160ms var(--settle); }
.ghost:hover, .ghost:focus-visible, .ghost:active { opacity: 1; }

/* ── the year row ── */
.yearrow { grid-area: year; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 var(--gr) 0 var(--gl); min-width: 0; }
.yr { flex: none; }
.yr-figure { position: relative; font-size: 28px; line-height: 1; font-weight: 600; font-stretch: 87.5%; letter-spacing: -0.01em; white-space: nowrap; }
.yr-figure.rolling #year { color: transparent; }
.roll { position: absolute; left: 0; top: 0; overflow: hidden; display: inline-flex; }
.roll span { display: inline-block; }
.roll span.in { animation: roll-in 90ms var(--settle); }
@keyframes roll-in { from { transform: translateY(0.55em); opacity: 0; } }
.yr-sub { font-size: 11px; color: var(--ink-2); margin-top: 3px; }
.yr-sub:empty { display: none; }
.read { min-width: 0; text-align: right; font-size: 12px; line-height: 1.4; color: var(--ink-2); }
.read b { color: var(--ink); font-weight: 600; }

/* ── the stripes track (ART's signature control) ── */
.track { grid-area: track; position: relative; padding: 0 var(--gr) 0 var(--gl); }
.track canvas { display: block; width: 100%; height: 64px; }
.track-hit { position: absolute; left: 0; right: 0; top: -8px; bottom: -8px; touch-action: none; cursor: ew-resize; z-index: 1; }
.track-hit:focus-visible { outline-offset: -4px; }

/* ── the controls row ── */
.controls { grid-area: controls; position: relative; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; padding: 2px max(10px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left)); }
.transport { display: flex; align-items: center; }
.controls .seg { margin-top: 6px; }
.focus-name { margin-top: 13px; font-size: 20px; line-height: 1; font-weight: 600; font-stretch: 87.5%; letter-spacing: -0.005em; white-space: nowrap; color: var(--ink); overflow: hidden; text-overflow: clip; }
#play .i-pause { display: none; }
#play.playing .i-play { display: none; }
#play.playing .i-pause { display: inline; }
.controls button:disabled, .panel button:disabled { opacity: 0.4; cursor: default; }
.side-legend:empty { display: none; }

/* About (DESIGN §3.6, ART): a full-height sheet; sentence-case heads, prose within 62 ch, no links */
.about { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: var(--sheet); color: var(--ink); padding-top: env(safe-area-inset-top); }
.ab-head { flex: none; display: flex; align-items: center; justify-content: space-between; height: 44px; padding: 0 max(6px, env(safe-area-inset-right)) 0 var(--gl); border-bottom: 1px solid var(--line); }
.ab-head h2 { margin: 0; font-size: 14px; font-weight: 650; font-stretch: 87.5%; }
.ab-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px var(--gr) calc(24px + env(safe-area-inset-bottom)) var(--gl); font-size: 13.5px; line-height: 1.45; }
.ab-body:focus { outline: none; }
.ab-body > * { max-width: 62ch; }
.ab-body section { border-top: 1px solid var(--line); padding: 4px 0 8px; }
.ab-body h3 { margin: 10px 0 4px; font-size: 14px; font-weight: 600; }
.ab-body h4 { margin: 10px 0 2px; font-size: 12px; font-weight: 600; line-height: 1.4; }
.ab-body p { margin: 0 0 8px; }
.ab-credit { font-size: 12px; color: var(--ink-2); margin: 10px 0 12px !important; }
.ab-label { font-weight: 600; }
.ab-src p, .ab-copy p { margin: 0 0 2px; font-size: 12px; line-height: 1.4; color: var(--ink-2); }
.ab-src p.ab-cite { color: var(--ink); }
.ab-src p.ab-addr { overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.ab-endorse { margin-top: 12px !important; }
.ab-copy { margin-top: 6px; }
.ab-ver { display: block; min-height: 44px; font-size: 12px; color: var(--ink-2); text-align: left; }
.perf { position: fixed; left: max(8px, env(safe-area-inset-left)); top: calc(48px + env(safe-area-inset-top)); z-index: 30; margin: 0; padding: 3px 6px; background: var(--sheet); color: var(--ink); border: 1px solid var(--line); border-radius: 3px; font-size: 10.5px; font-stretch: 87.5%; pointer-events: none; }

/* focus mode (DESIGN §10): the Earth, the stripes track with its keys, the step's name */
.app.focus { grid-template-columns: minmax(0, 1fr); grid-template-rows: env(safe-area-inset-top) minmax(0, 1fr) 0 64px calc(48px + env(safe-area-inset-bottom)); grid-template-areas: "top" "panel" "year" "track" "controls"; }
.focus .notice:not([data-id="restore"]), .focus #pole-read { display: none; }

/* pressed and hover (QA pass; ART "Designed objects", §20 Q-3): grays only — the plate is the key's own
   ink (a gray token) mixed with transparency, so no hue, no shadow, no glow, no scale. A press lays a
   plate of ink at 14 % behind the key (inside the play key's ring, the ring fills) — .down, set by pointer
   events in app.js, or :active from the keyboard; a hovering pointer
   (never a touch: (hover: hover)) brings a text key to full ink, or lays a 7 % plate behind an icon
   key. :focus-visible stays the 2 px ring, a different mark from either. The ghost key keeps its
   opacity rule: a plate would cover the data under it. */
.textkey::before, .stamp::before, .iconkey:not(.ghost):not(#play)::before, .seg button::after, .legend-caption::after, .ab-ver::before {
  content: ''; position: absolute; z-index: -1; border-radius: 3px; pointer-events: none; }
.textkey, .stamp, .iconkey, .seg button, .legend-caption, .ab-ver { position: relative; isolation: isolate; }
.textkey::before, .stamp::before { inset: 7px -3px; }
.iconkey::before { inset: 6px; }
.seg button::after { inset: 2px -6px 1px; }
.legend-caption::after { inset: -1px -4px; }
.ab-ver::before { inset: 6px -6px; }
.textkey:is(:active, .down):not(:disabled)::before, .stamp:is(:active, .down)::before, .iconkey:is(:active, .down):not(:disabled)::before, .seg button:is(:active, .down):not(:disabled)::after, .legend-caption:is(:active, .down)::after, .ab-ver:is(:active, .down)::before { background: color-mix(in srgb, currentColor 14%, transparent); }
.textkey:is(:active, .down):not(:disabled), .stamp:is(:active, .down), .legend-caption:is(:active, .down), .ab-ver:is(:active, .down), .seg button:is(:active, .down):not(:disabled) { color: var(--ink); }
.panel .textkey:is(:active, .down):not(:disabled), .panel .seg button:is(:active, .down):not(:disabled), .legend-caption:is(:active, .down) { color: var(--card-ink); }
#play circle { fill: transparent; }
#play:is(:active, .down):not(:disabled) circle { fill: color-mix(in srgb, currentColor 14%, transparent); }
@media (hover: hover) {
  .textkey:hover:not(:disabled), .stamp:hover, .ab-ver:hover, .seg button:hover:not(:disabled) { color: var(--ink); }
  .panel .textkey:hover:not(:disabled), .panel .seg button:hover:not(:disabled), .legend-caption:hover { color: var(--card-ink); }
  .iconkey:hover:not(:disabled):not(:active):not(.down)::before { background: color-mix(in srgb, currentColor 7%, transparent); }
  #play:hover:not(:disabled):not(:active):not(.down) circle { fill: color-mix(in srgb, currentColor 7%, transparent); }
}

@media (max-width: 359px) {
  :root { --gutter: 8px; }
  .seg { font-size: 10.5px; gap: 10px; }
  .pole-w { display: none; }
  .pole-g { display: block; }
  .pole[aria-pressed="true"]::after { left: 12px; right: 12px; bottom: 8px; }
  .focus-name { font-size: 16px; margin-top: 15px; }
  #stamp-2 { display: none; }
}

/* wide screens and landscape (DESIGN §3.8): the Earth on the left, everything else on the right */
@media (min-width: 700px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: calc(44px + env(safe-area-inset-top)) minmax(0, 1fr) auto 56px 64px 48px minmax(0, 1fr);
    grid-template-areas: "top top" "panel ." "panel legend" "panel year" "panel track" "panel controls" "panel .";
  }
  /* the last row never less than the bottom inset, so a docked card's foot stays above the home indicator */
  .app:not(.focus) { grid-template-rows: calc(44px + env(safe-area-inset-top)) minmax(0, 1fr) auto 56px 64px 48px auto minmax(env(safe-area-inset-bottom), 1fr); grid-template-areas: "top top" "panel ." "panel legend" "panel year" "panel track" "panel controls" "panel card" "panel ."; }
  .app:not(.focus) .yearrow, .app:not(.focus) .track, .app:not(.focus) .side-legend .legend { padding-left: var(--gutter); }
  .app:not(.focus) .controls { padding-left: 6px; }
  .app:not(.focus) .strip, .app:not(.focus) .chips { padding-right: var(--gutter); }
  .side-legend { grid-area: legend; padding-bottom: 10px; }
  .side-legend .legend { position: static; background: none; }
  .carded .side-legend { display: none; }
  .controls { padding-bottom: 0; }
  .app > .tapcard { position: relative; grid-area: card; left: auto; right: auto; bottom: auto; margin: 8px var(--gr) 0 var(--gutter);
    max-height: calc(100vh - 44px - 176px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); max-height: calc(100dvh - 44px - 176px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .seg .mark, .notice, .tapcard, .ghost { transition: none; }
  .tapcard { transform: none; }
  .roll span.in { animation: none; }
}
