/* ---------- Tokens ----------
   One card style, one body font (Nunito), Bungee for headings, VT323 only for
   the three big numbers. Light is the default theme; dark is opt-in.          */

:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #efece4;
  --border: #e1dccf;
  --border-strong: #cbc4b2;
  --text: #17181a;
  --muted: #55534e;
  --soft: #6b6862;

  --accent: #c8102e;          /* red: links, meters, the main series */
  --sign-paper: #fffdf3;
  --tape: #17181a;
  --series-1: #c8102e;
  --series-2: #8b9098;
  --series-3: #c25400;
  --grid: #e7e2d6;
  --meter: #c8102e;
  --tip: #ffffff;
  --mark-bg: #fff0a6;
  --mark-ink: #17181a;

  --i-red: #c8102e;
  --i-yellow: #8f6a00;
  --i-orange: #b84f00;
  --i-green: #0f7b45;
  --i-blue: #005fae;
  --i-purple: #6d3f98;

  --c-red: #c8102e;
  --c-orange: #ff7900;
  --c-yellow: #ffd100;
  --c-green: #008651;
  --c-blue: #0072ce;
  --c-purple: #6d3f98;
  --tile-off: #e6e2d8;
  --tile-off-ink: #6b6862;

  --red: #c8102e;
  --yellow: #ffd100;
  --black: #17181a;
  --white: #ffffff;

  --radius: 16px;
  --display: Bungee, Impact, sans-serif;
  --crt: VT323, "Courier New", monospace;
  --body: Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #111214;
  --surface: #1b1d21;
  --surface-2: #26292e;
  --border: #33363c;
  --border-strong: #24262b;
  --text: #f4f4f5;
  --muted: #bfc2c8;
  --soft: #a3a7ae;
  --accent: #ffd100;
  --tape: #111214;
  --series-1: #ffd100;
  --series-2: #8b9098;
  --series-3: #ff9a3d;
  --grid: #2f3237;
  --meter: #ffd100;
  --tip: #0b0c0e;
  --mark-bg: transparent;
  --mark-ink: #ffd100;
  --i-red: #ff6b7d;
  --i-yellow: #ffd100;
  --i-orange: #ff9a3d;
  --i-green: #3ecf7a;
  --i-blue: #5aa9ff;
  --i-purple: #c29cff;
  --tile-off: #2a2c31;
  --tile-off-ink: #8b9098;
  color-scheme: dark;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 600 1rem/1.55 var(--body);
}
main { max-width: 64rem; margin: 0 auto; padding: 1.5rem 1rem 3.5rem; }
section { margin-top: 3rem; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
h2 { font: 400 1.4rem/1.15 var(--display); text-transform: uppercase; letter-spacing: .01em; }
h3 { font: 900 1.05rem/1.25 var(--body); }
b, strong { font-weight: 800; }
a { color: var(--accent); font-weight: 800; text-underline-offset: 3px; }
[data-theme="light"] a { color: #a30d25; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; margin-bottom: 1rem; }
.section-head p { color: var(--soft); font-size: .95rem; }

.icon { width: 1.1em; height: 1.1em; vertical-align: -.18em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 3; background: var(--surface); padding: .5rem 1rem; }

.card, .panel, .firecon, .should li {
  min-width: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-bottom: 5px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 1.15rem;
}

/* ---------- Top bar ---------- */

.tape { height: 14px; background: repeating-linear-gradient(-45deg, var(--yellow) 0 16px, var(--tape) 16px 32px); }
.ticker { display: flex; align-items: center; justify-content: space-between; gap: .75rem; background: var(--red); color: var(--white); padding: .5rem 1rem; font-size: .9rem; }
.ticker p { min-width: 0; }
.ticker b { letter-spacing: .06em; text-transform: uppercase; margin-right: .35rem; }
@media (max-width: 40rem) { .ticker b { display: none; } .ticker { font-size: .82rem; } }
.theme-toggle {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: .35rem;
  font: 800 .8rem/1 var(--body);
  color: inherit; background: rgb(0 0 0 / .22);
  border: 0; border-radius: 999px; padding: .45rem .75rem; cursor: pointer;
}
.theme-toggle:hover { background: rgb(0 0 0 / .35); }
.math-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.math-top .theme-toggle { background: var(--surface-2); color: var(--text); }

.warning { display: flex; gap: .5rem; align-items: center; background: #fff0a6; color: var(--black); border: 2px solid #e8c200; border-radius: 12px; padding: .65rem .9rem; margin-bottom: 1rem; font-weight: 700; }

/* ---------- Safety sign ---------- */

.sign {
  margin: 0 6px;
  background: var(--sign-paper);
  color: var(--black);
  border-radius: 20px;
  border: 4px solid var(--black);
  box-shadow: 0 0 0 6px var(--yellow);
  text-align: center;
  overflow: hidden;
}
.sign-head { display: flex; justify-content: center; align-items: center; gap: .5rem; background: var(--red); color: var(--white); padding: .55rem; font: 400 clamp(1.15rem, 5vw, 2rem)/1.1 var(--display); text-transform: uppercase; }
.sign-head .icon { stroke-width: 2.5; }
.sign-body { padding: 1.4rem .75rem 1.5rem; }
.sign h1 { font: 400 clamp(1.05rem, 4.6vw, 2.1rem)/1.15 var(--display); text-transform: uppercase; }
.sign h1 span { display: block; }
.sign .sign-number {
  width: fit-content; min-width: 2.2ch;
  margin: .9rem auto; padding: 0 1.4rem;
  background: var(--black); color: var(--yellow);
  border-radius: 12px;
  font: clamp(6.5rem, 30vw, 11rem)/.95 var(--crt);
}
.timer { font: clamp(1.7rem, 7vw, 2.6rem)/1.1 var(--crt); margin-top: .9rem; }
.sign-record { display: inline-flex; gap: .4rem; align-items: center; font-weight: 800; margin-top: .5rem; color: #3d3b37; }
.sign.panic .sign-body { background: var(--yellow); }
.sign.panic .sign-number { background: var(--red); color: var(--white); }
.sign.panic { animation: flash 1.2s steps(2, jump-none) infinite; }
@keyframes flash { from { border-color: var(--red); } to { border-color: var(--black); } }

/* ---------- FIRE-CON ---------- */

.firecon {
  display: grid; gap: 1rem;
  margin-top: 1.75rem;
  border-left: 12px solid var(--level, var(--border));
}
.firecon h2 { font-size: clamp(1.8rem, 8vw, 2.6rem); }
.firecon-name { font: 900 1.05rem/1.3 var(--body); text-transform: uppercase; letter-spacing: .06em; color: var(--level-ink, var(--text)); margin-top: .15rem; }
.firecon p:last-child { color: var(--muted); }
.firecon-scale { display: flex; gap: 6px; }
.firecon-scale li { flex: 1; min-width: 2.5rem; padding: .4rem 0; text-align: center; border-radius: 10px; background: var(--surface-2); color: var(--soft); font: 400 1.25rem/1.2 var(--display); }
.firecon-scale li.on { background: var(--text); color: var(--surface); }
.firecon[data-level="5"] { --level: #0f7b45; --level-ink: #0f7b45; }
.firecon[data-level="4"] { --level: #6a8f00; --level-ink: #557300; }
.firecon[data-level="3"] { --level: #ffd100; --level-ink: #8f6a00; }
.firecon[data-level="2"] { --level: #ff7900; --level-ink: #b84f00; }
.firecon[data-level="1"] { --level: #c8102e; --level-ink: #c8102e; }
[data-theme="dark"] .firecon[data-level] { --level-ink: var(--level); }
[data-theme="dark"] .firecon[data-level="5"] { --level: #3ecf7a; }
[data-theme="dark"] .firecon[data-level="4"] { --level: #a7d129; }
[data-theme="dark"] .firecon[data-level="1"] { --level: #ff6b7d; }

/* ---------- Forecast ---------- */

.forecast { display: grid; gap: 1rem; }
.headline { text-align: center; display: grid; align-content: center; gap: .35rem; }
.big { color: var(--accent); font: clamp(5.5rem, 24vw, 8rem)/.9 var(--crt); }
.headline > p:nth-child(2) { font-weight: 800; }
.confidence { color: var(--muted); font-size: .9rem; }
.facts { display: grid; gap: 1rem; align-content: center; }
.facts dt { color: var(--soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; }
.facts dd { font: 900 1.25rem/1.25 var(--body); }
.forecast h3 { font-size: 1rem; }
.week { display: grid; gap: .45rem; margin-top: .75rem; }
.week li { display: grid; grid-template-columns: 5.5rem 1fr 2.75rem; align-items: center; gap: .75rem; font-weight: 800; font-size: .95rem; }
.week li b { text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; background: var(--meter); }

/* ---------- Should I ---------- */

.should { display: grid; gap: 1rem; }
.should li { display: grid; grid-template-columns: 1fr auto; gap: .4rem .75rem; align-items: center; }
.should p { grid-column: 1 / -1; color: var(--muted); }
.verdict { display: inline-flex; gap: .3rem; align-items: center; font: 900 .8rem/1 var(--body); text-transform: uppercase; letter-spacing: .05em; padding: .45rem .7rem; border-radius: 999px; white-space: nowrap; }
.verdict .icon { stroke-width: 3; }
.verdict.yes { background: #0f7b45; color: var(--white); }
.verdict.risky { background: var(--yellow); color: var(--black); }
.verdict.no { background: var(--red); color: var(--white); }

/* ---------- Stats ---------- */

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.stat-icon { width: 1.9rem; height: 1.9rem; stroke-width: 2.25; }
.stat-icon.red { color: var(--i-red); }
.stat-icon.yellow { color: var(--i-yellow); }
.stat-icon.orange { color: var(--i-orange); }
.stat-icon.green { color: var(--i-green); }
.stat-icon.blue { color: var(--i-blue); }
.stat-icon.purple { color: var(--i-purple); }
.stats .value { font-size: 2rem; font-weight: 900; line-height: 1.15; margin-top: .4rem; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stats .label { font-size: .75rem; font-weight: 800; line-height: 1.3; letter-spacing: .06em; text-transform: uppercase; color: var(--soft); }
.stats .note { font-size: .78rem; color: var(--soft); }

/* ---------- Charts ---------- */

.charts { display: grid; gap: 1rem; margin-top: 1rem; }
.chart figcaption b { font-size: 1.15rem; font-weight: 900; display: block; }
.chart figcaption span { color: var(--soft); font-size: .9rem; }
.plot { position: relative; margin-top: .75rem; }
.plot svg { display: block; overflow: visible; }
.plot text { font: 800 12px var(--body); }
.plot .tick { fill: var(--soft); text-anchor: end; }
.plot .axis { fill: var(--soft); text-anchor: middle; }
.plot .mark { fill: var(--text); text-anchor: middle; font-size: 13px; font-weight: 900; }
.plot .grid { stroke: var(--grid); stroke-width: 1; }
.plot .cross { stroke: var(--soft); stroke-width: 1.5; }
.plot .line { fill: none; stroke-width: 3; stroke-linecap: round; }
.plot .dot { stroke: var(--surface); stroke-width: 2; }
.plot .actual { stroke: var(--series-1); }
.plot .dot.actual { fill: var(--series-1); stroke: var(--surface); }
.plot .expected { stroke: var(--series-2); stroke-width: 2; }
.plot .dot.expected { fill: var(--series-2); stroke: var(--surface); }
.plot .gap { stroke: var(--series-3); }
.plot .dot.gap { fill: var(--series-3); stroke: var(--surface); }
.plot .dot.hot { fill: var(--surface); stroke: var(--series-1); stroke-width: 3; }
.plot .hit { fill: transparent; cursor: pointer; outline: none; }
.plot .hit:focus-visible { fill: rgb(127 127 127 / .1); }
.legend { display: flex; flex-wrap: wrap; gap: .25rem 1.1rem; margin-bottom: .5rem; font-size: .88rem; color: var(--muted); }
.legend li::before { content: ""; display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .4rem; vertical-align: -.05rem; }
.legend .actual::before { background: var(--series-1); }
.legend .expected::before { background: var(--series-2); }
.tip { position: absolute; top: 2rem; z-index: 1; pointer-events: none; display: grid; background: var(--tip); color: var(--text); border: 2px solid var(--border); border-radius: 12px; padding: .5rem .7rem; font-size: .85rem; white-space: nowrap; box-shadow: 0 6px 18px rgb(0 0 0 / .12); }
.tip b { font-weight: 900; }
.tip span { color: var(--muted); }
.empty { padding: 2rem .5rem; text-align: center; color: var(--soft); }

/* ---------- Achievements ---------- */

.achievements { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem 1rem; }
.achievements li { min-width: 0; }
.tile {
  --c: var(--c-red);
  --ink: var(--white);
  aspect-ratio: 1 / .9;
  display: grid; place-items: center; grid-template-rows: 1fr auto;
  padding: 1rem .5rem .65rem;
  border-radius: 18px;
  background: var(--c);
  color: var(--ink);
  border-bottom: 7px solid color-mix(in srgb, var(--c) 70%, #000);
}
.tile.orange { --c: var(--c-orange); --ink: var(--black); }
.tile.yellow { --c: var(--c-yellow); --ink: var(--black); }
.tile.green { --c: var(--c-green); }
.tile.blue { --c: var(--c-blue); }
.tile.purple { --c: var(--c-purple); }
.tile.off { --c: var(--tile-off); --ink: var(--tile-off-ink); }
.tile-icon { width: 44%; height: auto; aspect-ratio: 1; stroke-width: 1.75; }
.level { font-weight: 900; font-size: .78rem; letter-spacing: .07em; text-transform: uppercase; }
.achievements h3 { margin: .7rem 0 .1rem; }
.achievements .desc { color: var(--muted); font-size: .88rem; line-height: 1.35; }
.achievements .bar { display: block; height: 8px; border-radius: 99px; background: var(--surface-2); margin-top: .55rem; overflow: hidden; }
.achievements .bar i { display: block; height: 100%; background: var(--meter); border-radius: 99px; }
.achievements .hint { color: var(--soft); font-size: .78rem; margin-top: .3rem; }
.achievements .locked h3 { color: var(--muted); }

/* ---------- Log ---------- */

.search { display: grid; gap: .35rem; max-width: 24rem; font-weight: 800; }
.search input { font: 700 1rem var(--body); padding: .7rem .9rem; border: 2px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px; }
.search input:focus { border-color: var(--accent); outline: none; }
.search input::placeholder { color: var(--soft); }
.table-wrap { overflow-x: auto; margin-top: 1rem; background: var(--surface); border: 2px solid var(--border); border-bottom: 5px solid var(--border-strong); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { background: var(--surface-2); color: var(--muted); text-align: left; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 900; }
th, td { padding: .7rem .85rem; vertical-align: top; }
td { border-top: 1px solid var(--border); }
td:nth-child(4), td:nth-child(5) { white-space: nowrap; }
td:first-child { min-width: 8.5rem; }
td:nth-child(2) { min-width: 8rem; }
td:last-child { min-width: 9rem; overflow-wrap: anywhere; }
.cause { display: inline-flex; gap: .45rem; align-items: center; }
.cause .icon { color: var(--i-red); }
.fine { color: var(--soft); margin-top: .6rem; font-size: .9rem; }

.how { margin-top: 3rem; }
.how > * + * { margin-top: .85rem; }
.how li + li { margin-top: .5rem; }
.more { display: inline-flex; gap: .4rem; align-items: center; }

footer { max-width: 44rem; margin: 0 auto; padding: 2rem 1rem 3rem; text-align: center; color: var(--soft); font-size: .92rem; }
.evacuate { color: var(--text); font: 400 1.15rem/1.3 var(--display); margin-bottom: .6rem; }

/* ---------- Math page ---------- */

.math-page main { max-width: 50rem; }
.math-intro h1 { font: 400 clamp(1.7rem, 7vw, 2.6rem)/1.1 var(--display); text-transform: uppercase; margin-bottom: .75rem; }
.math-intro p + p { margin-top: .75rem; }
.step { margin-top: 1.5rem; }
.step > * + * { margin-top: .9rem; }
.step h2 { display: flex; gap: .65rem; align-items: center; font-size: 1.15rem; }
.num { flex-shrink: 0; display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: var(--yellow); color: var(--black); font: 400 1rem/1 var(--display); }
mark { background: var(--mark-bg); color: var(--mark-ink); font-weight: 900; padding: 0 .15em; border-radius: 4px; }
math { font-size: 1.15em; }
math[display="block"] { overflow-x: auto; overflow-y: hidden; padding: .9rem .5rem; background: var(--surface-2); border-radius: 12px; }
math.live mn { color: var(--accent); }
[data-theme="light"] math.live mn { color: #a30d25; }
var { font-style: italic; }
.result { font-weight: 800; }
.dist { display: grid; gap: .45rem; }
.dist li { display: grid; grid-template-columns: 5.5rem 1fr 3.5rem; align-items: center; gap: .75rem; font-weight: 800; font-size: .95rem; }
.dist b { text-align: right; font-variant-numeric: tabular-nums; }
.caveats { list-style: disc; padding-left: 1.25rem; }
.caveats li + li { margin-top: .4rem; }
.math-page td { min-width: 0 !important; white-space: normal !important; }
.math-page .chart { margin-top: 1rem; }

/* ---------- Wider screens ---------- */

@media (min-width: 46rem) {
  .firecon { grid-template-columns: 1fr auto; align-items: center; }
  .forecast { grid-template-columns: 1fr 1fr; }
  .forecast .panel:last-child { grid-column: 1 / -1; }
  .should { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .achievements { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 60rem) {
  .charts { grid-template-columns: 1fr 1fr; }
  .should { grid-template-columns: repeat(3, 1fr); }
  .achievements { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Visitors page ---------- */

.box-link { display: inline-flex; gap: .3rem; align-items: center; margin-top: .35rem; font-size: .85rem; }
.visitor-stats { margin-top: 1.5rem; }
.pages { display: grid; gap: .55rem; margin-top: .75rem; }
.pages li { display: grid; grid-template-columns: 7.5rem 1fr 3rem; align-items: center; gap: .75rem; font-weight: 800; font-size: .95rem; }
.pages b { text-align: right; font-variant-numeric: tabular-nums; }
.notes { list-style: disc; padding-left: 1.25rem; color: var(--muted); }
.notes li + li { margin-top: .35rem; }
