:root {
  color-scheme: light;
  --ink: #172b50;
  --primary: #1859b8;
  --primary-hover: #12478f;
  --accent: #ffd65a;
  --warm-surface: #fff4cd;
  --page: #f5faff;
  --model-surface: #eaf5ff;
  --model-fill: #d9edff;
  --line: #c9def4;
  --control-border: #6c97cc;
  --paper: #fff;
  --muted: #455d7a;
  --warning: #912d47;
  font: 17px/1.55 "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea { font: inherit; }
a { color: var(--primary); text-underline-offset: .22em; }
p, h1, h2 { margin: 0; }
p + p { margin-top: .65rem; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 4px; }
.topbar :focus-visible { outline-color: var(--accent); }
.skip { position: fixed; z-index: 1; left: 1rem; top: .5rem; padding: .65rem 1rem; background: var(--paper); clip-path: inset(100%); }
.skip:focus { clip-path: none; }

.shell { width: min(100% - 2.2rem, 70rem); margin-inline: auto; }
.topbar { background: var(--ink); color: var(--paper); border-bottom: 3px solid var(--accent); }
.topbar-inner { min-height: 4.1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0 .65rem; flex-wrap: wrap; }
.topbar-actions .text-button { display: inline-flex; align-items: center; text-align: left; }
.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--paper); font-weight: 700; text-decoration: none; }
.lantern { position: relative; display: inline-block; width: 1rem; height: 1.05rem; border: 2px solid var(--accent); border-radius: 42%; }
.lantern::before, .lantern::after { content: ""; position: absolute; height: 2px; width: .45rem; inset-inline-start: 50%; transform: translateX(-50%); background: var(--accent); }
.lantern::before { top: -.24rem; }
.lantern::after { bottom: -.24rem; }
.main { padding-block: clamp(1.2rem, 4vw, 3.5rem) 3rem; }

