:root {
  --bg: #0c0d12; --s1: #14161f; --s2: #1b1e2a; --line: rgba(255,255,255,.07);
  --tx: #eef0f6; --mu: #8a90a2; --c: #ff5d73; --r: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--tx); font-family: Outfit, 'Hind Vadodara', system-ui, sans-serif; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: var(--tx); -webkit-user-select: text; user-select: text; }
svg.lucide { width: 20px; height: 20px; stroke-width: 2.2; flex: none; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--mu); }

#app { height: 100dvh; max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.screen { height: 100%; display: flex; flex-direction: column; padding: 20px 16px; gap: 14px; animation: rise .35s ease; }
.screen.center { justify-content: center; align-items: center; text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 54px; padding: 0 22px;
  border-radius: 14px; background: var(--s2); border: 1px solid var(--line); font-weight: 600; font-size: 16px; transition: transform .12s, background .2s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--c); border-color: transparent; color: #12060a; }
.btn.ghost { background: none; border-color: transparent; color: var(--mu); }
.btn.sm { height: 40px; padding: 0 14px; font-size: 14px; border-radius: 11px; }
.btn:disabled { opacity: .5; }
.icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--s1); border: 1px solid var(--line); }

/* home */
.home { justify-content: center; gap: 16px; }
.brand { text-align: center; margin-bottom: 18px; }
.brand .logo { width: 84px; height: 84px; margin-bottom: 14px; }
.brand h1 { font-size: 46px; font-weight: 800; letter-spacing: -1.5px; }
.brand p { color: var(--mu); margin-top: 6px; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--mu); }
.field input, .joinrow input { height: 54px; border-radius: 14px; background: var(--s1); border: 1px solid var(--line); padding: 0 16px; font-size: 17px; outline: none; }
.field input:focus, .joinrow input:focus { border-color: var(--c); }
.or { display: flex; align-items: center; gap: 12px; color: var(--mu); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.joinrow { display: flex; gap: 10px; }
.joinrow input { flex: 1; min-width: 0; letter-spacing: 6px; font-weight: 700; text-align: center; }

/* waiting */
.waiting { gap: 18px; }
.bigcode { display: flex; gap: 10px; }
.bigcode span { width: 64px; height: 80px; display: grid; place-items: center; font-size: 44px; font-weight: 800; border-radius: 16px; background: var(--s1); border: 1px solid var(--line); }
.waiting p { max-width: 300px; }
.pulse { display: flex; align-items: center; gap: 8px; color: var(--mu); font-size: 14px; margin-top: 10px; animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--c); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.duo { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; font-size: 14px; min-width: 0; }
.duo .who { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.tally { font-weight: 800; font-size: 18px; padding: 3px 10px; border-radius: 10px; background: var(--s1); font-variant-numeric: tabular-nums; }
.tally em { font-style: normal; color: var(--mu); margin: 0 3px; }
.game .top .duo { justify-content: flex-end; font-size: 13px; }
.game .top .duo .who { display: none; }
.gt { font-weight: 700; font-size: 18px; }

/* lobby */
.lobby { overflow-y: auto; }
.lobby h2 { font-size: 30px; font-weight: 800; letter-spacing: -.6px; margin-top: 8px; }
.lobby .sub { margin-top: -8px; }
.cards { display: grid; gap: 12px; padding-bottom: 20px; }
.card { display: flex; gap: 14px; align-items: center; text-align: left; padding: 16px; border-radius: var(--r); background: var(--s1); border: 1px solid var(--line); transition: transform .15s, border-color .2s; }
.card:active { transform: scale(.98); border-color: var(--c); }
.card .ic { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; flex: none;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); }
.card .ic svg { width: 28px; height: 28px; }
.card .tag { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--c); font-weight: 700; }
.card h3 { font-size: 19px; font-weight: 700; margin: 1px 0 3px; }
.card p { color: var(--mu); font-size: 14px; line-height: 1.35; }

