:root {
  --bg: #070a1a;
  --panel: rgba(16, 20, 48, 0.82);
  --panel-solid: #11163a;
  --line: rgba(140, 160, 255, 0.18);
  --text: #eef1ff;
  --dim: #8f97c7;
  --p0: #3df2ff;
  --p1: #ff4fd8;
  --gold: #ffe14d;
  --good: #7cff6b;
  --bad: #ff5a6e;
  --action: #3df2ff;
  --reflex: #ffe14d;
  --brain: #b98cff;
  --mind: #ff4fd8;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: Rubik, system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

#stage, #stage canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; padding: 16px; }
#ui > * { pointer-events: auto; }

/* ---------- shared bits ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; backdrop-filter: blur(10px); box-shadow: 0 30px 80px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .06); }
.screen { animation: rise .45s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.97); } }

.btn { border: 0; cursor: pointer; padding: 14px 26px; border-radius: 14px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; font-size: 15px;
  background: linear-gradient(180deg, #4a5cff, #2a35c9); box-shadow: 0 6px 0 #1a2190, 0 12px 30px rgba(74, 92, 255, .35); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #1a2190; }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: not-allowed; transform: none; }
.btn.hot { background: linear-gradient(180deg, #ff6ad9, #c3249f); box-shadow: 0 6px 0 #7d1466, 0 12px 30px rgba(255, 79, 216, .35); }
.btn.go { background: linear-gradient(180deg, #8cff7c, #2fbf4a); color: #06210c; box-shadow: 0 6px 0 #1b7a2d, 0 12px 30px rgba(124, 255, 107, .3); }
.btn.ghost { background: rgba(255, 255, 255, .06); box-shadow: inset 0 0 0 1px var(--line); }
.btn.ghost:active { transform: translateY(1px); }
.btn.small { padding: 8px 14px; font-size: 12px; border-radius: 10px; }

.field { width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); outline: none; font-size: 18px; font-weight: 500; }
.field:focus { border-color: #6b7cff; box-shadow: 0 0 0 4px rgba(107, 124, 255, .2); }

.kbd { display: inline-block; min-width: 30px; padding: 5px 9px; border-radius: 8px; font: 700 13px 'JetBrains Mono', monospace; text-align: center;
  background: linear-gradient(180deg, #2b3270, #1c2152); border: 1px solid rgba(255, 255, 255, .14); box-shadow: 0 3px 0 #0c0f2e; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.tag.action { background: rgba(61, 242, 255, .14); color: var(--action); }
.tag.reflex { background: rgba(255, 225, 77, .14); color: var(--reflex); }
.tag.brain { background: rgba(185, 140, 255, .16); color: var(--brain); }
.tag.mind { background: rgba(255, 79, 216, .14); color: var(--mind); }
.p0 { color: var(--p0); } .p1 { color: var(--p1); }

/* ---------- home ---------- */
.home { width: min(460px, 100%); padding: 34px; text-align: center; }
.logo { font-family: Bungee, sans-serif; font-size: clamp(40px, 8vw, 64px); line-height: .95; margin: 0 0 6px; letter-spacing: .02em;
  background: linear-gradient(90deg, var(--p0), #a98bff 50%, var(--p1)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(169, 139, 255, .55)); animation: logo 4s ease-in-out infinite; }
@keyframes logo { 50% { filter: drop-shadow(0 0 34px rgba(255, 79, 216, .6)); } }
.sub { color: var(--dim); margin: 0 0 26px; }
.home .row { display: flex; gap: 10px; margin-top: 12px; }
.home .row .field { flex: 1; text-transform: uppercase; letter-spacing: .3em; text-align: center; font-family: 'JetBrains Mono', monospace; }
.home .btn { width: 100%; }
.home .row .btn { width: auto; flex: none; }
.home .or { color: var(--dim); font-size: 13px; margin: 18px 0 6px; display: flex; align-items: center; gap: 10px; }
.home .or::before, .home .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.label { display: block; text-align: left; color: var(--dim); font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; margin: 0 0 8px 2px; }

/* ---------- lobby ---------- */
.lobby { width: min(1100px, 100%); max-height: calc(100vh - 32px); padding: 24px; display: grid; gap: 18px; grid-template-columns: 300px 1fr; overflow: auto; }
.lobby h2 { font-family: Bungee, sans-serif; font-weight: 400; margin: 0 0 12px; font-size: 18px; letter-spacing: .04em; }
.code-box { padding: 18px; border-radius: 16px; background: rgba(0, 0, 0, .25); border: 1px dashed rgba(140, 160, 255, .35); text-align: center; }
.code { font: 700 48px 'JetBrains Mono', monospace; letter-spacing: .25em; margin: 4px 0 10px 12px; text-shadow: 0 0 24px rgba(107, 124, 255, .8); }
.pcard { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; background: rgba(255, 255, 255, .04); margin-top: 10px; border: 1px solid transparent; }
.pcard.me { border-color: rgba(255, 255, 255, .14); }
.pcard .dot { width: 34px; height: 34px; border-radius: 50%; flex: none; box-shadow: 0 0 18px currentColor; background: currentColor; position: relative; }
.pcard .dot::after { content: ''; position: absolute; width: 8px; height: 10px; background: #fff; border-radius: 50%; top: 10px; left: 9px; box-shadow: 9px 0 0 #fff; }
.pcard .nm { font-weight: 700; font-size: 17px; }
.pcard .meta { color: var(--dim); font-size: 12px; }
.pcard.empty { color: var(--dim); }
.pcard.empty .dot { background: transparent; box-shadow: none; border: 2px dashed var(--dim); animation: pulse 1.4s infinite; }
.pcard.empty .dot::after { display: none; }
@keyframes pulse { 50% { opacity: .35; } }
.lobby .start { width: 100%; margin-top: 16px; padding: 18px; font-size: 18px; }
.hint { color: var(--dim); font-size: 13px; margin-top: 10px; text-align: center; }

.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.gcard { position: relative; text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); cursor: pointer; transition: transform .12s, background .12s, border-color .12s; }
.gcard:hover { transform: translateY(-2px); background: rgba(255, 255, 255, .07); border-color: var(--c); }
.gcard .gname { font-weight: 800; font-size: 19px; letter-spacing: .01em; margin: 8px 0 4px; color: var(--c); }
.gcard .gblurb { color: var(--dim); font-size: 12px; line-height: 1.35; }
.gcard .count { position: absolute; top: 10px; right: 10px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--c); color: #071022; font-weight: 800; font-size: 12px; display: grid; place-items: center; }
.gcard.ro { cursor: default; }
.gcard.ro:hover { transform: none; }
.plist-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 10px; flex-wrap: wrap; }
.plist-head h2 { margin: 0; }
.plist { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; padding: 10px; border-radius: 14px; background: rgba(0, 0, 0, .22); }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, .06); border-left: 3px solid var(--c); font-weight: 600; font-size: 14px; animation: rise .25s both; }
.chip .n { color: var(--dim); font: 700 12px 'JetBrains Mono', monospace; }
.chip button { border: 0; background: rgba(255, 255, 255, .08); border-radius: 6px; width: 22px; height: 22px; cursor: pointer; padding: 0; color: var(--dim); }
.chip button:hover { color: var(--text); background: rgba(255, 255, 255, .18); }
.plist .empty-msg { color: var(--dim); align-self: center; padding: 4px; }