.cover { display: grid; grid-template-columns: 1.04fr 1fr; border: 1px solid var(--line); border-radius: 1.5rem; overflow: hidden; background: var(--paper); box-shadow: 0 16px 48px #172b5010; }
.cover-copy { padding: clamp(1.45rem, 4.4vw, 4rem); align-self: center; }
.edition, .stage-label { color: var(--primary); font-weight: 750; font-size: .9rem; }
.cover h1, .stage h1 { font-family: "DM Serif Display", Georgia, serif; font-weight: 700; line-height: 1.05; letter-spacing: -.035em; text-wrap: balance; }
.cover h1 { font-size: clamp(2.75rem, 5.35vw, 4.8rem); margin: .55rem 0 1.2rem; max-width: 11ch; }
.opening { max-width: 33ch; }
.play-meta { font-size: .9rem; color: var(--muted); margin-block: 1.1rem; font-weight: 700; }
.cover-art { min-height: 22rem; background: var(--ink) url("rooftop-garden.webp") center / cover no-repeat; }
.print-links { display: flex; flex-wrap: wrap; gap: .45rem 1rem; margin-top: 1.05rem; font-size: .9rem; font-weight: 700; }
.print-links a { padding-block: .35rem; }
.noscript { margin-top: 1rem; }
.cover-actions { display: flex; flex-wrap: wrap; gap: .7rem; }

.button, .text-button { cursor: pointer; min-height: 2.65rem; border-radius: .65rem; font-weight: 700; line-height: 1.25; }
.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: .65rem 1rem;
  background: var(--paper);
  border: 1px solid var(--control-border);
  color: var(--ink);
  text-decoration: none;
}
.button:hover { background: var(--model-surface); }
.button.primary { background: var(--primary); color: var(--paper); border-color: var(--primary); box-shadow: 0 3px 0 var(--ink); }
.button.primary:hover { background: var(--primary-hover); }
.button[aria-pressed="true"] { background: var(--model-fill); border-color: var(--primary); }
.text-button { border: 0; background: transparent; color: inherit; padding: .45rem .3rem; text-decoration: underline; text-underline-offset: .2em; }
.reset-button { color: var(--accent); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 16.5rem; align-items: start; gap: 1.4rem; }
.stage, .progress-panel { background: var(--paper); border: 1px solid var(--line); border-radius: 1.1rem; box-shadow: 0 8px 28px #172b5008; min-width: 0; }
.stage { padding: clamp(1rem, 4vw, 2.45rem); }
.stage h1 { font-size: clamp(2.1rem, 5vw, 3.3rem); margin: .25rem 0 .9rem; }
.stage-intro, .instructions { max-width: 64ch; }
.stage-intro { margin-bottom: 1.05rem; }
.instructions { color: var(--muted); margin: .8rem 0; }
.stage h2 { font-size: 1.13rem; margin-bottom: .35rem; line-height: 1.25; }
.model-board { background: var(--model-surface); border: 1px solid var(--line); border-radius: .85rem; padding: clamp(.75rem, 3vw, 1.4rem); margin-block: 1rem; }
.model-board > * + * { margin-top: .65rem; }
.model-label { font-size: .9rem; font-weight: 700; }
.example { margin-top: 1rem; }
.example .model-board, .station-form .model-board { margin-bottom: .9rem; }
.example .stage-label { margin-bottom: .25rem; }
.example-strip-row .model-label { margin-bottom: .35rem; }
.example-pairs { display: grid; grid-template-columns: repeat(var(--example-pair-count), minmax(0, 1fr)); gap: 4px; margin-top: .2rem; }
.example-pairs span { height: .55rem; border: 2px solid var(--ink); border-top: 0; border-radius: 0 0 .2rem .2rem; }
.inline-answer { display: flex; gap: .5rem .85rem; align-items: center; flex-wrap: wrap; margin-block: .65rem; }
.inline-answer label, .field > label { font-weight: 700; }
.field { display: grid; align-items: start; gap: .3rem; justify-items: start; }
.fraction-fields { display: flex; gap: .8rem; flex-wrap: wrap; margin-block: .7rem; }
.answer-input, .explanation {
  padding: .55rem .7rem;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--control-border);
  border-radius: .5rem;
  min-height: 2.75rem;
}
.answer-input { width: 5rem; }
.code-input { width: 9rem; font-size: 1.3rem; letter-spacing: .26ch; }
.explanation { width: min(100%, 33rem); resize: vertical; }
.equation { font-size: 1.42rem; font-weight: 750; line-height: 1.25; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.feedback { margin-block: .75rem; font-weight: 700; }
.feedback:empty { margin: 0; }
.feedback[data-tone="error"] { color: var(--warning); }
.feedback[data-tone="success"] { color: var(--primary); }
.repair-result { margin-top: 1rem; border: 1px solid var(--control-border); border-left: 5px solid var(--primary); border-radius: .7rem; background: var(--model-surface); padding: .85rem 1rem; }
.repair-result h2 { color: var(--primary); }
.repair-digit { display: inline-block; border-radius: .4rem; background: var(--accent); color: var(--ink); font-weight: 750; padding: .25rem .6rem; }
.help { display: grid; gap: .5rem; margin-top: 1.15rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.help h2 { margin-bottom: 0; }
.help-row { display: grid; justify-items: start; gap: .4rem; }
.hint-text { background: var(--page); border-left: 3px solid var(--control-border); padding: .6rem .8rem; width: 100%; }

.progress-panel { padding: 1.05rem; }
.progress-panel h2 { margin-bottom: .4rem; font-size: 1.06rem; }
.digits { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; margin: .6rem 0 .95rem; padding: 0; list-style: none; }
.digits li { text-align: center; min-width: 0; }
.digit { display: grid; place-items: center; background: var(--model-surface); border: 1px solid var(--line); font-size: 1.25rem; height: 2.45rem; font-weight: 750; border-radius: .45rem; }
.digit[data-earned="true"] { background: var(--accent); border-color: var(--control-border); }
.digit-number { color: var(--muted); font-size: .85rem; }
.station-nav { list-style: none; margin: 0; padding: 0; }
.station-nav li + li { margin-top: .25rem; }
.station-link { display: flex; align-items: center; gap: .5rem; color: var(--muted); width: 100%; padding: .45rem; min-height: 2.6rem; border: 1px solid transparent; border-radius: .5rem; font-size: .91rem; background: transparent; text-align: left; }
button.station-link { color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: .22em; }
button.station-link:hover { background: var(--model-surface); }
.station-link[aria-current="step"] { border-color: var(--control-border); background: var(--model-surface); color: var(--ink); font-weight: 750; }
.station-number { display: inline-grid; place-items: center; flex: 0 0 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--model-surface); color: var(--ink); font-weight: 750; }
.station-link[data-repaired="true"] .station-number { background: var(--accent); }
.station-repair { display: block; color: var(--muted); font-size: .82rem; font-weight: 650; }
.progress-msg { font-size: .9rem; color: var(--muted); margin-top: .65rem; }
.finale { background: var(--ink); color: var(--paper); padding: .95rem 1rem; border-radius: .7rem; border-left: 5px solid var(--accent); margin: .6rem 0 1.1rem; }
.finale p { max-width: 43ch; }
.lit-garden { position: relative; aspect-ratio: 1500 / 844; isolation: isolate; overflow: hidden; margin-top: .8rem; border-radius: .45rem; background: var(--ink) url("rooftop-garden.webp") center / cover no-repeat; }
.lit-garden::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 10% 16% at 18% 14.5%, #fff1b7ec, #ffad4d99 36%, transparent 100%),
    radial-gradient(ellipse 7% 12% at 29.4% 22%, #fff1b7e0, #ffad4d80 34%, transparent 100%),
    radial-gradient(ellipse 6% 10% at 40.5% 27%, #fff1b7e0, #ffad4d80 34%, transparent 100%),
    radial-gradient(ellipse 5% 9% at 51.7% 29%, #fff1b7e0, #ffad4d80 34%, transparent 100%),
    radial-gradient(ellipse 5% 9% at 62.1% 28%, #fff1b7e0, #ffad4d80 34%, transparent 100%),
    radial-gradient(ellipse 6% 10% at 71.2% 24.6%, #fff1b7e0, #ffad4d80 34%, transparent 100%),
    radial-gradient(ellipse 38% 53% at 54% 61%, #ffbd7933, transparent);
  mix-blend-mode: screen;
  animation: lantern-light 850ms ease-out both;
}
@keyframes lantern-light { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .lit-garden::after { animation: none; } }
.exit-explain { background: var(--model-surface); border-radius: .7rem; padding: .9rem; margin-block: 1rem; }
.exit-explain label { display: block; font-weight: 700; margin-block: .55rem .3rem; }
.completion { border: 1px solid var(--line); border-radius: .7rem; padding: .9rem; background: var(--model-surface); margin-top: 1rem; }

@media (max-width: 850px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 13rem; gap: 1rem; }
}
@media (max-width: 660px) {
  .shell { width: calc(100% - 1.4rem); }
  .cover { display: flex; flex-direction: column; }
  .cover-copy { align-self: stretch; }
  .cover h1 { max-width: 14ch; margin-bottom: .8rem; }
  .cover-art { min-height: 0; height: clamp(10rem, 40vw, 16rem); }
  .game-layout { display: flex; flex-direction: column; }
  .stage, .progress-panel { width: 100%; }
  .progress-panel { order: -1; }
  .digits { max-width: 15rem; margin-bottom: .5rem; }
  .station-nav { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem; }
  .station-nav li + li { margin-top: 0; }
}
