/* Tick-Tock Station: a country railway station. The page is deep railway
   green, like painted ironwork, so the sunny scene and the departures board
   carry the colour. Ultra (a heavy timetable-poster slab) for the title,
   Figtree for everything else, including the clock's numerals. */

:root {
  --iron: #1c3a2d;
  --iron-deep: #142a20;
  --iron-light: #285040;
  --cream: #fff4d8;
  --brass: #d6a54a;
  --board: #1b232e;
  --board-tile: #27313f;
  --flap: #ffd04d;
  --brick: #b5472f;
  --hour: #2a4fa8;
  --minute: #1d6b43;
  --text: #f5f0df;
  --text-soft: #bfd0c2;

  --display: "Ultra", "Rockwell Extra Bold", Georgia, serif;
  --body: "Figtree", system-ui, sans-serif;
}

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

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--iron);
  color: var(--text);
  font: 500 1.0625rem/1.5 var(--body);
}

.station {
  max-width: 76rem;
  margin: 0 auto;
  padding: clamp(0.5rem, 1.6vw, 1.2rem) clamp(1rem, 3vw, 2rem) 2rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.25rem;
  margin-bottom: 0.8rem;
}
.back { color: var(--text-soft); font-weight: 700; text-underline-offset: 3px; }
.back:hover { color: var(--text); }
h1 {
  margin: 0;
  flex: 1;
  font: 400 clamp(1.5rem, 3.4vw, 2.4rem)/1.05 var(--display);
  color: var(--flap);
  letter-spacing: 0.01em;
}