/* game shell */
.game { padding-bottom: 12px; position: relative; }
.stage { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.overlay { position: absolute; inset: 0; background: rgba(8,9,13,.78); backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 10; animation: rise .3s ease; }
.overlay[hidden] { display: none; }
.sheet { width: min(340px, 90%); display: flex; flex-direction: column; gap: 12px; text-align: center; align-items: stretch; }
.sheet h2 { font-size: 34px; font-weight: 800; }
.sheet .trophy { width: 56px; height: 56px; margin: 0 auto; color: var(--c); }
.turn { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 17px; padding: 4px 2px 12px; }
.turn .muted { font-weight: 500; font-size: 14px; }
.locked { cursor: default; }

/* hockey */
.hk { flex: 1; position: relative; touch-action: none; }
.hk canvas { position: absolute; inset: 0; touch-action: none; }
.hk-msg { position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; font-weight: 800; pointer-events: none; opacity: 0; transform: scale(.8); transition: .25s; text-shadow: 0 0 30px var(--c); }
.hk-msg.on { opacity: 1; transform: scale(1); }

/* quick draw */
.rx { flex: 1; border-radius: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--s1); border: 1px solid var(--line); transition: background .08s; touch-action: manipulation; position: relative; }
.rx[data-s="wait"] { background: #2a1418; }
.rx[data-s="go"] { background: #3dd67a; color: #04130a; }
.rx[data-s="go"] .rx-big { font-size: 96px; }
.rx-big { font-size: 46px; font-weight: 800; letter-spacing: -1px; }
.rx-sub { font-size: 16px; }
.rx-pips { position: absolute; top: 16px; left: 16px; right: 16px; display: flex; justify-content: space-between; }
.pips { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--mu); }
.pips.theirs { flex-direction: row-reverse; }
.pips i { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.12); }
.pips b { font-weight: 600; margin: 0 4px; }

