@font-face {
  font-family: Fredoka;
  src: url("../assets/fonts/Fredoka.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #2c3824;
  --paper: #f3e6c8;
  --paper-edge: #c6ae78;
  --sage: #8ea67c;
  --sage-deep: #6d865c;
  --cream: #f4ead4;
  --green: #2c4a32;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e5d2ae;
  color: var(--ink);
  font-family: Fredoka, "Trebuchet MS", "Gill Sans", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  padding: clamp(8px, 1.6vw, 22px);
}

.sheet {
  position: relative;
  height: 100%;
  min-height: 0;
  background: var(--paper);
  border: 3px solid var(--paper-edge);
  box-shadow: inset 0 0 0 7px var(--paper), inset 0 0 0 9px #b89a62;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  padding: clamp(8px, 1.4vh, 16px) clamp(10px, 2vw, 28px);
  overflow: hidden;
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.85'/></svg>");
  mix-blend-mode: multiply;
}

#root {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.sound, .gear {
  position: absolute;
  top: 10px;
  z-index: 6;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: #f7f1e2;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
}

.sound { right: 12px; }
.gear { right: 68px; }
.sound svg, .gear svg { width: 100%; height: 100%; display: block; }
.sound[aria-pressed="false"] { background: #e4d3b0; }

.settings {
  position: absolute;
  top: 64px;
  right: 12px;
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f7f1e2;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 4px 0 var(--ink);
}

.settings[hidden] { display: none; }

.settings button, .texty {
  font: inherit;
  font-size: 1.05rem;
  min-height: 44px;
  min-width: 132px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #fffaf0;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
}

.hero {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.poster-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  width: min(96%, calc((100dvh - 90px) * 4 / 3));
  max-height: calc(100% - 4px);
}

.poster {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: 8px;
}

.poster-copy {
  position: absolute;
  left: 50%;
  top: 43%;
  transform: translate(-50%, -50%);
  width: 28%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28em;
  text-align: center;
}

.poster-title {
  margin: 0;
  color: #243226;
  font-weight: 700;
  font-size: clamp(1.7rem, 4.6vw, 5.2rem);
  line-height: 0.82;
  letter-spacing: -0.04em;
}

.play-btn {
  position: static;
  width: 100%;
  min-height: 52px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--green);
  color: #f6f1e4;
  font: inherit;
  font-weight: 650;
  font-size: clamp(1.3rem, 3.4vw, 2.3rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  box-shadow: 0 4px 0 #1a2e1e;
  cursor: pointer;
}

.play-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #1a2e1e; }

.pick {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: clamp(10px, 2vh, 18px);
  padding: 54px 4px 8px;
}

.tile {
  font: inherit;
  color: var(--ink);
  background: #f7f1e2;
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 4px 0 var(--ink);
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  position: relative;
}

.tile b {
  font-size: clamp(1.5rem, 3vw, 2.3rem);
  font-weight: 650;
  letter-spacing: 0.04em;
}

.tile svg { width: min(42%, 120px); height: auto; }
.tile .seen {
  position: absolute;
  top: 10px;
  left: 12px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--sage-deep);
  border: 2px solid var(--ink);
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 52px;
}

.top {
  width: min(100%, 920px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
}

.back, .again, .next, .show {
  font: inherit;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f6f1e4;
  background: var(--sage-deep);
  border: 3px solid var(--ink);
  border-radius: 999px;
  min-height: 48px;
  min-width: 96px;
  padding: 0 16px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}

.show {
  min-width: 48px;
  width: 48px;
  padding: 0;
  background: #f7f1e2;
  color: var(--ink);
  font-size: 1.4rem;
}

.dots { display: flex; gap: 7px; margin: 0; padding: 0; }
.dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
  display: block;
}
.dots i.on { background: var(--sage-deep); }

.eq {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.18em;
  margin: 0;
  font-weight: 650;
  font-size: clamp(2.4rem, 7vh, 5rem);
  letter-spacing: -0.03em;
  line-height: 0.95;
  max-width: 100%;
}

.eq.long { font-size: clamp(1.45rem, 4.2vw, 3.1rem); }

.gap, .eq input {
  font: inherit;
  font-size: 1em;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 0.08em solid currentColor;
  min-width: 0.7em;
  text-align: center;
  padding: 0 0.04em;
  border-radius: 0.12em;
}

