/* Hallmark · pre-emit critique: P5 H5 E4 S5 R4 V5
 * genre: playful · macrostructure: Map / Diagram · theme: Hum
 * tone: colourful and springy · anchor: warm coral · nav: N9 · footer: Ft2
 * slop: pass (42–49) · contrast: pass (40–41) · mobile: pass (34, 49–57)
 */
* { box-sizing: border-box; }

html {
  min-width: 320px;
  overflow-x: clip;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: clip;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse 78% 52% at 0% 0%, var(--color-coral-band) 0 32%, transparent 58%),
    radial-gradient(ellipse 70% 48% at 100% 5%, var(--signal) 0 30%, transparent 56%),
    radial-gradient(ellipse 62% 44% at 94% 100%, var(--cyan) 0 31%, transparent 55%),
    radial-gradient(ellipse 56% 42% at 3% 95%, var(--safe) 0 28%, transparent 53%);
  background-attachment: fixed;
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
[tabindex="-1"]:focus { outline: none; }

.edge-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.2rem;
  padding: 0.45rem max(0.75rem, env(safe-area-inset-left));
  border-bottom: 3px solid var(--ink);
  background: var(--signal);
  box-shadow: 0 5px 0 var(--accent);
}

.edge-nav__brand {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.edge-nav__tools { display: flex; gap: 0.35rem; align-items: center; }
.edge-nav__link, .plain-button {
  min-height: 2.45rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid transparent;
  color: var(--ink);
  background: transparent;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  text-decoration: none;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
}
.edge-nav__link:hover, .plain-button:hover { color: var(--ink); border-color: var(--ink); background: var(--paper-2); }
.edge-nav__link:active, .plain-button:active { transform: translateY(2px); }
.plain-button:disabled { cursor: not-allowed; opacity: 0.55; background: var(--paper); }

.ad-rail {
  width: min(100% - 1.25rem, var(--measure));
  min-height: 5.5rem;
  margin: 0.7rem auto;
  border: 2px dashed var(--ink);
  border-radius: var(--radius-input);
  color: var(--muted);
  background: var(--paper-2);
  text-align: center;
}

.ad-rail__label {
  margin: 0;
  padding: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.switchyard-app {
  width: min(100% - 1.25rem, 60rem);
  margin: 0 auto;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: var(--radius-card);
  background: var(--paper-2);
  box-shadow: 12px 14px 0 var(--accent), 0 1.2rem 2.8rem var(--shadow);
  animation: app-arrive 520ms var(--spring);
}

.screen { min-height: min(45rem, calc(100vh - 9rem)); }
.screen--title {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(15rem, 0.9fr);
  align-items: stretch;
}

.title-copy { padding: clamp(1.4rem, 5vw, 4rem); padding-block-end: clamp(2rem, 7vw, 5.5rem); align-self: center; }
.kicker, .route-code, .metric dt, .control-key, .campaign-status {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.kicker { color: var(--accent); font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { min-width: 0; overflow-wrap: anywhere; }
.title-copy h1 {
  max-width: 11ch;
  margin-bottom: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--step-4);
  line-height: 0.98;
  letter-spacing: -0.055em;
  min-width: 0;
  overflow-wrap: anywhere;
}
.title-copy__lede { max-width: 36rem; color: var(--muted); font-size: var(--step-1); }
.campaign-status { margin-block: var(--space-4); color: var(--muted); }

.button-row { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.button {
  min-height: 2.9rem;
  padding: 0.7rem 1rem;
  border: 2px solid var(--ink);
  border-radius: var(--radius-input);
  color: var(--ink);
  background: var(--paper-3);
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
  transition: transform var(--dur-short) var(--ease-out), box-shadow var(--dur-short) var(--ease-out);
}
.button:hover:not(:disabled) { transform: translateY(-2px); }
.button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.button--primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button--signal { border-color: var(--ink); color: var(--ink); background: var(--signal); }
.button:disabled { cursor: not-allowed; opacity: 0.42; }

.route-map {
  display: grid;
  place-items: center;
  min-height: 22rem;
  padding: clamp(1.25rem, 4vw, 3rem);
  border-left: 4px solid var(--ink);
  background: var(--cyan);
}
.route-map svg { width: min(100%, 23rem); height: auto; }
.route-map:hover *, .route-map:focus-within * { animation-play-state: paused; }
.map-rail { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: square; stroke-dasharray: 12 8; animation: map-travel 6s linear infinite; }
.map-node { fill: var(--signal); stroke: var(--ink); stroke-width: 4; transform-box: fill-box; transform-origin: center; animation: node-bob 2.2s var(--spring) infinite; }
.map-node:nth-of-type(3) { fill: var(--safe); animation-delay: 160ms; }
.map-node:nth-of-type(4) { fill: var(--lavender); animation-delay: 320ms; }
.map-node:nth-of-type(5) { fill: var(--blue); animation-delay: 480ms; }
.map-depot { fill: var(--accent); stroke: var(--accent-ink); stroke-width: 3; }
.map-label { fill: var(--muted); font: 700 9px var(--font-mono); letter-spacing: 1px; }

.screen--levels { padding: clamp(1rem, 4vw, 2.5rem); animation: screen-pop 320ms var(--snap); }
.screen-heading { position: relative; display: block; padding-right: 5rem; border-bottom: 1px solid var(--rule); }
.screen-heading .plain-button { position: absolute; right: 0; bottom: 0.5rem; }
.screen-heading h1 { font-family: var(--font-mono); font-size: var(--step-3); letter-spacing: -0.04em; }
.district { margin-block: var(--space-5); }
.district h2 { color: var(--muted); font: 700 var(--step--1) var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.35rem; }
.level-button {
  display: grid;
  min-height: 4rem;
  padding: 0.45rem;
  border: 2px solid var(--ink);
  border-radius: var(--radius-input);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform var(--dur-short) var(--ease-out), box-shadow var(--dur-short) var(--ease-out);
}
.level-button strong { color: var(--signal); font: 700 var(--step-1) var(--font-mono); }
.level-button span { overflow: hidden; color: var(--muted); font-size: 0.68rem; text-overflow: ellipsis; white-space: nowrap; }
.level-button:disabled { opacity: 0.38; cursor: not-allowed; }
.level-button:not(:disabled):hover { transform: translateY(-2px); }
.level-button:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.level-button:nth-child(5n + 1) { background: var(--color-coral-band); }
.level-button:nth-child(5n + 2) { background: var(--color-cyan-band); }
.level-button:nth-child(5n + 3) { background: var(--color-mint); }
.level-button:nth-child(5n + 4) { background: var(--color-paper-2); }
.level-button:nth-child(5n) { background: color-mix(in oklch, var(--lavender) 42%, white); }

.screen--play { padding: clamp(0.65rem, 2vw, 1.2rem); animation: screen-pop 320ms var(--snap); }
.route-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: end;
  padding: 0.25rem 0 0.7rem;
  border-bottom: 1px solid var(--rule);
}
.route-header h1 { margin-bottom: 0.1rem; font: 700 var(--step-2) var(--font-mono); letter-spacing: -0.04em; }
.route-code { margin-bottom: 0; color: var(--signal); }
.route-district { margin: 0; color: var(--muted); }
.metric { margin: 0; min-width: 4.2rem; text-align: right; }
.metric dt { color: var(--muted); }
.metric dd { margin: 0; font: 700 var(--step-2) var(--font-mono); }

.board-shell {
  position: relative;
  width: min(100%, 32rem);
  margin: clamp(0.7rem, 3vw, 1.5rem) auto 0;
  padding: 0.32rem;
  border: 4px solid var(--ink);
  border-radius: 22px;
  background: var(--signal);
  box-shadow: 10px 12px 0 var(--accent);
}
.switchyard-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 1px;
  width: 100%;
}
.track-tile {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 18%;
  color: var(--ink);
  background: var(--tile-color, var(--paper-3));
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--dur-micro) var(--ease-out);
}
.track-tile:hover { transform: translateY(-2px); }
.track-tile:active { transform: translateY(2px) scale(0.97); }
.track-tile:disabled { cursor: not-allowed; opacity: 0.55; }
.track-tile.tone-0 { --tile-color: var(--color-paper-2); }
.track-tile.tone-1 { --tile-color: var(--color-coral-band); }
.track-tile.tone-2 { --tile-color: var(--color-cyan-band); }
.track-tile.tone-3 { --tile-color: color-mix(in oklch, var(--safe) 56%, white); }
.track-tile.tone-4 { --tile-color: color-mix(in oklch, var(--lavender) 42%, white); }
.track-drawing { display: block; width: 100%; height: 100%; pointer-events: none; }
.rail-bed { stroke: var(--ink); stroke-width: 21; stroke-linecap: butt; }
.rail-line { stroke: var(--paper-2); stroke-width: 9; stroke-linecap: butt; }
.rail-joint { fill: var(--paper-2); stroke: var(--ink); stroke-width: 7; }
.place-marker {
  position: absolute;
  inset: 4px auto auto 4px;
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border: 2px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: var(--signal);
  font: 800 0.7rem var(--font-mono);
  pointer-events: none;
}
.is-depot .place-marker { color: var(--accent-ink); background: var(--accent); }
.track-tile.is-hinted { outline: 5px dashed var(--blue); outline-offset: -7px; animation: hint-wiggle 760ms var(--spring) infinite; }
.track-tile.is-turning .track-drawing { animation: track-turn 260ms var(--spring); }
.track-tile.is-turning::after {
  content: "";
  position: absolute;
  inset: 34%;
  border: 5px solid var(--signal);
  border-radius: 50%;
  animation: signal-burst 320ms var(--snap) both;
}
.switchyard-board.is-solved .rail-line { stroke: var(--safe); }
.switchyard-board.is-solved .rail-joint { fill: var(--safe); stroke: var(--ink); }
.switchyard-board.is-solved .track-tile { animation: tile-cheer 430ms var(--spring) both; }
.switchyard-board.is-solved .track-tile:nth-child(3n + 2) { animation-delay: 50ms; }
.switchyard-board.is-solved .track-tile:nth-child(3n) { animation-delay: 100ms; }
.switchyard-board.is-dispatching .track-tile { cursor: wait; }

.inspection-train {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  width: clamp(1.1rem, 7vw, 1.8rem);
  aspect-ratio: 1.35;
  border: 2px solid var(--accent-ink);
  background: var(--accent);
  box-shadow: 0 3px 0 var(--paper);
  pointer-events: none;
  transition: transform 80ms linear;
}
.inspection-train::before, .inspection-train::after {
  content: "";
  position: absolute;
  bottom: -0.35rem;
  width: 0.42rem;
  height: 0.42rem;
  border: 2px solid var(--accent-ink);
  border-radius: 50%;
  background: var(--paper);
}
.inspection-train::before { left: 0.08rem; }
.inspection-train::after { right: 0.08rem; }

.route-status {
  min-height: 2.8rem;
  width: min(100%, 32rem);
  margin: 0 auto;
  padding: 0.65rem 0.1rem;
  color: var(--ink);
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: var(--step--1);
}
.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  width: min(100%, 32rem);
  margin: 0 auto;
}
.control { min-height: 3.15rem; padding: 0.45rem 0.25rem; }
.control-key { display: block; color: currentColor; opacity: 0.72; }
.dispatch { grid-column: 1 / -1; }
.dispatch:not(:disabled) { animation: signal-ready 1.4s var(--ease-in-out) infinite; }