/* sketch */
.sk { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.sk-head { display: flex; justify-content: space-between; align-items: center; }
.sk-word { font-weight: 800; font-size: 20px; letter-spacing: 2px; }
.sk-time { font-weight: 700; color: var(--c); font-variant-numeric: tabular-nums; }
.sk-board { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; }
.sk-board canvas { border-radius: 18px; touch-action: none; box-shadow: 0 0 0 1px var(--line); }
.sk-veil { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(12,13,18,.85); border-radius: 18px; }
.sk-veil[hidden] { display: none; }
.pick { display: flex; flex-direction: column; gap: 10px; align-items: stretch; text-align: center; min-width: 220px; }
.pick h2 { font-size: 34px; text-transform: capitalize; }
.sk-tools { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.sw { width: 34px; height: 34px; border-radius: 50%; background: var(--sw); border: 2px solid var(--line); display: grid; place-items: center; }
.sw.on { outline: 3px solid var(--tx); outline-offset: 2px; }
.sw svg { width: 16px; height: 16px; }
.sz { width: 34px; height: 34px; border-radius: 10px; background: var(--s2); display: grid; place-items: center; }
.sz i { width: 6px; height: 6px; border-radius: 50%; background: var(--tx); }
.sz.big i { width: 14px; height: 14px; }
.sz.on { outline: 2px solid var(--c); }
.sk-guess { display: none; flex-direction: column; gap: 8px; }
.sk[data-role="guess"] .sk-guess { display: flex; }
.sk[data-role="guess"] .sk-tools { display: none; }
.sk[data-role="draw"] .sk-guess { display: flex; }
.sk[data-role="draw"] .sk-guess form { display: none; }
.sk-feed { display: flex; gap: 6px; overflow-x: auto; min-height: 30px; }
.sk-feed span { padding: 5px 11px; border-radius: 99px; background: var(--s2); font-size: 14px; white-space: nowrap; }
.sk-feed span.ok { background: #3dd67a; color: #04130a; font-weight: 700; }
.sk-guess form { display: flex; gap: 8px; }
.sk-guess input { flex: 1; min-width: 0; height: 46px; border-radius: 12px; background: var(--s1); border: 1px solid var(--line); padding: 0 14px; outline: none; }
.sk-guess .btn { height: 46px; width: 52px; padding: 0; }

/* in sync */
.sy { flex: 1; display: flex; flex-direction: column; gap: 18px; }
.sy-meter { height: 6px; border-radius: 99px; background: var(--s1); overflow: hidden; }
.sy-meter div { height: 100%; background: var(--c); transition: width .5s; }
.sy-card { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.sy-card.in { animation: rise .4s ease; }
.sy-who { color: var(--c); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; }
.sy-card h2 { font-size: 32px; font-weight: 800; letter-spacing: -.6px; line-height: 1.15; }
.sy-opts { display: grid; gap: 10px; }
.opt { padding: 17px 18px; border-radius: 15px; background: var(--s1); border: 1.5px solid var(--line); text-align: left; font-size: 17px; font-weight: 500; transition: .2s; position: relative; }
.opt.mine { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, var(--s1)); }
.opt.theirs::after { content: 'their pick'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: 1px; }
.opt:disabled { opacity: 1; }
.sy-wait { min-height: 44px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sy-wait .btn { margin-left: auto; }
.yes { color: #3dd67a; } .no { color: #ff8a5d; }

/* pairs */
.pr { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pr-grid { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr); gap: 9px; min-height: 0; }
.pc { perspective: 600px; padding: 0; min-height: 0; }
.pc .in { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.3,1.3,.5,1); transform-style: preserve-3d; }
.pc.up .in, .pc.got .in { transform: rotateY(180deg); }
.back, .face { position: absolute; inset: 0; border-radius: 14px; -webkit-backface-visibility: hidden; backface-visibility: hidden; display: grid; place-items: center; }
/* Safari leaks back faces through 3D flips; hide the photo outright until mid-flip. */
.face { visibility: hidden; transition: visibility 0s .2s; }
.pc.up .face, .pc.got .face { visibility: visible; }
.back { background: var(--s1) repeating-linear-gradient(45deg, transparent 0 8px, rgba(255,255,255,.025) 8px 16px); border: 1px solid var(--line); }
.face { transform: rotateY(180deg); background: var(--s2); color: var(--f); border: 1.5px solid var(--line); }
.face img { width: 72%; height: 72%; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); }
.face { background: radial-gradient(circle at 50% 40%, #262b3d, #171a26); }
.face svg { width: 38%; height: 38%; max-width: 40px; max-height: 40px; }
.pc.got .face { border-color: var(--o); box-shadow: inset 0 0 0 1px var(--o); }
.pr.locked .pc:not(.up) .back { opacity: .7; }

/* four up */
.fr { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.fr-board { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 8px; border-radius: 20px; background: #1d2547; box-shadow: 0 20px 50px rgba(0,0,0,.5), inset 0 2px 0 rgba(255,255,255,.08); }
.col { display: grid; gap: 4px; padding: 0; border-radius: 12px; transition: background .2s; }
.fr:not(.locked) .col:active { background: rgba(255,255,255,.06); }
.hole { aspect-ratio: 1; border-radius: 50%; background: #0c0f1e; box-shadow: inset 0 3px 6px rgba(0,0,0,.6); position: relative; }
.disc { position: absolute; inset: 7%; border-radius: 50%; animation: fall .42s cubic-bezier(.5,0,.7,1.2); box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), inset 0 3px 0 rgba(255,255,255,.3); }
@keyframes fall { from { transform: translateY(var(--fall)); } }
.disc.win { animation: glow .8s ease infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 0 4px #fff, 0 0 24px #fff; } }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--tx); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; transition: .3s; pointer-events: none; max-width: calc(100% - 32px); z-index: 50; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* sketch picks */
.sk-word img { width: 30px; height: 30px; vertical-align: middle; }
.sk-word { display: flex; align-items: center; gap: 8px; letter-spacing: 1px; }
.sk-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sk-choice { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 16px; background: var(--s2); border: 1px solid var(--line); font-weight: 600; font-size: 16px; }
.sk-choice:active { transform: scale(.96); border-color: var(--c); }
.sk-choice img { width: 64px; height: 64px; }
.sk-reveal { width: 96px; height: 96px; margin: 0 auto; }

/* four up: board picker */
.mode { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.mode > p { text-align: center; }
.mode-opt { display: grid; grid-template-columns: 84px 1fr; grid-template-rows: auto auto; column-gap: 16px; align-items: center; text-align: left; padding: 18px; border-radius: var(--r); background: var(--s1); border: 1px solid var(--line); }
.mode-opt:active { border-color: var(--c); transform: scale(.98); }
.mode-opt .mini { grid-row: span 2; width: 84px; height: 72px; border-radius: 12px; background: #1d2547; display: grid; padding: 8px; gap: 4px; }
.mode-opt b { font-size: 19px; align-self: end; }
.mode-opt span { font-size: 14px; align-self: start; }
.mini.four { grid-template-columns: repeat(4, 1fr); }
.mini.four i { border-radius: 50%; background: #0c0f1e; }
.mini.four i:nth-child(10), .mini.four i:nth-child(7) { background: #ff5d73; }
.mini.four i:nth-child(11), .mini.four i:nth-child(12) { background: #3dd6c6; }
.mini.xo { grid-template-columns: 1fr 1fr; background: var(--s2); place-items: center; }

/* cross & circle */
.xo-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.xo-board { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px; aspect-ratio: 1; width: min(100%, 58vh); margin: 0 auto; }
.xo-cell { border-radius: 18px; background: var(--s1); border: 1px solid var(--line); display: grid; place-items: center; padding: 0; }
.xo-wrap:not(.locked) .xo-cell:empty:active { background: var(--s2); }
.xo-cell.win { background: color-mix(in srgb, var(--c) 18%, var(--s1)); border-color: var(--c); }
.mk { width: 70%; height: 70%; fill: none; stroke-width: 12; stroke-linecap: round; }
.mk path, .mk circle { stroke-dasharray: 200; stroke-dashoffset: 200; animation: ink .35s ease-out forwards; }
.mini .mk { width: 100%; height: 100%; }
@keyframes ink { to { stroke-dashoffset: 0; } }

/* untangle: light board like a paper puzzle, crisp ink arrows */
.ut { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; min-height: 0; }
.ut-head { display: flex; justify-content: space-between; align-items: center; }
.ut-side { display: flex; align-items: center; gap: 10px; }
.ut-side div { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.ut-side.r div { align-items: flex-end; }
.ut-count { font-size: 34px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; min-width: 1.2em; text-align: center; }
.ut-vs { font-size: 11px; color: var(--mu); text-transform: uppercase; letter-spacing: 1.4px; }
.ut-hearts { display: flex; gap: 3px; }
.ut-hearts svg { width: 16px; height: 16px; color: #3a3f52; fill: #3a3f52; transition: .3s; }
.ut-hearts svg.on { color: var(--hc); fill: var(--hc); }
.ut-board { flex: none; align-self: center; aspect-ratio: 8 / 12; width: min(100%, calc((100dvh - 210px) * 8 / 12)); position: relative; border-radius: 24px; background: #f7f4ee; padding: 10px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06), 0 18px 50px rgba(0,0,0,.45); }
.ut-board svg { width: 100%; height: 100%; display: block; overflow: hidden; touch-action: manipulation; }
.ut-dot { fill: #d9d3c7; }
.ar { --ink: color-mix(in srgb, var(--ac) 82%, #1a1020); }
.ar .body { fill: none; stroke: var(--ink); stroke-width: .15; stroke-linecap: round; stroke-linejoin: round; }
.ar .tip { fill: var(--ink); stroke: var(--ink); stroke-width: .03; stroke-linejoin: round; }
.ar .hit { fill: none; stroke: transparent; stroke-width: .92; stroke-linecap: round; stroke-linejoin: round; cursor: pointer; }
.ar.theirs .hit { cursor: not-allowed; }
.ar.crash { --ink: #e5262b; }
.ar.hit-by, .ar.nope { animation: shake .35s; transform-box: fill-box; transform-origin: center; }
@keyframes shake { 20% { transform: translateX(-.06px); } 40% { transform: translateX(.06px); } 60% { transform: translateX(-.04px); } 80% { transform: translateX(.03px); } }
.ut-banner { position: absolute; inset: 0; display: grid; place-items: center; font-size: 44px; font-weight: 800; pointer-events: none; opacity: 0; transform: scale(.9); transition: .25s; color: #1a1d29; }
.ut-banner.small { font-size: 22px; }
.ut-banner.on { opacity: 1; transform: none; }
