:root {
  --bg: #0b1118;
  --panel: rgba(16, 24, 33, 0.94);
  --panel-solid: #101821;
  --line: #243243;
  --text: #e6edf3;
  --muted: #8b9bab;
  --accent: #f0b429;
  --accent-ink: #1a1400;
  --good: #3fb97f;
  --war: #e5534b;
  --offer: #58a6ff;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); letter-spacing: .04em; margin: 0; }

button {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { border-color: var(--muted); }
button.war { background: var(--war); color: #fff; }
button.good { background: var(--good); color: #04140c; }
button.small { padding: 4px 10px; font-size: 12px; }
input {
  background: #0d151e; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus { border-color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- lobby ---------- */
#lobby {
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(240,180,41,.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(88,166,255,.08), transparent 60%),
    var(--bg);
}
.lobby-inner { max-width: 940px; margin: 0 auto; padding: 48px 16px 64px; }
.brand h1 { font-size: clamp(48px, 9vw, 88px); line-height: .9; color: var(--accent); }
.brand p { color: var(--muted); max-width: 560px; margin: 10px 0 28px; }
.field { display: flex; flex-direction: column; gap: 6px; max-width: 320px; margin-bottom: 28px; }
.field span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
#lobby h2 { font-size: 22px; margin: 8px 0 12px; }
.map-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 28px; }
.map-card {
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
  cursor: pointer; text-align: left; color: var(--text); display: flex; flex-direction: column; gap: 6px;
}
.map-card canvas { width: 100%; aspect-ratio: 16 / 10; border-radius: 6px; background: #0e2233; display: block; }
.map-card b { font-family: var(--display); font-size: 20px; letter-spacing: .04em; }
.map-card small { color: var(--muted); }
.map-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.server-head { display: flex; align-items: center; justify-content: space-between; }
.room-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.room {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 14px; align-items: center;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.room .players { font-variant-numeric: tabular-nums; }
.private-row { display: flex; gap: 8px; flex-wrap: wrap; }
.private-row input { flex: 1; min-width: 200px; }

/* ---------- game ---------- */
#game { position: fixed; inset: 0; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map.targeting { cursor: crosshair; }

#topbar {
  position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 6px; align-items: stretch; flex-wrap: wrap;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.tb-country, .tb-stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px;
  display: flex; align-items: center; gap: 8px; backdrop-filter: blur(6px);
}
.tb-country { font-family: var(--display); font-size: 20px; letter-spacing: .04em; cursor: pointer; }
.swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--muted); display: inline-block; flex: none; }
.tb-stat { flex-direction: column; align-items: flex-start; gap: 0; min-width: 92px; }
.tb-stat small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.tb-stat b { font-variant-numeric: tabular-nums; font-weight: 600; }
.tb-stat i { font-style: normal; font-size: 11px; color: var(--good); }
.tb-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.tb-actions button { padding: 8px 12px; }

#panel {
  position: absolute; top: 74px; right: 10px; width: 340px; max-height: calc(100% - 150px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  backdrop-filter: blur(6px);
}
#panel .close { position: absolute; top: 8px; right: 8px; background: transparent; color: var(--muted); font-size: 22px; padding: 0 8px; }
#panel h3 { font-size: 24px; display: flex; align-items: center; gap: 8px; padding-right: 24px; }
#panel h4 { margin: 16px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.sub { color: var(--muted); margin: 2px 0 10px; font-size: 13px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { font-variant-numeric: tabular-nums; text-align: right; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row > button { flex: 1; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.war { color: var(--war); border-color: var(--war); }
.tag.ally { color: var(--good); border-color: var(--good); }
.tag.player { color: var(--offer); border-color: var(--offer); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; background: transparent; color: var(--muted); border-radius: 0; padding: 6px 4px; font-size: 12px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
input[type=range] { width: 100%; padding: 0; accent-color: var(--accent); border: 0; background: none; }
.cost { font-size: 12px; color: var(--muted); }
.cost.bad { color: var(--war); }
.bar { height: 6px; background: #1b2633; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--accent); }
.list { display: flex; flex-direction: column; gap: 4px; }
.list .item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.list .item:hover { background: #17222e; border-color: var(--line); }
.list .item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item small { color: var(--muted); font-variant-numeric: tabular-nums; }
.tech { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.tech .pips { display: flex; gap: 3px; margin: 6px 0; }
.tech .pips i { flex: 1; height: 5px; border-radius: 2px; background: #1f2b38; }
.tech .pips i.on { background: var(--accent); }

#selBar {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px;
}
#selInfo { padding: 0 6px; font-variant-numeric: tabular-nums; }

#chat { position: absolute; left: 10px; bottom: 10px; width: 330px; max-width: calc(100% - 20px); display: flex; flex-direction: column; gap: 6px; }
#chatLog {
  max-height: 180px; overflow: auto; display: flex; flex-direction: column; gap: 2px; font-size: 13px;
  background: linear-gradient(to top, rgba(11,17,24,.85), rgba(11,17,24,.35)); border-radius: var(--radius); padding: 8px 10px;
}
#chatLog:empty { display: none; }
#chatLog b { font-weight: 600; }
#chatInput { width: 100%; background: var(--panel); }

#hint {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; color: var(--muted); pointer-events: none; white-space: nowrap;
}
#hint:empty { display: none; }

#toasts { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 8px; padding: 8px 14px;
  max-width: min(520px, 90vw); animation: toastIn .2s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.war, .toast.error { border-left-color: var(--war); }
.toast.offer { border-left-color: var(--offer); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }

#offers { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 8px; width: 320px; }
.offer { background: var(--panel); border: 1px solid var(--offer); border-radius: var(--radius); padding: 10px 12px; }

#overlay {
  position: absolute; inset: 0; background: rgba(5,9,13,.6); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(460px, 100%); max-height: 86vh; overflow: auto; }
.modal h3 { font-size: 28px; margin-bottom: 4px; }
.modal input { width: 100%; margin: 10px 0; }

@media (max-width: 720px) {
  #panel { left: 10px; right: 10px; width: auto; top: auto; bottom: 10px; max-height: 55%; }
  #chat { width: 240px; }
  #chatLog { max-height: 110px; }
  .tb-stat { min-width: 0; padding: 4px 8px; }
  .tb-actions button { padding: 6px 8px; font-size: 12px; }
  .room { grid-template-columns: 1fr auto; }
  #offers { width: auto; left: 10px; }
}
