:root {
  --text: #fff; --soft: #c5c8ee; --gold: #ffc14d; --line: #ffffff2e;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Arial Rounded MT Bold', 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(#111433, #1b1e4f 60%, #2b2a6b); 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(--gold); outline-offset: 3px; }
.defs { position: absolute; width: 0; height: 0; }
.sky { position: fixed; inset: 0; pointer-events: none; }
.sky-stars { width: 100%; height: 100%; transition: opacity .3s; }
body.playing .sky-stars { opacity: .22; } /* so stars don't read as dots in the text and on the board */
.sky-stars circle { fill: #fff; }
.sky-stars .twinkle { animation: twinkle 3.2s ease-in-out infinite; }

.splash { position: relative; height: 100%; display: grid; place-items: center; color: var(--soft); font-weight: 600; }
.screen { position: relative; height: 100%; max-width: 560px; margin: auto; padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; overflow: hidden; }

/* Menu */
#menu { overflow-y: auto; }
.moon { position: absolute; right: 42px; top: 34px; width: 62px; height: 62px; filter: drop-shadow(0 0 16px #ffeeb866); }
.hills { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 34%; }
.menu-main { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 100%; max-width: 400px; margin: 0 auto; gap: 12px; padding: 8px 8px 6px; text-align: center; }
.hero-art { flex: 0 1 auto; width: min(52vw, 220px); min-height: 0; max-height: 34vh; overflow: visible; margin-bottom: 4px; }
h1 { font-weight: 700; font-size: clamp(44px, 14.5vw, 64px); line-height: 1; margin: 0; color: var(--gold); background: linear-gradient(#fff6cf, #ffc14d); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tagline { color: var(--soft); font-size: 17px; font-weight: 500; margin: -3px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin: 4px 0 0; }
.stats dt { color: var(--soft); font-size: 13px; font-weight: 500; }
.stats dd { font-weight: 600; font-size: 25px; line-height: 1.1; margin: 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; font-weight: 600; transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(.98); }
.btn.gold { color: #4a2c02; background: linear-gradient(#ffe08a, #ffb533); box-shadow: 0 0 30px #ffb53370, inset 0 2px 0 #fff8; }
.btn.ghost { background: #ffffff14; box-shadow: inset 0 0 0 1.5px #ffffff40; }
.btn.big { width: 100%; min-height: 62px; justify-content: space-between; padding: 8px 26px; font-size: 22px; border-radius: 32px; }
.btn.big.center { justify-content: center; min-height: 54px; font-size: 19px; }
.btn.big small { font-size: 14.5px; font-weight: 500; opacity: .9; }
.round { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: #ffffff14; box-shadow: inset 0 0 0 1px var(--line); }
.round svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.round .fill { fill: currentColor; stroke: none; }
#sound[aria-pressed="false"] .waves { display: none; }
#sound[aria-pressed="false"] { opacity: .55; }
.text-btn { color: var(--soft); font-weight: 500; padding: 8px 10px; font-size: 15px; min-height: 44px; }

/* Play */
#play { gap: 7px; }
.hud { position: relative; flex: none; display: flex; align-items: center; gap: 10px; }
.hud-title { flex: 1; min-width: 0; text-align: center; font-size: 22px; font-weight: 600; }
#play.no-sound .hud-title { margin-right: 56px; }
.hud-title strong { font-weight: 700; }
.status-row { position: relative; flex: none; display: flex; justify-content: center; gap: 8px; }
.pill { background: #ffffff14; border-radius: 30px; padding: 6px 15px; font-size: 15.5px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
#moves i { font-style: normal; color: var(--gold); letter-spacing: 1px; margin-right: 3px; }
.coach { position: relative; flex: none; min-height: 21px; margin: 0; text-align: center; font-size: 15px; font-weight: 500; color: #ffe08a; line-height: 1.25; }
.board-wrap { position: relative; flex: 1; min-height: 0; min-width: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; overflow: visible; }

.tools { position: relative; flex: none; display: flex; justify-content: space-around; background: #ffffff0f; box-shadow: inset 0 0 0 1px var(--line); border-radius: 26px; padding: 9px 8px 7px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 76px; font-size: 13px; font-weight: 500; color: var(--soft); }
.tool-icon { position: relative; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: #ffffff14; color: #fff; 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 { color: #fff; }
.tool.main .tool-icon { background: linear-gradient(#ffe08a, #ffb533); color: #4a2c02; box-shadow: 0 0 20px #ffb53390; }
.tool b { position: absolute; top: -3px; right: -4px; min-width: 19px; height: 19px; display: grid; place-items: center; background: #fff; color: #4a2c02; border-radius: 50%; font-size: 11px; font-weight: 700; }
.tool:disabled { opacity: .4; cursor: default; }

/* Board pieces */
.cell { fill: #22255c; }
.wall { fill: #3b3e78; stroke: #5a5e9c; }
.wall-line { stroke: #24265a; stroke-linecap: round; fill: none; }
.beam { pointer-events: none; }
.beam line { stroke-linecap: round; }
.beam .b1 { stroke: #ffb733; stroke-opacity: .16; }
.beam .b2 { stroke: #ffb733; stroke-opacity: .34; }
.beam .b3 { stroke: #fff0b0; }
.beam.in line { stroke-dasharray: 1; animation: draw .17s ease-out both; }
.mirror { cursor: pointer; outline: none; }
.mirror-mount { fill: #ffffff14; transition: fill .15s; }
.mirror-spin { transition: transform .16s cubic-bezier(.3, 1.4, .6, 1); }
.mirror-frame { fill: #c9d1f5; }
.mirror.split .mirror-frame { fill: #6fe6d5; }
.mirror.split .mirror-mount { fill: #6fe6d51f; }
.mirror.locked { cursor: not-allowed; }
.mirror.locked .mirror-frame { fill: #ffc14d; }
.pin { fill: #ffc14d; stroke: #4a2c02; visibility: hidden; }
.mirror.locked .pin { visibility: visible; }
.mirror-hint { fill: #ffc14d; opacity: .45; visibility: hidden; }
.mirror.hint .mirror-hint { visibility: visible; animation: glow .8s ease-in-out infinite; }
.mirror:focus-visible .mirror-mount { fill: #ffc14d55; }
.shake { animation: shake .3s; }
.lamp-body { fill: var(--gold); }
.lamp-core { fill: #fff6c9; }

/* Candles */
.candle-halo { visibility: hidden; }
.candle.on .candle-halo { visibility: visible; }
.wax { fill: #c9d0ef; transition: fill .2s; }
.candle.on .wax { fill: #fff0d0; }
.wax-side { fill: #a7afd8; opacity: .7; transition: fill .2s; }
.candle.on .wax-side { fill: #f2dcae; }
.wax-drip { fill: #fff; opacity: .35; pointer-events: none; }
.candle.on .wax-drip { opacity: .7; }
.wick { stroke: #aab0da; fill: none; stroke-linecap: round; }
.candle.on .wick { visibility: hidden; }
.flame { visibility: hidden; transform-box: fill-box; transform-origin: 50% 100%; }
.candle.on .flame { visibility: visible; animation: flicker 1.1s ease-in-out infinite; }
.flame-out { fill: #ffb43d; }
.flame-in { fill: #fff6c9; }
.candle-face { visibility: hidden; }
.candle.on .candle-face { visibility: visible; }
.face-dark { fill: #2a1a2c; }
.face-line { fill: none; stroke: #2a1a2c; stroke-linecap: round; }
.cheek { fill: #ef8a6b; opacity: .6; }
.holder-stem { fill: #c98a22; }
.holder-handle { fill: none; stroke: #e8b44c; stroke-linecap: round; }
.emit-badge circle { fill: #161943; stroke: #c9d0ef; stroke-width: 1.8; }
.emit-badge path { fill: #c9d0ef; stroke: #c9d0ef; stroke-width: 1.4; stroke-linejoin: round; }
.candle.on .emit-badge circle { stroke: var(--gold); }
.candle.on .emit-badge path { fill: var(--gold); stroke: var(--gold); }
.candle.pop .candle-body { animation: pop .34s cubic-bezier(.3, 1.6, .5, 1); }
.spark { fill: #fff0b0; animation: spark .5s ease-out forwards; pointer-events: none; }

/* Result */
.overlay { position: fixed; inset: 0; background: #070920cc; display: grid; place-items: center; padding: 16px; z-index: 6; overflow-y: auto; }
.card { position: relative; width: min(100%, 370px); background: linear-gradient(170deg, #2b2e74, #171a45); border-radius: 30px; padding: 14px 24px 8px; text-align: center; box-shadow: inset 0 0 0 1px #ffffff2e, 0 0 60px #ffb53333, 0 24px 60px #000a; animation: land .34s cubic-bezier(.3, 1.4, .5, 1); }
.result-art { width: 110px; height: 116px; overflow: visible; display: block; margin: 0 auto; }
.card h2 { font-weight: 700; font-size: 27px; margin: 2px 0; }
.card p { color: var(--soft); font-size: 15.5px; font-weight: 500; margin: 0 0 15px; line-height: 1.4; }
.card .btn { margin-bottom: 10px; }
.result-stars { font-size: 44px; line-height: 1.1; color: #ffffff1f; }
.result-stars span { display: inline-block; margin: 0 2px; }
.result-stars .on { color: var(--gold); text-shadow: 0 0 20px #ffc14d99; animation: stamp .42s backwards; }
.result-stars .on:nth-child(2) { animation-delay: .15s; }
.result-stars .on:nth-child(3) { animation-delay: .3s; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #fff; color: #171a45; font-weight: 600; font-size: 15px; 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: -18px; width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 10px currentColor; animation: fall linear forwards; }

@keyframes twinkle { 50% { opacity: .25; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes flicker { 0%, 100% { transform: scale(1, 1); } 35% { transform: scale(.94, 1.06); } 70% { transform: scale(1.04, .96); } }
@keyframes pop { 0% { transform: scale(.75); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@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 spark { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }
@keyframes glow { 50% { opacity: .15; } }
@keyframes shake { 25% { transform: translateX(-.04px); } 75% { transform: translateX(.04px); } }
@keyframes fall { to { transform: translate3d(var(--drift), 112vh, 0); opacity: .2; } }

/* Short, wide screens: board on the left, controls on the right. */
@media (max-height: 520px) {
  .screen { max-width: none; }
  .moon { display: none; }
  .menu-main { max-width: none; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto auto; column-gap: 24px; align-items: center; justify-content: stretch; }
  .hero-art { grid-column: 1; grid-row: 1 / -1; justify-self: center; width: min(44vh, 170px); max-height: 80vh; }
  h1 { font-size: 42px; grid-column: 2; }
  .tagline { grid-column: 2; font-size: 14px; margin: -4px 0 0; }
  .btn.big { grid-column: 2; min-height: 48px; font-size: 18px; }
  .stats { grid-column: 2; }
  #play { display: grid; grid-template-columns: minmax(0, 1fr) 236px; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 6px 12px; }
  .board-wrap { grid-column: 1; grid-row: 1 / -1; }
  .hud { grid-column: 2; grid-row: 1; }
  .hud-title { font-size: 18px; }
  .status-row { grid-column: 2; grid-row: 2; }
  .coach { grid-column: 2; grid-row: 3; align-self: center; font-size: 13.5px; }
  .tools { grid-column: 2; grid-row: 4; }
  .tool { min-width: 58px; font-size: 11.5px; }
  .tool-icon { width: 40px; height: 40px; }
  .result-art { display: none; }
  .card { padding-top: 12px; width: min(100%, 420px); }
  .result-stars { font-size: 30px; }
  .card h2 { font-size: 21px; }
  .card p { margin-bottom: 8px; font-size: 14px; }
  .btn.big.center { min-height: 44px; font-size: 16px; }
  .card .btn { margin-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
