:root {
  --cream: #fff3d6; --red: #ff4d3d; --brick: #c92f24; --yellow: #ffcf3f; --teal: #22c7a9; --pink: #ff6fa3;
  --ink: #2a2433; --plum: #4a3f5e; --green: #4be36b;
  --display: 'Titan One', 'Arial Black', sans-serif; --body: 'Fredoka', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #ffb35c; color: var(--ink); font-family: var(--body); touch-action: none; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---- screens ---- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); overflow-y: auto;
  background: radial-gradient(ellipse at 50% 35%, rgba(255, 243, 214, .25), rgba(255, 77, 61, .35) 70%, rgba(42, 36, 51, .7)); }
.screen.dim { background: rgba(42, 36, 51, .6); backdrop-filter: blur(3px); }

.logo { margin: 0; display: flex; flex-direction: column; align-items: center; font-family: var(--display); font-weight: 400; line-height: .9; transform: rotate(-3deg) skewX(-8deg); }
.logo .l1 { font-size: clamp(56px, 13vw, 150px); color: var(--cream); white-space: nowrap; letter-spacing: .01em;
  text-shadow: 0 .035em 0 var(--red), 0 .07em 0 var(--brick), 0 .105em 0 var(--ink), 0 .16em .2em rgba(30, 10, 20, .4); }