/* ---------- intro card ---------- */
.intro { width: min(640px, 100%); padding: 34px 36px; text-align: center; border-top: 4px solid var(--c); }
.intro .num { color: var(--dim); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 13px; }
.intro .gtitle { font-family: Bungee, sans-serif; font-size: clamp(36px, 7vw, 56px); color: var(--c); margin: 10px 0 8px; text-shadow: 0 0 30px var(--c); line-height: 1; }
.intro .blurb { font-size: 18px; color: #cfd4f5; margin: 14px auto 22px; max-width: 480px; line-height: 1.45; }
.keys { display: flex; flex-wrap: wrap; gap: 10px 22px; justify-content: center; margin-bottom: 26px; }
.keys div { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 14px; }
.readies { display: flex; justify-content: center; gap: 14px; }
.ready { padding: 10px 16px; border-radius: 12px; background: rgba(255, 255, 255, .05); font-weight: 700; min-width: 170px; transition: background .2s; }
.ready.on { background: rgba(124, 255, 107, .14); color: var(--good); }
.press { margin-top: 18px; color: var(--dim); animation: pulse 1.6s infinite; }
.count-big { font-family: Bungee, sans-serif; font-size: 90px; line-height: 1; margin-top: 10px; color: #fff; text-shadow: 0 0 40px var(--c); animation: pop .5s both; }
@keyframes pop { from { transform: scale(1.8); opacity: 0; } }
.mini-score { margin-top: 18px; font-weight: 700; color: var(--dim); }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; padding: 14px 20px; pointer-events: none; z-index: 2; }
.hside { display: flex; align-items: center; gap: 12px; }
.hside.right { justify-content: flex-end; text-align: right; }
.hname { font-weight: 800; font-size: 18px; text-shadow: 0 0 14px currentColor; }
.hname small { display: block; font-size: 10px; letter-spacing: .14em; color: var(--dim); text-shadow: none; font-weight: 700; }
.hscore { font: 700 30px 'JetBrains Mono', monospace; padding: 2px 12px; border-radius: 10px; background: rgba(0, 0, 0, .35); }
.pips { display: flex; gap: 5px; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; opacity: .5; }
.pip.on { background: currentColor; opacity: 1; box-shadow: 0 0 10px currentColor; }
.hmid { text-align: center; padding: 6px 18px; border-radius: 12px; background: rgba(0, 0, 0, .3); }
.hmid .gn { font-family: Bungee, sans-serif; font-size: 18px; }
.hmid .st { color: var(--dim); font-size: 13px; font-weight: 600; min-height: 1em; }
.ping { position: fixed; bottom: 10px; left: 12px; font: 600 11px 'JetBrains Mono', monospace; color: var(--dim); z-index: 6; cursor: pointer; padding: 3px 7px; border-radius: 6px; background: rgba(0, 0, 0, .35); }
.ping:empty { display: none; }
.ping.good { color: var(--good); } .ping.meh { color: var(--gold); } .ping.bad { color: var(--bad); }
.diag { position: fixed; left: 12px; bottom: 40px; z-index: 6; min-width: 230px; padding: 10px 12px; border-radius: 10px; background: rgba(5, 7, 20, .88); border: 1px solid var(--line); font: 500 12px 'JetBrains Mono', monospace; }
.diag div { display: flex; justify-content: space-between; gap: 16px; line-height: 1.6; }
.diag span { color: var(--dim); }
.diag .good { color: var(--good); } .diag .meh { color: var(--gold); } .diag .bad { color: var(--bad); }
.diag .hint { color: var(--dim); font-size: 10px; margin-top: 4px; }

/* ---------- banner ---------- */
#banner { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 4; }
.bn { text-align: center; animation: bn var(--d, 1.2s) cubic-bezier(.2, .9, .3, 1) both; }
.bn .big { font-family: Bungee, sans-serif; font-size: clamp(42px, 9vw, 96px); line-height: 1; color: var(--c, #fff); text-shadow: 0 0 30px var(--c, #fff), 0 6px 0 rgba(0, 0, 0, .4); }
.bn .small { font-weight: 800; font-size: 20px; margin-top: 10px; letter-spacing: .06em; text-shadow: 0 2px 8px #000; }
@keyframes bn { 0% { transform: scale(2.2); opacity: 0; } 14% { transform: scale(1); opacity: 1; } 80% { opacity: 1; transform: scale(1.02); } 100% { opacity: 0; transform: scale(1.08); } }
.bn.hold { animation: bnin .35s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes bnin { from { transform: scale(2); opacity: 0; } }

/* ---------- result / final ---------- */
.result { width: min(520px, 100%); padding: 34px; text-align: center; }
.result .who { font-family: Bungee, sans-serif; font-size: clamp(30px, 6vw, 46px); line-height: 1.05; }
.result .what { color: var(--dim); margin: 8px 0 22px; font-weight: 600; }
.scoreline { display: flex; align-items: center; justify-content: center; gap: 18px; font: 700 64px 'JetBrains Mono', monospace; }
.scoreline .dash { color: var(--dim); font-size: 40px; }
.scoreline .bump { animation: bump .6s .5s cubic-bezier(.2, .9, .3, 1.6) both; display: inline-block; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.6); } }
.final { width: min(620px, 100%); padding: 36px; text-align: center; }
.final .crown { font-size: 54px; filter: drop-shadow(0 0 20px var(--gold)); animation: float 2.4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(4deg); } }
.final table { width: 100%; border-collapse: collapse; margin: 20px 0 24px; font-size: 14px; }
.final td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.final td:last-child { text-align: right; font-weight: 700; }
.final .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.pause { padding: 28px 34px; text-align: center; }
.pause .spin { width: 36px; height: 36px; margin: 0 auto 14px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--p0); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 9; padding: 12px 18px; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--line); font-weight: 600; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(-6px); }
#mute { position: fixed; bottom: 10px; right: 12px; z-index: 5; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); cursor: pointer; color: var(--dim); }
#mute.off { text-decoration: line-through; opacity: .5; }