.levels { display: flex; gap: 0.3rem; padding: 0.3rem; border-radius: 0.8rem; background: var(--iron-deep); }
.levels button {
  min-height: 2.75rem;
  min-width: 2.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font: 700 0.95rem/1.1 var(--body);
  padding: 0.4rem 0.8rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.levels .num {
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--iron-light);
  color: var(--text);
  font-weight: 800;
  font-size: 0.85rem;
}
.levels button[aria-pressed="true"] { background: var(--flap); color: #2b2205; }
.levels button[aria-pressed="true"] .num { background: #2b2205; color: var(--flap); }
.levels button:hover:not([aria-pressed="true"]) { color: var(--text); }

/* Phone first: board, scene, Ready, then the words. Wide screens put the
   scene on the left and everything you read on the right. */
.play {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "board" "scene" "act" "hint" "below";
  gap: 0.7rem;
}
.board { grid-area: board; }
.scene { grid-area: scene; position: relative; }
.act { grid-area: act; }
.hint { grid-area: hint; }
.below { grid-area: below; }

/* the departures board: dark slats, amber split-flap letters */
.board {
  padding: 0.6rem 0.75rem;
  border-radius: 0.6rem;
  background: var(--board);
  border: 3px solid #3a4351;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.06), 0 0.5rem 1.4rem rgba(0, 0, 0, 0.3);
}
.board-head {
  display: none;
  margin: 0 0 0.45rem;
  font: 400 1rem/1 var(--display);
  color: var(--cream);
  letter-spacing: 0.04em;
}
.board-row { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.chip {
  flex: none;
  width: 1.35rem;
  height: 2.4rem;
  border-radius: 0.3rem;
  background: #2f6fd0;
  box-shadow: inset 0 -0.6rem 0 rgba(0, 0, 0, 0.22), inset 0 0.25rem 0 rgba(255, 255, 255, 0.25);
}
.dest {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
  font: 800 1rem/1 var(--body);
  letter-spacing: 0.08em;
  color: var(--flap);
  padding: 0.55rem 0.5rem;
  border-radius: 0.3rem;
  background: linear-gradient(var(--board-tile) 49%, #11161d 49%, #11161d 52%, #222b37 52%);
}
.flaps { display: flex; gap: 0.18rem; flex: none; }
.flaps span {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2.9rem;
  border-radius: 0.3rem;
  font: 800 2rem/1 var(--body);
  font-variant-numeric: tabular-nums;
  color: var(--flap);
  background: linear-gradient(#303b4a 0%, var(--board-tile) 49%, #0d1117 49%, #0d1117 52%, #222b37 52%, #1d2530 100%);
}
.flaps span.colon { width: 0.8rem; background: none; }
.flaps span.flip { animation: flap 0.32s cubic-bezier(0.3, 0, 0.4, 1) both; }
@keyframes flap {
  0% { transform: perspective(12rem) rotateX(0); }
  45% { transform: perspective(12rem) rotateX(88deg); filter: brightness(0.6); }
  55% { transform: perspective(12rem) rotateX(-88deg); filter: brightness(0.6); }
  100% { transform: perspective(12rem) rotateX(0); }
}

.scene {
  border-radius: 0.9rem;
  overflow: hidden;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.4);
}
canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  touch-action: none;
  background: #9fd9f2;
}
.scene.has-focus { outline: 4px solid var(--flap); outline-offset: 3px; }

/* The hands are real sliders for keyboards and screen readers; the canvas
   draws them, and draws a glow round whichever one has focus. */
.hand-control {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.act { display: flex; gap: 0.5rem; }
.ready {
  flex: 1;
  min-height: 3.2rem;
  font: 800 1.25rem/1 var(--body);
  border: 0;
  border-radius: 0.7rem;
  background: var(--flap);
  color: #2b2205;
  box-shadow: 0 0.3rem 0 #b48a13;
  cursor: pointer;
}
.ready:hover { background: #ffdb73; }
.ready:active { transform: translateY(2px); box-shadow: 0 0.1rem 0 #b48a13; }
.ready:disabled { background: var(--iron-light); color: var(--text-soft); box-shadow: none; cursor: default; }
.ready[hidden] { display: none; }

.choices { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(4.5rem, 1fr)); gap: 0.4rem; }
.choices[hidden] { display: none; }
.choices button {
  min-height: 3.2rem;
  font: 800 1.6rem/1 var(--body);
  font-variant-numeric: tabular-nums;
  color: var(--flap);
  border: 3px solid #3a4351;
  border-radius: 0.5rem;
  background: linear-gradient(#303b4a 0%, var(--board-tile) 49%, #0d1117 49%, #0d1117 52%, #222b37 52%, #1d2530 100%);
  cursor: pointer;
}
.choices button:hover:not(:disabled) { border-color: var(--flap); }
.choices button:disabled { opacity: 0.35; cursor: default; text-decoration: line-through; text-decoration-thickness: 3px; }
.choices button.right { border-color: #8be0a4; color: #c9f5d5; }

.hint {
  margin: 0;
  min-height: 3em;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--cream);
}

.below {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.25rem;
}
.progress {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.progress li {
  height: 2.1rem;
  display: grid;
  place-items: center;
  border-radius: 0.4rem;
  background: var(--iron-deep);
  color: var(--flap);
  font-size: 0.6rem;
  letter-spacing: -0.05em;
}
.progress li.now { box-shadow: inset 0 0 0 2px var(--flap); }
.progress li.done { background: var(--iron-light); }

.tally { display: flex; gap: 1.25rem; margin: 0; }
.tally div { display: flex; align-items: baseline; gap: 0.4rem; }
.tally dt { font-size: 1rem; color: var(--text-soft); }
.tally dd { margin: 0; font-weight: 800; font-size: 1.35rem; font-variant-numeric: tabular-nums; }

.again {
  margin-left: auto;
  min-height: 2.75rem;
  font: 700 1rem/1 var(--body);
  padding: 0.7rem 1.2rem;
  border: 2px solid var(--flap);
  border-radius: 0.6rem;
  background: transparent;
  color: var(--flap);
  cursor: pointer;
}
.again:hover { background: rgba(255, 208, 77, 0.12); }

.again:focus-visible,
.ready:focus-visible,
.choices button:focus-visible,
.levels button:focus-visible,
.back:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

.about { max-width: 44rem; margin-top: 1.6rem; color: var(--text-soft); }
.about h2 { margin: 0 0 0.3rem; font: 700 1.1rem/1.3 var(--body); color: var(--text); }
.about p { margin: 0 0 0.8rem; font-size: 1rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Phones: only the chosen level shows its name, the others are numbers. */
@media (max-width: 640px) {
  .station { padding-top: 0.45rem; }
  .top { gap: 0.3rem 0.9rem; margin-bottom: 0.5rem; }
  h1 { font-size: 1.5rem; white-space: nowrap; }
  .levels { width: 100%; }
  .levels button { padding: 0.3rem 0.55rem; }
  .levels button[aria-pressed="false"] .name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .levels button[aria-pressed="true"] { flex: 1; font-size: 1rem; }
  .play { gap: 0.55rem; }
  .board { padding: 0.45rem 0.55rem; }
  .flaps span { width: 1.75rem; height: 2.5rem; font-size: 1.7rem; }
  .flaps span.colon { width: 0.6rem; }
  .chip { height: 2.1rem; width: 1.1rem; }
  .ready, .choices button { min-height: 3rem; }
  .hint { font-size: 1rem; min-height: 4.4em; }
}

/* Tablets: a squarer scene, so Ready stays on screen. */
@media (min-width: 641px) and (max-width: 899px) {
  canvas { aspect-ratio: 1 / 1; max-height: calc(100svh - 21rem); min-height: 24rem; }
}

/* Wide screens: scene left, board and buttons right. */
@media (min-width: 900px) {
  .play {
    grid-template-columns: minmax(0, 2fr) minmax(18rem, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas: "scene board" "scene act" "scene hint" "scene below";
    gap: 1rem 1.4rem;
    align-items: start;
  }
  canvas { aspect-ratio: 6 / 5; max-height: calc(100svh - 8rem); }
  .board { padding: 0.9rem 1rem 1rem; }
  .board-head { display: block; }
  .board-row { flex-wrap: wrap; }
  .dest { flex-basis: calc(100% - 2rem); }
  .flaps { margin-left: auto; }
  .flaps span { width: 2.6rem; height: 3.7rem; font-size: 2.6rem; }
  .hint { font-size: 1.1rem; }
}

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