:root {
  --bg: #0f1320;
  --bg2: #171c2e;
  --panel: #1e2538;
  --panel2: #262e44;
  --line: #2f3a55;
  --text: #e7ecf5;
  --muted: #93a0bd;
  --primary: #4f86f7;
  --primary-d: #3a6fd6;
  --warn: #e8a13a;
  --danger: #e6194b;
  --good: #2ecc71;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 800px at 70% -10%, #1c2236, var(--bg));
  color: var(--text);
  overflow: hidden;
}

.screen { display: none; height: 100vh; }
.screen.active { display: block; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s, transform .05s;
}
.btn:hover { background: #303a55; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary-d); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.warn { background: var(--warn); border-color: #c98a2c; color: #1a1208; }
.btn.ghost { background: transparent; }
.btn.big { padding: 12px 18px; font-size: 16px; width: 100%; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.error { color: var(--danger); min-height: 18px; font-size: 13px; margin-top: 6px; }
.muted { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; min-height: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

/* ---- AUTH ---- */
#auth-screen { display: none; place-items: center; }
#auth-screen.active { display: grid; }
.auth-card {
  width: 360px; max-width: 92vw;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.logo { font-size: 34px; margin: 0; }
.logo span { color: var(--primary); }
.tagline { color: var(--muted); margin: 6px 0 22px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { flex: 1; padding: 8px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary-d); }
#auth-form { display: flex; flex-direction: column; gap: 12px; }
input {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 9px;
  padding: 11px 12px; color: var(--text); font-size: 14px; width: 100%;
}
input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---- TOPBAR ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--bg2);
}
.brand { font-size: 20px; font-weight: 700; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.user-chip { background: var(--panel2); padding: 6px 12px; border-radius: 20px; font-size: 13px; }

/* ---- LOBBY ---- */
.lobby-body { padding: 28px; height: calc(100vh - 60px); overflow: auto; }
.lobby-main { max-width: 980px; margin: 0 auto; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.section-head h2 { margin: 0; }
.section-head > div { display: flex; gap: 10px; }
.rooms-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.room-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: transform .14s, border-color .14s, box-shadow .14s;
  animation: cardIn .3s ease both;
}
.room-card:hover { transform: translateY(-3px); border-color: var(--primary-d); box-shadow: 0 12px 30px rgba(0,0,0,.35); }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.room-card h3 { margin: 0; }
.room-card .meta { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--panel2); padding: 3px 9px; border-radius: 20px; font-size: 12px; color: var(--muted); }
.badge.live { background: #2a4d3a; color: #7be0a0; }
.badge.live { animation: liveGlow 1.8s ease-in-out infinite; }
@keyframes liveGlow { 0%,100% { box-shadow: 0 0 0 0 rgba(123,224,160,0); } 50% { box-shadow: 0 0 0 3px rgba(123,224,160,.18); } }
.empty-state { color: var(--muted); padding: 40px; text-align: center; }

/* ---- ROOM ---- */
.room-body { padding: 28px; display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px;
  max-width: 1100px; margin: 0 auto; height: calc(100vh - 60px); overflow: auto; }
.players-list, .room-players-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.players-list li { background: var(--panel2); padding: 10px 14px; border-radius: 9px; display: flex; justify-content: space-between; }
.crown { color: var(--warn); }
.room-actions { margin-top: 18px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.settings-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.settings-grid input, .settings-grid select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px; color: var(--text);
}

/* ---- MODAL ---- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(5,8,16,.7);
  place-items: center; z-index: 50; backdrop-filter: blur(2px);
}
.modal-backdrop.show { display: grid; }
.modal { width: 520px; max-width: 94vw; max-height: 90vh; overflow: auto; }
.modal label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal.center { text-align: center; }

/* ---- GAME ---- */
.game-layout { display: grid; grid-template-columns: 1fr 348px; height: 100vh; }
.board-wrap { position: relative; background:
  radial-gradient(1200px 700px at 50% 30%, #0d1626, #070a12); overflow: hidden; }
#board { display: block; cursor: pointer; touch-action: none; }
.zoom-controls { position: absolute; left: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.zoom-controls .btn { width: 40px; height: 40px; padding: 0; font-size: 18px;
  background: rgba(20,26,42,.82); backdrop-filter: blur(4px); }
.board-toolbar { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; }
.board-toolbar .icon { width: 38px; height: 38px; padding: 0; font-size: 17px; font-weight: 700;
  background: rgba(20,26,42,.82); backdrop-filter: blur(4px); border-radius: 10px; }
.board-overlay { position: absolute; top: 12px; left: 12px; font-size: 12px; color: var(--muted);
  background: rgba(10,13,22,.72); padding: 6px 11px; border-radius: 8px; pointer-events: none;
  backdrop-filter: blur(4px); }

.side-panel { background: linear-gradient(180deg, var(--panel), #1a2032); border-left: 1px solid var(--line);
  padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.turn-banner { padding: 13px; border-radius: 12px; text-align: center; font-weight: 700; font-size: 16px;
  background: var(--panel2); border: 2px solid var(--line); transition: border-color .25s, background .25s; }
@keyframes bannerPulse { 0% { transform: scale(1); } 40% { transform: scale(1.05); } 100% { transform: scale(1); } }
.turn-banner.pulse { animation: bannerPulse .5s ease; box-shadow: 0 0 22px rgba(46,204,113,.35); }
.panel-block h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.player-row { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px;
  background: var(--panel2); margin-bottom: 6px; font-size: 13px; transition: outline .2s, transform .12s;
  border: 1px solid transparent; }
.player-row.current { border-color: rgba(255,255,255,.12); box-shadow: inset 3px 0 0 0 var(--primary); }
.player-row.me { background: #28324c; }
.player-row.dead { opacity: .4; filter: grayscale(.7); }
.pname { display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none;
  box-shadow: 0 0 0 0 rgba(46,204,113,.6); animation: dotPulse 1.4s infinite; }
@keyframes dotPulse { 0% { box-shadow: 0 0 0 0 rgba(46,204,113,.55); } 70% { box-shadow: 0 0 0 6px rgba(46,204,113,0); } 100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); } }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.player-row .stats { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.player-row .gold { transition: color .2s; }
.player-row .gold.flash { animation: goldFlash .7s ease; }
@keyframes goldFlash { 0% { color: #ffe07a; transform: scale(1.18); } 100% { color: inherit; transform: scale(1); } }
.timer { font-weight: 700; transition: color .2s; }
.timer.low { color: var(--warn); }
.timer.crit { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.build-tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.chip { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 9px;
  padding: 8px 10px; cursor: pointer; font-size: 13px; transition: background .14s, transform .06s, border-color .14s; }
.chip:hover { background: #313b57; }
.chip:active { transform: translateY(1px); }
.chip.active { background: var(--primary); border-color: var(--primary-d); color: #fff;
  box-shadow: 0 0 14px rgba(79,134,247,.45); }
.chip.disabled { opacity: .42; cursor: not-allowed; }
.chip.disabled:hover { background: var(--panel2); }
.piece-build { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.piece-build .chip { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px; }
.piece-build .sym { font-size: 22px; line-height: 1; }
.piece-build .pl { font-size: 12px; }
.piece-build .cost { font-size: 10px; color: var(--muted); }
.piece-build .key { position: absolute; top: 3px; left: 5px; font-size: 9px; color: var(--muted); opacity: .7; }
.chip.active .cost, .chip.active .key { color: #dbe6ff; }

.actions-block { display: flex; flex-direction: column; gap: 10px; }
#end-turn.confirm { background: var(--warn); border-color: #c98a2c; color: #1a1208; animation: nudge .3s; }
@keyframes nudge { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.game-log { font-size: 12px; color: var(--muted); max-height: 120px; overflow: auto; display: flex; flex-direction: column-reverse; }
.game-log div { padding: 3px 0; border-bottom: 1px solid var(--line); }

.help-list { margin: 6px 0 14px; padding-left: 18px; display: grid; gap: 7px; font-size: 13px; color: var(--text); line-height: 1.45; }
.help-list strong { color: #fff; }
.shortcuts { line-height: 2; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 6px; font-size: 11px; font-family: inherit; color: var(--text); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--danger); color: #fff; padding: 11px 20px; border-radius: 11px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--good); color: #06210f; }

/* ---- move log ---- */
.log-block { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.log-head { display: flex; justify-content: space-between; align-items: baseline; }
.log-head h3 { margin: 0 0 8px; }
.game-log { font-size: 12px; color: var(--muted); flex: 1; max-height: 220px; overflow: auto; display: flex; flex-direction: column-reverse; }
.log-row { padding: 3px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 6px; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.log-turn { color: #6f7da0; font-variant-numeric: tabular-nums; font-size: 11px; }

/* ---- admin controls ---- */
#admin-block { border-top: 1px solid var(--line); padding-top: 12px; }
.settings-grid.compact { gap: 8px; }
.settings-grid.compact label { font-size: 11px; }
.settings-grid.compact input { padding: 6px; }
.kick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.kick-btn { display: flex; align-items: center; gap: 6px; justify-content: flex-start; }

.bottom-actions { display: flex; gap: 8px; }
.bottom-actions .btn { flex: 1; }
#resign-btn:hover { background: rgba(230,25,75,.18); border-color: var(--danger); color: #ffb3c0; }

/* ---- replay bar ---- */
.replay-bar { position: fixed; bottom: 0; left: 0; right: 348px; z-index: 55;
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: rgba(16,21,34,.94); border-top: 1px solid var(--line); backdrop-filter: blur(6px); }
.replay-bar .icon { width: 38px; height: 38px; padding: 0; font-size: 15px; }
.replay-bar input[type=range] { flex: 1; accent-color: var(--primary); }
.rp-label { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 64px; text-align: center; }

@media (max-width: 820px) {
  .game-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side-panel { flex-direction: row; flex-wrap: wrap; max-height: 42vh; }
  .room-body { grid-template-columns: 1fr; }
  .replay-bar { right: 0; }
}
