/* Is It Carnival Yet? — every visual effect derives from one number, --p
   (0..1), which app.js sets on <html>. effects.js only adds motion and seeded
   placement; nothing here needs JS to work. Lifted from mockups/carnival.css.
   Deliberately not base.css (DESIGN.md § Not base.css, deliberately). */

@font-face {
    font-family: "Recursive";
    /* Recursive 1.085, MONO pinned to 0, ASCII + Dutch accents (fonts/README.md). */
    src: url("recursive-subset.woff2") format("woff2");
    font-weight: 300 1000;
    /* The answer is sized by Recursive's widths (--fit); a fallback font
       would overflow. Better a moment of nothing than a wrong-size flash. */
    font-display: block;
}

/* --dark is 1 for the dark palette, 0 for light. Registered so it can fade. */
@property --dark {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

:root {
    --p: 0;

    /* palette: light (-l) and dark (-d), mixed by --dark */
    --paper-l: #f3f1ea;  --paper-d: #141311;
    --ink-l: #161513;    --ink-d: #efece4;
    --muted-l: #5d5a54;  --muted-d: #a39f95;
    --rule-l: #cfcbc0;   --rule-d: #34322d;
    --warm-l: #ffe07a;   --warm-d: #55290a;   /* where the paper drifts to; dark yellow is olive, so amber */
    --dark: 0;

    --paper: color-mix(in oklab, var(--paper-l), var(--paper-d) calc(var(--dark) * 100%));
    --ink:   color-mix(in oklab, var(--ink-l),   var(--ink-d)   calc(var(--dark) * 100%));
    --muted: color-mix(in oklab, var(--muted-l), var(--muted-d) calc(var(--dark) * 100%));
    --rule:  color-mix(in oklab, var(--rule-l),  var(--rule-d)  calc(var(--dark) * 100%));
    --warm:  color-mix(in oklab, var(--warm-l),  var(--warm-d)  calc(var(--dark) * 100%));

    --red: #d7262e;
    --yellow: #f7c600;
    --green: #128a43;
    --dust: #a9a8a3 #bdbcb7 #8f8e8a #c9c8c3;   /* hungover confetti, read by effects.js */

    --gutter: clamp(16px, 4vw, 48px);

    /* derived ramps — all unitless 0..1 */
    --stripes: clamp(0, calc((var(--p) - 0.6) / 0.4), 1);
    --streamers: clamp(0, calc((var(--p) - 0.5) / 0.2), 1);
    --hat: clamp(0, calc((var(--p) - 0.3) * 1000), 1);
    --t: clamp(0, calc((var(--p) - 0.2) / 0.7), 1);

    /* Recursive axes (DESIGN.md § Typography) */
    --wght: calc(700 + 300 * var(--p));
    --casl: calc(var(--t) * var(--t) * (3 - 2 * var(--t)));   /* smoothstep(0.2, 0.9, p) */
    --slnt: calc(-15 * var(--p) * var(--p));
    --crsv: clamp(0, calc((var(--p) - 0.7) * 1000), 1);      /* 0, then 1 above 0.7 */
    --blur: 0px;

    --bg: color-mix(in oklab, var(--paper), var(--warm) calc(min(var(--p), 0.85) * 100%));

    color-scheme: light dark;
}

/* Carnival overrides dark mode (DESIGN.md § Dark mode). Calm is the dark
   inversion; from the stripes threshold, p 0.6, the page is the light
   carnival palette whatever the setting. A step, faded in time (below), not a
   ramp over p: a ramp would pass ink and paper through the same grey and
   leave the text unreadable for the day the season spends near 0.6. */
@media (prefers-color-scheme: dark) {
    :root {
        /* × 1e6, not × 1000: near 0.6 p moves only ~0.0014 an hour, so a
           ×1000 "step" spent 40 minutes half-way, ink and paper the same grey. */
        --dark: clamp(0, calc((0.6 - var(--p)) * 1e6), 1);
        --dust: #4b4b48 #5a5a57 #3f3f3d #646461;
    }
}
/* Only once the first render has painted (effects.js sets data-fx), so a page
   loaded mid-carnival doesn't fade in from dark. */
:root[data-fx] { transition: --dark 2.4s ease-in-out; }

/* Ash Wednesday: off the p scale entirely. Grey and weak; dark grey in dark mode. */
:root[data-hungover] {
    --p: 0;
    --paper-l: #dcdbd7;  --paper-d: #262625;
    --ink-l: #4f4e4b;    --ink-d: #9d9c97;
    --muted-l: #5c5b57;  --muted-d: #8e8d88;
    --rule-l: #c3c2bd;   --rule-d: #3a3a38;
    --bg: var(--paper);
    --wght: 300;
    --casl: 0.5;
    --slnt: -4;
    --crsv: 0;
    --hat: 0;
    --stripes: 0;
    --streamers: 0;
}

/* Hidden until app.js has rendered. If the module never runs (old browser,
   a load error), the sheet appears anyway after 3 s with the no-JS line:
   a page that stays blank forever is the worse failure. */
html.pending { visibility: hidden; animation: reveal 0s 3s forwards; }
@keyframes reveal { to { visibility: visible; } }

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

html { background: var(--bg); }

body {
    margin: 0;
    min-height: 100svh;
    color: var(--ink);
    background: var(--bg);
    font-family: "Recursive", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-variation-settings: "CASL" var(--casl), "slnt" var(--slnt), "CRSV" var(--crsv);
    font-size: 1.0625rem;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
a { color: inherit; }

/* --- effect layers: all aria-hidden in the markup, none takes a click -------- */

body::before {                     /* stripes */
    content: "";
    position: fixed;
    inset: -50%;
    z-index: 0;
    pointer-events: none;
    opacity: var(--stripes);
    background: repeating-linear-gradient(-35deg,
        var(--red) 0 56px, var(--yellow) 56px 112px, var(--green) 112px 168px);
}

.fx {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
#streamers { z-index: 1; opacity: var(--streamers); }
#confetti  { z-index: 3; }                       /* over the answer, on purpose */
:root[data-hungover] #confetti { z-index: 1; filter: blur(var(--blur)); } /* swept-up dust: under the text, as blurred */

/* --- the sheet ----------------------------------------------------------------- */

.sheet {
    position: relative;
    z-index: 2;
    min-height: 100svh;
    padding: var(--gutter);
    display: grid;
    grid-template-columns: minmax(0, 1fr); /* a wide answer must not widen the page */
    grid-template-rows: auto 1fr auto auto auto;
}
:root[data-hungover] .sheet { filter: blur(var(--blur)); }

.meta, .foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    /* Wobbled stickers need room, or they land on each other on a phone. */
    gap: calc(0.25rem + var(--stripes) * 1rem) 1.5rem;
    font-size: 0.8125rem;
    letter-spacing: 0.01em;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.meta { padding-bottom: 0.75rem; border-bottom: 1px solid var(--rule); }
.foot { padding-top: 0.75rem; border-top: 1px solid var(--rule); margin-top: clamp(2rem, 6vh, 4rem); }
.foot nav { display: flex; flex-wrap: wrap; gap: calc(0.25rem + var(--stripes) * 1rem) 1.5rem; }
.foot a, .foot button { text-decoration: none; }
/* Buttons that read as the footer's links: same type, no chrome. */
.foot button {
    font: inherit;
    letter-spacing: inherit;
    font-variant-numeric: inherit;
    color: inherit;
    background-color: color-mix(in srgb, var(--paper) calc(var(--stripes) * 100%), transparent);
    border: 0;
    cursor: pointer;
}
.foot a:hover, .foot a:focus-visible, .foot button:hover, .foot button:focus-visible { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 639px) {
    .foot { align-items: start; }
    .foot nav { flex-direction: column; align-items: flex-start; }
}

/* The herring lies beside the answer, on its baseline (hungover only). */
.qa {
    align-self: end;
    padding-top: clamp(3rem, 12vh, 8rem);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: end;
    column-gap: clamp(0.75rem, 2vw, 2rem);
}
.qa:has(.a:empty) { display: none; } /* no JS: the line says it all */

.q {
    grid-column: 1 / -1;
    margin: 0 0 0.5rem;
    font-size: clamp(1rem, 0.9rem + 0.4vw, 1.25rem);
    font-weight: 450;
}

/* The answer: as big as the word allows. --fit is the word's width in em
   (strings.js). Recursive is uniwidth — the width is identical at every
   wght/CASL/slnt — so one number per word holds at every p, and animating
   the axes never reflows. */
.a {
    margin: 0 0 0 -0.06em;         /* optical flush-left */
    font-size: min(22rem, 50svh, calc((100vw - 2 * var(--gutter)) / var(--fit, 1.455)));
    font-weight: var(--wght);
    line-height: 0.82;
    letter-spacing: -0.035em;
    white-space: nowrap;
    /* Carnival: a paper outline keeps it legible-ish over stripes and confetti. */
    -webkit-text-stroke: calc(var(--stripes) * 0.06em) var(--paper);
    paint-order: stroke fill;
}
/* The answer fills the measure flush left, so it may only wobble rightward
   (0..12 px), or a phone loses the first letter off the edge. */
.a.wob {
    transform:
        translate(calc((var(--r1, 0) + 1) * 6px * var(--p)), calc(var(--r2, 0) * 12px * var(--p)))
        rotate(calc(var(--r3, 0) * 4deg * var(--p)));
}
.a .ch { display: inline-block; will-change: transform; }

.herring { display: none; }
:root[data-hungover] { --herring: clamp(3.5rem, 14vw, 11rem); }
:root[data-hungover] .a {
    font-size: min(22rem, 50svh, calc((100vw - 2 * var(--gutter) - var(--herring) - clamp(0.75rem, 2vw, 2rem)) / var(--fit, 1.9)));
}
:root[data-hungover] .herring {
    display: block;
    width: var(--herring);
    margin-bottom: 0.4rem;
    color: var(--ink);
    pointer-events: none;
}

.line {
    margin: clamp(1rem, 3vh, 2rem) 0 0;
    max-width: 34ch;
    font-size: clamp(1.0625rem, 0.95rem + 0.5vw, 1.375rem);
    font-weight: calc(400 + 100 * var(--p));
}
/* The rivers answer and "Link copied.": quieter than the line, hidden until used. */
.aside { margin-top: 1.1rem; max-width: 34ch; font-size: clamp(0.9375rem, 0.9rem + 0.25vw, 1.0625rem); }
.aside:empty { display: none; }
.aside { width: fit-content; background: color-mix(in srgb, var(--paper) calc(var(--stripes) * 100%), transparent); border-radius: 3px; padding: 0 calc(var(--stripes) * 0.4em); }
.countdown { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Small text becomes stickers once the stripes arrive, so it stays readable. */
.sticker {
    display: inline-block;
    padding: calc(var(--stripes) * 0.15em) calc(var(--stripes) * 0.4em);
    background: color-mix(in srgb, var(--paper) calc(var(--stripes) * 100%), transparent);
    border-radius: 3px;
}
/* With no backing yet, the sticker padding is 0; keep the line's wrap tidy. */
.line .sticker { display: inline; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

/* Party hat, CSS only: zero width until p 0.3. */
.line .sticker::before {
    content: "";
    display: inline-block;
    width: calc(var(--hat) * 0.9em);
    height: 0.9em;
    margin-right: calc(var(--hat) * 0.35em);
    vertical-align: -0.08em;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 1 L17 19 H3 Z' fill='%23d7262e'/%3E%3Cpath d='M6.2 11 L13.8 11 L15 14 L5 14Z' fill='%23f7c600'/%3E%3Ccircle cx='10' cy='1.8' r='1.8' fill='%23128a43'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Per-element wobble. --r1..--r3 are seeded per day (−1..1) by effects.js;
   without them nothing moves. */
.wob {
    transform:
        translate(calc(var(--r1, 0) * 12px * var(--p)), calc(var(--r2, 0) * 12px * var(--p)))
        rotate(calc(var(--r3, 0) * 4deg * var(--p)));
    transform-origin: left bottom;
    /* Composited, so the rotation is drawn as one smooth image. Without it,
       Chromium sets small-angle rotated text glyph by glyph on snapped
       baselines, and p 0.1–0.5 looks like a rendering bug (stair steps). */
    will-change: transform;
}

/* --- og.png capture (?og=1): the question set big where the answer goes ----------- */

:root[data-og] .meta, :root[data-og] .q, :root[data-og] .line, :root[data-og] .foot { display: none; }
:root[data-og] .sheet { grid-template-rows: 1fr; align-content: center; }
:root[data-og] .qa { align-self: center; padding: 0; }
:root[data-og] .a { font-size: 11.5rem; line-height: 0.9; white-space: normal; max-width: 9ch; }

/* --- debug panel (?debug=1) ---------------------------------------------------- */

.debug {
    position: fixed;
    right: 12px; bottom: 12px;
    z-index: 10;
    width: 15rem;
    padding: 0.75rem;
    font: 12px/1.4 ui-monospace, monospace;
    font-variation-settings: normal;
    color: #eee;
    background: rgb(20 20 20 / 0.88);
    border-radius: 6px;
    display: grid;
    gap: 0.5rem;
    color-scheme: dark;
}
.debug label { display: grid; gap: 0.2rem; }
.debug input, .debug select, .debug button { width: 100%; font: inherit; }

.vh {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    *, :root[data-fx] { transition: none !important; }
}

/* --- world mode (world.html): calm style, never infected ----------------------- */

.world .sheet { grid-template-rows: auto auto auto 1fr auto; }
.world .qa { align-self: start; padding-top: clamp(2rem, 7vh, 4rem); }
.world .a {
    margin-left: -0.06em;
    font-size: min(9rem, calc((100vw - 2 * var(--gutter)) / var(--fit, 1.455)));
    line-height: 0.88;
}
/* The Basel headline is a sentence: smaller, and it wraps. */
.world .a.long {
    font-size: clamp(2.75rem, 1.5rem + 4.5vw, 5.5rem);
    white-space: normal;
    max-width: 16ch;
    line-height: 0.95;
}

.tiles {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    margin-top: clamp(2rem, 6vh, 4rem);
    border-top: 1px solid var(--rule);
}
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--gutter); } }
@media (min-width: 960px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.tile {
    container-type: inline-size;       /* the word is sized against the tile's width */
    padding: 1.25rem 0 1.5rem;
    border-bottom: 1px solid var(--rule);
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    row-gap: 0.25rem;
}
.tile p, .tile h2 { margin: 0; }
.tile .city { font-size: 0.9375rem; font-weight: 600; }
.tile .time { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile .word {
    grid-column: 1 / -1;
    /* "Technically." is 5.39em wide (strings.js), plus the dot and its gap. */
    font-size: min(3.5rem, calc(100cqi / 6.4));
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.035em;
    display: flex;
    align-items: center;
    gap: 0.25em;
    white-space: nowrap;
}
.dot { width: 0.32em; height: 0.32em; border-radius: 50%; flex: none; background: var(--green); }
.dot[data-s="technically"] { background: var(--yellow); }
.dot[data-s="yes"] { background: var(--red); }
.tile .note { grid-column: 1 / -1; font-size: 0.8125rem; color: var(--muted); }
