:root {
  --gold: #f0c060; --gold2: #a07830; --gold3: #3a2800;
  --bg: #07070f; --bg2: #0e0e1c; --bg3: #13131f; --bg4: #181828;
  --border: #1e1e30; --text: #d8d0c8; --muted: #554433;
  --red: #e74c3c; --blue: #2980b9; --green: #27ae60; --orange: #e67e22;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: Georgia, serif; min-height: 100vh; }
.hidden { display: none !important; }

/* ── Topbar ── */
#topbar {
  background: #04040c; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; height: 52px;
  gap: 8px; flex-shrink: 0; position: sticky; top: 0; z-index: 50;
}
.logo { font-size: 20px; font-weight: 900; color: var(--gold); letter-spacing: 3px; text-shadow: 0 0 20px #a0781030; flex: 1; }
.topbar-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 6px 14px; border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 12px; transition: all 0.15s; white-space: nowrap; }
.topbar-btn:hover, .topbar-btn.active { border-color: var(--gold2); color: var(--gold); }
.topbar-user { color: var(--gold); font-size: 13px; white-space: nowrap; }

/* ── Screens ── */
.screen { display: none; min-height: calc(100vh - 52px); }
.screen.active { display: block; }
#screen-main.active { display: flex; }
#screen-game.active { display: flex; height: calc(100vh - 52px); overflow: hidden; }
/* ── Cards ── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.section-label { font-size: 10px; letter-spacing: 4px; color: var(--muted); margin-bottom: 14px; }

/* ── Buttons ── */
.btn { cursor: pointer; border: none; font-family: inherit; transition: all 0.15s; border-radius: 9px; font-size: 13px; }
.btn-gold { background: linear-gradient(135deg, #2a1e00, #1a1200); border: 1.5px solid #f0c06066; color: var(--gold); padding: 12px 24px; letter-spacing: 2px; }
.btn-gold:hover:not(:disabled) { border-color: var(--gold); box-shadow: 0 0 16px #f0c06020; }
.btn-outline { background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 10px 20px; }
.btn-outline:hover { border-color: var(--gold2); color: var(--gold); }
.btn-danger { background: #1a0404; border: 1px solid #e74c3c44; color: var(--red); padding: 10px 20px; }
.btn-danger:hover { border-color: var(--red); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 16px; font-size: 12px; }

/* ── Inputs ── */
.input { background: #08081a; border: 1px solid var(--border); color: var(--text); padding: 10px 14px; border-radius: 8px; font-family: inherit; font-size: 14px; outline: none; width: 100%; transition: border-color 0.15s; }
.input:focus { border-color: var(--gold2); }
.form-group { margin-bottom: 14px; }
.form-label { font-size: 10px; letter-spacing: 3px; color: var(--muted); display: block; margin-bottom: 6px; }
.error-msg { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 18px; }
.success-msg { color: var(--green); font-size: 12px; margin-top: 8px; min-height: 18px; }

/* ── Auth ── */
#screen-auth { display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 380px; }
.auth-title { text-align: center; margin-bottom: 32px; }
.auth-title h1 { font-size: 46px; font-weight: 900; color: var(--gold); text-shadow: 0 0 40px #a0781040; letter-spacing: 4px; }
.auth-title p { font-size: 11px; color: var(--muted); letter-spacing: 3px; margin-top: 8px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tab { flex: 1; padding: 10px; background: var(--bg3); border: 1px solid var(--border); color: var(--muted); cursor: pointer; border-radius: 8px; font-family: inherit; font-size: 12px; letter-spacing: 1px; transition: all 0.15s; }
.auth-tab.active { background: var(--gold3); border-color: var(--gold2); color: var(--gold); }

/* ── Lobby ── */
#screen-lobby { padding: 20px; overflow-y: auto; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 900px; margin: 0 auto; }
@media(max-width:640px) { .lobby-grid { grid-template-columns: 1fr; } }
.player-count-btns { display: flex; gap: 8px; }
.pcount-btn { flex: 1; padding: 10px; background: var(--bg3); border: 1.5px solid var(--border); color: var(--muted); cursor: pointer; border-radius: 8px; font-family: inherit; font-size: 20px; font-weight: 900; transition: all 0.15s; }
.pcount-btn.active { background: var(--gold3); border-color: var(--gold2); color: var(--gold); }
.room-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; cursor: pointer; transition: all 0.15s; }
.room-item:hover { border-color: var(--gold2); }
.room-code-tag { font-size: 13px; color: var(--gold); letter-spacing: 2px; font-weight: 700; }
.room-host { flex: 1; font-size: 13px; }
.room-count { font-size: 12px; color: var(--muted); }
.no-rooms { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; }

/* ── Room waiting ── */
#screen-room { display: flex; align-items: center; justify-content: center; padding: 20px; }
.room-wrap { width: 100%; max-width: 480px; }
.big-code { font-size: 54px; font-weight: 900; color: var(--gold); letter-spacing: 10px; text-shadow: 0 0 24px #f0c06040; text-align: center; }
.player-slot { display: flex; align-items: center; gap: 12px; padding: 11px 16px; background: var(--bg3); border-radius: 9px; border: 1px solid var(--border); margin-bottom: 8px; transition: all 0.25s; }
.player-slot.me { border-color: #4af4; background: #0a1020; }
.pdot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.host-badge { font-size: 10px; color: var(--gold); letter-spacing: 1px; }
.waiting-msg { text-align: center; color: var(--muted); font-size: 13px; padding: 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; }

/* ── Avatar picker ── */
.avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.av-btn { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--border); background: var(--bg3); font-size: 22px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.av-btn.selected { border-color: var(--gold); box-shadow: 0 0 10px #f0c06040; }
.av-btn:hover { border-color: var(--gold2); }

/* ── Game ── */
#map-area { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px; overflow: hidden; }
#map-svg { width: 100%; max-width: 580px; height: auto; display: block; }
#side-panel { width: 185px; flex-shrink: 0; background: #06060e; border-left: 1px solid var(--border); padding: 14px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
@media(max-width:600px) { #screen-game.active { flex-direction: column; } #side-panel { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 8px; border-left: none; border-top: 1px solid var(--border); padding: 10px; max-height: 160px; } }
.score-card { padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg3); transition: all 0.3s; }
.score-card.active { border-color: #88f8; background: #0a1020; box-shadow: 0 0 12px #4af2; }
.score-bar { height: 3px; background: var(--border); border-radius: 2px; margin: 5px 0 4px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 2px; transition: width 0.5s ease; }
.score-num { text-align: right; font-weight: 700; font-size: 20px; line-height: 1; }

/* ── Territory bar ── */
#territory-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: auto; }
.tbar-seg { height: 100%; transition: width 0.5s ease; }

/* ── Question modal ── */
#qmodal { position: fixed; inset: 0; background: rgba(0,0,8,.9); display: none; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
#qmodal.open { display: flex; }
.qbox { width: 100%; max-width: 520px; background: var(--bg2); border: 2px solid var(--border); border-radius: 16px; padding: 26px; animation: popIn .25s cubic-bezier(.34,1.56,.64,1); }
.q-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.q-cat { font-size: 10px; letter-spacing: 2px; padding: 3px 10px; border-radius: 20px; background: var(--bg3); border: 1px solid var(--border); }
.q-timer { font-size: 30px; font-weight: 900; transition: color .3s; }
.q-progress { height: 4px; background: var(--border); border-radius: 2px; margin-bottom: 20px; overflow: hidden; }
.q-progress-fill { height: 100%; border-radius: 2px; transition: width .95s linear, background .3s; }
.q-text { font-size: 17px; line-height: 1.65; text-align: center; color: #e8e0d0; margin-bottom: 22px; min-height: 52px; display: flex; align-items: center; justify-content: center; }
.q-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.q-ans { background: #0e0e20; border: 1.5px solid #242438; color: #b0a898; padding: 13px 11px; border-radius: 9px; font-size: 13px; text-align: left; cursor: pointer; font-family: inherit; transition: all .15s; line-height: 1.4; }
.q-ans:hover:not(:disabled) { filter: brightness(1.3); }
.q-ans:disabled { cursor: default; }
.q-ans.selected { background: #1a1800; border-color: var(--gold); color: var(--gold); }
.q-ans.correct { background: #0a2018; border-color: var(--green); color: var(--green); }
.q-ans.wrong { background: #200a0a; border-color: var(--red); color: var(--red); }
.q-letter { color: var(--muted); margin-right: 7px; font-size: 11px; font-weight: 700; }
.q-result { margin-top: 16px; text-align: center; font-size: 15px; font-weight: 700; letter-spacing: 2px; }
.q-result.ok { color: var(--green); }
.q-result.fail { color: var(--red); }
.q-spectate { text-align: center; color: var(--muted); font-size: 12px; margin-top: 12px; }

/* ── End modal ── */
#endmodal { position: fixed; inset: 0; background: rgba(0,0,8,.92); display: none; align-items: center; justify-content: center; z-index: 300; padding: 16px; }
#endmodal.open { display: flex; }
.end-box { width: 100%; max-width: 400px; text-align: center; }
.end-winner { font-size: 38px; font-weight: 900; color: var(--gold); text-shadow: 0 0 30px #a0781050; }
.end-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-radius: 10px; margin-bottom: 8px; background: var(--bg3); border: 1px solid var(--border); }
.end-row.gold { background: #1a1500; border-color: #f0c06055; }
.end-medal { font-size: 22px; min-width: 28px; }
.end-pname { flex: 1; text-align: left; font-size: 14px; }
.end-score { font-size: 20px; font-weight: 700; color: var(--gold); }

/* ── Leaderboard ── */
#screen-leaderboard { padding: 20px; overflow-y: auto; }
.lb-wrap { max-width: 720px; margin: 0 auto; }
.lb-row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.lb-row.me { border-color: var(--gold2); background: var(--gold3); }
.lb-rank { font-size: 17px; font-weight: 700; color: var(--muted); min-width: 28px; text-align: right; }
.lb-name { flex: 1; font-size: 14px; }
.lb-score { font-size: 15px; font-weight: 700; color: var(--gold); }
.lb-sub { font-size: 11px; color: var(--muted); }

/* ── Profile ── */
#screen-profile { padding: 20px; overflow-y: auto; }
.profile-wrap { max-width: 640px; margin: 0 auto; }
.profile-header { display: flex; align-items: center; gap: 20px; margin-bottom: 24px; }
.profile-avatar-big { font-size: 56px; }
.profile-username { font-size: 32px; font-weight: 900; color: var(--gold); }
.profile-since { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
@media(max-width:480px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-box { background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: center; }
.stat-num { font-size: 28px; font-weight: 900; color: var(--gold); }
.stat-label { font-size: 10px; color: var(--muted); letter-spacing: 2px; margin-top: 4px; }
.profile-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.profile-tab { flex: 1; padding: 9px; background: var(--bg3); border: 1px solid var(--border); color: var(--muted); cursor: pointer; border-radius: 8px; font-family: inherit; font-size: 12px; letter-spacing: 1px; transition: all .15s; }
.profile-tab.active { background: var(--gold3); border-color: var(--gold2); color: var(--gold); }
.history-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.history-winner { color: var(--gold); font-weight: 700; }
.history-date { font-size: 11px; color: var(--muted); margin-left: auto; }

/* ── Misc ── */
@keyframes popIn { from { transform: scale(.85) translateY(20px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
@keyframes shimmer { 0%{opacity:.5} 50%{opacity:1} 100%{opacity:.5} }
.pulse { animation: pulse 1.2s infinite; }
.flex-row { display: flex; gap: 10px; }
.flex-row > * { flex: 1; }
.mt8{margin-top:8px} .mt16{margin-top:16px} .mt24{margin-top:24px}
.gap8{gap:8px} .text-center{text-align:center} .text-muted{color:var(--muted)} .text-gold{color:var(--gold)}