.logo .l1 span { display: inline-block; animation: wob 1.4s ease-in-out infinite; animation-delay: calc(var(--i) * -.12s); }
.logo .l1 span.o { color: var(--yellow); animation: spin 2.6s cubic-bezier(.5, -.4, .3, 1.4) infinite; animation-delay: calc(var(--i) * -.3s); }
.logo .l2 { margin-top: .5em; font-size: clamp(20px, 4.4vw, 50px); letter-spacing: .34em; padding: .12em .3em .12em .6em; color: var(--ink); background: var(--yellow); border: 4px solid var(--ink); border-radius: 12px; box-shadow: 0 6px 0 var(--ink); transform: rotate(2deg); }
@keyframes wob { 0%, 100% { transform: rotate(-4deg) translateY(0); } 50% { transform: rotate(4deg) translateY(-.05em); } }
@keyframes spin { 0%, 55% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
.tagline { margin: 6px 0 2px; font-size: clamp(16px, 2.6vw, 24px); font-weight: 600; color: var(--cream); text-shadow: 0 2px 0 var(--ink); text-align: center; }
.title { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(34px, 6.4vw, 68px); color: var(--cream); text-align: center; transform: rotate(-2deg) skewX(-6deg);
  text-shadow: 0 .05em 0 var(--red), 0 .1em 0 var(--ink); }

.card { background: var(--cream); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink), 0 16px 30px rgba(30, 10, 20, .3); padding: 18px; }
.menu-card { display: flex; flex-direction: column; gap: 11px; width: min(390px, 100%); }
.menu-card.wide { width: min(470px, 100%); }
.btn { font: 700 20px var(--body); color: var(--ink); background: var(--cream); border: 3px solid var(--ink); border-radius: 999px; padding: 10px 22px; cursor: pointer;
  box-shadow: 0 5px 0 var(--ink); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { filter: brightness(1.06); transform: translateY(-1px) rotate(-.5deg); box-shadow: 0 6px 0 var(--ink); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible, .round:focus-visible, input:focus-visible, .stop:focus-visible { outline: 4px solid var(--pink); outline-offset: 2px; }
.btn.big { font-size: 25px; background: var(--red); color: var(--cream); padding: 14px 22px; }
.btn.teal { background: var(--teal); }
.btn.yellow { background: var(--yellow); }
.btn.ghost { background: transparent; }
.btn.small { font-size: 16px; padding: 7px 16px; background: var(--cream); }
.btn:disabled { opacity: .5; pointer-events: none; }
.or { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; opacity: .7; }
.or::before, .or::after { content: ''; flex: 1; border-top: 2px dashed var(--ink); opacity: .4; }
.join-row { display: flex; gap: 10px; }
.join-row > * { flex: 1; min-width: 0; }
.join-row input { font: 700 24px var(--body); letter-spacing: .3em; text-align: center; text-transform: uppercase; color: var(--ink);
  background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 8px 6px 8px 14px; user-select: text; -webkit-user-select: text; }
.join-row input::placeholder { color: #d9c9a8; }
.msg { margin: 0; min-height: 1.3em; text-align: center; font-weight: 600; color: var(--brick); }
.msg:empty { display: none; }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-weight: 600; color: var(--cream); text-shadow: 0 2px 0 rgba(42, 36, 51, .8); max-width: 680px; }
kbd { display: inline-block; min-width: 1.7em; margin: 0 2px; padding: 1px 7px; font: 700 14px var(--body); text-align: center; text-shadow: none; color: var(--ink); background: var(--cream); border: 2px solid var(--ink); border-radius: 8px; box-shadow: 0 2px 0 var(--ink); }

/* ---- lobby ---- */
.status { width: min(720px, 100%); text-align: center; font-size: 18px; font-weight: 600; padding: 12px 16px; }
.status .code { font-family: var(--display); font-size: 40px; letter-spacing: .12em; color: var(--red); line-height: 1.1; display: block; }
.status .dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.stops { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; width: min(820px, 100%); }
.stop { flex: 1 1 220px; max-width: 262px; text-align: left; font-family: var(--body); color: var(--ink); background: var(--cream); border: 4px solid var(--ink); border-radius: 22px; padding: 10px 14px 12px; cursor: pointer;
  box-shadow: 0 6px 0 var(--ink); transition: transform .1s, box-shadow .1s; }
.stop:hover { transform: translateY(-3px) rotate(-1deg); box-shadow: 0 9px 0 var(--ink); }
.stop:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.stop .num { font-family: var(--display); font-size: 32px; line-height: 1; color: var(--red); float: left; margin-right: 10px; }
.stop:nth-child(2) .num { color: var(--teal); }
.stop:nth-child(3) .num { color: var(--pink); }
.stop:nth-child(4) .num { color: #3fa9ff; }
.stop:nth-child(5) .num { color: #ff8a3d; }
.stop:nth-child(6) .num { color: #8a5fbf; }
.stop h3 { margin: 4px 0 4px; font-size: 19px; line-height: 1.1; }
.stop p { margin: 0; font-size: 14.5px; opacity: .85; clear: left; }
.stop .best { margin-top: 7px; font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; }
.stop .best i, .stars i { font-style: normal; color: #d9c9a8; }
.stop .best i.on, .stars i.on { color: #f5a800; }
.stops.locked .stop { pointer-events: none; opacity: .65; }

/* ---- in game ---- */
#hud > * { position: fixed; }
.hud-left { top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); color: var(--cream); text-shadow: 0 2px 0 var(--ink), 0 0 8px rgba(42, 36, 51, .5); }
#hud-stop { font-family: var(--display); font-size: clamp(16px, 2.6vw, 24px); transform: skewX(-6deg); transform-origin: left; }
#hud-time { font-family: var(--display); font-size: clamp(30px, 5vw, 52px); line-height: 1; font-variant-numeric: tabular-nums; color: var(--yellow); }
#hud-time.over { color: var(--red); animation: late .5s steps(2) infinite; }
@keyframes late { 50% { color: var(--cream); } }
#board { list-style: none; margin: 8px 0 0; padding: 8px 12px; font-weight: 700; font-size: clamp(13px, 1.7vw, 16px); text-shadow: none; color: var(--ink); background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink); transform: rotate(-1.5deg); min-width: 150px; }
#board:empty { display: none; }
#board li { padding: 1px 0; white-space: nowrap; }
#board li::before { content: '☐ '; }
#board li.ok { opacity: .5; text-decoration: line-through; }
#board li.ok::before { content: '☑ '; }
#board li.head { font-family: var(--display); font-weight: 400; }
#board li.head::before { content: ''; }
#board .dot { display: inline-block; width: .8em; height: .8em; border-radius: 50%; border: 2px solid var(--ink); vertical-align: -.08em; }
.hud-right { top: max(12px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); display: flex; gap: 8px; }
.round { width: 44px; height: 44px; font: 700 20px var(--body); color: var(--ink); background: var(--cream); border: 3px solid var(--ink); border-radius: 50%; cursor: pointer; box-shadow: 0 4px 0 var(--ink); }
.round:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.round.off { opacity: .55; }
#radio { top: max(14px, env(safe-area-inset-top)); left: 50%; max-width: min(520px, 56vw); transform: translate(-50%, -20px) scale(.9); opacity: 0; transition: opacity .25s, transform .3s cubic-bezier(.3, 1.6, .5, 1); pointer-events: none;
  display: flex; align-items: center; gap: 10px; font-size: clamp(14px, 2vw, 18px); font-weight: 600; color: var(--cream); background: var(--ink); border: 3px solid var(--cream); border-radius: 16px; padding: 8px 14px; }
#radio.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#radio span { font-family: var(--display); font-size: .8em; color: var(--ink); background: var(--teal); border-radius: 6px; padding: 1px 7px; }
#radio b { font-weight: 600; }
#coach { bottom: max(22px, 4vh); left: 50%; width: max-content; max-width: min(620px, 90vw); transform: translate(-50%, 16px) scale(.95); opacity: 0; transition: opacity .3s, transform .3s cubic-bezier(.3, 1.6, .5, 1);
  text-align: center; font-size: clamp(16px, 2.4vw, 21px); font-weight: 700; background: var(--yellow); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); padding: 9px 18px; pointer-events: none; }
#coach.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#coach::before { content: 'NEXT  '; font-family: var(--display); font-weight: 400; color: var(--brick); white-space: pre; }

#world-ui { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.bubble, .prompt, .ring { position: absolute; left: 0; top: 0; white-space: nowrap; opacity: 0; will-change: transform; }
.bubble { font-family: var(--display); font-size: 24px; color: var(--ink); background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 3px 14px 5px; transform-origin: 50% 100%; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -11px; width: 14px; height: 14px; margin-left: -7px; background: #fff; border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(45deg); }
.bubble.driver { font-family: var(--body); font-weight: 700; font-size: 19px; background: var(--yellow); max-width: 300px; white-space: normal; text-align: center; }
.bubble.driver::after { background: var(--yellow); }
.bubble.on { opacity: 1; }
.bubble.pop { animation: pop .35s cubic-bezier(.3, 1.8, .5, 1); }
.bubble.loud { color: var(--brick); animation: pop .35s cubic-bezier(.3, 1.8, .5, 1), rattle .09s linear infinite .35s; }
@keyframes pop { from { scale: .2; } to { scale: 1; } }
@keyframes rattle { 0% { rotate: -3deg; } 50% { rotate: 3deg; } 100% { rotate: -3deg; } }
.prompt { font-weight: 700; font-size: 15px; color: var(--cream); background: var(--ink); border-radius: 999px; padding: 3px 12px 3px 5px; transition: opacity .12s; }
.prompt kbd { margin: 0 6px 0 0; box-shadow: none; }
.prompt.on { opacity: .96; }
.prompt.no { background: var(--brick); padding-left: 12px; }
.ring { width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; border: 3px solid var(--ink); background: conic-gradient(var(--green) calc(var(--p) * 1turn), var(--cream) 0); box-shadow: 0 3px 0 var(--ink); }
.ring.on { opacity: 1; }

#toast { position: fixed; left: 50%; bottom: max(26px, 6vh); transform: translate(-50%, 30px); opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
  font-weight: 700; font-size: 18px; color: var(--cream); background: var(--plum); border-radius: 999px; padding: 8px 20px; z-index: 5; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- results ---- */
.stars { text-align: center; font-size: 46px; line-height: 1; letter-spacing: .08em; }
.stars i.on { display: inline-block; animation: pop .4s cubic-bezier(.3, 1.8, .5, 1) backwards; animation-delay: calc(var(--i) * .22s + .2s); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats div { background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 8px 4px; }
.stats b { display: block; font-family: var(--display); font-weight: 400; font-size: 25px; color: var(--red); line-height: 1.15; }
.stats span { font-size: 13px; font-weight: 600; }
.pens { list-style: none; margin: 0; padding: 0; font-weight: 600; font-size: 15px; }
.pens li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 4px; border-bottom: 2px dashed rgba(42, 36, 51, .2); }
.pens li b { color: var(--brick); white-space: nowrap; }
.pens li.none { justify-content: center; border: 0; opacity: .8; }
.quip { margin: 0; text-align: center; font-weight: 600; font-style: italic; }

/* ---- touch ---- */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch > * { pointer-events: auto; position: absolute; }
.stick-zone { left: 0; top: 70px; bottom: 0; width: 46%; }
.stick { width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%; background: rgba(255, 243, 214, .35); border: 3px solid rgba(42, 36, 51, .6); pointer-events: none !important; }
.stick i { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px; border-radius: 50%; background: var(--cream); border: 3px solid var(--ink); }
.tb { font: 400 17px var(--display); color: var(--ink); background: rgba(255, 243, 214, .92); border: 3px solid var(--ink); border-radius: 50%; box-shadow: 0 4px 0 var(--ink); }
.tb.on { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); filter: brightness(.9); }
.tb-act { right: max(18px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom)); width: 98px; height: 98px; background: var(--red); color: var(--cream); font-size: 22px; }
.tb-toss { right: 130px; bottom: 30px; width: 72px; height: 72px; background: var(--yellow); }
.tb-shout { right: 30px; bottom: 140px; width: 84px; height: 52px; border-radius: 999px; background: #fff; }

@media (max-height: 560px) {
  .screen { gap: 8px; justify-content: flex-start; }
  .logo .l1 { font-size: clamp(40px, 15vh, 90px); }
  .logo .l2 { font-size: clamp(14px, 5vh, 30px); border-width: 3px; }
  .card { padding: 12px; }
  .btn { font-size: 17px; padding: 6px 18px; }
  .btn.big { font-size: 20px; padding: 8px 18px; }
  .menu-card { gap: 8px; }
  .or, .keys, .tagline { display: none; }
  #coach { bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { .logo .l1 span, .bubble.loud, #hud-time.over { animation: none; } }