/* ---------- typing race ---------- */
.typebox { position: fixed; left: 50%; top: 58%; transform: translate(-50%, -50%); width: min(980px, calc(100% - 32px)); padding: 30px 34px; z-index: 1;
  font: 500 clamp(22px, 2.6vw, 34px)/1.6 'JetBrains Mono', monospace; letter-spacing: .01em; word-break: break-word; transition: border-color .15s; }
.typebox.lock { border-color: var(--bad); animation: shake .3s; }
@keyframes shake { 20%, 60% { transform: translate(calc(-50% - 8px), -50%); } 40%, 80% { transform: translate(calc(-50% + 8px), -50%); } }
.typebox span { position: relative; color: #5a6196; transition: color .08s; }
.typebox span.done { color: var(--me); text-shadow: 0 0 12px var(--me); }
.typebox span.cur { color: #fff; }
.typebox span.cur::before { content: ''; position: absolute; left: -1px; top: 12%; bottom: 8%; width: 3px; background: var(--me); border-radius: 2px; animation: blink 1s steps(1) infinite; box-shadow: 0 0 10px var(--me); }
.typebox span.opp::after { content: ''; position: absolute; left: 0; right: 0; bottom: 2px; height: 4px; border-radius: 2px; background: var(--them); box-shadow: 0 0 10px var(--them); }
@keyframes blink { 50% { opacity: 0; } }
.typebox .sp { display: inline-block; }
.typestats { display: flex; justify-content: space-between; margin-top: 16px; font: 600 14px Rubik, sans-serif; color: var(--dim); }

@media (max-width: 860px) {
  .lobby { grid-template-columns: 1fr; }
}

/* Typing Race: a pit-wall timing screen */
.typebox.racing { top: 70%; background: linear-gradient(180deg, rgba(20, 22, 30, .94), rgba(12, 13, 18, .96)); border: 0; border-radius: 14px; padding-top: 38px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 0 0 2px #2a2c36; }
.typebox.racing::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 12px; border-radius: 14px 14px 0 0;
  background: repeating-linear-gradient(135deg, #ffd23f 0 18px, #1a1a1a 18px 36px); }
.typebox.racing span { color: #6a6e80; }
.typebox.racing .typestats { font-family: 'Racing Sans One', Rubik, sans-serif; font-size: 18px; letter-spacing: .03em; }

/* ---------- spectators ---------- */
.hmid .watching { margin-top: 4px; font: 600 12px 'JetBrains Mono', monospace; color: var(--dim); }
.emotebar { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 7; display: flex; gap: 8px; padding: 8px; border-radius: 16px; background: rgba(8, 10, 26, .72); border: 1px solid var(--line); transition: opacity .2s; }
.emotebar button { position: relative; width: 62px; height: 62px; padding: 0; border: 0; border-radius: 12px; background: rgba(255, 255, 255, .06); cursor: pointer; transition: transform .08s, background .15s; }
.emotebar button:hover { background: rgba(255, 255, 255, .14); transform: translateY(-2px); }
.emotebar button:active { transform: scale(.94); }
.emotebar.cool { opacity: .45; pointer-events: none; }
.emotebar .eimg { width: 100%; height: 100%; object-fit: contain; display: grid; place-items: center; font-size: 34px; }
.emotebar .ek { position: absolute; right: 3px; bottom: 1px; font: 700 10px 'JetBrains Mono', monospace; color: var(--dim); }
.emotepop { position: fixed; bottom: 90px; z-index: 8; width: 120px; text-align: center; pointer-events: none; animation: emote-pop 2.6s ease-out forwards; }
.emotepop .eimg { width: 120px; height: auto; display: block; font-size: 72px; line-height: 1.1; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .5)); }
.emotepop .en { font: 700 13px Rubik, sans-serif; color: #fff; text-shadow: 0 2px 6px #000; margin-top: 2px; }
@keyframes emote-pop {
  0% { transform: translateY(30px) scale(.4); opacity: 0; }
  12% { transform: translateY(0) scale(1.12); opacity: 1; }
  20% { transform: translateY(0) scale(1); }
  80% { opacity: 1; }
  100% { transform: translateY(-120px) scale(.95); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .emotepop { animation-duration: 2.6s; animation-timing-function: steps(1); } }
