:root {
  --peach: #f6e2c6; --sheet: #fffdf9; --line: #f2e6d5; --text: #3d2a24; --muted: #8f7d72; --maroon: #4a2323;
  --olive: #5f6f52; --leaf: #a9c47f; --orange: #eb9a2f; --sand: #fbcf94; --terracotta: #ad5a3f; --good: #6fae50;
  --font: 'Poppins', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; color: var(--text); font-family: var(--font); background: linear-gradient(160deg, #f8e6cc, #e7e0d4); overscroll-behavior: none; -webkit-user-select: none; user-select: none; overflow: hidden; }
body.paused *, body.paused *::before, body.paused *::after { animation-play-state: paused !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--terracotta); outline-offset: 2px; }
.defs { position: absolute; width: 0; height: 0; }
.splash { height: 100%; display: grid; place-items: center; color: var(--muted); font-weight: 600; }
.screen { position: relative; height: 100%; max-width: 520px; margin: auto; display: flex; flex-direction: column; overflow: hidden; background: var(--sheet); }

/* Illustrated scene: each colour band sets its own palette. */
.scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.s-cloud { fill: #ffffffb3; }
.s-snow { fill: #fff; }
.s-tree path { stroke: var(--trunk); stroke-width: 3; stroke-linecap: round; fill: none; }
.s-tree .s-leaf { fill: var(--tree); stroke: none; }
.s-peak { fill: var(--peak); }
.s-far { fill: var(--far); }
.s-near { fill: var(--near); }
.olive { --sky: #bcd59b; --peak: #5f6f52; --far: #a9c47f; --near: #8fae68; --tree: #5d8f3e; --trunk: #3f5a2c; background: var(--sky); }
.sand { --sky: #fbd6a4; --peak: #d88f46; --far: #f6be7c; --near: #eda65a; --tree: #b5603f; --trunk: #7c3f28; background: var(--sky); }

/* Menu */
#menu { overflow-y: auto; }
.hero { position: relative; flex: 1 1 34%; min-height: 200px; display: grid; place-items: center; padding-bottom: 28px; overflow: hidden; }
.hero .scene { inset: auto 0 0 0; height: auto; aspect-ratio: 400 / 180; }
.mascot-ring { position: relative; width: min(36vh, 176px); aspect-ratio: 1; }
.mascot-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ring-track, .ring-fill { fill: none; stroke-width: .07; stroke-linecap: round; }
.ring-track { stroke: #ffffff80; }
.ring-fill { stroke: var(--maroon); }
.spin-slow { animation: turn 18s linear infinite; }
.sheet { position: relative; background: var(--sheet); border-radius: 32px 32px 0 0; margin-top: -30px; display: flex; flex-direction: column; }
.menu-sheet { flex: none; padding: 22px 20px max(18px, env(safe-area-inset-bottom)); gap: 15px; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
h1 { font-weight: 700; font-size: clamp(32px, 10vw, 40px); line-height: 1.05; letter-spacing: -.6px; margin: 0; }
.tagline { color: var(--muted); font-size: 14px; font-weight: 500; margin: 3px 0 0; }
.badge { flex: none; width: 66px; height: 74px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--orange); color: #fff; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); line-height: 1; }
.badge strong { font-size: 22px; font-weight: 700; }
.badge span { font-size: 10px; font-weight: 600; margin-top: 2px; }
.game-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.game-card { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; text-align: left; min-height: 176px; padding: 15px 14px; border-radius: 22px; transition: transform .1s; }
.game-card:active { transform: scale(.97); }
.game-card.orange { background: var(--sand); }
.game-card.green { background: var(--leaf); }
.card-title { font-size: 18px; font-weight: 700; }
.game-card small { font-size: 11.5px; font-weight: 500; line-height: 1.3; opacity: .8; max-width: 84%; margin-top: 2px; }
.go { position: relative; z-index: 1; background: var(--maroon); color: #fff; font-size: 12.5px; font-weight: 600; padding: 8px 15px; border-radius: 30px; margin-top: 10px; }
.card-art { position: absolute; right: -16px; bottom: -14px; width: 92px; height: 92px; overflow: visible; }
.ribbon { position: absolute; top: 0; right: 13px; min-width: 32px; padding: 7px 5px 12px; background: var(--terracotta); color: #fff; font-size: 12.5px; font-weight: 600; text-align: center; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.stats div { display: flex; align-items: center; gap: 9px; background: #f8f3ea; border-radius: 16px; padding: 10px 14px; }
.stats dd { order: -1; margin: 0; font-size: 21px; font-weight: 700; }
.stats dt { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.15; }

/* Play */
.top-bar { position: relative; flex: none; height: 112px; display: flex; align-items: flex-start; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px 0; }
.round-plain { position: relative; flex: none; width: 44px; height: 44px; display: grid; place-items: center; color: var(--maroon); border-radius: 50%; background: #ffffff8c; }
.round-plain svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.round-plain .fill { fill: currentColor; stroke: none; }
#sound[aria-pressed="false"] .waves { display: none; }
#sound[aria-pressed="false"] { opacity: .55; }
.hud-title { position: relative; flex: 1; min-width: 0; text-align: center; font-size: 20px; font-weight: 600; color: var(--maroon); padding-top: 8px; margin-right: 0; }
#play.no-sound .hud-title { margin-right: 54px; }
.hud-title strong { font-weight: 700; }
.play-sheet { flex: 1; min-height: 0; padding: 14px 14px max(10px, env(safe-area-inset-bottom)); gap: 6px; }
.status-row { flex: none; display: flex; justify-content: center; gap: 8px; }
.pill { background: #f8f3ea; border-radius: 30px; padding: 6px 14px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
#moves i { font-style: normal; color: var(--orange); letter-spacing: 1px; margin-right: 3px; }
.coach { flex: none; min-height: 19px; margin: 0; text-align: center; font-size: 13.5px; font-weight: 500; color: var(--terracotta); line-height: 1.3; }
.board-wrap { flex: 1; min-height: 0; min-width: 0; position: relative; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; cursor: pointer; }

/* Tools: a soft bar of circles, the main one dark. */
.tools { flex: none; display: flex; justify-content: space-around; background: #f8f3ea; border-radius: 26px; padding: 9px 8px 7px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 76px; font-size: 11.5px; font-weight: 500; color: var(--text); }
.tool-icon { position: relative; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: var(--sheet); border: 1.5px solid var(--line); color: var(--orange); transition: transform .08s; }
.tool:active .tool-icon { transform: scale(.92); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool.main .tool-icon { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.tool b { position: absolute; top: -3px; right: -4px; min-width: 19px; height: 19px; display: grid; place-items: center; background: var(--orange); color: #fff; border: 2px solid #f8f3ea; border-radius: 50%; font-size: 10.5px; font-weight: 700; }
.tool:disabled { opacity: .4; cursor: default; }

/* Gears */
.link { stroke: #e0cfb5; stroke-linecap: round; transition: stroke .12s; }
.link.pulse { stroke: var(--orange); }
.gear { outline: none; cursor: pointer; }
.gear-press { transform-box: fill-box; transform-origin: center; }
.gear-press.tapped { animation: tap .2s ease-out; }
.gear-shadow { fill: #3d2a24; opacity: .1; }
.teeth { fill: #dd8a22; transition: fill .2s; }
.face { fill: #f6ae4b; transition: fill .2s; }
.gear.big .teeth { fill: #9c4d33; }
.gear.big .face { fill: #c56f4d; }
.gear.free .teeth { fill: #64804c; }
.gear.free .face { fill: #a9c47f; }
.gear.locked .teeth { fill: #6e5d52; }
.gear.locked .face { fill: #a08e81; }
.gear.solved .teeth { fill: #4f8f38; }
.gear.solved .face { fill: #86c663; }
.halo-hint { fill: #f6ae4b; opacity: .4; visibility: hidden; }
.gear.hint .halo-hint { visibility: visible; animation: glow .8s ease-in-out infinite; }
.tick { fill: #4a232366; }
.tick.home { fill: #fff; stroke: var(--maroon); }
.bead { fill: var(--maroon); stroke: #fff; }
.hub { fill: var(--sheet); }
.hub-text { fill: var(--maroon); font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.smile { visibility: hidden; pointer-events: none; }
.gear.solved .smile { visibility: visible; }
.smile circle { fill: var(--maroon); }
.smile path { fill: none; stroke: var(--maroon); stroke-linecap: round; }
.rust { fill: none; stroke: #5b4a40; stroke-dasharray: .04 .08; stroke-linecap: round; visibility: hidden; }
.gear.locked { cursor: not-allowed; }
.gear.locked .rust { visibility: visible; }
.gear.shake { animation: shake .3s; }
.focus-ring { fill: none; stroke: var(--terracotta); visibility: hidden; }
.gear:focus-visible .focus-ring { visibility: visible; }
.spark { fill: var(--orange); animation: spark .5s ease-out forwards; pointer-events: none; }
.burst { fill: none; stroke: var(--good); transform-box: fill-box; transform-origin: center; animation: burst .5s ease-out forwards; pointer-events: none; }

/* Mascot */
.m-white { fill: #fff; }
.m-dark { fill: #2b1a16; }
.m-mouth { fill: none; stroke: #2b1a16; stroke-linecap: round; }
.m-cheek { fill: #ef8a6b; opacity: .55; }

/* Result */
.overlay { position: fixed; inset: 0; background: #3d2a2499; display: grid; place-items: center; padding: 16px; z-index: 6; overflow-y: auto; }
.card { width: min(100%, 360px); background: var(--sheet); border-radius: 30px; overflow: hidden; text-align: center; box-shadow: 0 22px 50px #3d2a2466; animation: land .34s cubic-bezier(.3, 1.4, .5, 1); }
.card-top { position: relative; height: 128px; display: grid; place-items: center; }
#result-art { position: relative; width: 104px; height: 104px; overflow: visible; }
.card-body { position: relative; background: var(--sheet); border-radius: 26px 26px 0 0; margin-top: -22px; padding: 12px 22px 8px; }
.card h2 { font-weight: 700; font-size: 23px; letter-spacing: -.3px; margin: 2px 0; }
.card p { color: var(--muted); font-size: 14px; font-weight: 500; margin: 0 0 14px; line-height: 1.4; }
.result-stars { font-size: 40px; line-height: 1.1; color: var(--line); }
.result-stars span { display: inline-block; margin: 0 1px; }
.result-stars .on { color: var(--orange); animation: stamp .42s backwards; }
.result-stars .on:nth-child(2) { animation-delay: .15s; }
.result-stars .on:nth-child(3) { animation-delay: .3s; }
.dark-pill, .line-pill { display: block; width: 100%; min-height: 50px; border-radius: 30px; font-size: 15.5px; font-weight: 600; margin-bottom: 9px; transition: transform .08s; }
.dark-pill { background: var(--maroon); color: #fff; }
.line-pill { border: 1.5px solid var(--line); color: var(--text); }
.dark-pill:active, .line-pill:active { transform: scale(.98); }
.text-btn { color: var(--muted); font-weight: 500; padding: 6px 10px; font-size: 13.5px; min-height: 44px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--maroon); color: #fff; font-weight: 500; font-size: 14px; padding: 10px 16px; border-radius: 14px; z-index: 8; white-space: nowrap; }
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 7; }
.confetti span { position: absolute; top: -24px; width: 12px; height: 12px; border-radius: 3px; animation: fall linear forwards; }

@keyframes turn { to { transform: rotate(360deg); } }
@keyframes tap { 40% { transform: scale(.93); } }
@keyframes stamp { 0% { transform: scale(2.2); opacity: 0; } 70% { transform: scale(.9); opacity: 1; } 100% { } }
@keyframes land { from { transform: translateY(26px) scale(.94); opacity: 0; } }
@keyframes burst { from { transform: scale(.75); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }
@keyframes glow { 50% { opacity: .15; } }
@keyframes shake { 25% { transform: translateX(-.05px); } 75% { transform: translateX(.05px); } }
@keyframes fall { to { transform: translate3d(var(--drift), 112vh, 0) rotate(var(--spin)); } }

/* Larger screens: the game sits as a framed card on the warm background. */
@media (min-width: 560px) and (min-height: 521px) {
  .screen { max-height: min(100%, 900px); top: 50%; transform: translateY(-50%); border-radius: 34px; box-shadow: 0 24px 60px #3d2a2433; height: calc(100% - 32px); }
}
/* Short, wide screens: board on the left, scene and controls on the right. */
@media (max-height: 520px) {
  .screen { max-width: none; }
  #menu { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); }
  .hero { min-height: 0; padding-bottom: 0; }
  .mascot-ring { width: min(62vh, 170px); }
  .menu-sheet { margin-top: 0; border-radius: 28px 0 0 28px; margin-left: -24px; padding: 12px 16px; gap: 9px; overflow-y: auto; }
  .game-card { min-height: 128px; padding: 10px 12px; }
  .game-card small { display: none; }
  .card-art { width: 70px; height: 70px; }
  .stats div { padding: 6px 12px; }
  #play { display: grid; grid-template-columns: minmax(0, 1fr) 216px; grid-template-rows: 88px minmax(0, 1fr); }
  .top-bar { grid-column: 2; grid-row: 1; height: 100%; }
  .hud-title { font-size: 17px; }
  .play-sheet { display: contents; }
  .board-wrap { grid-column: 1; grid-row: 1 / span 2; margin: 8px; }
  .status-row { grid-column: 2; grid-row: 2; align-self: start; margin-top: 8px; flex-wrap: wrap; }
  .coach { grid-column: 2; grid-row: 2; align-self: center; padding: 0 10px; font-size: 12.5px; }
  .tools { grid-column: 2; grid-row: 2; align-self: end; margin: 0 8px 8px; }
  .tool { min-width: 56px; font-size: 10.5px; }
  .tool-icon { width: 40px; height: 40px; }
  .overlay { padding: 8px; }
  .card { display: grid; grid-template-columns: 34% 1fr; width: min(100%, 560px); }
  .card-top { height: auto; }
  .card-body { margin: 0 0 0 -18px; border-radius: 22px 0 0 22px; padding: 8px 16px 2px; }
  .result-stars { font-size: 30px; }
  .card h2 { font-size: 19px; }
  .card p { margin-bottom: 8px; font-size: 13px; }
  .dark-pill, .line-pill { min-height: 44px; margin-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