button.gap { cursor: pointer; }
.eq input { width: 1.5em; height: 1.05em; line-height: 1; padding: 0; caret-color: var(--ink); }
.eq.shake { animation: shake 0.35s ease; }

.pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(46px, 62px));
  gap: 6px;
  width: min(100%, 210px);
}

.pad button {
  font: inherit;
  font-size: 1.3rem;
  min-width: 46px;
  min-height: 46px;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: #f7f1e2;
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}

.pad [data-act="back"] { font-size: 1rem; }
.pad .check-answer {
  grid-column: 1 / -1;
  min-height: 48px;
  background: var(--green);
  color: #f6f1e4;
  font-size: 1.02rem;
  box-shadow: 0 3px 0 #1a2e1e;
}

.pad .check-answer:active { transform: translateY(2px); box-shadow: 0 1px 0 #1a2e1e; }

.work {
  width: min(100%, 980px);
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: safe center;
  justify-content: safe center;
  gap: 16px;
}

.stage.typing { justify-content: flex-start; }
.stage.typing .work { align-items: flex-start; flex: 0 1 auto; }
.pad { position: relative; z-index: 2; }

.mascot { width: 96px; flex: none; pointer-events: none; align-self: end; }
.mascot svg { width: 100%; height: auto; display: block; }
.mascot.react { animation: wobble 0.8s ease; }
.stage.crowd .mascot, .stage.typing .mascot, .stage.wide .mascot, .stage.bars .mascot, .stage.quick .mascot { display: none; }

.board { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }

.stage.trays { --well: min(calc((100dvh - 300px) / 3.6), calc((100vw - 160px) / 4.5), 120px); }
.stage.trays.wide { --well: min(calc((100dvh - 280px) / 2.7), calc((100vw - 56px) / 6.6), 100px); }
.stage.trays.typing { --well: min(calc((100dvh - 620px) / 3.4), calc((100vw - 48px) / 4.6), 72px); }
.stage.trays.wide.typing { --well: min(calc((100dvh - 600px) / 2.5), calc((100vw - 36px) / 6.8), 64px); }

.tray {
  display: grid;
  grid-template-columns: repeat(4, var(--well));
  gap: 8px 10px;
  padding: 12px;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.28), transparent 32%),
    linear-gradient(#9aaf88, #7f9870);
  border: 3px solid var(--ink);
  border-radius: 28px;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.18), 0 4px 0 rgba(44, 56, 36, 0.18);
}

.stage.wide .tray { grid-template-columns: repeat(6, var(--well)); }

.well {
  width: var(--well);
  height: calc(var(--well) * 1.02);
  border-radius: 46%;
  background: radial-gradient(ellipse at 50% 40%, #b7c7a4, #6d865c 72%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.28);
  display: grid;
  place-items: center;
}

.well.empty { cursor: pointer; }
.pool span { display: flex; flex-direction: column; align-items: center; }
.well svg, .egg svg { width: 100%; height: auto; display: block; }

.pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: end;
  gap: 6px 8px;
  max-width: 100%;
}

