:root {
  --bg: rgba(8, 12, 22, 0.72);
  --line: rgba(255, 255, 255, 0.1);
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #ffcc00;
  --danger: #ff4d3d;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text); font: 14px/1.4 var(--font); }
button { font: inherit; color: inherit; cursor: pointer; }
#webgl { position: fixed; inset: 0; }
#webgl canvas { display: block; }

.panel {
  position: fixed; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 5;
}
.panel h3 { margin: 14px 0 8px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* Top bar */
#topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; z-index: 6;
}
#topbar > * { pointer-events: auto; }
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px 14px 6px 6px; backdrop-filter: blur(10px); }
.brand img { width: 40px; height: 40px; border-radius: 8px; background: #fff; object-fit: cover; }
.brand b { display: block; font-size: 15px; letter-spacing: .14em; color: var(--accent); }
.brand span { font-size: 11px; color: var(--muted); }
.stats { display: flex; gap: 8px; }
.stats > div { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px 14px; text-align: center; backdrop-filter: blur(10px); min-width: 92px; }
.stats small { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.stats b { font: 600 18px var(--mono); font-variant-numeric: tabular-nums; }

/* Left panel */
#left { top: 76px; left: 12px; width: 250px; padding: 12px; max-height: calc(100% - 88px); overflow: auto; }
.row { display: flex; gap: 8px; align-items: center; }
.row.center { justify-content: center; flex-wrap: wrap; }
.row.foot { margin-top: 12px; justify-content: space-between; }
button.primary { flex: 1; background: var(--accent); color: #1a1400; border: 0; border-radius: 8px; padding: 9px 14px; font-weight: 700; letter-spacing: .04em; }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .5; cursor: wait; }
button.primary.running { background: #2a3142; color: var(--text); }
button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
button.ghost:hover { background: rgba(255,255,255,.06); }
button.big { padding: 14px 28px; font-size: 16px; }
.speed { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 10px; }
.speed button { background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 6px; padding: 5px 0; font: 600 12px var(--mono); }
.speed button.on { background: rgba(255,204,0,.18); border-color: var(--accent); color: var(--accent); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.toggles label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.toggles input { accent-color: var(--accent); margin: 0; }
#seedLabel { font: 11px var(--mono); color: var(--muted); }

#board { list-style: none; margin: 0; padding: 0; }
#board li { display: grid; grid-template-columns: 18px 10px 1fr auto; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 6px; cursor: default; position: relative; }
#board li:hover { background: rgba(255,255,255,.06); }
#board .rk { font: 11px var(--mono); color: var(--muted); text-align: right; }
#board .sw { width: 10px; height: 10px; border-radius: 3px; }
#board .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#board .ct { font: 600 12px var(--mono); }
#board .bar { position: absolute; left: 0; bottom: 0; height: 2px; border-radius: 2px; opacity: .8; }
#board li.me .nm { font-weight: 700; }
#board li.me .nm::after { content: " ★"; color: var(--accent); }

#pickBox { margin-top: 12px; padding: 10px; border-radius: 8px; background: rgba(255,204,0,.07); border: 1px solid rgba(255,204,0,.25); font-size: 12px; }
#pickBox b { font-size: 14px; }
#pickBox .dead { color: var(--danger); }

/* Feed */
#feed { top: 76px; right: 12px; width: 360px; bottom: 12px; padding: 0 0 0 12px; display: flex; flex-direction: column; }
#feed h3 { padding-right: 12px; }
#feedCount { float: right; font-family: var(--mono); letter-spacing: 0; }
#events { overflow-y: auto; flex: 1; padding-right: 8px; padding-bottom: 8px; }
.ev { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; animation: slidein .35s ease-out; border-radius: 6px; }
.ev:hover { background: rgba(255,255,255,.04); }
.ev img { width: 34px; height: 34px; border-radius: 50%; background: #fff; object-fit: cover; }
.ev .meta { font-size: 12px; color: var(--muted); }
.ev .meta b { color: var(--text); }
.ev .txt { margin-top: 2px; }
.ev .c { font-weight: 700; }
.ev.minor { opacity: .6; font-size: 13px; }
.ev.minor img { width: 24px; height: 24px; }
.ev.big { background: rgba(255, 77, 61, .08); }
.ev.rebel { background: rgba(255, 204, 0, .07); }
.ev.win { background: rgba(255, 204, 0, .18); }
.ev.mine { box-shadow: inset 3px 0 0 var(--accent); }
.tag { display: inline-block; font: 700 10px var(--mono); letter-spacing: .06em; padding: 1px 6px; border-radius: 4px; margin-right: 4px; vertical-align: 1px; }
.tag.red { background: var(--danger); color: #fff; }
.tag.yel { background: var(--accent); color: #1a1400; }
.tag.blu { background: #3d7bff; color: #fff; }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } }

/* Labels over the globe */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; white-space: nowrap; font: 700 11px var(--font); letter-spacing: .08em; text-transform: uppercase;
  text-shadow: 0 1px 3px #000, 0 0 8px #000; will-change: transform, opacity; }
.lbl.empire { font-size: 12px; }
.lbl.empire i { font-style: normal; opacity: .8; font-family: var(--mono); margin-left: 4px; }
.lbl.pop { font-size: 13px; }
.lbl.pop small { display: block; font-size: 10px; opacity: .85; letter-spacing: .05em; }

#tooltip { position: fixed; z-index: 8; pointer-events: none; background: rgba(8,12,22,.9); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 260px; }
#tooltip b { font-size: 14px; }
#tooltip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

#headline { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 4; text-align: center; pointer-events: none; width: min(560px, 80vw); }
#headline .h { font: 800 26px var(--font); letter-spacing: .02em; text-shadow: 0 2px 12px #000, 0 0 2px #000; animation: headline 3.6s ease-out forwards; }
#headline .h small { display: block; font-size: 13px; font-weight: 600; color: var(--text); opacity: .85; }
@keyframes headline { 0% { opacity: 0; transform: scale(1.3); } 8% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* Modals */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: radial-gradient(ellipse at center, rgba(0,0,0,.25), rgba(0,0,0,.75)); }
.modal[hidden] { display: none; }
.card { width: min(520px, calc(100vw - 32px)); background: rgba(10,14,26,.9); border: 1px solid var(--line); border-radius: 16px; padding: 28px; text-align: center; backdrop-filter: blur(14px); max-height: calc(100vh - 32px); overflow: auto; }
.card h1 { margin: 8px 0 10px; font-size: 26px; letter-spacing: .14em; color: var(--accent); }
.card p { color: #c5cbd8; margin: 0 0 16px; }
.card .logo { width: 88px; height: 88px; border-radius: 18px; background: #fff; }
.card .hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; }
.card code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; }
.field { display: block; text-align: left; font-size: 12px; color: var(--muted); margin: 0 0 18px; }
.field select { display: block; width: 100%; margin-top: 6px; padding: 9px 10px; background: #141a2a; color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.trophy { font-size: 56px; }
#vStats { text-align: left; margin: 0 auto 20px; max-width: 360px; color: #c5cbd8; }
#vStats li { margin: 4px 0; }

/* Narrow screens */
@media (max-width: 860px) {
  #topbar { flex-direction: column; gap: 6px; }
  .brand span { display: none; }
  .stats > div { min-width: 0; padding: 4px 10px; }
  .stats b { font-size: 14px; }
  #left { top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 40vh; padding: 10px; }
  #left h3, #board, .toggles, .row.foot, #pickBox { display: none; }
  #feed { top: auto; bottom: calc(12px + 90px); left: 12px; right: 12px; width: auto; height: 26vh; }
  #headline { top: 130px; }
  #headline .h { font-size: 18px; }
}
