:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1f232c;
  --line: rgba(255,255,255,0.08);
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --red: #ef4444;
  --blue: #3b82f6;
  --gold: #fbbf24;
  --green: #4ade80;
  --font: "Hanken Grotesk", system-ui, -apple-system, Segoe UI, sans-serif;
  --mono: "Rubik Mono One", Impact, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; -webkit-text-size-adjust: 100%; }
button, input { font: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px; background: var(--panel2); color: var(--text); font-weight: 700; transition: transform .08s, background .15s, opacity .15s; -webkit-tap-highlight-color: transparent; }
button:active { transform: translateY(1px) scale(.98); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: linear-gradient(180deg, #fde68a, #f59e0b); color: #1a1200; box-shadow: 0 6px 20px rgba(245,158,11,.25); }
button.primary:hover { filter: brightness(1.05); }
button.big { padding: 14px 28px; font-size: 18px; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
button.ghost:hover { color: var(--text); border-color: rgba(255,255,255,.25); }
button.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: rgba(23,26,33,.85); border: 1px solid var(--line); }
input { background: #0b0d11; border: 1px solid rgba(255,255,255,.12); border-radius: 10px; color: var(--text); padding: 11px 14px; width: 100%; outline: none; }
input:focus { border-color: var(--gold); }
.hidden { display: none !important; }
kbd { font-family: var(--font); font-size: 11px; background: rgba(255,255,255,.12); border-radius: 5px; padding: 1px 6px; margin-left: 6px; }

.screen { position: fixed; inset: 0; }
.bgfx { position: absolute; inset: 0; background:
  radial-gradient(1200px 600px at 10% 0%, rgba(239,68,68,.16), transparent 60%),
  radial-gradient(1200px 600px at 90% 100%, rgba(59,130,246,.18), transparent 60%),
  repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 40px),
  repeating-linear-gradient(90deg, rgba(255,255,255,.025) 0 1px, transparent 1px 40px);
}
.menu-wrap { position: relative; height: 100%; overflow: auto; padding: 24px 16px calc(24px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.brand { text-align: center; margin-top: 8px; }
.kicker { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.brand h1 { font-family: var(--mono); font-size: clamp(30px, 6vw, 56px); line-height: .95; margin: 8px 0 10px; letter-spacing: .01em; }
.brand h1 span { color: var(--gold); }
.brand .sub { color: var(--muted); margin: 0; }
.red { color: var(--red); } .blue { color: var(--blue); }
.card { width: min(880px, 100%); background: rgba(23,26,33,.92); border: 1px solid var(--line); border-radius: 18px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.5); backdrop-filter: blur(6px); }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.center { justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 700px) { .split { grid-template-columns: 1fr; } }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.status { color: var(--muted); font-size: 14px; min-height: 18px; margin-top: 8px; }
.status.err { color: #fca5a5; }
.foot { color: var(--muted); font-size: 12px; opacity: .7; text-align: center; }

.chars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
@media (max-width: 700px) { .chars { grid-template-columns: repeat(4, 1fr); } }
.char { background: #0b0d11; border: 2px solid transparent; border-radius: 12px; padding: 6px 4px 4px; text-align: center; cursor: pointer; transition: border-color .15s, transform .1s; }
.char:hover { transform: translateY(-2px); }
.char.sel { border-color: var(--gold); background: #1b1706; }
.char canvas { width: 100%; height: auto; display: block; image-rendering: auto; }
.char .nm { font-weight: 800; font-size: 13px; margin-top: 4px; }
.char .rl { font-size: 11px; color: var(--muted); }

.rooms { display: flex; flex-direction: column; gap: 8px; max-height: 210px; overflow: auto; margin-bottom: 10px; }
.rooms .empty { color: var(--muted); font-size: 14px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; }
.room { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #0b0d11; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.room .rn { font-weight: 800; }
.room .rm { font-size: 12px; color: var(--muted); }
.room button { padding: 8px 14px; }

.room-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.room-head h2 { margin: 4px 0 0; font-family: var(--mono); font-size: 26px; }
.code-box { text-align: center; font-size: 12px; color: var(--muted); background: #0b0d11; border-radius: 12px; padding: 8px 16px; border: 1px solid var(--line); }
.code-box b { font-family: var(--mono); font-size: 26px; color: var(--gold); letter-spacing: .1em; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .teams { grid-template-columns: 1fr; } }
.team { border-radius: 14px; padding: 14px; background: #0b0d11; border: 1px solid var(--line); min-height: 170px; display: flex; flex-direction: column; }
.team h3 { margin: 0 0 10px; font-family: var(--mono); font-size: 16px; }
.team.t0 h3 { color: var(--red); } .team.t1 h3 { color: var(--blue); }
.team ul { list-style: none; margin: 0 0 12px; padding: 0; flex: 1; }
.team li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.team li canvas { width: 28px; height: 40px; }
.team li .who { font-weight: 700; }
.team li .tag { font-size: 11px; color: var(--muted); margin-left: auto; }
.team li.off { opacity: .45; }
.howto { margin-top: 14px; color: var(--muted); font-size: 14px; }
.howto summary { cursor: pointer; font-weight: 700; color: var(--text); }
.howto ul { padding-left: 18px; line-height: 1.5; }

/* ---------- game ---------- */
#game { position: absolute; inset: 0; display: block; touch-action: none; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud-top { position: absolute; top: calc(8px + var(--safe-t)); left: 10px; right: 10px; display: flex; align-items: flex-start; gap: 12px; pointer-events: none; }
#hud-top > * { pointer-events: auto; }
.money-box { background: rgba(15,17,21,.85); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; min-width: 150px; }
.money { font-family: var(--mono); font-size: 22px; color: var(--gold); }
.income { font-size: 12px; color: var(--muted); }
.bases { flex: 1; display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; }
.base { flex: 1; }
.base .lbl { font-family: var(--mono); font-size: 11px; letter-spacing: .05em; margin-bottom: 4px; text-shadow: 0 1px 3px #000; }
.base.t0 .lbl { color: var(--red); } .base.t1 .lbl { color: var(--blue); text-align: right; }
.bar { height: 12px; background: rgba(0,0,0,.6); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; width: 100%; background: var(--red); transition: width .3s; }
.base.t1 .bar .fill { background: var(--blue); margin-left: auto; }
.clock { font-family: var(--mono); font-size: 18px; background: rgba(15,17,21,.85); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.top-right { display: flex; gap: 6px; }

#hero-status { position: absolute; left: 10px; top: calc(78px + var(--safe-t)); width: 190px; }
#hero-status .hp { position: relative; height: 16px; background: rgba(0,0,0,.6); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#hero-status .hp .fill { height: 100%; background: var(--green); transition: width .2s; }
#hero-status .hp span { position: absolute; inset: 0; font-size: 11px; font-weight: 800; text-align: center; line-height: 16px; text-shadow: 0 1px 2px #000; }
.buffs { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.buff { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.12); }

#hud-bottom { position: absolute; left: 10px; bottom: calc(10px + var(--safe-b)); display: flex; align-items: flex-end; gap: 10px; }
.build-bar { display: flex; gap: 8px; }
.bbtn { width: 118px; background: rgba(15,17,21,.9); border: 2px solid var(--line); border-radius: 12px; padding: 8px 8px 6px; text-align: left; position: relative; }
.bbtn .nm { font-weight: 800; font-size: 14px; display: flex; justify-content: space-between; }
.bbtn .nm kbd { margin: 0; }
.bbtn .cost { color: var(--gold); font-family: var(--mono); font-size: 13px; margin-top: 2px; }
.bbtn .ds { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.2; }
.bbtn.sel { border-color: var(--gold); background: #1b1706; }
.bbtn.poor .cost { color: #fca5a5; }
.hud-btn { background: rgba(15,17,21,.9); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.hud-btn.on { border-color: var(--gold); }

#btn-special { position: absolute; right: 16px; bottom: calc(150px + var(--safe-b)); width: 92px; height: 92px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #93c5fd, #1d4ed8 60%, #0b1f5e); border: 3px solid rgba(255,255,255,.35); color: #fff; font-family: var(--mono); font-size: 11px; display: none; align-items: center; justify-content: center; box-shadow: 0 0 30px rgba(59,130,246,.5); }
#btn-special .ring { position: absolute; inset: -3px; border-radius: 50%; background: conic-gradient(rgba(0,0,0,.65) var(--cd, 0%), transparent 0); pointer-events: none; }
#btn-special .txt { position: relative; }
#btn-special.ready { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 20px rgba(59,130,246,.5); } 50% { box-shadow: 0 0 40px rgba(147,197,253,.9); } }
body.touch #btn-special { display: flex; }
body.touch .bbtn .ds { display: none; }
body.touch kbd { display: none; }

#minimap { position: absolute; right: 10px; bottom: calc(10px + var(--safe-b)); width: 220px; height: 124px; border: 1px solid var(--line); border-radius: 8px; background: rgba(0,0,0,.6); }

#toasts { position: absolute; right: 12px; top: calc(70px + var(--safe-t)); width: 300px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: rgba(15,17,21,.88); border-left: 3px solid var(--muted); border-radius: 8px; padding: 7px 10px; font-size: 13px; animation: toast-in .25s ease-out; transition: opacity .5s; }
.toast.t0 { border-left-color: var(--red); } .toast.t1 { border-left-color: var(--blue); }
.toast.error { border-left-color: #fca5a5; color: #fca5a5; }
.toast.quiz { border-left-color: var(--gold); }
.toast.kill { border-left-color: #fb923c; }
.toast.fade { opacity: 0; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } }
body.touch #toasts { width: 220px; font-size: 12px; }

#notice { position: absolute; top: 30%; left: 50%; transform: translateX(-50%); background: rgba(15,17,21,.9); border: 1px solid var(--line); border-radius: 14px; padding: 12px 20px; font-weight: 700; font-size: 16px; text-align: center; max-width: 90vw; }

.panel { position: absolute; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); width: min(560px, 94vw); background: rgba(15,17,21,.96); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.6); max-height: 70vh; overflow: auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h3 { margin: 0; font-family: var(--mono); font-size: 16px; }
.upg { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; background: #0b0d11; margin-bottom: 8px; border: 1px solid var(--line); }
.upg .info { flex: 1; }
.upg .nm { font-weight: 800; }
.upg .ds { font-size: 12px; color: var(--muted); }
.upg .lvl { display: flex; gap: 3px; margin-top: 4px; }
.upg .lvl i { width: 14px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.12); }
.upg .lvl i.on { background: var(--gold); }
.upg button { min-width: 100px; font-family: var(--mono); font-size: 12px; }
.helplist { margin: 0; padding-left: 18px; line-height: 1.6; color: var(--muted); font-size: 14px; }
.helplist b { color: var(--text); }

.modal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); padding: 16px; }
.quiz-card { width: min(640px, 100%); background: #171a21; border: 2px solid var(--gold); border-radius: 18px; padding: 18px 20px; box-shadow: 0 0 60px rgba(251,191,36,.25); }
.quiz-head { display: flex; justify-content: space-between; align-items: center; }
#quiz-timer { font-family: var(--mono); font-size: 26px; color: var(--gold); }
#quiz-timer.hot { color: #f87171; }
.quiz-bar { height: 6px; background: rgba(255,255,255,.1); border-radius: 3px; margin: 8px 0 12px; overflow: hidden; }
#quiz-bar-fill { height: 100%; width: 100%; background: var(--gold); }
.quiz-card h3 { margin: 0 0 14px; font-size: clamp(17px, 2.6vw, 22px); line-height: 1.3; }
.alts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .alts { grid-template-columns: 1fr; } }
.alt { text-align: left; padding: 14px 14px; background: #0b0d11; border: 2px solid var(--line); border-radius: 12px; font-weight: 700; font-size: 15px; display: flex; gap: 10px; align-items: center; }
.alt b { font-family: var(--mono); color: var(--gold); font-size: 12px; }
.alt:hover { border-color: rgba(255,255,255,.3); }
.alt.ok { border-color: var(--green); background: #0d2016; }
.alt.bad { border-color: #f87171; background: #2a0f0f; }
.alt:disabled { opacity: .8; }
.quiz-res { min-height: 22px; font-weight: 800; margin-top: 10px; text-align: center; font-size: 17px; }
.quiz-res.ok { color: var(--green); } .quiz-res.bad { color: #fca5a5; }
.quiz-card .hint { text-align: center; }

#countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: clamp(60px, 18vw, 160px); color: var(--gold); text-shadow: 0 10px 40px rgba(0,0,0,.8); pointer-events: none; }
#respawn { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); text-align: center; font-family: var(--mono); font-size: 22px; color: #fca5a5; text-shadow: 0 4px 20px #000; pointer-events: none; }
#respawn small { display: block; font-family: var(--font); color: var(--muted); font-size: 14px; margin-top: 6px; }

.end-card { width: min(620px, 100%); background: #171a21; border: 1px solid var(--line); border-radius: 18px; padding: 22px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.end-card h2 { font-family: var(--mono); font-size: clamp(22px, 5vw, 36px); margin: 6px 0 14px; }
.end-card h2.t0 { color: var(--red); } .end-card h2.t1 { color: var(--blue); }
#end-stats { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
#end-stats th { color: var(--muted); font-weight: 700; text-align: right; padding: 6px 6px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
#end-stats td { text-align: right; padding: 6px 6px; border-bottom: 1px solid var(--line); }
#end-stats th:first-child, #end-stats td:first-child { text-align: left; }
#end-stats tr.me td { color: var(--gold); }
#end-stats .t0 { color: var(--red); } #end-stats .t1 { color: var(--blue); }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.15); border-top-color: var(--gold); border-radius: 50%; margin: 0 auto 14px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- compact layout: phones & small landscape screens ---------- */
.hud-btn { white-space: nowrap; }
@media (max-width: 760px), (max-height: 520px) {
  #hud-top { gap: 6px; left: 6px; right: 6px; top: calc(6px + var(--safe-t)); }
  .money-box { min-width: 0; padding: 5px 9px; border-radius: 10px; }
  .money { font-size: 15px; }
  .income { display: none; }
  .bases { gap: 6px; }
  .base .lbl { font-size: 8px; margin-bottom: 2px; }
  .bar { height: 8px; }
  .clock { font-size: 12px; padding: 3px 6px; }
  .top-right { gap: 4px; }
  .top-right button.icon { width: 30px; height: 30px; font-size: 13px; }
  #hero-status { width: 120px; top: calc(48px + var(--safe-t)); left: 6px; }
  #hero-status .hp { height: 12px; }
  #hero-status .hp span { font-size: 9px; line-height: 12px; }
  .buff { font-size: 9px; padding: 1px 6px; }
  #hud-bottom { left: 50%; transform: translateX(-50%); bottom: calc(6px + var(--safe-b)); gap: 6px; }
  .build-bar { gap: 6px; }
  .bbtn { width: 82px; padding: 6px 7px 5px; border-radius: 10px; }
  .bbtn .nm { font-size: 12px; }
  .bbtn .cost { font-size: 11px; }
  .bbtn .ds { display: none; }
  .hud-btn { padding: 8px 9px; font-size: 11px; border-radius: 10px; }
  #minimap { width: 120px; height: 68px; right: 6px; bottom: calc(70px + var(--safe-b)); }
  #btn-special { width: 72px; height: 72px; right: 30px; bottom: calc(150px + var(--safe-b)); font-size: 9px; }
  #toasts { width: 190px; top: calc(48px + var(--safe-t)); right: 6px; gap: 4px; }
  .toast { padding: 4px 8px; font-size: 11px; }
  #notice { top: 22%; font-size: 13px; padding: 8px 12px; }
  .panel { bottom: calc(76px + var(--safe-b)); padding: 10px; max-height: 60vh; }
  .upg { padding: 7px; gap: 8px; }
  .upg .ds { display: none; }
  .upg button { min-width: 78px; padding: 8px; }
  #respawn { font-size: 16px; }
  .quiz-card { padding: 12px 14px; }
  .quiz-card h3 { font-size: 16px; margin-bottom: 10px; }
  .alt { padding: 10px 12px; font-size: 14px; }
  .quiz-card .hint { display: none; }
  #countdown { font-size: 90px; }
}
body.touch #hud-bottom { left: 50%; transform: translateX(-50%); }
body.touch .bbtn { width: 82px; }
body.touch #minimap { width: 120px; height: 68px; bottom: calc(70px + var(--safe-b)); }
body.touch #btn-special { bottom: calc(150px + var(--safe-b)); }