.game-note {
  width: min(100% - 1.25rem, 60rem);
  margin: var(--space-6) auto;
  columns: 2 22rem;
  column-gap: 3rem;
  color: var(--muted);
}
.game-note h2, .game-note h3 { break-after: avoid; color: var(--ink); font-family: var(--font-mono); }
.game-note h2 { font-size: var(--step-2); }
.game-note h3 { font-size: var(--step-1); }
.game-note a { color: var(--signal); }

.inline-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem max(0.75rem, env(safe-area-inset-left)) max(1.2rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  color: var(--muted);
  background: var(--paper-2);
  font-size: var(--step--1);
}
.inline-footer nav { display: flex; flex-wrap: wrap; gap: 1rem; }
.inline-footer a { white-space: nowrap; }

dialog {
  width: min(calc(100% - 1.25rem), 34rem);
  max-height: min(85vh, 42rem);
  padding: 0;
  overflow: auto;
  border: 4px solid var(--ink);
  border-radius: var(--radius-card);
  color: var(--ink);
  background: var(--paper-2);
  box-shadow: 12px 14px 0 var(--accent);
  animation: dialog-stamp 300ms var(--snap);
}
dialog::backdrop { background: var(--backdrop); }
.dialog-body { padding: clamp(1rem, 4vw, 2rem); }
.dialog-body h2 { font: 700 var(--step-2) var(--font-mono); }
.dialog-body ol { padding-left: 1.25rem; }
.dialog-body li + li { margin-top: 0.65rem; }
.stars { color: var(--accent); font-size: var(--step-3); letter-spacing: 0.1em; animation: stars-pop 560ms var(--spring); }

