* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #06121f;
  --panel: linear-gradient(160deg, rgba(16, 32, 50, 0.94), rgba(8, 18, 30, 0.94));
  --panel-flat: rgba(10, 22, 36, 0.92);
  --panel-border: rgba(120, 170, 220, 0.22);
  --text: #d7e4f2;
  --dim: #7f95ab;
  --accent: #40c4ff;
  --accent-soft: rgba(64, 196, 255, 0.28);
  --gold: #ffce54;
  --danger: #ff5f56;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  user-select: none;
}

#map { position: fixed; inset: 0; width: 100vw; height: 100vh; cursor: grab; }
#map.mode-target { cursor: crosshair; }
#map.dragging { cursor: grabbing; }

#minimap {
  position: fixed; right: 12px; bottom: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 5;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 12px; left: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 15px;
  min-width: 200px;
  z-index: 5;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.hud-row { display: flex; justify-content: space-between; gap: 16px; padding: 1px 0; }
.hud-label { color: var(--dim); }
.hud-sub { font-size: 12px; color: var(--dim); }
#hud-gold { color: var(--gold); font-weight: 600; }
#hud-combat { color: var(--danger); }

/* ---------- Leaderboard ---------- */
#leaderboard {
  position: fixed; top: 12px; right: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 9px 12px;
  min-width: 195px;
  z-index: 5;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.lb-row { display: flex; align-items: center; gap: 7px; padding: 2.5px 0; }
.lb-row.me { font-weight: 700; }
.lb-row.dead { opacity: 0.35; text-decoration: line-through; }
.lb-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; box-shadow: 0 0 4px rgba(0,0,0,0.5); }
.lb-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-pct { color: var(--dim); font-variant-numeric: tabular-nums; }
.lb-ally { width: 15px; text-align: center; font-size: 11px; }
.lb-team { font-size: 12px; color: var(--dim); padding: 1px 0; }
.lb-team.me { color: var(--text); font-weight: 700; }
.lb-team-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 4px; font-size: 10px; font-weight: 700;
  color: #06121f; flex: none;
}
.lb-team-dot.t0 { background: #7fd4ff; }
.lb-team-dot.t1 { background: #ff9a76; }
.lb-team-dot.t2 { background: #b9f36c; }

/* ---------- Controls ---------- */
#controls {
  position: fixed; bottom: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap; justify-content: center;
  max-width: min(880px, 96vw);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 11px 18px;
  z-index: 5;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.ctl { display: flex; flex-direction: column; gap: 4px; }
.ctl label { font-size: 11px; color: var(--dim); letter-spacing: 0.04em; text-transform: uppercase; }
.ctl label span { color: var(--text); font-weight: 700; text-transform: none; }

/* sliders */
input[type=range] { width: 155px; appearance: none; background: transparent; }
input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, rgba(64,196,255,0.55), rgba(64,196,255,0.18));
}
input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: #eaf6ff; border: 2px solid var(--accent);
  margin-top: -5px; cursor: pointer;
  box-shadow: 0 1px 5px rgba(0,0,0,0.5);
}

.btn-group { display: flex; gap: 6px; }
button {
  background: linear-gradient(160deg, rgba(70, 125, 180, 0.32), rgba(45, 85, 130, 0.22));
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
button:hover { background: linear-gradient(160deg, rgba(90, 155, 215, 0.45), rgba(60, 110, 165, 0.3)); border-color: rgba(140, 195, 245, 0.4); }
button:active { transform: translateY(1px); }
button.on, button.active { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 10px rgba(64,196,255,0.25) inset; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button .cost { color: var(--gold); font-size: 11px; margin-left: 3px; }
#speed button { padding: 7px 10px; font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- Log ---------- */
#log {
  position: fixed; bottom: 12px; left: 12px;
  z-index: 4;
  font-size: 12px;
  max-width: 345px;
  pointer-events: none;
  display: flex; flex-direction: column; gap: 3px;
}
.log-line {
  background: rgba(8, 18, 30, 0.8);
  border-left: 2px solid rgba(120, 170, 220, 0.35);
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--dim);
  animation: fadein 0.25s;
  backdrop-filter: blur(3px);
}
.log-line b { color: var(--text); }
.log-line.warn { color: #ffb454; border-left-color: #ffb454; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }

/* ---------- Toasts (alliance requests etc.) ---------- */
#toasts {
  position: fixed; top: 70px; left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 11px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55), 0 0 18px rgba(64, 196, 255, 0.12);
  animation: fadein 0.2s;
  backdrop-filter: blur(8px);
}
.toast .t-yes { background: rgba(80, 200, 120, 0.32); border-color: rgba(110, 224, 138, 0.5); }
.toast .t-no  { background: rgba(220, 90, 80, 0.28); border-color: rgba(255, 120, 105, 0.5); }

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed;
  z-index: 9;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
