:root {
  --bg: #0d1121;
  --card: #171d33;
  --card2: #1f2743;
  --line: #2c365a;
  --text: #e8ecff;
  --muted: #8d97c0;
  --accent: #ffb020;
  --accent2: #ff5a3d;
  --good: #5cd65c;
  --bad: #ff4d4d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.error { color: var(--bad); min-height: 1.2em; margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; }
#menu, #lobby { align-items: center; justify-content: center; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse at 50% 120%, #3a1f4d 0%, transparent 60%), radial-gradient(ellipse at 20% -20%, #1b3a6b 0%, transparent 55%), var(--bg); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.menu-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.logo { margin: 0; font-size: 44px; letter-spacing: 2px; font-weight: 900; text-align: center; font-style: italic;
  background: linear-gradient(180deg, #fff 0%, #ffd27a 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo span { background: linear-gradient(180deg, #ffb020, #ff4d2d); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { text-align: center; margin: -6px 0 8px; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
input, select { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.code-input { flex: 1; text-transform: uppercase; letter-spacing: 6px; font-weight: 700; text-align: center; min-width: 0; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.help { color: var(--muted); font-size: 14px; }
.help ul { padding-left: 18px; margin: 8px 0 0; line-height: 1.6; }
.help b { color: var(--text); }

.btn { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; transition: transform .05s, background .15s, border-color .15s; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.btn:hover { border-color: #46528a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #ffb020, #f07b12); border-color: #ffb020; color: #1a1000; }
.btn.big { padding: 13px 18px; font-size: 17px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 4px 0; width: 32px; font-size: 16px; }

/* lobby */
.lobby-card { width: min(900px, 100%); display: flex; flex-direction: column; gap: 16px; }
.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.room-code { font-size: 40px; font-weight: 900; letter-spacing: 8px; color: var(--accent); }
.lobby-actions { display: flex; gap: 8px; }
.lobby-body { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
@media (max-width: 720px) { .lobby-body { grid-template-columns: 1fr; } }
.lobby-body h3 { margin: 0 0 10px; font-size: 16px; }
.lobby-settings { display: flex; flex-direction: column; gap: 10px; }
#teamCols { display: grid; gap: 10px; grid-template-columns: 1fr; margin-bottom: 12px; }
#teamCols.teams { grid-template-columns: 1fr 1fr; }
.team-col { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-height: 60px; }
.team-col h4 { margin: 2px 4px 8px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.team-col.t0 { border-color: #7a2e2e; }
.team-col.t1 { border-color: #2e4a7a; }
.pl { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.pl + .pl { margin-top: 2px; }
.pl.me { background: rgba(255,255,255,.05); }
.pl .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.pl .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #333c63; color: var(--muted); }
.pl.off { opacity: .45; }
.color-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.color-pick button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.color-pick button.sel { border-color: #fff; }
.color-pick button:disabled { opacity: .2; cursor: default; }

.chat-log { overflow-y: auto; font-size: 14px; line-height: 1.4; }
.chat-log .m b { font-weight: 700; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.lobby-chat { display: flex; flex-direction: column; gap: 6px; }
.lobby-chat .chat-log { height: 110px; background: var(--card2); border-radius: 10px; padding: 8px; border: 1px solid var(--line); }

/* game */
#game { flex-direction: column; position: relative; }
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; background: #0a0e1c; border-bottom: 1px solid var(--line); min-height: 48px; }
#scoreboard { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.sb { display: flex; align-items: center; gap: 6px; background: var(--card2); border-radius: 8px; padding: 3px 8px; font-size: 12px; border: 1px solid transparent; }
.sb.cur { border-color: var(--accent); }
.sb.dead { opacity: .35; text-decoration: line-through; }
.sb .dot { width: 10px; height: 10px; border-radius: 50%; }
.sb .hp { width: 42px; height: 5px; background: #333; border-radius: 3px; overflow: hidden; }
.sb .hp i { display: block; height: 100%; background: var(--good); }
#turnBox { text-align: center; min-width: 140px; }
#turnName { font-weight: 800; font-size: 15px; }
#turnTimer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
#turnTimer.low { color: var(--bad); font-weight: 700; }
.top-right { display: flex; gap: 6px; flex: 1; justify-content: flex-end; }

#stage { position: relative; flex: 1; min-height: 0; background: #05070f; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#toast { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(10,14,28,.85); padding: 8px 16px; border-radius: 10px; font-weight: 700; pointer-events: none; opacity: 0; transition: opacity .3s; white-space: nowrap; }
#toast.show { opacity: 1; }
#gameChat { position: absolute; left: 10px; bottom: 10px; width: min(340px, 60%); display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#gameChatLog { max-height: 140px; text-shadow: 0 1px 3px #000, 0 0 2px #000; }
#gameChatLog .m { transition: opacity 1s; }
#gameChatLog .m.fade { opacity: 0; }
#gameChatInput { pointer-events: auto; background: rgba(10,14,28,.6); padding: 6px 10px; font-size: 13px; opacity: .5; }
#gameChatInput:focus { opacity: 1; }

#hud { display: flex; align-items: center; gap: 12px; padding: 8px 10px; background: #0a0e1c; border-top: 1px solid var(--line); flex-wrap: wrap; }
#hud.disabled #controls, #hud.disabled #fireBtn, #hud.disabled #weapons { opacity: .5; pointer-events: none; }
#weapons { display: flex; gap: 4px; flex-wrap: wrap; flex: 1 1 360px; }
.wp { position: relative; background: var(--card2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 5px; }
.wp .sw { width: 9px; height: 9px; border-radius: 50%; }
.wp .am { color: var(--muted); font-variant-numeric: tabular-nums; }
.wp.sel { border-color: var(--accent); background: #3a2e14; }
.wp.empty { opacity: .35; }
.wp.ability { border-style: dashed; }
.wp.tier-rare { border-color: #4a6aa8; background: #1c2848; }
.wp.tier-epic { border-color: #b8901c; background: #3a2e0a; box-shadow: 0 0 8px rgba(255,210,77,.35); }
.wp.sel { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -1px; }
#controls { display: flex; flex-direction: column; gap: 4px; flex: 1 1 320px; }
.ctrl { display: flex; align-items: center; gap: 6px; }
.ctrl .lbl { width: 56px; font-size: 12px; color: var(--muted); }
.ctrl input[type=range] { flex: 1; padding: 0; accent-color: var(--accent); min-width: 60px; }
.ctrl .val { width: 42px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.fuel { flex: 1; height: 10px; background: #2a2f45; border-radius: 5px; overflow: hidden; }
#fuelBar { height: 100%; width: 100%; background: linear-gradient(90deg, #ffb020, #ffd86b); }
.btn.fire { background: linear-gradient(180deg, #ff5a3d, #c8261a); border-color: #ff7a5d; font-size: 20px; font-weight: 900; padding: 14px 26px; letter-spacing: 1px; }

#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5,7,15,.6); z-index: 5; padding: 16px; }
.over-card { width: min(480px, 100%); text-align: center; }
.over-card h2 { margin: 0 0 16px; font-size: 30px; color: var(--accent); }
#statsTable { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
#statsTable th, #statsTable td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; }
#statsTable th { color: var(--muted); font-weight: 600; font-size: 13px; }

@media (max-width: 700px) {
  #turnBox { min-width: 100px; }
  .btn.fire { flex: 1; }
  #gameChat { display: none; }
}
