:root {
  --bg: #0d0a1a;
  --panel: #171329;
  --panel-2: #211b3a;
  --line: #342b57;
  --text: #ece6ff;
  --muted: #9a90c0;
  --hot: #ff6b4a;
  --cool: #4ad8ff;
  --gold: #ffc857;
  --radius: 10px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: radial-gradient(ellipse at top, #2a1840, var(--bg) 70%); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- buttons ---------- */
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; cursor: pointer; transition: transform .05s, background .15s; }
.btn:hover:not(:disabled) { background: #2c2450; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #ff7d55, #e0452a); border-color: #ff9a7a; color: #1a0b06; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ff9068, #ef5537); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.fire { background: linear-gradient(180deg, var(--gold), #f08a24); color: #241200; font-weight: 800; letter-spacing: 2px; padding: 12px 26px; border-color: #ffe0a0; }

/* ---------- title ---------- */
#screen-title { align-items: center; justify-content: center; padding: 24px; }
.title-card { width: min(720px, 100%); text-align: center; }
.logo { font-size: clamp(42px, 9vw, 84px); margin: 0; letter-spacing: 4px; line-height: 1; color: var(--hot); text-shadow: 0 0 24px rgba(255,107,74,.45); }
.logo span { color: var(--gold); }
.site { margin-top: 28px; font-size: 13px; }
.site a { color: var(--muted); text-decoration: none; }
.site a:hover { color: var(--gold); }
.tagline { color: var(--muted); margin: 10px 0 28px; }
.field { display: inline-flex; flex-direction: column; gap: 6px; text-align: left; margin-bottom: 24px; }
.field span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.field input, .chat-form input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; outline: none; }
.field input:focus, .chat-form input:focus { border-color: var(--gold); }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mode { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.mode h2 { margin: 0; }
.mode p { margin: 0; color: var(--muted); font-size: 14px; min-height: 2.6em; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--gold); }
.help { margin-top: 20px; text-align: left; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; text-align: center; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; color: var(--text); }
@media (max-width: 640px) { .mode-grid { grid-template-columns: 1fr; } }

/* ---------- lobby ---------- */
.bar { display: flex; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.bar h2 { margin: 0; flex: 1; }
.who { color: var(--muted); }
.lobby-grid { flex: 1; display: grid; grid-template-columns: 1fr 1.6fr .8fr; gap: 16px; padding: 16px 20px; min-height: 0; height: calc(100vh - 70px); }
@media (max-width: 900px) { .lobby-grid { grid-template-columns: 1fr; height: auto; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h3 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; }
.list { list-style: none; padding: 0; margin: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.list li { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list .sub { font-size: 12px; color: var(--muted); }
.list .empty { background: transparent; color: var(--muted); justify-content: center; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #2e2852; color: var(--muted); }
.badge.waiting { background: #3b3214; color: var(--gold); }
.badge.playing { background: #3d1a14; color: var(--hot); }
.my-game { display: flex; align-items: center; gap: 10px; background: #2a2412; border: 1px solid #5c4b1c; padding: 10px; border-radius: 8px; margin-bottom: 10px; color: var(--gold); font-size: 14px; }
.my-game .btn { margin-left: auto; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .2; } }
.conn { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #3d1a14; border: 1px solid var(--hot); padding: 8px 14px; border-radius: 8px; }

/* ---------- chat ---------- */
.chat-panel { min-height: 300px; }
.chat-log { list-style: none; margin: 0; padding: 0 4px 0 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; font-size: 14px; word-wrap: break-word; }
.chat-log .from { color: var(--gold); margin-right: 6px; }
.chat-log .me .from { color: var(--cool); }
.chat-log .sys { color: var(--muted); font-style: italic; font-size: 13px; }
.chat-log time { color: #5f578a; font-size: 11px; margin-right: 6px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; min-width: 0; }

/* ---------- game ---------- */
#screen-game { padding: 16px; }
.game-wrap { display: flex; gap: 16px; justify-content: center; align-items: stretch; flex: 1; }
.game-main { flex: 0 1 1000px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.canvas-box { position: relative; width: 100%; aspect-ratio: 1000 / 600; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#game-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.controls { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.controls.locked .ctl, .controls.locked .fire { opacity: .45; pointer-events: none; }
.ctl { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); flex: 1; min-width: 140px; }
.ctl b { color: var(--text); }
input[type=range] { accent-color: var(--gold); width: 100%; }
.game-chat { width: 280px; flex: 0 0 280px; }
@media (max-width: 1200px) { .game-wrap { flex-direction: column; } .game-chat { width: auto; flex: none; height: 260px; } }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8, 5, 18, .6); backdrop-filter: blur(2px); }
.overlay-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 36px; text-align: center; }
.overlay-card h2 { margin: 0 0 8px; font-size: 32px; color: var(--gold); }
.overlay-card p { color: var(--muted); margin: 0 0 20px; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; }