#tooltip .tt-name { font-weight: 700; margin-bottom: 1px; }
#tooltip .tt-sub { color: var(--dim); line-height: 1.5; }

/* ---------- Hint ---------- */
#hint {
  position: fixed; top: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 10px 24px;
  font-size: 15px;
  z-index: 8;
  animation: pulse 1.6s infinite;
  backdrop-filter: blur(6px);
}
@keyframes pulse { 50% { box-shadow: 0 0 22px rgba(64, 196, 255, 0.5); } }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  background:
    radial-gradient(1200px 700px at 30% 20%, rgba(28, 90, 140, 0.2), transparent 60%),
    radial-gradient(900px 600px at 75% 80%, rgba(64, 196, 255, 0.08), transparent 55%),
    rgba(3, 9, 16, 0.85);
  display: flex; justify-content: center;
  overflow-y: auto; /* panels taller than the screen must scroll */
  padding: 26px 12px;
  z-index: 20;
  backdrop-filter: blur(4px);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 36px 46px;
  text-align: center;
  max-width: 470px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(120, 170, 220, 0.06) inset;
  margin: auto;        /* centers when short, scrolls when tall */
  height: fit-content;
}
.panel h1 {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0.16em;
  background: linear-gradient(120deg, #40c4ff, #9be8ff 55%, #d6f4ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
  text-shadow: 0 0 34px rgba(64, 196, 255, 0.25);
}
#end-title.defeat { background: linear-gradient(120deg, var(--danger), #ffb0a8); -webkit-background-clip: text; background-clip: text; }
/* long titles (SURRENDERED) must not outgrow the gradient box — outside it the
   text paints transparent and letters get chopped */
#end-title { font-size: min(42px, 11cqw, 38px); letter-spacing: 0.08em; padding-right: 0.1em; white-space: nowrap; }
.tagline { color: var(--dim); margin-bottom: 22px; line-height: 1.5; }
.opt {
  display: flex; justify-content: space-between; align-items: center;
  margin: 9px 0; gap: 20px;
}
.opt label { color: var(--dim); }
.opt select {
  background: rgba(20, 40, 60, 0.9);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  min-width: 190px;
  cursor: pointer;
}
.opt select:hover { border-color: rgba(140, 195, 245, 0.45); }
#btn-play, #btn-again {
  margin-top: 20px;
  width: 100%;
  padding: 13px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(120deg, #1d78b8, #40c4ff);
  border: none;
  color: #04121e;
  box-shadow: 0 6px 22px rgba(64, 196, 255, 0.3);
}
#btn-play:hover, #btn-again:hover { filter: brightness(1.15); }
.help { margin-top: 18px; font-size: 12px; color: var(--dim); line-height: 1.65; }
#end-desc { color: var(--dim); margin-top: 6px; line-height: 1.6; }

/* ---------- HUD facilities ---------- */
.hud-fac {
  display: flex; flex-wrap: wrap; gap: 5px 9px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--panel-border);
  font-size: 12.5px; color: var(--text);
  max-width: 210px;
}
.hud-fac span { white-space: nowrap; }
.hud-fac .dim { color: var(--dim); }

/* ---------- build tray ---------- */
#tray {
  position: fixed; left: 50%; bottom: 82px;
  transform: translateX(-50%);
  z-index: 6;
  max-width: min(94vw, 940px);
}
.tray-group {
  display: none;
  gap: 7px; flex-wrap: wrap; justify-content: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 9px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.tray-group.on { display: flex; }
.tray-group button {
  display: flex; flex-direction: column; align-items: center;
  gap: 1px; width: 88px; padding: 8px 4px 7px;
  position: relative; line-height: 1.2;
}
.tray-group button .ic { font-size: 21px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.tray-group button .bl { font-size: 11px; font-weight: 600; }
.tray-group button .cost { color: var(--gold); font-size: 10.5px; margin: 0; }
.tray-group button .sub, .tray-group button .cap { font-size: 10px; color: var(--dim); }
.tray-group button.active { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 12px rgba(64,196,255,0.3) inset; }
.tray-group button.poor { opacity: 0.45; }
.tray-group button.poor .cost { color: var(--danger); }

#tabs button.on { background: var(--accent-soft); border-color: var(--accent); }

/* hotkey hint on tray buttons */
.tray-group button .hk {
  position: absolute; top: 3px; right: 6px;
  font-size: 9px; color: var(--dim);
  border: 1px solid rgba(127, 149, 171, 0.4);
  border-radius: 3px; padding: 0 3px; line-height: 1.3;
}

/* ---------- quick-chat emotes (multiplayer) ---------- */
#emotes {
  position: fixed; left: 12px; top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 5;
}
#emotes button {
  width: 42px; height: 42px; padding: 0;
  font-size: 20px; line-height: 1;
  border-radius: 50%;
  background: var(--panel);
}
#emotes button.sent { background: rgba(64, 196, 255, 0.45); transform: scale(1.12); }

