:root {
  --paper: #fff6ea;
  --ink: #241833;
  --muted: #6c617c;
  --m: #e23b4a;
  --i: #2c6bed;
  --u: #f0a202;
  --u-ink: #3d2a00;
  --card: #fffdf8;
  --line: #eadcc6;
  --glow: #ffd15c;
  --shadow: 0 16px 40px rgba(36, 24, 51, 0.08);
  color: var(--ink);
  background: var(--paper);
  font-family: ui-rounded, "Trebuchet MS", "Segoe UI", sans-serif;
  line-height: 1.35;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 420px at 10% -10%, #ffe7c2 0%, transparent 60%),
    var(--paper);
}
main { flex: 1; width: min(1080px, calc(100% - 32px)); margin: 0 auto; padding: 8px 0 32px; }
a { color: inherit; }
button, .tile, .back, .enter { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--i); outline-offset: 3px; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  z-index: 5;
}
.skip:focus { top: 8px; }

.top {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 8px;
}
.topbar, .toolbar, .footer-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.brand {
  font-weight: 800;
  text-decoration: none;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
}
.version {
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
}
.language-flags { display: flex; flex-wrap: wrap; gap: 6px; }
.language-flags button, .tool, .text-button, .back {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  min-height: 44px;
  padding: 8px 12px;
}
.language-flags button[aria-pressed="true"], .tool[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.eyebrow, .goal {
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.95rem;
}
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -0.04em; margin: 0 0 8px; }
h2 { font-size: 1.05rem; margin: 0; }

.tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 18px;
}
.tile {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 92px;
  padding: 16px;
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.tile h2 { font-size: 1.25rem; }
.tile.open {
  background: linear-gradient(135deg, #fff, #fff4d8);
  border-color: #f0c14d;
}
.tile.locked { filter: saturate(0.7); }
.badge {
  border-radius: 999px;
  padding: 6px 10px;
  background: #efe7da;
  color: var(--muted);
  font-size: 0.85rem;
}
.tile.open .badge { background: var(--ink); color: white; }
.mark { width: 72px; height: 56px; display: block; }
.lock-icon { font-size: 1.4rem; }

.stage {
  display: grid;
  gap: 18px;
  margin-top: 12px;
}
.blocks {
  min-height: 104px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 12px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 28px;
}
.block, .mini {
  display: grid;
  place-items: center;
  font-weight: 800;
  border: 0;
  padding: 0;
}
.block {
  width: clamp(58px, 16vw, 88px);
  height: clamp(58px, 16vw, 88px);
  font-size: clamp(1.4rem, 4vw, 2rem);
  box-shadow: 0 8px 0 rgba(36, 24, 51, 0.08);
}
.block.m, .mini.m { background: var(--m); color: white; }
.block.m { border-radius: 18px; }
.mini.m { border-radius: 5px; }
.block.i, .mini.i { background: var(--i); color: white; border-radius: 999px; }
.block.i { width: clamp(46px, 12vw, 68px); }
.mini.i { width: 16px; }
.block.u, .mini.u { background: var(--u); color: var(--u-ink); border-radius: 50%; }
.block.in-span { box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.75), 0 8px 0 rgba(36, 24, 51, 0.08); }
.block.spot { outline: 4px solid var(--glow); outline-offset: 4px; }
.block.pop { animation: pop 0.42s cubic-bezier(.2, 1.4, .4, 1) both; }
.block.leave { animation: leave 0.24s ease both; }
.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rule {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 96px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #f7f1e7;
  color: var(--ink);
  opacity: 0.42;
}
.rule svg { width: min(100%, 132px); height: 36px; }
.rule svg .m { fill: var(--m); }
.rule svg .i { fill: var(--i); }
.rule svg .u { fill: var(--u); }
.rule span { font-size: 0.92rem; font-weight: 700; }
.rule.is-ready {
  opacity: 1;
  background: white;
  box-shadow: 0 0 0 3px var(--glow), 0 10px 24px rgba(240, 162, 2, 0.25);
}
.rule.is-picking { box-shadow: 0 0 0 3px var(--i), 0 10px 24px rgba(44, 107, 237, 0.25); }
.pick {
  text-align: center;
  font-weight: 700;
  color: var(--i);
}
.tree-hint {
  margin: 0 auto 8px;
  max-width: 280px;
  text-align: center;
  font-weight: 700;
}
.text-button.is-hot {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--i);
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.text-button { min-width: 112px; border-radius: 16px; font-weight: 700; }
.text-button.is-dim { opacity: 0.45; }

.counter {
  margin-top: 22px;
  padding: 16px;
  border-radius: 24px;
  background: white;
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
}
.count-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#icount { font-size: 2rem; font-variant-numeric: tabular-nums; }
.dots { display: flex; flex-wrap: wrap; gap: 4px; }
.mini { width: 22px; height: 22px; font-size: 11px; }
#hint { justify-self: start; }
#hint-body { margin: 0; }
#hint-body:not([hidden]) { display: grid; gap: 4px; }

.trail { margin-top: 22px; }
.trail-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 2px 8px;
  scroll-behavior: smooth;
}
.step {
  display: flex;
  gap: 3px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
}
.step.latest { box-shadow: 0 0 0 2px var(--glow); }
.arrow { align-self: center; color: var(--muted); }