.egg {
  width: clamp(48px, 9vh, 92px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
}
.stage.crowd .egg, .stage.typing .egg { width: clamp(40px, 6.5vh, 64px); }
.well .egg, .cell .egg, .well .seated, .cell .seated { width: 84%; }
.egg.selected { transform: translateY(-8px); }
.egg.dragging {
  position: fixed;
  z-index: 30;
  margin: 0;
  pointer-events: none;
  cursor: grabbing;
}
.arrow { width: 18px; height: 22px; display: block; margin: 0 auto 2px; }

.tenframes { display: flex; gap: 18px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.frame { display: grid; grid-template-columns: repeat(5, var(--cell)); gap: 6px; padding: 10px; border: 3px solid var(--ink); border-radius: 16px; background: #f7f1e2; }
.stage.frames { --cell: min(calc((100dvh - 360px) / 3.2), calc((100vw - 80px) / 11.4), 74px); }
.stage.frames.typing { --cell: min(calc((100dvh - 640px) / 3.4), 16vw, 56px); }
.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 46%;
  background: radial-gradient(ellipse at 50% 40%, #c5d4b4, #7f986c 74%);
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
}
.cell.empty { background: #e7e1cf; cursor: pointer; }
.cell .egg, .cell .seated { width: 86%; }
.numeral { text-align: center; font-size: 1.4rem; margin: 4px 0 0; min-height: 1.2em; }

.tracks { width: min(100%, 860px); display: flex; flex-direction: column; gap: 14px; }
.lane {
  position: relative;
  height: 72px;
  border-bottom: 3px solid var(--ink);
  background-image: repeating-linear-gradient(90deg, transparent, transparent calc(10% - 1px), rgba(44, 56, 36, 0.18) calc(10% - 1px), rgba(44, 56, 36, 0.18) 10%);
}
.stage[data-max="40"] .lane, .stage[data-max="52"] .lane {
  background-image: repeating-linear-gradient(90deg, transparent, transparent calc(12.5% - 1px), rgba(44, 56, 36, 0.16) calc(12.5% - 1px), rgba(44, 56, 36, 0.16) 12.5%);
}
.block {
  position: absolute;
  bottom: 8px;
  height: 52px;
  min-width: 18px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #f4ead4;
  color: var(--ink);
  display: grid;
  place-items: center;
  font: inherit;
  font-size: clamp(1rem, 2vw, 1.5rem);
  font-weight: 650;
  touch-action: none;
  cursor: grab;
  padding: 0;
}
.block.known { background: #b7c7a4; }
.block.diff, .block.part { background: #6d865c; color: #f6f1e4; }
.handle, .cut {
  position: absolute;
  top: -6px;
  width: 44px;
  height: 64px;
  border: 0;
  background: transparent;
  padding: 0;
}
.handle { right: -18px; cursor: ew-resize; }
.handle::after, .cut::after {
  content: "";
  position: absolute;
  top: 18px;
  left: 18px;
  width: 8px;
  height: 28px;
  border-radius: 4px;
  background: var(--ink);
}
.cut { left: 50%; transform: translateX(-50%); cursor: ew-resize; }
.cut::after { background: #f6f1e4; box-shadow: 0 0 0 2px var(--ink); }

.reveal { display: flex; gap: 10px; align-items: end; justify-content: center; min-height: 72px; }
.chip {
  height: 56px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #f4ead4;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: 650;
}
.chip.ten { background: #b7c7a4; }

.end {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.end .mascot { width: min(28vh, 160px); display: block; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.iris {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 46%, transparent 0 10%, rgba(232, 220, 190, 0.2) 12%, #8ea67c 28%, #5d784f 46%, #2c3824 68%);
}

.iris.show { animation: iris 0.7s ease; }

@keyframes iris {
  0% { opacity: 0; transform: scale(1.2); }
  40% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(0deg); }
  40% { transform: rotate(-4deg); }
  70% { transform: rotate(3deg); }
}

@media (max-width: 980px) {
  .mascot { display: none; }
}

@media (max-width: 720px) {
  .poster-frame {
    width: min(100%, calc((100dvh - 160px) * 4 / 3));
    aspect-ratio: 4 / 3;
  }
  .poster { object-fit: contain; }
  .poster-copy { width: 30%; top: 42%; }
  .poster-title { font-size: clamp(1.45rem, 6.4vw, 2.2rem); }
  .play-btn { min-height: 44px; font-size: 1.05rem; }
  .stage.typing .eq { font-size: 2rem; }
  .stage.typing .eq.long { font-size: 1.35rem; }
  .stage.typing .pad { gap: 4px; }
  .stage.typing .pad button { min-height: 44px; min-width: 44px; font-size: 1.15rem; line-height: 1; }
  .stage.trays.typing { --well: 48px; }
  .stage.trays.wide.typing { --well: 44px; }
  .stage.frames.typing { --cell: 44px; }
  .stage.typing .egg { width: 44px; }
  .tenframes { flex-direction: column; align-items: center; }
  .stage.frames { --cell: min(calc((100vw - 64px) / 5.4), 58px); }
  .stage.trays { --well: min(calc((100vw - 48px) / 4.5), 86px); }
  .stage.trays.wide { --well: min(calc((100vw - 36px) / 6.6), 58px); }
  .lane { height: 64px; }
  .block { height: 46px; font-size: 1rem; }
  .pick { padding-top: 58px; gap: 8px; }
  .tile b { font-size: 1.35rem; }
}

body.still *, body.still *::before, body.still *::after {
  animation: none !important;
  transition: none !important;
}

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