/* ---------- room browser ---------- */
#rooms-box { margin-top: 12px; text-align: left; }
.rooms-head { font-size: 12px; color: var(--dim); margin-bottom: 6px; letter-spacing: 0.04em; }
.rooms-head .dim { opacity: 0.7; }
#rooms-list { display: flex; flex-direction: column; gap: 4px; max-height: 150px; overflow-y: auto; }
.room-row {
  display: flex; align-items: center; gap: 8px;
  background: rgba(20, 40, 60, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 5px 9px;
  font-size: 12.5px;
}
.room-row.dim { opacity: 0.55; }
.room-row .room-name { font-weight: 700; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row .room-meta { flex: 1; color: var(--dim); font-size: 11.5px; }
.room-row button { padding: 3px 10px; font-size: 12px; }
#create-box { margin-top: 8px; font-size: 13px; }
#create-box summary { cursor: pointer; color: var(--accent); font-size: 12.5px; padding: 4px 0; }
#create-box .opt { margin: 6px 0; }
#create-box input[type=text], #create-box input:not([type]) {
  background: rgba(20, 40, 60, 0.9); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 7px;
  padding: 6px 10px; font-size: 13px; width: 150px;
}
#btn-create { width: 100%; margin-top: 4px; padding: 8px; font-weight: 700; }
.lb-row.lb-click { cursor: pointer; }
.lb-row.lb-click:hover { background: rgba(64, 196, 255, 0.12); border-radius: 5px; }

/* ---------- touch devices (body.touch set from JS) ---------- */
#map { touch-action: none; }
body.touch button { padding: 9px 11px; font-size: 13px; }
body.touch #speed button { padding: 9px 10px; font-size: 12px; }
body.touch .tray-group button { width: 78px; padding: 8px 4px 7px; }
body.touch .tray-group button .ic { font-size: 18px; }
body.touch .ctl { gap: 2px; }
body.touch .ctl label { font-size: 10px; }
body.touch .ctl input[type=range] { width: min(38vw, 150px); height: 26px; }
/* controls dock bottom-LEFT so the minimap stays visible bottom-right */
body.touch #controls {
  left: 6px; right: auto; bottom: 6px;
  transform: none;
  max-width: min(74vw, 460px);
  gap: 8px; padding: 8px 10px;
}
body.touch #tray { left: 6px; transform: none; bottom: 108px; max-width: 96vw; }
body.touch #hud { font-size: 12.5px; min-width: 150px; padding: 8px 10px; top: 8px; left: 8px; }
body.touch .hud-fac { font-size: 11px; max-width: 160px; }
body.touch #leaderboard { font-size: 12.5px; min-width: 140px; max-width: 45vw; top: 8px; right: 8px; padding: 6px 9px; }
body.touch #log { bottom: 132px; max-width: 48vw; font-size: 11px; }
body.touch #emotes { left: 6px; }
body.touch #emotes button { width: 40px; height: 40px; font-size: 19px; }
body.touch #hint { font-size: 13px; padding: 8px 14px; top: auto; bottom: 148px; width: max-content; max-width: 92vw; }
body.touch #minimap { opacity: 0.95; }
.lb-more { font-size: 11px; color: var(--accent); padding: 3px 0 1px; cursor: pointer; text-align: center; }

/* ---------- directed messages in the diplomacy toast ---------- */
.toast.diplo { flex-wrap: wrap; max-width: 340px; }
.dm-row { display: flex; gap: 5px; width: 100%; justify-content: center; padding-top: 2px; }
.dm-row button { padding: 6px 9px; font-size: 16px; line-height: 1; }

/* ---------- feedback modal ---------- */
.fb-panel { max-width: 420px; text-align: left; }
.fb-panel .fb-title { font-size: 26px; }
.fb-panel textarea {
  width: 100%; margin: 8px 0; padding: 9px 11px;
  background: rgba(20, 40, 60, 0.9); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px;
  font: inherit; font-size: 13px; resize: vertical;
}
.fb-panel input {
  background: rgba(20, 40, 60, 0.9); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 7px;
  padding: 6px 10px; font-size: 13px; width: 180px;
}
.fb-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
#fb-send { background: linear-gradient(120deg, #1d78b8, #40c4ff); border: none; color: #04121e; font-weight: 700; }
#fb-status { margin: 4px 0 0; min-height: 16px; }

