:root {
  --bg: #0b1018;
  --panel: #161b22cc;
  --panel-solid: #151b26;
  --panel-2: #0e131c;
  --border: #263041;
  --text: #e6edf3;
  --muted: #8b98ab;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --gold: #ffd479;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background:
    radial-gradient(1200px 700px at 20% -10%, #16233a 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 110%, #10202c 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;                 /* never a page scrollbar */
}

.screen { display: none; position: absolute; inset: 0; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* slim, unobtrusive scrollbars anywhere we do scroll */
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: #33415c transparent; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: #33415c; border-radius: 8px; }

/* ---------- main menu ---------- */
.menu-shell {
  height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}
.topline {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex: 0 0 auto;
}
.logo { font-size: 40px; margin: 0; letter-spacing: -1.5px; line-height: 1; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.who { display: flex; align-items: center; gap: 8px; }
.who .bi { color: var(--muted); }
.who input { width: 190px; }
.conn { color: var(--muted); font-size: 12px; max-width: 220px; }

.menu-grid {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(360px, 1.15fr);
  gap: 16px;
}
.col { min-height: 0; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: linear-gradient(180deg, #1a2230 0%, var(--panel-solid) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 10px 30px #00000055;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card-head h2 { margin: 0; }
.card h2 .bi { color: var(--accent); }

.play-card { display: flex; flex-direction: column; gap: 10px; flex: 0 0 auto; }
.play-card .row { margin-top: 0; }
.help { flex: 1 1 auto; min-height: 0; }
.tips { margin: 4px 0 0; padding-left: 18px; color: var(--muted); line-height: 1.65; font-size: 13.5px; }
.tips b { color: var(--text); }

.games-card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.games-card .lobby-list { flex: 1 1 auto; min-height: 0; }
#runningWrap { flex: 1 1 auto; min-height: 0; display: flex; margin-top: 10px; }
#runningWrap .lobby-list { flex: 1 1 auto; }
button.wide { width: 100%; margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input, select, button { font-family: inherit; font-size: 15px; }
input[type=text], input:not([type]), input[type=number], select {
  width: 100%; padding: 10px 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }

button {
  padding: 10px 16px; border-radius: 9px; cursor: pointer;
  background: #212a38; color: var(--text); border: 1px solid var(--border);
  transition: background .12s, transform .05s, border-color .12s;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
button:hover { background: #2c3648; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #2f6fd0; }
button.ghost { background: transparent; }
button.ghost:hover { background: #ffffff10; }
button.danger { background: #7f1d1d; border-color: #7f1d1d; }
button.big { padding: 14px; font-size: 16px; font-weight: bold; }
button.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.row { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.row.end { justify-content: flex-end; }
.code { text-transform: uppercase; letter-spacing: 3px; max-width: 190px; }

.lobby-list { display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
.lobby-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2);
}
.lobby-row:hover { border-color: #3a4a68; }
.lobby-row.live { border-color: #7f3f2a; }
.lobby-row .nm { font-weight: bold; }
.lobby-row .meta { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }
.badge-live {
  font-size: 11px; padding: 2px 7px; border-radius: 20px;
  background: #4a1d1d; color: #ffb3a7; margin-left: 6px;
}

.settings { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.settings b { color: var(--text); }
.members { display: flex; flex-direction: column; gap: 6px; }
.member { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel-2); border-radius: 8px; border: 1px solid var(--border); }
.member .nm { flex: 1; }
.member .tag { font-size: 12px; padding: 2px 7px; border-radius: 20px; background: #212a38; color: var(--muted); }
.member .tag.ready { background: #14532d; color: #86efac; }
.member .tag.host { background: #1e3a8a; color: #bfdbfe; }
.code-badge { color: var(--muted); font-size: 13px; }
.code-badge b { color: var(--accent); letter-spacing: 3px; font-size: 16px; }

.lobby-shell { height: 100%; max-width: 900px; margin: 0 auto; padding: 24px 18px; display: flex; flex-direction: column; gap: 16px; }

.chat-log {
  height: 170px; overflow-y: auto; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px;
  font-size: 14px; line-height: 1.5;
  scrollbar-width: thin; scrollbar-color: #33415c transparent;
}
.chat-log.small { height: 130px; font-size: 13px; background: #0b0f14aa; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log .who { color: var(--accent); font-weight: bold; }

/* ---------- dialogs ---------- */
.overlay {
  position: absolute; inset: 0; background: #000000aa;
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.dialog {
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: min(460px, 92vw);
  max-height: 92vh; overflow-y: auto; scrollbar-width: thin;
}
.dialog h2 { margin: 0 0 16px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- game ---------- */
#screen-game { background: #05070b; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 52px;
  display: flex; align-items: center; gap: 22px; padding: 0 16px;
  background: linear-gradient(#000000cc, #00000000);
  pointer-events: none;
}
#topbar .stat { display: flex; flex-direction: column; line-height: 1.15; min-width: 74px; }
#topbar .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
#topbar b { font-size: 18px; }
#btnQuit { margin-left: auto; pointer-events: auto; }

#leaderboard {
  position: absolute; top: 60px; right: 12px; width: 232px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; max-height: 52vh; overflow-y: auto; backdrop-filter: blur(3px);
  scrollbar-width: thin; scrollbar-color: #33415c transparent;
}
.lb-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px;
  border-radius: 6px; font-size: 13px; cursor: pointer;
}
.lb-row:hover { background: #ffffff14; }
.lb-row .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.lb-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pc { color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-row.me { outline: 1px solid var(--accent); }
.lb-row.dead { opacity: .4; text-decoration: line-through; }
.lb-row .ally { color: #86efac; }

#bottombar {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 10px 16px 12px;
  background: linear-gradient(#00000000, #000000cc);
  display: flex; flex-direction: column; gap: 4px; align-items: center;
}
#bottombar .sliders { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.ratio { display: flex; align-items: center; gap: 12px; width: min(420px, 40vw); }
.ratio span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ratio b { width: 46px; text-align: right; }
.hint { font-size: 12px; color: var(--muted); }

.build-bar { display: flex; gap: 8px; margin: 8px 0 4px; flex-wrap: wrap; }
.build-bar .build { padding: 6px 12px; font-size: 13px; }
.build-bar .build .bi { font-size: 15px; }
.build-bar .build small { opacity: .75; font-size: 11px; }
.build-bar .build.on { outline: 2px solid var(--gold); background: #2a3350; }
.build-bar .build:disabled { opacity: .45; cursor: not-allowed; }
#bCity .bi { color: #ffe27a; }
#bPort .bi { color: #7fd8ff; }
#bFort .bi { color: #ff9d6e; }
#bBuyTroops .bi { color: #b6f0c2; }

#gameChat { position: absolute; left: 12px; bottom: 110px; width: 300px; }
#gameChatInput {
  width: 100%; margin-top: 6px; padding: 7px 10px; font-size: 13px;
  background: #0b0f14cc; color: var(--text); border: 1px solid var(--border); border-radius: 8px;
}

.banner {
  position: absolute; top: 62px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 20px; font-size: 16px; text-align: center;
}
.toast {
  position: absolute; top: 120px; left: 50%; transform: translateX(-50%);
  background: #7f1d1dee; border: 1px solid #ef4444; border-radius: 8px;
  padding: 8px 16px; font-size: 14px; z-index: 60;
}

.panel {
  position: absolute; right: 12px; top: 60px; width: 260px; z-index: 20;
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel .row { flex-wrap: wrap; }
.panel button { flex: 1; font-size: 13px; padding: 8px; }
.np-stats { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 6px; }

.ally-reqs { position: absolute; left: 12px; top: 60px; display: flex; flex-direction: column; gap: 8px; }
.ally-req {
  background: var(--panel-solid); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px; font-size: 13px; width: 250px;
}
.ally-req .row { margin-top: 8px; }
.ally-req button { flex: 1; padding: 6px; font-size: 13px; }

.over-board { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.over-row { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.over-row .sw { width: 12px; height: 12px; border-radius: 3px; }
.over-row .nm { flex: 1; }

/* ---------- right click ring (radial) menu ---------- */
.radial { position: absolute; inset: 0; z-index: 40; }
.radial-core {
  position: absolute; width: 74px; height: 74px; margin: -37px 0 0 -37px;
  border-radius: 50%; background: #0d1420ee; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 11px; color: var(--muted); padding: 6px; line-height: 1.2;
  box-shadow: 0 8px 24px #000000aa;
}
.radial-item {
  position: absolute; width: 74px; height: 74px; margin: -37px 0 0 -37px;
  border-radius: 50%;
  background: #182233f2; border: 1px solid #33415c; color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; user-select: none;
  box-shadow: 0 8px 20px #000000aa;
  transition: transform .12s ease, background .12s, border-color .12s, opacity .12s;
  animation: radial-pop .13s ease-out;
}
.radial-item .bi { font-size: 20px; line-height: 1; }
.radial-item .rl { font-size: 11px; font-weight: 700; }
.radial-item .rc { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.radial-item:hover { background: #24344e; border-color: var(--accent); transform: scale(1.08); }
.radial-item.off { opacity: .4; cursor: not-allowed; }
.radial-item.off:hover { transform: none; border-color: #33415c; background: #182233f2; }
.radial-item.danger { border-color: #7f3030; }
.radial-item.danger .bi { color: #ff8b8b; }
@keyframes radial-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- previews ---------- */
.map-thumb {
  width: 108px; height: 68px; border-radius: 6px; border: 1px solid #2b3550;
  background: #0b1220; image-rendering: pixelated; object-fit: cover; flex: 0 0 auto;
}
.lobby-info { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.lobby-info .start { color: #9fd0ff; font-variant-numeric: tabular-nums; }
.map-preview-big {
  border-radius: 8px; overflow: hidden; border: 1px solid #2b3550;
  background: #0b1220; max-width: 260px;
}
.map-preview-big canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.lobby-map { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 12px; }
.lobby-map-meta { flex: 1 1 220px; min-width: 200px; }
.map-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.countdown { color: #9fd0ff; font-variant-numeric: tabular-nums; margin-bottom: 8px; }

@media (max-width: 900px) {
  .menu-grid { grid-template-columns: 1fr; overflow-y: auto; scrollbar-width: thin; }
  .topline { flex-direction: column; align-items: flex-start; }
  .help { display: none; }
}