.soon-main { text-align: center; padding-top: 12vh; }
.lock {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: #efe7da;
  font-size: 2rem;
}
.back { display: inline-flex; align-items: center; text-decoration: none; margin-top: 12px; }
.resting { text-align: center; font-weight: 700; }
footer {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto 18px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
#debug {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 6;
  width: min(420px, calc(100% - 24px));
  margin: 0;
  padding: 12px 14px;
  background: #241833;
  color: #fff6ea;
  border-radius: 14px;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.78rem;
}
#debug p { margin: 4px 0; overflow-wrap: anywhere; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.splash-body {
  background: radial-gradient(circle at 50% 40%, #322656, #1a1430 62%);
  color: #fff6ea;
}
.splash-body .version, .splash-body footer { color: #d9cfe8; }
.splash-body .language-flags button,
.splash-body .tool { background: transparent; color: #fff6ea; border-color: rgba(255, 246, 234, 0.35); }
#loop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  pointer-events: none;
}
.splash-body header, .splash-body .skip { position: relative; z-index: 3; }
.splash-body footer {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(1080px, calc(100% - 32px));
  margin: 0;
}
.enter {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 18vh 24px 16vh;
  text-align: center;
  text-decoration: none;
  color: inherit;
}
.enter h1, .enter p { text-shadow: 0 2px 18px rgba(26, 20, 48, 0.85); }
.enter h1 { font-size: clamp(2.4rem, 8vw, 4.6rem); }
.tile h2 { min-width: 0; }
.hint-line { font-weight: 700; letter-spacing: 0.04em; }

.picture-frame {
  background: #e2d0ba;
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
}
#picture { width: 100%; height: auto; display: block; touch-action: manipulation; background: #e2d0ba; overflow: hidden; }
.bird { cursor: pointer; }
.bird .halo { opacity: 0; pointer-events: none; }
.bird.lit .halo { animation: bird-pulse 1.15s ease-in-out infinite; }
#picture circle { pointer-events: none; }
@keyframes bird-pulse {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.95; }
}
@media (prefers-reduced-motion: reduce) {
  .bird.lit .halo { animation: none; opacity: 0.9; }
}
.animal { cursor: pointer; outline: none; }
.animal .body { stroke: none; }
.animal.gap .body {
  stroke: #241833;
  stroke-width: 3.5px;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.animal .glow {
  fill: none;
  stroke: #7eb6ff;
  stroke-width: 18;
  stroke-linejoin: round;
  opacity: 0;
  pointer-events: none;
}
.animal.found .glow { opacity: 0.9; }
.animal .mark, .animal .bill-upper, .animal .bill-lower, .animal .bill-mouth, .animal .bill-shine, .animal .eye-ring, .animal .eye-white, .animal .pupil {
  pointer-events: none;
}
.bill-upper { fill: url(#bill-shade); stroke: #9a3d04; stroke-width: 2.4px; stroke-linejoin: round; }
.bill-lower { fill: #f0b56a; stroke: #9a3d04; stroke-width: 2.4px; stroke-linejoin: round; }
.bill-mouth { fill: none; stroke: #6b320c; stroke-width: 1.6px; stroke-linecap: round; }
.bill-shine { fill: none; stroke: #fff1d6; stroke-width: 1.4px; stroke-linecap: round; }
.eye-ring { fill: #241833; }
.eye-white { fill: #fff6ea; }
.pupil { fill: #241833; }
.fade {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  gap: 12px;
  align-items: center;
  margin: 14px 0;
  font-weight: 700;
}
.mark-icon { width: 32px; height: 24px; display: block; }

.rec-part { margin: 28px 0 36px; }
.rec-part h2 { text-align: center; margin-bottom: 12px; }
.story {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.level-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: min(100%, 560px);
  max-width: 100%;
  margin-inline: auto;
}
.level-stack {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  gap: 8px;
}
.level-stack li {
  width: 22px;
  height: 10px;
  border-radius: 999px;
  flex: none;
}
#level-n {
  min-width: 2.4em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.frame-box { cursor: pointer; }
.frame-box {
  width: min(100%, 560px);
  margin-inline: auto;
  position: relative;
}
.frame-box::before {
  content: "";
  display: block;
  padding-top: 100%;
}
.story-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 28px;
}
.scene-cam { position: absolute; inset: 0; transform-origin: 0 0; }
.scene-root { display: block; width: 100%; height: 100%; }
#tree, #rabbits {
  width: min(100%, 720px);
  cursor: pointer;
  margin: 0 auto;
  display: block;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 28px;
}
.rec-depth { grid-template-columns: auto 1fr auto; max-width: 640px; margin-inline: auto; }
#depth-n, #rabbit-n { font-variant-numeric: tabular-nums; font-size: 1.6rem; }
@media (prefers-reduced-motion: reduce) {
  .scene-cam { transition: none !important; }
}
.fade input { width: 100%; accent-color: var(--ink); min-height: 44px; }
@keyframes wiggle {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-5px); }
  70% { transform: translateY(3px); }
}
.animal.wiggle { animation: wiggle 0.42s ease; }

.race {
  background: linear-gradient(#fffdf8, #ffe8c4);
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
}
.lane { position: relative; height: 168px; }
.ground {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 22px;
  height: 6px;
  border-radius: 6px;
  background: #e7d3b0;
}
.runner, .tortoise { position: absolute; bottom: 10px; }
.runner { left: 0; width: 72px; z-index: 1; transition: left 0.5s cubic-bezier(.2, .8, .2, 1); }
.runner svg, .tortoise svg { display: block; width: 100%; height: auto; }
.tortoise { right: 4px; width: min(38vw, 176px); }
.still { font-weight: 700; text-align: center; }
.bar-wrap { margin-top: 8px; }
.bar {
  display: flex;
  height: 44px;
  border-radius: 14px;
  overflow: hidden;
  background: #efe7da;
  border: 1px solid var(--line);
}
.crumb { flex: 0 1 auto; min-width: 0; height: 100%; }
.crumb.c0 { background: var(--m); }
.crumb.c1 { background: var(--i); }
.crumb.c2 { background: var(--u); }
.crumb.rest {
  background: repeating-linear-gradient(90deg, #f7f1e7, #f7f1e7 7px, #e7d7bc 7px, #e7d7bc 9px);
}
#step.is-ready { box-shadow: 0 0 0 3px var(--glow); }

@keyframes pop {
  from { transform: scale(0.2); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes leave {
  to { transform: scale(0.2); opacity: 0; }
}
@keyframes glow {
  50% { box-shadow: 0 0 0 5px #ffe7a3, 0 10px 24px rgba(240, 162, 2, 0.35); }
}
.rule.is-ready { animation: glow 1.8s ease-in-out infinite; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile.open { grid-column: 1 / -1; }
}
@media (min-width: 900px) {
  .stage { grid-template-columns: 1fr 300px; align-items: center; }
  .lane { height: 200px; }
  .tortoise { width: 190px; }
}
@media (max-width: 520px) {
  .lane { height: 132px; }
  .runner { width: 56px; }
  .text-button { min-width: 0; flex: 1 1 42%; }
}
@media (max-width: 640px) {
  .language-name { 
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .language-flags button { position: relative; min-width: 44px; padding-inline: 10px; }
}
.canon-lead, .rec-part h2 { text-align: center; }
.letter-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 8px auto 0;
  max-width: 640px;
}
.letter {
  flex: 1 1 0;
  min-width: 0;
  max-width: 52px;
  min-height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font-weight: 800;
  font-size: clamp(0.85rem, 3.2vw, 1.2rem);
  line-height: 1;
}
.letter.is-gap { color: #cbbba6; }
.canon-mark {
  margin: 10px 0 0;
  text-align: center;
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
}
.canon-mark.yes { color: #1f7a4a; }
.canon-mark.no { color: #c4492a; }
.staff {
  width: min(100%, 880px);
  margin: 0 auto;
  display: block;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 28px;
}
.staff .note { cursor: pointer; }
.colony {
  width: min(100%, 840px);
  height: auto;
  aspect-ratio: 28 / 18;
  display: block;
  margin: 8px auto 0;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 28px;
  touch-action: manipulation;
  cursor: pointer;
}
.ant-zoom { max-width: 520px; margin-inline: auto; grid-template-columns: auto 1fr auto; }
.fugue { width: min(100%, 420px); margin: 0 auto; }
.fugue-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0;
  opacity: 0.38;
}
.fugue-row.is-in { opacity: 1; }
.fugue-voice { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.fugue-note {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  display: grid;
  place-items: center;
  font-weight: 800;
}
.fugue-note.is-on {
  background: var(--voice, #e7a008);
  color: white;
  border-color: transparent;
}
.staff .bar, .staff .halo { pointer-events: none; }
.crab-stage {
  --crab-w: 108px;
  position: relative;
  height: 150px;
  margin: 0 auto;
  max-width: 720px;
  overflow: hidden;
  border-radius: 28px;
  background: linear-gradient(#fffdf8, #ffe8c4);
  border: 1px solid var(--line);
}
.crab-stage::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 16px;
  background: #f0c9a0;
}
.crab {
  position: absolute;
  bottom: 12px;
  width: var(--crab-w);
  z-index: 1;
}
.crab svg { display: block; width: 100%; height: auto; }
.crab.a { animation: crab-right 7s ease-in-out infinite alternate; }
.crab.b { animation: crab-left 7s ease-in-out infinite alternate; transform: scaleX(-1); }
@keyframes crab-right {
  from { left: 4%; }
  to { left: calc(100% - var(--crab-w) - 4%); }
}
@keyframes crab-left {
  from { left: calc(100% - var(--crab-w) - 4%); }
  to { left: 4%; }
}
@media (max-width: 520px) {
  .letter-row { gap: 3px; }
  .crab-stage { --crab-w: 84px; height: 128px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .crab { animation: none !important; }
  .crab.a { left: 8%; }
  .crab.b { left: auto; right: 8%; }
}