/* ---------- start-screen help grid ---------- */
.help-grid {
  margin-top: 16px;
  display: flex; flex-direction: column; gap: 5px;
  text-align: left; font-size: 12px;
}
.help-grid > div { display: flex; gap: 10px; align-items: baseline; }
.help-grid .hg-k {
  flex: none; width: 74px;
  color: var(--accent); font-weight: 600; font-size: 11.5px;
  letter-spacing: 0.02em;
}
.help-grid span:last-child { color: var(--dim); line-height: 1.45; }
.help-grid b { color: var(--text); }

/* ---------- house ads (our own projects; hidden in portal embeds) ---------- */
.house-ad { margin-top: 14px; }
.ha-card {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  background: linear-gradient(120deg, hsla(var(--ha-hue), 45%, 22%, 0.55), hsla(var(--ha-hue), 55%, 14%, 0.65));
  border: 1px solid hsla(var(--ha-hue), 60%, 55%, 0.35);
  transition: border-color 0.15s, transform 0.15s;
  animation: fadein 0.4s;
}
.ha-card:hover { border-color: hsla(var(--ha-hue), 75%, 60%, 0.8); transform: translateY(-1px); }
.ha-emoji { font-size: 22px; flex: none; }
.ha-body { flex: 1; min-width: 0; text-align: left; }
.ha-title { display: block; font-size: 13px; font-weight: 700; color: var(--text); }
.ha-line { display: block; font-size: 11.5px; color: var(--dim); line-height: 1.35; }
.ha-cta {
  flex: none; font-size: 11.5px; font-weight: 700;
  color: hsl(var(--ha-hue), 80%, 70%);
  white-space: nowrap;
}
.ha-tag {
  position: absolute; top: -7px; right: 8px;
  font-size: 8.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--dim); background: var(--bg);
  padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--panel-border);
}
body.touch .ha-line { display: none; }

/* community buttons */
.community { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.community a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; font-size: 12.5px; text-decoration: none;
  color: var(--text); border: 1px solid var(--panel-border);
  background: rgba(60, 110, 160, 0.25);
}
.community a:hover { border-color: var(--accent); }

/* footer */
.footer {
  margin-top: 20px; padding-top: 14px;
  border-top: 1px solid var(--panel-border);
  font-size: 11.5px; color: var(--dim);
  display: flex; flex-direction: column; gap: 5px;
}
.footer a { color: var(--dim); text-decoration: none; border-bottom: 1px dotted rgba(127,149,171,0.5); }
.footer a:hover { color: var(--accent); border-color: var(--accent); }
.footer .credit a { color: var(--gold); border-color: rgba(255,206,84,0.4); }

/* static pages (faq / privacy / terms) */
.page {
  max-width: 720px; margin: 0 auto; padding: 48px 24px 80px;
  height: 100%; overflow-y: auto;
}
.page h1 { font-size: 30px; margin-bottom: 4px;
  background: linear-gradient(120deg, #40c4ff, #9be8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.page h2 { font-size: 17px; margin: 26px 0 8px; color: var(--text); }
.page p, .page li { color: var(--dim); line-height: 1.7; font-size: 14px; }
.page ul { padding-left: 20px; margin: 6px 0; }
.page b { color: var(--text); }
.page a { color: var(--accent); }
.page .back { display: inline-block; margin-bottom: 22px; font-size: 13px; text-decoration: none; }
.page .small { font-size: 12px; margin-top: 30px; opacity: 0.8; }
body.doc { overflow: auto; }

/* multiplayer */
.mp-sep { color: var(--dim); font-size: 12px; margin: 16px 0 4px; letter-spacing: 0.04em; }
.opt input {
  background: rgba(20, 40, 60, 0.9);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  min-width: 190px;
}
.opt input:focus { outline: none; border-color: var(--accent); }
#btn-online {
  margin-top: 8px; width: 100%; padding: 11px;
  font-size: 15px; font-weight: 700;
  background: linear-gradient(120deg, #14855c, #2fd58a);
  border: none; color: #04121e;
}
#mp-status { margin-top: 10px; }
/* server drives the clock online — local speed controls make no sense */
body.mp #speed [data-speed], body.mp #btn-pause { display: none; }

/* end-game stats */
#end-chart { margin: 14px auto 4px; display: block; border-radius: 8px; }
#end-stats {
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  margin-top: 10px; font-size: 12.5px; color: var(--dim);
}
#end-stats b { color: var(--text); }
