:root {
  --ink: #1f2a44;
  --ink-soft: #4b5878;
  --paper: #ffffff;
  --sun: #ffc22e;
  --coral: #ff5a5f;
  --sky: #3b9dff;
  --mint: #22c993;
  --edge: 3px solid var(--ink);
  --pop: 0 6px 0 var(--ink);
  --font: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd0ff; color: var(--ink); font-family: var(--font); }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#tags { position: fixed; inset: 0; pointer-events: none; z-index: 2; }

.card { background: var(--paper); border: var(--edge); border-radius: 26px; box-shadow: var(--pop); }
.btn { border: var(--edge); background: #fff; border-radius: 18px; padding: 10px 22px; font-weight: 800; font-size: 1.15rem; box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible, .icon-btn:focus-visible, .game:focus-visible { outline: 4px solid var(--sky); outline-offset: 3px; }
.btn-sun { background: var(--sun); }

/* ---------- Lobby ---------- */
.screen { position: fixed; inset: 0; z-index: 3; display: none; }
.screen.on { display: block; }
#lobby { padding: clamp(14px, 2.4vw, 34px); display: none; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); grid-template-rows: auto 1fr auto; gap: clamp(12px, 1.8vw, 24px); pointer-events: none; }
#lobby.on { display: grid; }
#lobby > * { pointer-events: auto; }
.brand { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; pointer-events: none !important; }
.brand-mark { width: 52px; height: 52px; filter: drop-shadow(0 4px 0 rgba(31, 42, 68, .25)); transform: rotate(-8deg); }
.brand h1 { margin: 0; font-size: clamp(2.2rem, 4.4vw, 3.8rem); line-height: 1; font-weight: 800; color: #fff; letter-spacing: .5px; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }

.join { align-self: start; justify-self: start; display: flex; gap: 22px; padding: 18px 24px 18px 18px; align-items: center; max-width: 640px; }
.qr { width: clamp(150px, 15vw, 210px); aspect-ratio: 1; border-radius: 16px; background: #fff; display: grid; place-items: center; border: 3px solid #e7ecf5; overflow: hidden; }
.qr svg, .qr img { width: 100%; height: 100%; display: block; }
.join-lead { margin: 0; font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.join-or { margin: 6px 0 10px; color: var(--ink-soft); font-size: 1.02rem; font-weight: 600; }
.join-or b { color: var(--ink); word-break: break-all; }
.code { display: flex; gap: 8px; }
.code span { width: clamp(46px, 4.6vw, 62px); height: clamp(56px, 5.6vw, 74px); display: grid; place-items: center; border: var(--edge); border-radius: 14px; background: var(--sun); font-size: clamp(2rem, 3.4vw, 2.8rem); font-weight: 800; box-shadow: 0 4px 0 var(--ink); }
.code span:nth-child(2n) { transform: rotate(3deg); }
.code span:nth-child(2n+1) { transform: rotate(-2deg); }
.net-state { margin: 12px 0 0; font-weight: 600; color: var(--ink-soft); font-size: .98rem; }
.net-state.bad { color: #c8102e; }

.players { grid-row: 2 / 4; grid-column: 2; align-self: start; padding: 16px 18px 14px; }
.players h2 { margin: 0 0 8px; font-size: 1.6rem; }
.slots { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.slot { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 16px; border: 3px dashed #c9d2e3; min-height: 62px; color: #8b97b0; font-weight: 700; font-size: 1.1rem; }
.slot.on { border: var(--edge); color: var(--ink); background: color-mix(in srgb, var(--pc) 18%, white); animation: hop .45s cubic-bezier(.3, 1.6, .5, 1); }
.slot .dot { width: 40px; height: 40px; border-radius: 50%; background: #e7ecf5; flex: none; display: grid; place-items: center; }
.slot.on .dot { background: var(--pc); border: var(--edge); }
.slot .dot svg { width: 24px; height: 24px; }
.slot .crown { margin-left: auto; width: 26px; height: 26px; }
.players-tip { margin: 10px 2px 0; color: var(--ink-soft); font-weight: 600; font-size: .95rem; line-height: 1.3; }
@keyframes hop { 0% { transform: scale(.85); } 100% { transform: scale(1); } }

.games { grid-column: 1; grid-row: 3; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(8px, 1vw, 14px); max-width: 1000px; }
.game { position: relative; display: flex; flex-direction: column; text-align: left; border: var(--edge); border-radius: 24px; background: #fff; box-shadow: var(--pop); padding: 0; overflow: hidden; transition: transform .12s; }
.game:hover { transform: translateY(-4px) rotate(-.6deg); }
.game.sel { outline: 5px solid var(--sun); outline-offset: 0; transform: translateY(-6px); }
.game .art { height: clamp(52px, 8.5vh, 84px); display: block; border-bottom: var(--edge); flex: none; }
.game .art svg { width: 100%; height: 100%; display: block; }
.game h3 { margin: 8px 10px 0; font-size: clamp(1.05rem, 1.5vw, 1.35rem); line-height: 1.05; }
.game p { margin: 2px 10px 8px; color: var(--ink-soft); font-weight: 600; font-size: clamp(.78rem, .95vw, .92rem); line-height: 1.2; }
.game .opt { display: flex; align-items: center; gap: 6px; margin: -4px 10px 8px; font-weight: 700; font-size: .85rem; }
.game .opt input { width: 20px; height: 20px; accent-color: var(--mint); }

/* ---------- Tags above characters ---------- */
.tag { position: absolute; left: 0; top: 0; padding: 0 10px; border-radius: 12px; background: var(--pc, #fff); color: #fff; border: 2.5px solid var(--ink); font-weight: 800; font-size: 1rem; white-space: nowrap; box-shadow: 0 3px 0 var(--ink); -webkit-text-stroke: .5px var(--ink); }
.tag.bubble { background: #fff; color: var(--ink); -webkit-text-stroke: 0; padding: 4px; border-radius: 14px; display: flex; gap: 3px; }
.tag.bubble svg { width: 30px; height: 30px; display: block; }
.tag.bar { padding: 0; width: 46px; height: 12px; background: #fff; overflow: hidden; border-radius: 8px; }
.tag.bar i { display: block; height: 100%; background: var(--mint); }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; display: none; }
.hud.on { display: block; }
.hud .pill { position: absolute; background: #fff; border: var(--edge); border-radius: 18px; box-shadow: 0 4px 0 var(--ink); padding: 4px 16px; font-weight: 800; font-size: 1.5rem; }
.hud .timer { top: 18px; left: 50%; transform: translateX(-50%); min-width: 120px; text-align: center; font-variant-numeric: tabular-nums; }
.hud .timer.low { background: var(--coral); color: #fff; }
.hud .score { top: 18px; right: 18px; display: flex; align-items: center; gap: 8px; }
.hud .score svg { width: 28px; height: 28px; }
.hud .orders { position: absolute; top: 16px; left: 16px; display: flex; gap: 10px; }
.order { width: 128px; background: #fff; border: var(--edge); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); overflow: hidden; animation: drop .4s cubic-bezier(.3, 1.6, .5, 1); }
.order .t { height: 8px; background: var(--mint); transition: width .25s linear; }
.order .t.mid { background: var(--sun); }
.order .t.low { background: var(--coral); }
.order h4 { margin: 4px 8px 0; font-size: 1.05rem; }
.order .parts { display: flex; gap: 4px; padding: 2px 8px 8px; }
.order .parts svg { width: 30px; height: 30px; }
@keyframes drop { 0% { transform: translateY(-40px); opacity: 0; } 100% { transform: none; opacity: 1; } }
.hud .race-board { position: absolute; top: 16px; left: 16px; display: grid; gap: 6px; }
.race-row { display: flex; align-items: center; gap: 10px; background: #fff; border: var(--edge); border-radius: 14px; padding: 2px 12px 2px 4px; font-weight: 800; font-size: 1.1rem; box-shadow: 0 3px 0 var(--ink); min-width: 200px; transition: transform .3s; }
.race-row .pos { width: 34px; height: 34px; border-radius: 10px; background: var(--pc); border: 2.5px solid var(--ink); display: grid; place-items: center; color: #fff; -webkit-text-stroke: .5px var(--ink); }
.race-row .lap { margin-left: auto; color: var(--ink-soft); font-size: .95rem; }
.race-row .turbo { width: 44px; height: 8px; border-radius: 6px; background: #e7ecf5; overflow: hidden; }
.race-row .turbo i { display: block; height: 100%; background: linear-gradient(90deg, #ffc22e, #ff5a5f); }
.hud .needs { position: absolute; left: 16px; top: 16px; display: grid; gap: 8px; }

.banner { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(0); z-index: 6; pointer-events: none; font-size: clamp(4rem, 12vw, 10rem); font-weight: 800; color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; text-shadow: 0 10px 0 var(--ink); white-space: nowrap; }
.banner.small { font-size: clamp(2.2rem, 6vw, 4.6rem); -webkit-text-stroke: 4px var(--ink); text-shadow: 0 6px 0 var(--ink); }
.banner.show { animation: bannerIn .9s cubic-bezier(.3, 1.6, .5, 1) forwards; }
@keyframes bannerIn { 0% { transform: translate(-50%, -50%) scale(.2) rotate(-8deg); opacity: 0; } 30% { transform: translate(-50%, -50%) scale(1.08) rotate(2deg); opacity: 1; } 75% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 0; } }

/* ---------- Results ---------- */
#results { background: rgba(31, 42, 68, .35); }
#results.on { display: grid; place-items: center; }
.results { width: min(560px, 92vw); padding: 22px 26px 18px; text-align: center; animation: hop .5s cubic-bezier(.3, 1.6, .5, 1); }
.results h2 { margin: 0; font-size: 2.6rem; line-height: 1.05; }
.podium { display: grid; gap: 8px; margin: 14px 0; text-align: left; }
.podium .row { display: flex; align-items: center; gap: 12px; border: var(--edge); border-radius: 16px; padding: 6px 14px 6px 6px; font-weight: 800; font-size: 1.3rem; background: color-mix(in srgb, var(--pc) 16%, white); }
.podium .row .n { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--pc); color: #fff; border: var(--edge); -webkit-text-stroke: .6px var(--ink); }
.podium .row .v { margin-left: auto; color: var(--ink-soft); font-size: 1.1rem; }
.stars { display: flex; justify-content: center; gap: 10px; margin: 12px 0 4px; }
.stars svg { width: 70px; height: 70px; }
.stars svg.on { animation: hop .5s cubic-bezier(.3, 1.8, .5, 1) both; }
.res-big { font-size: 1.4rem; font-weight: 700; margin: 4px 0 10px; }
.res-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.res-tip { margin: 10px 0 0; color: var(--ink-soft); font-weight: 600; }

.corner { position: fixed; right: 14px; bottom: 14px; z-index: 7; display: flex; gap: 8px; }
.icon-btn { width: 46px; height: 46px; border-radius: 14px; border: var(--edge); background: #fff; box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center; padding: 0; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.off #soundWave { display: none; }

@media (max-width: 860px) {
  #lobby { grid-template-columns: 1fr; grid-template-rows: auto auto auto auto; overflow-y: auto; pointer-events: auto; }
  .players { grid-row: auto; grid-column: 1; }
  .games { grid-column: 1; grid-row: auto; grid-template-columns: 1fr; }
  .join { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Doodle Guess ---------- */
.dg-paper { position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%) rotate(-1.2deg); width: min(54vw, calc(64vh * 4 / 3)); aspect-ratio: 4 / 3; background: #fffdf8; border: var(--edge); border-radius: 10px; box-shadow: 0 8px 0 var(--ink), 0 18px 40px rgba(31, 42, 68, .25); }
.dg-paper::before, .dg-paper::after { content: ''; position: absolute; top: -14px; width: 70px; height: 26px; background: rgba(255, 194, 46, .75); border: 2px solid rgba(31, 42, 68, .25); transform: rotate(-6deg); }
.dg-paper::before { left: 18px; } .dg-paper::after { right: 18px; transform: rotate(5deg); }
.dg-paper canvas { width: 100%; height: 100%; display: block; border-radius: 8px; }
.dg-who { position: absolute; left: 50%; bottom: -46px; transform: translateX(-50%); white-space: nowrap; font-weight: 800; font-size: 1.3rem; background: #fff; border: var(--edge); border-radius: 14px; padding: 0 14px; box-shadow: 0 3px 0 var(--ink); }
.hud .dg-word { top: 82px; left: 50%; transform: translateX(-50%); font-size: 1.7rem; letter-spacing: 3px; white-space: nowrap; }
.hud .dg-board { top: 16px; left: 16px; }
.race-row.dg-drawing { background: color-mix(in srgb, var(--pc) 22%, white); }
.race-row .pos svg { width: 22px; height: 22px; }
.dg-feed { position: absolute; right: 16px; top: 16px; width: min(260px, 22vw); display: grid; gap: 8px; }
.dg-msg { background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; padding: 4px 12px; font-weight: 700; font-size: 1.05rem; box-shadow: 0 3px 0 var(--ink); animation: drop .35s cubic-bezier(.3, 1.6, .5, 1); overflow-wrap: anywhere; }
.dg-msg.dg-good { background: #d9f7ea; }
.dg-msg.dg-word-was { background: #fff3c4; }

/* ---------- Dragon Boat / Crane Tower ---------- */
.hud .beat { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; background: #fff; border: var(--edge); border-radius: 30px; padding: 6px 18px 6px 8px; box-shadow: 0 4px 0 var(--ink); font-weight: 800; font-size: 1.15rem; }
.hud .beat i { width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ff8a8a, #ff5a5f 60%); border: 3px solid var(--ink); display: block; }
.hud .lives { gap: 4px; }
.crane-turn { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); background: #fff; border: var(--edge); border-radius: 18px; padding: 4px 18px; font-weight: 800; font-size: 1.5rem; box-shadow: 0 4px 0 var(--ink); }
.crane-turn:empty { display: none; }
.crane-turn span { color: var(--pc); -webkit-text-stroke: .6px var(--ink); }
