:root {
  --board: #1f3d31; --board-light: #2f5a47; --chalk: #f4f1e6; --muted: #c9d8cc; --card: #ffffff1a; --line: #ffffff26;
  --yellow: #ffd166; --yellow-dark: #c99a2e; --pink: #ff8fa3; --blue: #7ed6df; --green: #b8e994; --bad: #ff6b6b;
  --title: 'Gochi Hand', 'Patrick Hand', 'Comic Sans MS', system-ui, sans-serif;
  --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(--chalk); font-family: var(--font); font-weight: 600; background: #17302a; 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(--yellow); outline-offset: 2px; }
.defs { position: absolute; width: 0; height: 0; }
.splash { height: 100%; display: grid; place-items: center; color: var(--muted); }
.screen { position: relative; height: 100%; max-width: 520px; margin: auto; display: flex; flex-direction: column; overflow: hidden; background: radial-gradient(circle at 50% 38%, var(--board-light), var(--board) 75%); }

/* Chalk dust smudges and a few doodles in the corners. */
.chalk-bg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.dust ellipse { fill: #ffffff; opacity: .035; }
.doodle path, .doodle circle { fill: none; stroke: #ffffff; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; opacity: .12; }

/* Menu */
#menu { overflow-y: auto; }
.menu-inner { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: max(28px, env(safe-area-inset-top)) 22px max(18px, env(safe-area-inset-bottom)); }
h1 { font-family: var(--title); font-weight: 400; font-size: clamp(54px, 17vw, 70px); line-height: 1; margin: 6px 0 0; }
.tagline { color: var(--muted); font-size: 16px; margin: 8px 0 0; }
.hero-art { flex: 1 1 auto; width: 100%; max-width: 300px; min-height: 160px; max-height: 330px; margin: 12px 0 16px; overflow: visible; }
.big-btn { position: relative; width: min(100%, 300px); min-height: 60px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: var(--title); font-weight: 400; font-size: 27px; line-height: 1; margin-bottom: 14px; transition: transform .08s, box-shadow .08s; }
.big-btn small { font-family: var(--font); font-size: 13px; font-weight: 600; opacity: .8; margin-top: 3px; }
.big-btn b { font-weight: 400; }
.big-btn.chalk { background: var(--chalk); color: var(--board); box-shadow: 0 5px 0 #b9b4a2; }
.big-btn.yellow { background: var(--yellow); color: var(--board); box-shadow: 0 5px 0 var(--yellow-dark); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b9b4a2; }
.big-btn.yellow:active { box-shadow: 0 2px 0 var(--yellow-dark); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 300px); margin: 4px 0 0; }
.stats div { display: flex; flex-direction: column; align-items: center; background: var(--card); border-radius: 14px; padding: 6px 4px 5px; }
.stats dd { margin: 0; font-family: var(--title); font-size: 26px; line-height: 1; }
.stats dt { color: var(--muted); font-size: 11.5px; }

/* Play */
.top-bar { position: relative; flex: none; display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px 0; }
.round-plain { position: relative; flex: none; width: 46px; height: 46px; display: grid; place-items: center; color: var(--chalk); border-radius: 50%; background: var(--card); }
.round-plain svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; 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 { flex: 1; min-width: 0; text-align: center; font-family: var(--title); font-size: 30px; line-height: 1; }
.hud-title strong { font-weight: 400; }
#play.no-sound .hud-title { margin-right: 56px; }
.status-row { position: relative; flex: none; display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.pill { background: var(--card); color: var(--chalk); border-radius: 30px; padding: 4px 15px 3px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
#moves i { font-style: normal; color: var(--yellow); letter-spacing: 1px; margin-right: 3px; }
.coach { position: relative; flex: none; min-height: 42px; margin: 6px 18px 0; text-align: center; font-size: 14.5px; color: var(--yellow); line-height: 1.3; display: flex; align-items: center; justify-content: center; }
.board-wrap { position: relative; flex: 1; min-height: 0; min-width: 0; margin: 0 8px 6px; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.tools { position: relative; flex: none; display: flex; justify-content: space-around; background: var(--card); border-radius: 26px; padding: 8px 8px 6px; margin: 0 14px max(12px, env(safe-area-inset-bottom)); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 76px; font-size: 13px; font-weight: 700; color: var(--chalk); }
.tool-icon { position: relative; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: #ffffff14; transition: transform .08s; }
.tool:active .tool-icon { transform: scale(.92); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tool.main .tool-icon { background: var(--yellow); color: var(--board); }
.tool b { position: absolute; top: -4px; right: -5px; min-width: 20px; height: 20px; display: grid; place-items: center; background: var(--pink); color: var(--board); border: 2px solid var(--board); border-radius: 50%; font-size: 11px; font-weight: 800; }
.tool:disabled { opacity: .4; cursor: default; }

/* Board in chalk */
.lane { stroke: var(--line); stroke-width: 2; stroke-dasharray: 6 7; }
.chute { cursor: pointer; outline: none; }
.chute .funnel { fill: none; stroke: var(--chalk); stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; }
.chute .arrow { fill: none; stroke: var(--chalk); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
.chute .key { font-family: var(--font); font-weight: 700; text-anchor: middle; fill: var(--muted); opacity: .7; }
.chute .glow { fill: var(--yellow); opacity: .32; visibility: hidden; }
.chute.hint .glow { visibility: visible; animation: glow .8s ease-in-out infinite; }
.chute .ring { fill: none; stroke: var(--yellow); stroke-width: 3; visibility: hidden; }
.chute:focus-visible .ring { visibility: visible; }
.chute:active .arrow { transform: translateY(4px); }
.chute.busy { cursor: default; }
.lever-arm { transition: transform .22s cubic-bezier(.3, 1.5, .5, 1); }
.lever-bar { stroke: var(--chalk); stroke-width: 5; stroke-linecap: round; }
.lever-tip { fill: none; stroke: var(--pink); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.pivot { fill: var(--board); stroke: var(--chalk); stroke-width: 3; }
.lever.pinned .lever-bar { stroke: var(--yellow); }
.lever.pinned .pivot { stroke: var(--yellow); }
.pin { stroke: var(--yellow); stroke-width: 2.5; stroke-linecap: round; }
.link { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-dasharray: 3 7; stroke-linecap: round; opacity: .8; }
.lever.linked .pivot { stroke: var(--blue); }
.cup-body { fill: #ffffff10; stroke: var(--chalk); stroke-width: 3; stroke-linejoin: round; }
.cup.full .cup-body { stroke: var(--green); stroke-width: 4; }
.cup.over .cup-body { stroke: var(--bad); stroke-width: 4; }
.cup-label { font-family: var(--title); text-anchor: middle; fill: var(--chalk); }
.cup.full .cup-label { fill: var(--green); }
.cup.over .cup-label { fill: var(--bad); }
.cup-want { font-family: var(--font); font-weight: 600; fill: var(--muted); }
.drain-box { fill: none; stroke: var(--line); stroke-width: 2; stroke-dasharray: 5 6; }
.drain-x { stroke: var(--muted); stroke-width: 4; stroke-linecap: round; }
.drain-label { font-family: var(--font); font-weight: 600; text-anchor: middle; fill: var(--muted); }
.drain-count { font-family: var(--title); text-anchor: middle; fill: var(--muted); }
.stone { fill: none; stroke-width: 3; }
.stone-mark { stroke-width: 1.6; opacity: .7; }
.trail { fill: none; stroke: var(--chalk); stroke-width: 2.5; stroke-dasharray: 2 7; stroke-linecap: round; opacity: .45; }

/* Result */
.overlay { position: fixed; inset: 0; background: #0b1a1588; display: grid; place-items: center; padding: 16px; z-index: 6; overflow-y: auto; }
.card { width: min(100%, 360px); background: var(--board); border: 2px solid #ffffff22; border-radius: 30px; overflow: hidden; text-align: center; box-shadow: 0 22px 50px #0007; animation: land .34s cubic-bezier(.3, 1.4, .5, 1); }
.card-top { position: relative; height: 130px; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, var(--board-light), var(--board)); }
#result-art { position: relative; width: 120px; height: 110px; overflow: visible; margin-bottom: 14px; }
.card-body { position: relative; display: flex; flex-direction: column; align-items: center; background: var(--board); border-radius: 26px 26px 0 0; margin-top: -22px; padding: 12px 22px 8px; border-top: 2px solid #ffffff1a; }
.card h2 { font-family: var(--title); font-weight: 400; font-size: 32px; margin: 2px 0 0; line-height: 1.1; }
.card p { color: var(--muted); font-size: 14.5px; margin: 4px 0 14px; line-height: 1.35; }
.card .big-btn { min-height: 54px; font-size: 24px; margin-bottom: 12px; }
.result-stars { font-size: 42px; line-height: 1.1; color: #ffffff22; }
.result-stars span { display: inline-block; margin: 0 1px; }
.result-stars .on { color: var(--yellow); animation: stamp .42s backwards; }
.result-stars .on:nth-child(2) { animation-delay: .15s; }
.result-stars .on:nth-child(3) { animation-delay: .3s; }
.text-btn { color: var(--muted); font-weight: 700; padding: 6px 10px; font-size: 15px; min-height: 44px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--chalk); color: var(--board); 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: -24px; width: 12px; height: 12px; border-radius: 50%; border: 3px solid; animation: fall linear forwards; }

@keyframes glow { 50% { opacity: .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 fall { to { transform: translate3d(var(--drift), 112vh, 0) rotate(var(--spin)); } }

/* Larger screens: the board sits as a framed card on a dark wall. */
@media (min-width: 560px) and (min-height: 521px) {
  .screen { max-height: min(100%, 900px); top: 50%; transform: translateY(-50%); border-radius: 30px; box-shadow: 0 0 0 10px #6b4a2f, 0 24px 60px #0007; height: calc(100% - 52px); }
}
/* Short, wide screens: the board on the left, controls on the right. */
@media (max-height: 520px) {
  .screen { max-width: none; }
  #menu .menu-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); grid-template-rows: repeat(5, auto); align-content: center; column-gap: 24px; align-items: center; justify-items: center; padding: 12px 20px; }
  #menu h1 { grid-column: 2; font-size: 50px; margin: 0; }
  #menu .tagline { grid-column: 2; font-size: 15px; margin-bottom: 10px; }
  .hero-art { grid-column: 1; grid-row: 1 / span 5; height: calc(100vh - 24px); max-height: none; min-height: 0; margin: 0; }
  #play-level, #play-daily, .stats { grid-column: 2; }
  .big-btn { min-height: 50px; margin-bottom: 10px; font-size: 24px; }
  .big-btn small { display: none; }
  .stats dd { font-size: 22px; }
  #play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); grid-template-rows: auto auto 1fr auto; }
  .top-bar { grid-column: 2; grid-row: 1; padding-top: 8px; }
  .round-plain { width: 40px; height: 40px; }
  .hud-title { font-size: 26px; }
  .status-row { grid-column: 2; grid-row: 2; margin-top: 6px; }
  .coach { grid-column: 2; grid-row: 3; align-self: center; font-size: 13.5px; margin: 0 10px; }
  .board-wrap { grid-column: 1; grid-row: 1 / span 4; margin: 8px 4px 8px 12px; }
  .tools { grid-column: 2; grid-row: 4; margin: 0 8px 8px; }
  .tool { min-width: 56px; font-size: 11.5px; }
  .tool-icon { width: 40px; height: 40px; }
  .overlay { padding: 8px; }
  .card { display: grid; grid-template-columns: 36% 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; border-top: 0; }
  .result-stars { font-size: 30px; }
  .card h2 { font-size: 26px; }
  .card p { margin-bottom: 8px; font-size: 13.5px; }
  .card .big-btn { min-height: 46px; margin-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
