:root {
  --paper: #f3ead8; --sheet: #fbf6ea; --ink: #2b2720; --muted: #6b6354; --line: #cfc2a6;
  --coral: #f07a5a; --mustard: #f4bd4a; --teal: #5cc2b2; --periwinkle: #a3adf2; --kraft: #c79a63; --twine: #8a6f4d; --good: #2f9e63;
  --display: 'Space Grotesk', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --body: 'DM Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); font-family: var(--body); background: var(--paper) url(paper.png) repeat; 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; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #4f5bd5; outline-offset: 3px; }

.splash { height: 100%; display: grid; place-items: center; color: var(--muted); font-weight: 600; }
.screen { height: 100%; max-width: 760px; margin: auto; padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
.eyebrow { color: #b4472a; font-size: 10px; font-weight: 700; letter-spacing: 1.7px; }

/* Menu */
#menu { overflow-y: auto; }
.menu-main { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; max-width: 420px; margin: auto; gap: 11px; padding: 8px 0; }
.hero-art { display: block; width: 100%; max-height: 22vh; flex: 0 1 auto; min-height: 0; overflow: visible; }
.hero-beam { transform-origin: 160px 44px; animation: sway 4.5s ease-in-out infinite; }
h1 { font-family: var(--display); font-size: clamp(46px, 14vw, 72px); line-height: 1; letter-spacing: -3px; margin: 0; }
h1 em { font-style: normal; color: #d9542f; }
.lead { color: var(--muted); line-height: 1.5; margin: 0 0 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 0; }
.stats div { position: relative; background: var(--sheet); border: 2px solid var(--ink); border-radius: 4px 12px 5px 10px; padding: 12px 6px 9px; text-align: center; box-shadow: 2px 3px 0 #2b272033; }
.stats div:nth-child(1) { transform: rotate(-1.4deg); }
.stats div:nth-child(2) { transform: rotate(.8deg); }
.stats div:nth-child(3) { transform: rotate(-.6deg); }
.stats div::before { content: ''; position: absolute; left: 50%; top: -8px; width: 38px; height: 14px; margin-left: -19px; background: #f4bd4acc; transform: rotate(-3deg); }
.stats dt { color: var(--muted); font-size: 11px; font-weight: 600; }
.stats dd { font-family: var(--display); font-size: 24px; font-weight: 700; margin: 3px 0 0; }

/* Buttons are thick paper stickers that press down onto their ink shadow. */
.chunky { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 20px; color: var(--ink); background: var(--sheet); border: 2.5px solid var(--ink); border-radius: 16px 18px 15px 19px; font-family: var(--display); font-weight: 700; font-size: 18px; box-shadow: 0 5px 0 var(--ink); margin-bottom: 5px; transition: transform .07s, box-shadow .07s, background .15s; }
.chunky:hover { filter: brightness(1.04); }
.chunky:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.chunky small { font-family: var(--body); font-size: 13px; font-weight: 700; background: #ffffff8c; padding: 3px 9px; border-radius: 20px; }
.primary { background: var(--coral); }
.secondary { background: var(--teal); }
.plain { background: var(--sheet); }
.chunky.small { width: auto; flex: none; min-height: 44px; padding: 6px 13px; font-size: 14px; border-width: 2px; border-radius: 11px 13px 10px 12px; box-shadow: 0 3px 0 var(--ink); margin-bottom: 3px; }
.chunky.small:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.chunky:disabled { opacity: .5; cursor: default; }
.chunky b { background: var(--mustard); border: 1.5px solid var(--ink); min-width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 50%; font-size: 12px; }

/* Play */
#play { gap: 7px; overflow: hidden; }
.hud { display: flex; align-items: center; gap: 10px; flex: none; }
.hud-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.hud-title strong { font-family: var(--display); font-size: 20px; line-height: 1.15; }
.readout { color: var(--ink); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
#moves { background: var(--sheet); border: 2px solid var(--ink); border-radius: 9px; padding: 5px 9px; }
#moves i { font-style: normal; color: #c98a0b; letter-spacing: 1px; }
.coach { flex: none; min-height: 20px; margin: 0; text-align: center; font-size: 14px; font-weight: 700; color: #a63d20; }
.board-wrap { flex: 1; min-height: 0; min-width: 0; position: relative; }
.board-wrap::before, .board-wrap::after { content: ''; position: absolute; top: -6px; width: 58px; height: 18px; background: #f4bd4abf; z-index: 1; pointer-events: none; }
.board-wrap::before { left: 18px; transform: rotate(-4deg); }
.board-wrap::after { right: 18px; transform: rotate(3deg); }
#board { position: absolute; inset: 0; width: 100%; height: 100%; border: 2px solid var(--ink); border-radius: 6px 14px 8px 12px; touch-action: none; box-shadow: 3px 4px 0 #2b272038;
  background-color: var(--sheet);
  background-image: linear-gradient(#7c9fc42e 1px, transparent 1px), linear-gradient(90deg, #7c9fc42e 1px, transparent 1px);
  background-size: 22px 22px; }

.ceiling { stroke: var(--ink); stroke-linecap: round; }
.ceiling-top { stroke: var(--kraft); stroke-linecap: round; }
.string { stroke: var(--twine); }
.beam-edge { stroke: var(--ink); stroke-linecap: round; }
.beam-bar { stroke: var(--kraft); stroke-linecap: round; transition: stroke .2s; }
.beam.ok .beam-bar { stroke: #6fd39a; }
.pivot { fill: var(--mustard); stroke: var(--ink); }
.beam.ok .pivot { fill: var(--good); }
.check { fill: none; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.beam.ok .check { visibility: visible; }
.dist { fill: var(--ink); font-family: var(--display); font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: var(--sheet); stroke-linejoin: round; }
.dist.mystery { fill: #b4472a; }
.burst { fill: none; stroke: var(--good); transform-box: fill-box; transform-origin: center; animation: burst .55s ease-out forwards; }
.slot { cursor: pointer; outline: none; }
.slot-ring { fill: #efe6d2; stroke: #7d7362; stroke-dasharray: .24 .2; stroke-linecap: round; transition: fill .15s, stroke .15s; }
.slot.target .slot-ring { stroke: #d9542f; fill: #fbe2d5; animation: want .9s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.slot:focus-visible .slot-ring { stroke: #4f5bd5; }
.chip-wrap { transform-box: fill-box; transform-origin: center; }
.chip-wrap.drop { animation: drop .36s cubic-bezier(.3, 1.5, .5, 1); }
.chip { stroke: var(--ink); stroke-width: .13; }
.chip-hole { fill: var(--sheet); stroke: var(--ink); stroke-width: .06; visibility: hidden; }
.slot.filled .chip-hole { visibility: visible; }
.chip-text { fill: var(--ink); font-family: var(--display); font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.slot.pinned { cursor: default; }
.slot.pinned .chip { stroke-width: .26; }
.slot.pinned .chip-hole { fill: var(--ink); }

.tray { flex: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; min-height: 54px; align-items: center; touch-action: none; }
.weight { width: 48px; height: 48px; flex: none; padding: 0; border: 2.5px solid var(--ink); border-radius: 50%; color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 20px; box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s; touch-action: none; animation: pop .22s backwards; }
.weight.selected { transform: translateY(-5px) rotate(-5deg); box-shadow: 0 9px 0 var(--ink); outline: 3px dashed var(--ink); outline-offset: 3px; }
.c0 { background: var(--coral); }
.c1 { background: var(--mustard); }
.c2 { background: var(--teal); }
.c3 { background: var(--periwinkle); }
.tools { flex: none; display: flex; justify-content: center; gap: 8px; }
.ghost { position: fixed; left: 0; top: 0; width: 48px; height: 48px; margin: -24px 0 0 -24px; border: 2.5px solid var(--ink); border-radius: 50%; display: grid; place-items: center; color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 20px; pointer-events: none; z-index: 5; box-shadow: 0 8px 0 #2b272055; }

/* Result */
.overlay { position: fixed; inset: 0; background: #2b2720a6; display: grid; place-items: center; padding: 16px; z-index: 6; overflow-y: auto; }
.card { position: relative; width: min(100%, 400px); background: var(--paper) url(paper.png); border: 2.5px solid var(--ink); border-radius: 6px 16px 8px 14px; padding: 22px; text-align: center; box-shadow: 5px 7px 0 #2b2720; transform: rotate(-.7deg); animation: land .34s cubic-bezier(.3, 1.4, .5, 1); }
.card::before { content: ''; position: absolute; left: 50%; top: -11px; width: 92px; height: 22px; margin-left: -46px; background: #f4bd4ad9; transform: rotate(2deg); }
.card h2 { font-family: var(--display); font-size: 28px; letter-spacing: -1px; margin: 6px 0; }
.card p { color: var(--muted); font-weight: 600; margin: 0 0 16px; line-height: 1.5; }
.card .chunky { justify-content: center; margin-bottom: 13px; }
.result-stars { font-size: 52px; line-height: 1.1; color: #d6c9ad; }
.result-stars span { display: inline-block; }
.result-stars span:nth-child(1) { transform: rotate(-10deg); }
.result-stars span:nth-child(3) { transform: rotate(10deg); }
.result-stars .on { color: #eda90f; -webkit-text-stroke: 2px var(--ink); animation: stamp .42s backwards; }
.result-stars .on:nth-child(2) { animation-delay: .15s; }
.result-stars .on:nth-child(3) { animation-delay: .3s; }
.link { background: none; border: 0; color: var(--muted); font-weight: 600; text-decoration: underline; padding: 10px; font-size: 14px; min-height: 44px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--sheet); font-weight: 600; font-size: 14px; padding: 10px 16px; border-radius: 10px; z-index: 8; }
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 7; }
.confetti span { position: absolute; top: -24px; width: 11px; height: 15px; border: 1.5px solid var(--ink); animation: fall linear forwards; }

@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes stamp { 0% { transform: scale(2.4); opacity: 0; } 70% { transform: scale(.9); opacity: 1; } 100% { } }
@keyframes land { from { transform: translateY(26px) rotate(3deg) scale(.92); opacity: 0; } }
@keyframes drop { 0% { transform: translateY(-1.6px) scale(.8); } 60% { transform: translateY(.14px) scale(1.06, .94); } 100% { transform: none; } }
@keyframes burst { from { transform: scale(.4); opacity: 1; } to { transform: scale(2.6); opacity: 0; } }
@keyframes want { 50% { transform: scale(1.06); } }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes fall { to { transform: translate3d(var(--drift), 112vh, 0) rotate(var(--spin)); } }

/* Short, wide screens: board on the left, controls on the right. */
@media (max-height: 520px) {
  .hero-art { display: none; }
  #play { display: grid; max-width: none; 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; flex-wrap: wrap; gap: 4px 8px; }
  .hud .chunky.small { padding: 6px 10px; }
  .hud-title { flex: 1 1 44px; }
  .hud-title .eyebrow { overflow: hidden; white-space: nowrap; }
  .hud .readout { order: 5; }
  .coach { grid-column: 2; grid-row: 2; min-height: 0; font-size: 12px; }
  .tray { grid-column: 2; grid-row: 3; align-content: center; min-height: 0; gap: 6px; }
  .tools { grid-column: 2; grid-row: 4; }
  .weight { width: 40px; height: 40px; font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
