:root { --bg: #07070f; --grid: #1b1f3a; --x: #ff2e88; --o: #21e6ff; --yel: #ffe14d; --org: #ff8a00; --txt: #f2f2ff;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif, "Noto Color Emoji"; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--txt); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --- top HUD: scores, phase, the rival --- */
#top { position: fixed; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 8px) 12px 0; pointer-events: none; z-index: 2; }
#scores { display: flex; align-items: center; justify-content: space-between; max-width: 560px; margin: 0 auto; gap: 8px; }
.side { display: flex; align-items: baseline; gap: 8px; min-width: 104px; padding: 6px 12px; border-radius: 12px; border: 1.5px solid var(--grid);
  background: #0c0d1ccc; transition: box-shadow .25s, border-color .25s; }
.side b { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.side .who { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.side.x { color: var(--x); } .side.o { color: var(--o); justify-content: flex-end; }
.side.turn.x { border-color: var(--x); box-shadow: 0 0 18px #ff2e8877, inset 0 0 10px #ff2e8833; }
.side.turn.o { border-color: var(--o); box-shadow: 0 0 18px #21e6ff77, inset 0 0 10px #21e6ff33; }
.side b.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.35); color: var(--yel); } }
#phase { text-align: center; display: flex; flex-direction: column; line-height: 1.1; }
#phaseName { font-weight: 900; letter-spacing: .2em; font-size: 15px; color: var(--yel); text-shadow: 0 0 10px #ffe14d88; }
#phase.brk #phaseName { color: var(--org); text-shadow: 0 0 12px #ff8a00aa; }
#phaseSub { font-size: 12px; opacity: .7; }
#rival { display: flex; align-items: center; gap: 10px; max-width: 560px; margin: 8px auto 0; min-height: 46px; }
.face { flex: none; position: relative; width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--o); box-shadow: 0 0 14px #21e6ffaa, inset 0 0 8px #21e6ff66; transition: transform .2s; }
.face i { position: absolute; top: 10px; width: 5px; height: 7px; border-radius: 3px; background: var(--o); }
.face i:first-child { left: 8px; } .face i:nth-child(2) { right: 8px; }
.face u { position: absolute; left: 9px; right: 9px; bottom: 7px; height: 6px; border-bottom: 3px solid var(--o); border-radius: 0 0 8px 8px; }
.face.smug u { border-radius: 0 0 10px 2px; transform: rotate(-8deg); }
.face.sad u { border-bottom: 0; border-top: 3px solid var(--o); border-radius: 8px 8px 0 0; bottom: 4px; }
.face.shock u { left: 13px; right: 13px; height: 8px; border: 3px solid var(--o); border-radius: 50%; }
.face.talk { animation: talk .5s; }
@keyframes talk { 30% { transform: scale(1.12) rotate(-6deg); } 60% { transform: scale(.96) rotate(4deg); } }
#say { margin: 0; padding: 8px 12px; border-radius: 12px 12px 12px 2px; background: #0f1430e6; border: 1px solid #21e6ff55; font-size: 14px; line-height: 1.3;
  color: #d8fbff; flex: 1; min-height: 20px; }
#say.new { animation: sayIn .25s; }
@keyframes sayIn { from { opacity: 0; transform: translateX(-8px); } }

/* --- the title, over the opening board --- */
#title { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 64px); text-align: center; z-index: 2; transition: opacity .35s, transform .35s; }
#title h1 { margin: 0 0 8px; font-size: 32px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase;
  background: linear-gradient(90deg, var(--x), #fff 50%, var(--o)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 10px #ff2e8866); }
#title h1 span { font-size: .6em; vertical-align: middle; }
#modes { display: inline-flex; gap: 8px; }
#modes button { min-height: 44px; padding: 8px 13px; border-radius: 22px; border: 1.5px solid var(--grid); background: #0c0d1ccc; font-weight: 700; font-size: 15px; }
#modes button.on { border-color: var(--yel); color: var(--yel); box-shadow: 0 0 12px #ffe14d44; }
body.playing #title { opacity: 0; transform: translateY(16px); pointer-events: none; }

/* --- bottom bar --- */
#bottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 0 10px calc(env(safe-area-inset-bottom) + 10px); display: flex; align-items: center; gap: 10px; z-index: 2; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#hint { flex: 1; margin: 0; text-align: center; font-size: 14px; color: #c9c9e8; line-height: 1.3; pointer-events: none; }
#hint b { color: var(--org); }
.icon { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--grid); background: #0c0d1ccc; font-weight: 900; font-size: 18px; display: grid; place-items: center; }
#muteCross { display: none; } body.muted #muteCross { display: inline; } body.muted #muteWaves { display: none; }
#mark { position: fixed; top: calc(env(safe-area-inset-top) + 128px); right: 12px; z-index: 2; opacity: .8; }
body.playing #mark { display: none; }

/* --- toast, banner, pops --- */
#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 70px); transform: translateX(-50%); padding: 8px 16px; border-radius: 20px;
  background: #1a1030ee; border: 1px solid var(--org); color: var(--txt); font-weight: 700; font-size: 15px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 3; white-space: nowrap; }
#toast.on { opacity: 1; }
#banner { position: fixed; left: 0; right: 0; top: 46%; text-align: center; pointer-events: none; z-index: 3; opacity: 0; }
#banner b { display: block; font-size: 64px; font-weight: 900; letter-spacing: .12em; color: var(--org); text-shadow: 0 0 24px var(--org), 0 0 4px #fff; }
#banner small { display: block; font-size: 16px; font-weight: 700; color: var(--txt); margin-top: 6px; text-shadow: 0 0 8px #000, 0 0 2px #000; }
#banner.on { animation: banner 2.2s forwards; }
@keyframes banner { 0% { opacity: 0; transform: scale(2.2); } 12% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(.96); } }
#pops { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
.pop { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 20px; color: var(--yel); text-shadow: 0 0 10px #ffe14d, 0 0 2px #000; animation: pop 1s forwards; white-space: nowrap; }
.pop.x { color: #ffd0e6; text-shadow: 0 0 12px var(--x), 0 0 2px #000; } .pop.o { color: #d0faff; text-shadow: 0 0 12px var(--o), 0 0 2px #000; }
.pop.loss { color: #fff; text-shadow: 0 0 12px var(--org), 0 0 2px #000; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 20% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -160%) scale(1); } }

/* --- screens --- */
.screen { position: fixed; inset: 0; z-index: 5; display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; background: #07070fcc;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); padding: calc(env(safe-area-inset-top) + 16px) 12px calc(env(safe-area-inset-bottom) + 16px); }
.screen[hidden] { display: none; }
.panel { width: 100%; max-width: 440px; margin: auto 0; text-align: center; }
.panel h2 { margin: 0 0 6px; font-size: 34px; font-weight: 900; }
.panel ol { text-align: left; padding-left: 22px; line-height: 1.45; font-size: 15px; } .panel li { margin-bottom: 8px; }
.panel button { min-height: 44px; border-radius: 12px; border: 1.5px solid var(--grid); background: #0f1124; padding: 8px 14px; font-weight: 700; font-size: 15px; }
.panel button.big { background: var(--x); border-color: var(--x); color: #fff; font-size: 18px; box-shadow: 0 0 18px #ff2e8866; }
.kicker { margin: 0; color: var(--yel); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: 13px; }
#resScore { font-size: 46px; font-weight: 900; display: flex; justify-content: center; gap: 14px; line-height: 1; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
#resScore .x { color: var(--x); text-shadow: 0 0 14px #ff2e8888; } #resScore .o { color: var(--o); text-shadow: 0 0 14px #21e6ff88; } #resScore i { opacity: .4; font-style: normal; }
#resDaily { margin: 0 0 8px; font-size: 14px; color: #c9c9e8; } #resDaily b { color: var(--yel); }
#dayMark { margin-left: 4px; color: var(--yel); } #dayMark:empty { display: none; }
#resSub { margin: 0 0 8px; font-size: 14px; color: #c9c9e8; line-height: 1.35; } #resSub b { color: var(--yel); }
#resGrid { margin: 0 auto 10px; font-family: "Noto Color Emoji", var(--font); font-size: 13px; line-height: 1.12; letter-spacing: 1px; }
.two { display: flex; gap: 8px; margin-bottom: 8px; } .two button { flex: 1; }
#shareBtn { width: 100%; margin-bottom: 10px; }
#vote p { margin: 4px 0 6px; font-size: 13px; opacity: .8; }
#vote .opts { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
#vote .opts button { flex: none; font-size: 13px; padding: 6px 10px; min-height: 44px; }
#door { width: 100%; margin: 6px 0; font-size: 13px; border-style: dashed; color: #c9c9e8; }
#doorNote { font-size: 13px; } #doorNote a, .credit a { color: var(--o); }
.credit { font-size: 12px; opacity: .6; margin: 8px 0 0; }
.hint { font-size: 12px; opacity: .55; margin: 6px 0 0; }
[data-wefav-row] { margin-top: 6px; }

/* Hints for the device in hand. */
.how .m, .how .p, .hint .m, .hint .p { display: none; }
body.mouse .how .t, body.mouse .hint .t { display: none; } body.mouse .how .m, body.mouse .hint .m { display: inline; }
body.pad .how .t, body.pad .how .m, body.pad .hint .t, body.pad .hint .m { display: none; } body.pad .how .p, body.pad .hint .p { display: inline; }

/* Desktop: room to breathe. */
@media (min-width: 900px) {
  #title { bottom: auto; top: 50%; left: 24px; right: auto; width: calc(50vw - 300px); min-width: 220px; transform: translateY(-50%); text-align: left; }
  body.playing #title { transform: translateY(-50%) translateX(-16px); }
  #title h1 { font-size: 40px; }
  #modes { flex-direction: column; }
  #mark { top: auto; bottom: 16px; right: 70px; }
}
@media (max-height: 640px) { #rival { margin-top: 4px; } .side b { font-size: 24px; } }

/* Round 3: the rival ladder and the "how it went" strip */
#rival { cursor: pointer; }
#modes #rivalBtn span { opacity: .7; }
#modes #rivalBtn.locked { opacity: .6; border-style: dashed; }
#modes #rivalBtn.on { border-color: var(--org); color: var(--org); box-shadow: 0 0 12px #ff8a0044; }
.face em { display: none; }
[data-rival="crash"] .face { border-color: var(--org); box-shadow: 0 0 14px #ff8a00aa, inset 0 0 8px #ff8a0066; }
[data-rival="crash"] .face i { background: var(--org); top: 12px; }
[data-rival="crash"] .face u, [data-rival="crash"] .face.shock u { border-color: var(--org); }
[data-rival="crash"] .face em { display: block; position: absolute; left: 6px; right: 6px; top: 6px; height: 4px;
  background: linear-gradient(160deg, var(--org) 45%, transparent 45% 55%, var(--org) 55%); border-radius: 2px; }
[data-rival="crash"] #say { border-color: #ff8a0066; color: #ffe9d2; }
.vs { margin: -4px 0 6px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: #8d8db0; }
#resBars { margin: 0 0 8px; text-align: left; }
#resBars .cap { margin: 0 0 2px; font-size: 11px; line-height: 1.2; color: #8d8db0; text-align: center; }
#resBars .bar { display: grid; grid-template-columns: 52px 1fr 64px; align-items: center; gap: 8px; margin: 1px 0; font-size: 13px; }
#resBars .who { color: #c9c9e8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#resBars .track { display: flex; height: 12px; border-radius: 6px; background: #ffffff0d; overflow: hidden; }
#resBars .kept { display: block; height: 100%; }
#resBars .lost { display: block; height: 100%; background: repeating-linear-gradient(135deg, #ffffff30 0 3px, transparent 3px 7px); }
#resBars .x .kept { background: var(--x); box-shadow: 0 0 10px var(--x); } #resBars .o .kept { background: var(--o); box-shadow: 0 0 10px var(--o); }
#resBars .x .lost { border: 1px solid #ff2e8866; } #resBars .o .lost { border: 1px solid #21e6ff66; }
#resBars .num { text-align: right; color: #8d8db0; white-space: nowrap; } #resBars .num b { color: var(--txt); font-size: 15px; }
#resUnlock { margin: 0 0 8px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--org); background: #ff8a0018; font-size: 14px; color: #ffe9d2; }
#resUnlock b { color: var(--org); }