@keyframes app-arrive {
  from { opacity: 0; transform: translateY(18px) rotate(-0.6deg) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes screen-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
@keyframes map-travel { to { stroke-dashoffset: -80; } }
@keyframes node-bob { 0%, 80%, 100% { transform: translateY(0); } 88% { transform: translateY(-8px) scale(1.12); } }
@keyframes track-turn { 0% { transform: rotate(-18deg) scale(0.84); } 70% { transform: rotate(5deg) scale(1.07); } 100% { transform: none; } }
@keyframes signal-burst { from { opacity: 0.9; transform: scale(0.2); } to { opacity: 0; transform: scale(3.4); } }
@keyframes hint-wiggle { 0%, 100% { transform: rotate(0); } 45% { transform: rotate(-3deg) scale(1.03); } 65% { transform: rotate(3deg) scale(1.03); } }
@keyframes tile-cheer { 0% { transform: scale(0.88) rotate(-2deg); } 65% { transform: scale(1.08) rotate(1deg); } 100% { transform: none; } }
@keyframes signal-ready { 0%, 75%, 100% { transform: translateY(0); } 84% { transform: translateY(-4px) rotate(-0.5deg); } 92% { transform: translateY(0) rotate(0.5deg); } }
@keyframes dialog-stamp { from { opacity: 0; transform: translateY(16px) rotate(-2deg) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes stars-pop { 0% { opacity: 0; transform: scale(0.35) rotate(-8deg); } 70% { transform: scale(1.15) rotate(2deg); } 100% { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .screen--title { grid-template-columns: 1fr; }
  .route-map { min-height: 14rem; border-top: 4px solid var(--ink); border-left: 0; }
  .route-map svg { max-height: 14rem; }
  .level-grid { grid-template-columns: repeat(3, 1fr); }
  .game-note { columns: auto; }
}

@media (max-width: 420px) {
  .edge-nav__link { display: none; }
  .switchyard-app, .ad-rail { width: calc(100% - 0.7rem); }
  .screen--play { padding-inline: 0.35rem; }
  .route-header { grid-template-columns: 1fr auto auto; gap: 0.4rem; }
  .metric { min-width: 3.3rem; }
  .title-copy { padding-inline: 1.15rem; }
  .controls { gap: 0.25rem; }
  .control { font-size: 0.76rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}
