:root {
  --ink: #2b2d42;
  --paper: #fff8ec;
  --coral: #ff6b6b; --coral-d: #d94848;
  --sun: #ffc93c; --sun-d: #e0a400;
  --sky: #4da8ff; --sky-d: #2a7fd6;
  --leaf: #3fbf7f; --leaf-d: #2a9660;
  --grape: #9b6bff; --grape-d: #7445dc;
  --accent: var(--sky); --accent-d: var(--sky-d);
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}
.theme-coral { --accent: var(--coral); --accent-d: var(--coral-d); }
.theme-sky { --accent: var(--sky); --accent-d: var(--sky-d); }
.theme-leaf { --accent: var(--leaf); --accent-d: var(--leaf-d); }
.theme-grape { --accent: var(--grape); --accent-d: var(--grape-d); }
.theme-teal { --accent: #1fa89f; --accent-d: #14807a; }
.theme-orange { --accent: #f7883a; --accent-d: #d0651a; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  background:
    radial-gradient(circle at 6% 10%, #ffe6c4 0 90px, transparent 91px),
    radial-gradient(circle at 96% 88%, #e1f0ff 0 150px, transparent 151px),
    radial-gradient(circle at 90% 6%, #e6f8ee 0 60px, transparent 61px),
    var(--paper);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
button { font-family: inherit; color: inherit; }

/* Game header */
.bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.bar h1 { flex: 1; margin: 0; font-size: clamp(20px, 5vw, 30px); }
.round-btn {
  flex: none; width: 56px; height: 56px; border-radius: 50%; border: none;
  background: #fff; box-shadow: 0 4px 0 #0000001f; font-size: 28px;
  display: grid; place-items: center; text-decoration: none; cursor: pointer;
}
.stars { display: flex; gap: 2px; }
.star { font-size: 28px; color: #e8dcc8; transition: color .3s; }
.star.lit { color: var(--sun); text-shadow: 0 2px 0 var(--sun-d); }

/* Play area */
.stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: 8px 16px 40px; text-align: center;
}
.prompt { margin: 0; font-size: clamp(26px, 6.5vw, 42px); font-weight: 800; }
.picture { font-size: clamp(100px, 28vw, 170px); line-height: 1.1; }
.word { font-size: clamp(40px, 10vw, 68px); font-weight: 800; letter-spacing: .08em; }
.word .hl { color: var(--accent); }
.target-card {
  min-width: 120px; padding: 6px 28px; border-radius: 28px; background: #fff;
  box-shadow: 0 6px 0 #0000001a; font-size: clamp(72px, 18vw, 110px); font-weight: 800; line-height: 1.2;
}

.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(12px, 3.5vw, 28px); }
.tile {
  --c: var(--sky); --cd: var(--sky-d);
  width: clamp(96px, 27vw, 150px); aspect-ratio: 1; border: none; border-radius: 28px;
  background: var(--c); box-shadow: 0 8px 0 var(--cd); color: #fff;
  font-size: clamp(58px, 16vw, 96px); font-weight: 800; line-height: 1; cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.tile:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--cd); }
.tile:focus-visible, .btn:focus-visible, .round-btn:focus-visible, .game-card:focus-visible { outline: 4px solid var(--ink); outline-offset: 4px; }
.tile.used { visibility: hidden; }
.tile.yes { outline: 6px solid var(--sun); outline-offset: 4px; }
.c0 { --c: var(--coral); --cd: var(--coral-d); }
.c1 { --c: var(--sky); --cd: var(--sky-d); }
.c2 { --c: var(--leaf); --cd: var(--leaf-d); }
.c3 { --c: var(--grape); --cd: var(--grape-d); }
.choices.small .tile { width: clamp(72px, 20vw, 110px); font-size: clamp(44px, 12vw, 72px); border-radius: 22px; }

.btn {
  border: none; border-radius: 999px; padding: 14px 26px; background: #fff;
  box-shadow: 0 5px 0 #0000001f; font-size: 22px; font-weight: 800; cursor: pointer;
}
a.btn { display: inline-block; text-decoration: none; }
.hero .back { margin-top: 24px; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #0000001f; }
.btn.go { background: var(--accent); color: #fff; box-shadow: 0 6px 0 var(--accent-d); font-size: 30px; padding: 18px 44px; }
.btn.hear { font-size: 20px; padding: 10px 20px; }
.chips { display: flex; gap: 10px; }
.chip { font-size: 20px; padding: 10px 20px; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* Spelling */
.slots { display: flex; gap: clamp(8px, 2.5vw, 14px); }
.slot {
  width: clamp(64px, 18vw, 100px); aspect-ratio: 1; border-radius: 20px;
  border: 4px dashed #d8c8ac; background: #ffffff88;
  display: grid; place-items: center; font-size: clamp(44px, 12vw, 72px); font-weight: 800;
}
.slot.filled { border-style: solid; border-color: var(--accent); background: #fff; }

/* Alphabet train */
.train { display: flex; align-items: flex-end; gap: 8px; }
.engine { font-size: clamp(72px, 19vw, 110px); line-height: 1; }
.car {
  position: relative; width: clamp(66px, 18vw, 100px); aspect-ratio: 1.1; margin-bottom: 14px;
  border-radius: 14px 14px 8px 8px; background: var(--coral); color: #fff;
  display: grid; place-items: center; font-size: clamp(40px, 11vw, 64px); font-weight: 800;
}
.car:nth-of-type(odd) { background: var(--grape); }
.car::before, .car::after {
  content: ""; position: absolute; bottom: -14px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--ink); border: 5px solid #8d90a6;
}
.car::before { left: 10%; }
.car::after { right: 10%; }
.car.q { background: #fff; color: var(--accent); border: 4px dashed var(--accent); }

/* Letter tracing */
.trace-box {
  height: min(52vh, 440px); aspect-ratio: 100 / 140; max-width: 86vw; padding: 6px;
  border-radius: 28px; background: #fff; box-shadow: 0 6px 0 #0000001a;
}
.trace { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
.trace path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trace .guide { stroke: #efe6d6; stroke-width: 15; }
.trace .dots { stroke: #c4b393; stroke-width: 2.6; stroke-dasharray: 0.1 6; }
.trace .ink { stroke: var(--accent); stroke-width: 15; }
.trace .start { pointer-events: none; }
.trace .start circle { fill: var(--leaf); stroke: #fff; stroke-width: 2; }
.trace .start text { fill: #fff; font-size: 9px; font-weight: 800; text-anchor: middle; dominant-baseline: central; }
.trace .demo { fill: var(--coral); opacity: .85; pointer-events: none; }

/* Road building */
.board {
  --cols: 3; --rows: 3;
  position: relative; container-type: inline-size;
  display: grid; grid-template-columns: repeat(var(--cols), 1fr);
  width: min(92vw, 440px, calc(44vh * var(--cols) / var(--rows)));
  border-radius: 22px; overflow: hidden; background: #c4e8a6; box-shadow: 0 6px 0 #0000001a;
}
.cell { position: relative; aspect-ratio: 1; display: grid; place-items: center; font-size: calc(36cqw / var(--cols)); }
.cell svg, .piece svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.road-edge, .road-top, .road-line { fill: none; stroke-linecap: round; }
.road-edge { stroke: #d6ab5f; stroke-width: 46; }
.road-top { stroke: #f7dc9f; stroke-width: 38; }
.road-line { stroke: #fff; stroke-width: 3; stroke-dasharray: 7 9; opacity: .9; }
.cell.hole {
  margin: 8%; aspect-ratio: auto; border: 4px dashed #ffffffd9; border-radius: 16px;
  background: #ffffff4d; cursor: pointer; padding: 0;
}
.cell.hole.target { border-color: var(--sun-d); background: #fff9; }
.token {
  position: absolute; z-index: 2; font-size: calc(58cqw / var(--cols)); line-height: 1;
  transform: translate(-50%, -55%); pointer-events: none;
}
.friend { z-index: 3; transition: left .4s ease-in-out, top .4s ease-in-out; }
.tray { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.piece {
  position: relative; width: clamp(66px, 19vw, 90px); aspect-ratio: 1; padding: 0; border: none;
  border-radius: 16px; overflow: hidden; background: #c4e8a6; box-shadow: 0 6px 0 #8fbf73; cursor: pointer;
  transition: transform .12s;
}
.piece.selected { outline: 5px solid var(--sun-d); outline-offset: 3px; transform: translateY(-6px); }
.piece:focus-visible, .cell.hole:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }

/* Overlays and effects */
.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: #2b2d4270; }
.card { width: 100%; max-width: 420px; padding: 32px 24px; border-radius: 32px; background: #fff; text-align: center; box-shadow: 0 20px 50px #0003; }
.card .actions { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 8px; }
.paul {
  display: block; width: 150px; height: 150px; margin: 0 auto; object-fit: cover;
  border: 6px solid #fff; border-radius: 50%; background: #fff; box-shadow: 0 6px 0 #0000001a;
}
.paul.paul-wave { width: 210px; height: 210px; border-radius: 32px; }
.paul-mini { flex: none; width: 44px; height: 44px; border: 3px solid #fff; border-radius: 50%; object-fit: cover; box-shadow: 0 3px 0 #0000001a; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(-3deg); } }
.bob { animation: bob 1.6s ease-in-out infinite; }
.lead { margin: 12px 0 22px; font-size: 24px; font-weight: 700; }
.spark { position: fixed; z-index: 20; margin: -16px 0 0 -16px; font-size: 32px; pointer-events: none; animation: fly .9s ease-out forwards; }

@keyframes fly { to { transform: translate(var(--dx), var(--dy)) scale(.4) rotate(160deg); opacity: 0; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-10deg); } 40% { transform: rotate(10deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(6deg); } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
.wiggle { animation: wiggle .45s; }
.pop { animation: pop .35s ease-out; }

/* Portal */
.hero { padding: 32px 16px 20px; text-align: center; }
.hero .paul { animation: bob 2.4s ease-in-out infinite; }
.hero h1 { margin: 8px 0 4px; font-size: clamp(36px, 9vw, 60px); }
.hero p { margin: 0; font-size: clamp(18px, 4.5vw, 22px); font-weight: 700; color: #5a5d75; }
.total { display: inline-block; margin-top: 14px; padding: 8px 18px; border-radius: 999px; background: #fff; font-size: 20px; font-weight: 800; box-shadow: 0 4px 0 #0000001a; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 22px; width: 100%; max-width: 1000px; margin: 12px auto 0; padding: 0 16px; }
.game-card {
  display: flex; flex-direction: column; gap: 6px; padding: 22px 24px; border-radius: 28px;
  background: var(--accent); box-shadow: 0 8px 0 var(--accent-d); color: #fff; text-decoration: none;
  transition: transform .1s;
}
.game-card:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--accent-d); }
.game-card .icon { font-size: 60px; line-height: 1.1; }
.game-card h2 { margin: 0; font-size: 28px; }
.game-card p { margin: 0; font-size: 18px; font-weight: 600; }
.note { max-width: 680px; margin: 36px auto 32px; padding: 16px 20px; border-radius: 20px; background: #fff; font-size: 16px; line-height: 1.5; -webkit-user-select: text; user-select: text; }
.note h2 { margin: 0 0 4px; font-size: 18px; }
.note p { margin: 0; }
.note a { color: var(--sky-d); }

.bar h1 { min-width: 0; }
@media (max-width: 420px) {
  .bar { gap: 8px; }
  .bar h1 { font-size: 19px; }
  .paul-mini { display: none; }
  .star { font-size: 20px; }
  .round-btn { width: 48px; height: 48px; font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
