:root {
  --bg: #16121f;
  --panel: #221c30;
  --panel2: #2c2440;
  --edge: #0a0810;
  --hi: #4a3d68;
  --text: #f3ead8;
  --muted: #a99fbf;
  --gold: #f7d046;
  --green: #5fd26b;
  --red: #ff5a4e;
  --orange: #ffa13d;
  --blue: #69b7ff;
  --font: 'Pixelify Sans', 'Courier New', monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; image-rendering: pixelated; cursor: default; touch-action: none; }
.hidden { display: none !important; }
img.ico { image-rendering: pixelated; vertical-align: middle; width: 18px; height: 18px; }
img.ico.s { width: 14px; height: 14px; }
img.ico.l { width: 26px; height: 26px; }
b { font-weight: 600; }

.panel {
  background: var(--panel);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 2px var(--hi), inset 0 -4px 0 2px rgba(0, 0, 0, .25), 0 4px 0 rgba(0, 0, 0, .35);
  image-rendering: pixelated;
}

.btn {
  font-family: var(--font); font-size: 14px; color: var(--text); cursor: pointer;
  background: #4b3d72; border: 2px solid var(--edge); padding: 4px 10px;
  box-shadow: inset 0 -3px 0 #2e2550, inset 0 2px 0 #6c5ba0;
  transition: transform .05s;
}
.btn:hover { background: #5a4a88; }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 #2e2550; }
.btn:disabled, .btn.off { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.btn.big { font-size: 22px; padding: 10px 28px; background: #c0392b; box-shadow: inset 0 -4px 0 #7d2119, inset 0 2px 0 #e4685a; width: 100%; margin-top: 12px; }
.btn.big:hover { background: #d64535; }
.btn.small { font-size: 13px; padding: 3px 8px; }
.btn.green { background: #2f8a46; box-shadow: inset 0 -3px 0 #1d5a2c, inset 0 2px 0 #4cb766; }
.btn.red { background: #a8382c; box-shadow: inset 0 -3px 0 #6b2018, inset 0 2px 0 #d05a4d; }
.btn.gold { background: #a87a16; box-shadow: inset 0 -3px 0 #6a4c0b, inset 0 2px 0 #d8a838; }
.icon-btn { width: 30px; height: 30px; padding: 0; font-size: 16px; }

/* ── top bar ── */
#topbar { position: fixed; top: 6px; left: 6px; right: 6px; height: 44px; display: flex; align-items: center; gap: 6px; padding: 0 8px; z-index: 5; }
.logo { font-size: 20px; font-weight: 700; color: var(--gold); text-shadow: 2px 2px 0 #000; margin-right: 8px; letter-spacing: 1px; }
.logo span { color: var(--red); }
.res { display: flex; align-items: center; gap: 5px; padding: 3px 8px; background: var(--panel2); border: 2px solid var(--edge); min-width: 74px; white-space: nowrap; }
.res b { font-size: 16px; }
.res small { font-size: 12px; color: var(--green); }
.res small.neg { color: var(--red); }
.res.warn { animation: blink 0.8s steps(2) infinite; }
.spacer { flex: 1; }
.prot { color: #7fd3ff; font-size: 13px; padding: 3px 8px; border: 2px solid #2a6c99; background: #173550; }
@keyframes blink { 50% { background: #6b1d1d; } }

/* ── leaderboard ── */
#leaderboard { position: fixed; top: 58px; right: 6px; width: 250px; padding: 6px 8px; z-index: 4; font-size: 14px; }
#leaderboard h4 { margin: 0 0 4px; color: var(--gold); font-size: 14px; display: flex; justify-content: space-between; }
.lb-row { display: flex; align-items: center; gap: 6px; padding: 2px 3px; cursor: pointer; }
.lb-row:hover { background: rgba(255, 255, 255, .07); }
.lb-row.me { background: rgba(247, 208, 70, .15); }
.lb-row .sw { width: 11px; height: 11px; border: 2px solid var(--edge); flex: none; }
.lb-row .nm { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lb-row .pc { color: var(--muted); font-size: 12px; min-width: 40px; text-align: right; }
.lb-row .tag { font-size: 11px; color: #7fd3ff; }

/* ── event log ── */
#log { position: fixed; top: 58px; left: 8px; width: 330px; z-index: 3; pointer-events: none; display: flex; flex-direction: column; gap: 3px; }
.ev { pointer-events: auto; cursor: pointer; font-size: 13px; padding: 3px 8px; background: rgba(16, 12, 24, .82); border-left: 4px solid var(--muted); text-shadow: 1px 1px 0 #000; animation: evin .25s steps(3); transition: opacity 1s; }
.ev.good { border-color: var(--green); }
.ev.bad { border-color: var(--red); color: #ffd2cd; }
.ev.warn { border-color: var(--orange); }
.ev.capture { border-color: var(--gold); }
.ev.fall { border-color: #b06cff; }
.ev.pact { border-color: #7fd3ff; }
.ev.war { border-color: var(--red); }
.ev.camp { border-color: #c0703a; }
.ev.spawn { border-color: #888; color: var(--muted); }
.ev.end { border-color: var(--gold); color: var(--gold); }
.ev.fade { opacity: 0; }
@keyframes evin { from { transform: translateX(-20px); opacity: 0; } }

/* ── selection panel ── */
#selpanel { position: fixed; left: 6px; bottom: 6px; width: 380px; max-height: calc(100vh - 190px); overflow-y: auto; padding: 8px 10px; z-index: 6; font-size: 14px; }
#selpanel::-webkit-scrollbar { width: 8px; }
#selpanel::-webkit-scrollbar-thumb { background: var(--hi); }
.sp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sp-head .t { font-size: 18px; font-weight: 600; flex: 1; }
.sp-head .sub { color: var(--muted); font-size: 13px; }
.sp-sec { margin-top: 8px; border-top: 2px dashed #3b3150; padding-top: 6px; }
.sp-sec h5 { margin: 0 0 4px; font-size: 13px; color: var(--gold); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; display: flex; justify-content: space-between; }
.bar { height: 8px; background: #0e0b15; border: 2px solid var(--edge); position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); }
.bar.blue > i { background: #69b7ff; }
.bar.gold > i { background: var(--gold); }
.row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.units { display: flex; gap: 10px; flex-wrap: wrap; }
.units span { display: flex; align-items: center; gap: 3px; }
.rec { display: grid; grid-template-columns: 30px 1fr auto; gap: 2px 6px; align-items: center; padding: 2px 0; }
.rec .nm { font-size: 14px; }
.rec .cost { font-size: 12px; color: var(--muted); }
.rec .btns { display: flex; gap: 3px; }
.rec .btns .btn { padding: 2px 6px; font-size: 12px; }
.rec.locked { opacity: .5; }
.queue { display: flex; flex-wrap: wrap; gap: 4px; }
.qi { display: flex; align-items: center; gap: 2px; background: var(--panel2); border: 2px solid var(--edge); padding: 1px 4px; font-size: 12px; position: relative; cursor: pointer; }
.qi .qp { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--green); }
.qi:hover { background: #5a2a2a; }
.blds { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.bld { display: flex; align-items: center; gap: 5px; background: var(--panel2); border: 2px solid var(--edge); padding: 3px 5px; cursor: pointer; font-size: 13px; }
.bld:hover { background: #3a3056; }
.bld.off { opacity: .5; cursor: not-allowed; }
.bld.max { opacity: .8; cursor: default; border-color: #2f6b35; }
.bld .lv { font-size: 11px; color: var(--gold); }
.bld .c { margin-left: auto; font-size: 12px; color: var(--gold); }
.pips { letter-spacing: -1px; color: var(--gold); font-size: 11px; }
.kv { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.kv b { color: var(--text); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ── decrees ── */
#decrees { position: fixed; bottom: 6px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 5px; z-index: 5; }
.dec { width: 50px; height: 50px; position: relative; background: var(--panel2); border: 2px solid var(--edge); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.dec:hover { background: #3a3056; }
.dec img { width: 26px; height: 26px; image-rendering: pixelated; }
.dec .k { position: absolute; top: 0; left: 2px; font-size: 11px; color: var(--muted); }
.dec .c { font-size: 11px; color: var(--gold); line-height: 1; }
.dec .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, .65); pointer-events: none; }
.dec .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; text-shadow: 1px 1px 0 #000; pointer-events: none; }
.dec.active { box-shadow: 0 0 0 2px var(--gold), 0 0 12px var(--gold); }
.dec.poor { opacity: .55; }

/* ── minimap ── */
#minimap-wrap { position: fixed; right: 6px; bottom: 6px; width: 258px; height: 178px; padding: 3px; z-index: 5; }
#minimap-wrap canvas { position: absolute; left: 3px; top: 3px; width: 246px; height: 166px; image-rendering: pixelated; cursor: pointer; }

/* ── chat ── */
#chat { position: fixed; right: 270px; bottom: 6px; width: 290px; z-index: 4; }
#chat-log { max-height: 130px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 13px; text-shadow: 1px 1px 0 #000; }
#chat-log div { padding: 1px 4px; background: rgba(10, 8, 16, .55); margin-top: 1px; word-break: break-word; }
#chat-input { width: 100%; font-family: var(--font); font-size: 13px; padding: 4px 6px; background: rgba(20, 16, 30, .85); color: var(--text); border: 2px solid var(--edge); outline: none; margin-top: 3px; }
#chat-input:focus { border-color: var(--gold); }

#tileinfo { position: fixed; left: 50%; bottom: 66px; transform: translateX(-50%); font-size: 13px; color: var(--muted); text-shadow: 1px 1px 0 #000; z-index: 3; pointer-events: none; white-space: nowrap; }

#toasts { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 20; }
.toast { padding: 8px 12px; font-size: 14px; display: flex; gap: 8px; align-items: center; animation: evin .25s steps(3); }

/* ── overlays ── */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 30; background: radial-gradient(ellipse at center, rgba(10, 8, 20, .35), rgba(10, 8, 20, .8)); }
.menu-box { width: 440px; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow-y: auto; padding: 20px 24px; text-align: center; }
.menu-box.wide { width: 860px; text-align: left; }
.title { font-size: 46px; margin: 0; color: var(--gold); text-shadow: 4px 4px 0 #000, -2px -2px 0 #6b4a0a; letter-spacing: 2px; font-weight: 700; text-align: center; }
.title span { color: var(--red); }
h2.title { font-size: 32px; }
.title.red { color: var(--red); }
.subtitle { color: var(--muted); margin: 4px 0 16px; }
.lbl { text-align: left; color: var(--muted); font-size: 13px; margin: 8px 0 4px; }
#name { width: 100%; font-family: var(--font); font-size: 20px; padding: 8px 10px; background: #0f0c18; color: var(--text); border: 3px solid var(--edge); box-shadow: inset 0 0 0 2px var(--hi); outline: none; }
#name:focus { box-shadow: inset 0 0 0 2px var(--gold); }
#colors { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.cs { aspect-ratio: 1; border: 3px solid var(--edge); cursor: pointer; }
.cs.sel { outline: 3px solid #fff; outline-offset: -1px; transform: scale(1.12); }
.cs.taken { opacity: .3; }
.menu-info { color: var(--muted); font-size: 13px; margin-top: 10px; }
.menu-feats { text-align: left; font-size: 13px; color: var(--muted); margin: 12px 0; display: grid; gap: 3px; }
.menu-feats b { color: var(--text); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; font-size: 14px; line-height: 1.35; }
.help-grid h3 { color: var(--gold); margin: 10px 0 4px; font-size: 16px; }
.help-grid ul { padding-left: 18px; margin: 0; }
.help-grid p { margin: 0; color: #ddd3c0; }
#help-close { margin-top: 14px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 14px 0; text-align: left; }
.stat-grid div { background: var(--panel2); border: 2px solid var(--edge); padding: 6px 8px; }
.stat-grid b { display: block; font-size: 20px; color: var(--gold); }
.standings { text-align: left; margin: 12px 0; }
.standings .lb-row { cursor: default; font-size: 15px; }

#diplo-menu { position: fixed; z-index: 25; padding: 8px; display: flex; flex-direction: column; gap: 5px; min-width: 200px; font-size: 14px; }
#diplo-menu .h { color: var(--gold); font-weight: 600; }
#tooltip { position: fixed; z-index: 50; max-width: 280px; padding: 6px 9px; font-size: 13px; background: #0f0c18; border: 2px solid var(--gold); pointer-events: none; line-height: 1.3; white-space: pre-line; }

@media (max-width: 900px) {
  #chat, #log { display: none; }
  #leaderboard { width: 170px; font-size: 12px; }
  .logo { display: none; }
  .res { min-width: 0; padding: 2px 5px; }
  .res small { display: none; }
  #selpanel { width: calc(100vw - 12px); max-height: 45vh; bottom: 66px; }
  #minimap-wrap { display: none; }
  .help-grid { grid-template-columns: 1fr; }
  .dec { width: 42px; height: 42px; }
}
