:root {
  /* Season 2: Neon horizon. Deep indigo night, neon sunset accents. */
  --void: #0c0919;
  --hull: #161127;
  --hull-2: #201836;
  --line: #3a2d5e;
  --ink: #efe9ff;
  --ink-dim: #a99cc9;
  --signal: #ff9a62;
  --sunset: linear-gradient(90deg, #b48cff, #f28a4b);
  --on-sunset: #170c22;
  --f-neon: "Monoton", "Chakra Petch", system-ui, sans-serif;
  --xenium: #6fc3df;
  --nova: #f28a4b;
  --nebulite: #b48cff;
  --ok: #6fd3a4;
  --tabs-h: 56px;
  --enemy: #ef6b6b;
  --danger: #ef8a6b;
  --f-display: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--void);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  -webkit-user-select: none;
  user-select: none;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#map.dragging { cursor: grabbing; }

.series {
  font-family: var(--f-display);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--signal);
}

.muted { color: var(--ink-dim); }
.error { color: var(--danger); }

/* --- Top bar --- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: linear-gradient(var(--void), transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title .name { font-family: var(--f-display); font-weight: 700; font-size: 18px; }

button {
  font-family: var(--f-display);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  background: var(--hull-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
}
button:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* --- Loading screen --- */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: var(--void);
  text-align: center;
}
.loading h1 {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  font-family: var(--f-display);
  font-size: clamp(32px, 10vw, 44px);
  line-height: 1.05;
}

/* --- Planet info sheet --- */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--hull);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
}
.sheet-close {
  position: absolute;
  top: 10px; right: 12px;
  width: 32px; height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}
.sheet h2 { margin: 0 32px 4px 0; font-family: var(--f-display); font-size: 22px; }
.sheet .coords { font-family: var(--f-display); color: var(--ink-dim); font-size: 13px; }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 16px 0 0; }
.sheet dt { color: var(--ink-dim); }
.sheet dd { margin: 0; }

.tag {
  display: inline-block;
  margin-top: 10px;
  margin-right: 6px;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid currentColor;
  font-family: var(--f-display);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tag.you { color: var(--signal); }
.tag.rich { color: var(--nebulite); }
.tag.enemy { color: var(--enemy); }

/* The map sheet sits above the tab bar. */
.sheet { bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: 20px; }

/* --- "Open in Telegram" link --- */
.open-tg {
  font-family: var(--f-display);
  font-weight: 700;
  color: var(--on-sunset);
  background: var(--signal);
  border-radius: 4px;
  padding: 12px 20px;
  text-decoration: none;
}

/* --- Tab bar --- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding: 0 max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
  background: var(--hull);
  border-top: 1px solid var(--line);
  z-index: 5;
}
.tab {
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--ink-dim);
  font-size: 15px;
  letter-spacing: 0.05em;
}
.tab.active { color: var(--signal); box-shadow: inset 0 2px 0 var(--signal); }

/* --- Planet screen --- */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--void);
  padding: calc(16px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px) max(16px, env(safe-area-inset-left));
  -webkit-user-select: none;
}
.screen > * { max-width: 560px; margin-left: auto; margin-right: auto; }

.planet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.planet-head h1 { margin: 0; font-family: var(--f-display); font-size: 26px; line-height: 1.1; }
.coords { font-family: var(--f-display); color: var(--ink-dim); font-size: 13px; margin-top: 2px; }
.allegiance {
  flex: none;
  text-align: right;
  font-family: var(--f-display);
  font-size: 12px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.allegiance b { display: block; font-size: 20px; color: var(--ink); letter-spacing: 0; }

.resources { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.res {
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  min-width: 0;
}
.res-name {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--f-display); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-dim);
}
.res-name i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.res-amount { font-family: var(--f-display); font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.res-amount.full { color: var(--danger); }
.res-meta { font-size: 11.5px; line-height: 1.35; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.res-bar { height: 3px; background: var(--hull-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.res-bar > span { display: block; height: 100%; background: var(--c); }

.section-title {
  font-family: var(--f-display); font-size: 13px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--ink-dim); margin: 24px auto 10px;
}

/* Build queue */
.queue { margin-top: 18px; display: grid; gap: 8px; }
.queue-item {
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}
.queue-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.queue-row .time { font-family: var(--f-display); font-variant-numeric: tabular-nums; color: var(--signal); }
.queue-item.waiting .time { color: var(--ink-dim); }
.progress { height: 4px; background: var(--hull-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--signal); transition: width 1s linear; }

/* Buildings */
.buildings { display: grid; gap: 8px; }
.building {
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.building-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.building-head h3 { margin: 0; font-family: var(--f-display); font-size: 17px; }
.level { font-family: var(--f-display); font-size: 13px; color: var(--ink-dim); white-space: nowrap; }
.building p { margin: 0; font-size: 13px; color: var(--ink-dim); }
.building-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.costs { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px; font-variant-numeric: tabular-nums; }
.cost { display: inline-flex; align-items: center; gap: 4px; }
.cost i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.cost.short { color: var(--danger); }
.cost.time { color: var(--ink-dim); }
.build-btn { min-width: 96px; }
.build-btn.primary { background: var(--sunset); border-color: transparent; color: var(--on-sunset); font-weight: 700; }
.build-btn:disabled { opacity: 0.45; cursor: default; }
.locked { font-size: 13px; color: var(--ink-dim); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  background: var(--hull-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  z-index: 10;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--ok); color: var(--ok); }

/* --- Screens shared by tabs --- */
.screen-title { margin: 0; font-family: var(--f-display); font-size: 26px; line-height: 1.15; text-wrap: balance; }
.screen.overlay { z-index: 8; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.screen.overlay .sheet-close { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
.screen.overlay .screen-title { margin-right: 40px; }
.section-title.danger { color: var(--enemy); }
.notice {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--ok) 50%, transparent);
  border-radius: 6px;
  color: var(--ok);
  font-size: 13px;
}
.tag { color: var(--ink-dim); }
.planet-switch {
  margin-top: 8px;
  max-width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--hull-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
}

/* Troops */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--hull); font-size: 13px; }
.chip b { font-family: var(--f-display); font-variant-numeric: tabular-nums; }
#training .queue { margin-top: 10px; }
.building .stats { font-size: 12px; font-variant-numeric: tabular-nums; }
.train-row { display: flex; gap: 6px; align-items: center; }
input.count {
  width: 72px;
  font: inherit;
  font-family: var(--f-display);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 8px;
  -webkit-user-select: text;
  user-select: text;
}
input.count:focus { outline: none; border-color: var(--signal); }

/* Tab badges */
.badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--signal);
  color: var(--on-sunset);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.badge.danger { background: var(--enemy); color: #fff; }
.tabs { grid-template-columns: repeat(4, 1fr); }
.tab { font-size: 14px; padding: 0 4px; }

/* Planet sheet buttons */
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.sheet-actions .build-btn { flex: 1 1 0; }

/* Fleets */
.fleet { background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; display: grid; gap: 4px; font-size: 14px; }
.fleet.incoming { border-color: color-mix(in srgb, var(--enemy) 60%, var(--line)); }
.fleet.incoming .time { color: var(--enemy); }
.fleet.returning .time { color: var(--ink-dim); }
.fleet .muted { font-size: 13px; }
.fleet-units { font-size: 13px; }

/* Send screen */
.send-units { display: grid; gap: 8px; margin-top: 16px; }
.send-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
.send-preview dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 16px 0; }
.send-preview dt { color: var(--ink-dim); }
.send-preview dd { margin: 0; font-variant-numeric: tabular-nums; }
.build-btn.wide { width: 100%; padding: 12px; font-size: 16px; margin-top: 8px; }

/* Reports */
.report-list { display: grid; gap: 6px; margin-top: 16px; }
.report-row {
  display: grid;
  gap: 2px;
  text-align: left;
  font-family: var(--f-body);
  background: var(--hull);
  padding: 10px 12px;
  border-radius: 6px;
}
.report-row .muted { font-size: 12px; }
.report-row.unread { border-color: var(--signal); }
.report-row.unread .report-title { font-weight: 500; }
.report-title { font-size: 14px; }
#report-body h3 { font-family: var(--f-display); font-size: 16px; margin: 20px 0 2px; }
#report-body p { margin: 4px 0; }
.report-outcome { font-family: var(--f-display); font-size: 18px; margin-top: 12px !important; }
.report-outcome.attacker { color: var(--signal); }
.report-outcome.defender { color: var(--enemy); }
.report-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.report-table th, .report-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.report-table th { font-family: var(--f-display); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); font-weight: 500; }
.report-table td.lost { color: var(--danger); }

/* --- Fixes after the first screenshot pass --- */
.report-table { table-layout: fixed; }
.report-table th:first-child { width: 50%; }
.tab { white-space: nowrap; position: relative; }
.tab .badge { position: absolute; top: 8px; right: 6px; margin: 0; }
/* Toasts sit at the top so they never cover buttons near the bottom. */
.toast { bottom: auto; top: calc(12px + env(safe-area-inset-top)); z-index: 20; }

/* --- Welcome screen and rename --- */
.setup {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow-y: auto;
  background: var(--void);
  padding: calc(32px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.setup-inner { max-width: 420px; margin: 0 auto; display: grid; gap: 12px; }
.setup h1 { margin: 0; font-family: var(--f-display); font-size: clamp(30px, 9vw, 40px); line-height: 1.05; text-wrap: balance; }
.setup p { margin: 0; }
.setup-form { display: grid; gap: 8px; margin-top: 12px; }
.setup-form label {
  margin-top: 8px;
  font-family: var(--f-display); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-dim);
}
.text-input {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  -webkit-user-select: text;
  user-select: text;
}
.text-input:focus { outline: none; border-color: var(--signal); }
.small { font-size: 13px; }
.planet-title { display: flex; align-items: center; gap: 8px; }
.icon-btn { padding: 2px 8px; font-size: 16px; line-height: 1.4; color: var(--ink-dim); background: none; }

/* --- Map legend --- */
.legend {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 10px);
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 10px;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 11.5px;
  color: var(--ink-dim);
  background: color-mix(in srgb, var(--hull) 85%, transparent);
  border: 1px solid var(--line);
  border-radius: 6px;
  pointer-events: none;
}
.legend li { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend.arena .old-galaxy { display: none; }
.legend i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.legend i.double { box-shadow: 0 0 0 2px var(--hull), 0 0 0 3px var(--c); }
.legend i.glow { box-shadow: 0 0 6px 2px color-mix(in srgb, var(--c) 70%, transparent); }
/* The planet sheet covers the legend while open. */
.sheet { z-index: 6; }
.tag.mine { color: #2ee6a8; }
.tag.visited { color: #dfe3ec; }

/* --- Chat --- */
.tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
.tab { font-size: 12px; letter-spacing: 0.02em; padding: 0 2px; }
.chat-screen { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 96px); }
.chat-log { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.chat-day { align-self: center; font-size: 12px; color: var(--ink-dim); margin: 8px 0 2px; }
.msg { max-width: 82%; align-self: flex-start; display: grid; gap: 2px; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg-meta { font-size: 12px; color: var(--ink-dim); }
.msg-meta b { color: var(--signal); font-weight: 500; }
.msg-report { background: none; border: 0; padding: 0 4px; color: var(--ink-dim); font: inherit; font-size: 12px;
  cursor: pointer; opacity: 0.6; }
.msg-report:hover, .msg-report[data-confirm] { opacity: 1; color: var(--danger); }
.chat-bar { flex-wrap: wrap; }
.chat-rules { flex: 1 0 100%; margin: 0 0 6px; font-size: 11.5px; color: var(--ink-dim); text-align: center; }
.msg-text {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--hull);
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
}
.msg.mine .msg-text { background: color-mix(in srgb, var(--signal) 16%, var(--hull)); border-color: color-mix(in srgb, var(--signal) 40%, var(--line)); }
.chat-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  gap: 8px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--void);
  border-top: 1px solid var(--line);
}
.chat-bar .text-input { padding: 10px 12px; font-size: 16px; flex: 1 1 0; width: auto; min-width: 0; }
.chat-bar .build-btn { flex: none; }

/* --- Social tab: sections and alliance --- */
.segments {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.segment {
  position: relative;
  border: 0;
  background: none;
  color: var(--ink-dim);
  font-size: 13px;
  padding: 8px 4px;
  white-space: nowrap;
}
.segment.active { background: var(--hull-2); color: var(--signal); }
.segment .badge { position: absolute; top: -6px; right: -2px; margin: 0; }
.tag-inline { color: var(--ink-dim); font-weight: 500; }
.tag.ally { color: #7fb2ff; }
#alliance-panel { margin-top: 8px; }
.alliance-name { margin: 20px 0 2px; font-family: var(--f-display); font-size: 22px; }
.member {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  background: var(--hull);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
}
.member .build-btn { padding: 6px 10px; font-size: 13px; }
.invite-row { display: flex; gap: 8px; }
.invite-row .text-input { padding: 10px 12px; font-size: 16px; }
#leave-area { margin-top: 28px; }
.danger-btn { color: var(--enemy); border-color: color-mix(in srgb, var(--enemy) 50%, var(--line)); background: none; }

/* Toasts are only messages: taps go through to whatever is underneath. */
.toast { pointer-events: none; }

/* --- Events --- */
.head-right { display: flex; align-items: flex-start; gap: 8px; }
.admin-btn, .settings-btn { font-size: 18px; }
.events { display: grid; gap: 8px; margin-top: 14px; }
.events:empty { display: none; }
.event-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  text-align: left;
  font-family: var(--f-body);
  padding: 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--signal) 10%, var(--hull));
  border: 1px solid color-mix(in srgb, var(--signal) 55%, var(--line));
}
.event-card.arena {
  background: color-mix(in srgb, var(--enemy) 14%, var(--hull));
  border-color: var(--enemy);
}
.event-card.arena .event-body { width: 100%; }
.arena-board { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 4px; }
.arena-board td { padding: 3px 0; }
.arena-board td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.arena-board tr.you td { color: var(--signal); }
.arena-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.arena-actions .build-btn { flex: 1 1 0; }
.event-card.titan {
  background: color-mix(in srgb, #e2574c 10%, var(--hull));
  border-color: color-mix(in srgb, #e2574c 55%, var(--line));
}
.event-icon { font-size: 26px; line-height: 1; }
.event-body { display: grid; gap: 4px; min-width: 0; }
.event-title { font-family: var(--f-display); font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.event-time { font-weight: 500; color: var(--signal); font-variant-numeric: tabular-nums; white-space: nowrap; }
.event-text { font-size: 13.5px; color: var(--ink-dim); }
.event-text b { color: var(--ink); font-weight: 500; }
#event-body p { margin: 10px 0; }
#story-body { white-space: pre-line; line-height: 1.5; margin-bottom: 18px; }
#story-screen .build-btn { margin-top: 8px; }
#finale-screen {
  background: radial-gradient(circle at 50% 110px, color-mix(in srgb, var(--signal) 22%, transparent), transparent 300px), var(--void);
}
#finale-screen .build-btn { margin-top: 8px; }
.finale-hero { text-align: center; padding: 18px 0 8px; animation: finale-rise 0.9s ease-out both; }
.finale-kicker { margin: 0; font-family: var(--f-display); font-size: 13px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--ink-dim); }
.finale-trophy { font-size: 68px; line-height: 1.25; animation: finale-glow 3s ease-in-out infinite; }
.finale-title { margin: 0; font-family: var(--f-display); font-size: 15px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--signal); }
.finale-winner { margin: 4px 0; font-family: var(--f-display); font-size: 38px; line-height: 1.1; overflow-wrap: anywhere; text-wrap: balance; }
.finale-line { margin: 0; color: var(--ink-dim); }
.finale-heading { margin: 26px 0 10px; font-family: var(--f-display); font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--signal); }
.finale-board { font-size: 15px; }
.finale-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.finale-tile { display: grid; align-content: start; gap: 2px; padding: 10px 8px; text-align: center; background: var(--hull); border: 1px solid var(--line); border-radius: 8px; }
.finale-tile b { font-family: var(--f-display); font-size: 20px; font-variant-numeric: tabular-nums; }
.finale-tile span { font-size: 11.5px; line-height: 1.25; color: var(--ink-dim); }
.finale-battle { margin: 0; line-height: 1.5; color: var(--ink-dim); }
.finale-battle b { color: var(--ink); font-weight: 500; }
.finale-awards { display: grid; gap: 8px; }
.finale-award {
  display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px;
  background: var(--hull); border: 1px solid var(--line); border-radius: 8px;
  animation: finale-rise 0.6s ease-out both; animation-delay: calc(0.5s + var(--i) * 0.08s);
}
.finale-award.you { border-color: var(--signal); }
.finale-award-icon { font-size: 22px; text-align: center; }
.finale-award-who, .finale-award-value { display: grid; gap: 1px; min-width: 0; }
.finale-award-who small { font-size: 12px; color: var(--signal); }
.finale-award-who b { font-weight: 500; overflow-wrap: anywhere; }
.finale-award-value { text-align: right; max-width: 42vw; }
.finale-award-value b { font-family: var(--f-display); font-size: 17px; font-variant-numeric: tabular-nums; }
.finale-award-value small { font-size: 11px; line-height: 1.2; color: var(--ink-dim); }
.finale-thanks { margin: 24px 0 10px; text-align: center; color: var(--ink-dim); text-wrap: balance; }
@keyframes finale-rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes finale-glow { 50% { filter: drop-shadow(0 0 16px var(--signal)); } }
@media (prefers-reduced-motion: reduce) {
  .finale-hero, .finale-trophy, .finale-award { animation: none; }
}
.ranking td:first-child { width: 2.5em; color: var(--ink-dim); }
.ranking tr.you td { color: var(--signal); }
select.text-input { appearance: auto; }
.legend i.titan { box-shadow: 0 0 0 2px var(--hull), 0 0 0 3px var(--signal); }

/* --- Daily reward and invites --- */
.rewards { display: grid; gap: 8px; margin-top: 8px; }
.reward-card { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--hull); }
.reward-card.ready { border-color: color-mix(in srgb, var(--ok) 60%, var(--line)); background: color-mix(in srgb, var(--ok) 8%, var(--hull)); }
.reward-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 15px; }
.reward-head .build-btn { padding: 6px 14px; }
.reward-card p { margin: 0; }
.reward-card .costs { align-items: center; color: var(--ink-dim); }
#report-share { margin-top: 24px; }

/* Shown when an upgrade costs more than the planet can store. */
.building .storage-hint { flex-basis: 100%; margin: 0; font-size: 13px; color: var(--danger); }

/* --- Settings --- */
.settings { display: grid; gap: 8px; }
.setting-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--hull); border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.mini-seg { display: flex; gap: 4px; padding: 3px; background: var(--void); border: 1px solid var(--line); border-radius: 6px; }
.mini-seg button { border: 0; background: none; color: var(--ink-dim); padding: 6px 10px; font-size: 13px; }
.mini-seg button.active { background: var(--hull-2); color: var(--signal); }

/* --- Guide --- */
.guide { display: grid; gap: 8px; margin-top: 16px; }
.guide-section { background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 0 14px; }
.guide-section > summary {
  font-family: var(--f-display); font-size: 16px; font-weight: 700; padding: 13px 0; cursor: pointer;
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.guide-section > summary::-webkit-details-marker { display: none; }
.guide-section > summary::after { content: "+"; color: var(--ink-dim); font-size: 20px; line-height: 1; }
.guide-section[open] > summary::after { content: "−"; }
.guide-section[open] { padding-bottom: 12px; }
.guide-section p { margin: 0 0 10px; line-height: 1.5; color: var(--ink); }
.guide-section p.muted { color: var(--ink-dim); margin-bottom: 4px; }
.guide-section h3 { font-family: var(--f-display); font-size: 14px; letter-spacing: 0.05em; color: var(--signal); margin: 14px 0 6px; }
.guide-item { border-top: 1px solid var(--line); padding: 10px 0 6px; }
.guide-item h3 { margin-top: 0; }
.guide-colors { list-style: none; margin: 0; padding: 0 0 4px; display: grid; gap: 10px; }
.guide-colors li { display: flex; gap: 10px; align-items: baseline; line-height: 1.45; }
.guide-colors i { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c); transform: translateY(1px); }
.guide-colors i.double { box-shadow: 0 0 0 2px var(--hull), 0 0 0 3px var(--c); }
.guide-colors i.glow { box-shadow: 0 0 6px 2px color-mix(in srgb, var(--c) 70%, transparent); }
.guide-colors b { font-weight: 500; }

/* --- Waiting room (before the game opens) --- */
.wait-countdown {
  font-family: var(--f-display); font-size: clamp(24px, 8.5vw, 48px); font-weight: 700; color: var(--signal); white-space: nowrap;
  font-variant-numeric: tabular-nums; margin: 8px 0 4px;
}
.waitroom h1 { margin: 0; font-family: var(--f-display); font-size: clamp(30px, 9vw, 40px); line-height: 1.05; }
.waitroom p { margin: 0; }
.waitroom .setup-inner { padding-top: 16px; }
/* Before the opening only a few tabs show: share the bar between them. */
.tabs.lobby { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }

/* --- Admin statistics --- */
.stat-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.stat-tile { background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.stat-num { font-family: var(--f-display); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--ink); }
.stat-sub { font-size: 11.5px; color: var(--ink-dim); }
.stat-strip { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--ink-dim); }
.stat-strip b { color: var(--ink); font-variant-numeric: tabular-nums; }
.chart { position: relative; background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .bar { fill: var(--signal); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .baseline { stroke: var(--ink-dim); stroke-width: 1; }
.chart .axis { fill: var(--ink-dim); font-size: 10px; font-family: var(--f-body); }
.chart-tip {
  position: absolute; top: 6px; width: 150px; padding: 6px 8px; border-radius: 6px; pointer-events: none;
  background: var(--hull-2); border: 1px solid var(--line); color: var(--ink); font-size: 12px; line-height: 1.4;
}
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: 9.5em 1fr 3em; gap: 8px; align-items: center; font-size: 13px; }
.hbar b { text-align: right; font-variant-numeric: tabular-nums; }
.hbar-track { height: 8px; background: var(--hull-2); border-radius: 4px; overflow: hidden; }
.hbar-track i { display: block; height: 100%; background: var(--signal); border-radius: 0 4px 4px 0; }
.pcards { display: grid; gap: 8px; }
.pcard { background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; display: grid; gap: 4px; }
.pcard-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.pcard-line { font-size: 12.5px; line-height: 1.45; }
.pcard-planet { font-size: 12.5px; padding: 6px 0 0; margin-top: 4px; border-top: 1px dashed var(--line); }
.pcard-planet .muted { margin-top: 2px; }
.pcard .build-btn { justify-self: start; margin-top: 4px; padding: 6px 10px; font-size: 13px; }
.online { color: var(--ok); font-size: 12.5px; white-space: nowrap; }
.feed, .pfeed { display: grid; gap: 6px; }
.feed-row { display: grid; grid-template-columns: 6.2em 1fr; gap: 8px; font-size: 12.5px; line-height: 1.4;
  border-top: 1px solid var(--line); padding-top: 6px; }
.pfeed { max-height: 320px; overflow-y: auto; margin-top: 4px; }
/* Lists you tap to open an alliance or a player, and their close-up */
.arows { display: grid; gap: 6px; }
.arow { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px; color: var(--ink);
  font: inherit; cursor: pointer; }
.arow:hover { border-color: var(--signal); }
.arow-main { display: grid; gap: 2px; min-width: 0; }
.arow-sub { font-size: 12px; color: var(--ink-dim); line-height: 1.4; }
.arow-tools { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 8px; }
.arow-tools .text-input { margin: 0; }
.detail-head { margin: 12px 0 8px; }
.detail-name { font-family: var(--f-display); font-size: 22px; font-weight: 700; }
.pcard-res { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* What a building upgrade brings */
.building p.effect { margin: 6px 0 0; font-size: 13px; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.5; }
.building p.effect b { color: var(--ok); font-weight: 500; }

/* --- Marketplace --- */
.market-panel { margin-top: 14px; }
.market-sub { margin: 6px 0 0; font-size: 13px; color: var(--ink-dim); line-height: 1.8; }
.market-sub .cost, .offer .cost { margin-right: 6px; }
.market-form { display: grid; gap: 6px; }
.market-form label { font-size: 13px; color: var(--ink-dim); }
.market-row { display: grid; grid-template-columns: 1fr 9em; gap: 8px; }
.offers { display: grid; gap: 8px; }
.offer { background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; display: grid; gap: 6px; }
.offer.mine { border-color: color-mix(in srgb, var(--signal) 45%, var(--line)); }
.offer-deal { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 14px; }
.offer-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.offer-foot .build-btn { padding: 6px 14px; }
/* Four Social sections share the bar; long labels may wrap to two lines. */
.segments { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.segment { white-space: normal; font-size: 12px; line-height: 1.2; }
/* The Social menu stays on screen while long chats scroll under it. */
#social-sections {
  position: sticky;
  top: calc(16px + env(safe-area-inset-top));
  z-index: 2;
  box-shadow: 0 0 0 8px var(--void), 0 -40px 0 40px var(--void);
}

/* Guide: every level of a building */
.levels { margin-top: 6px; }
.levels summary { font-size: 13px; color: var(--signal); cursor: pointer; padding: 4px 0; }
.levels-scroll { overflow-x: auto; margin-top: 4px; }
.levels table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.levels th { text-align: left; font-weight: 500; color: var(--ink-dim); padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); }
.levels td { padding: 4px 6px 4px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); vertical-align: top; }
.levels .nowrap { white-space: nowrap; }
.levels .cost { margin-right: 4px; }
.levels .unlock-row td { color: var(--ok); border-bottom: none; padding-top: 0; }

/* Gifts between allies */
.gift-amounts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.gift-amounts label { display: grid; gap: 4px; }

/* Cancel a training batch */
.queue-right { display: inline-flex; align-items: center; gap: 8px; }
.queue-cancel {
  border: 1px solid var(--line); background: var(--hull-2); color: var(--ink-dim); border-radius: 4px;
  font-size: 12px; padding: 2px 8px; line-height: 1.4; min-height: 24px;
}
.queue-cancel[data-confirm] { color: var(--danger); border-color: var(--danger); }

/* Planet screen: Buildings and Train units fold away */
details.fold > summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--hull); border: 1px solid var(--line); border-radius: 6px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "+"; font-size: 18px; letter-spacing: 0; color: var(--ink-dim); }
details.fold[open] > summary::after { content: "−"; }
details.fold[open] > summary { margin-bottom: 10px; }

/* Settings: message groups */
.notify-topics { margin: 6px 0 0 12px; padding-left: 10px; border-left: 2px solid var(--line); }
.topic-row span { font-size: 13px; }
.notify-topics p { margin: 6px 0 0; }

/* Galactic Exchange */
.exchange-prices { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 10px; font-size: 13px; }
.exchange-prices .up { color: var(--danger); font-size: 12px; }
.exchange-prices .down { color: var(--ok); font-size: 12px; }
.exchange-arrow { text-align: center; color: var(--ink-dim); font-size: 16px; line-height: 1; }
.exchange-get { display: flex; align-items: center; padding: 0 12px; background: var(--hull-2); border: 1px solid var(--line);
  border-radius: 6px; font-family: var(--f-display); font-size: 18px; font-variant-numeric: tabular-nums; }

/* Galactic Exchange: live rates */
.exchange-rates { margin: 0 0 12px; }
.rate-board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 4px; }
.rate { display: grid; justify-items: center; gap: 1px; padding: 6px 4px; background: var(--hull); border: 1px solid var(--line);
  border-radius: 6px; font-size: 11.5px; color: var(--ink-dim); text-align: center; }
.rate b { font-family: var(--f-display); font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* Admin: game settings */
.tuning-group { margin-top: 8px; }
.tuning-row { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.tuning-row.changed .tuning-label b { color: var(--signal); }
.tuning-label { display: grid; gap: 2px; font-size: 13px; }
.tuning-edit { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.tuning-edit .text-input { padding: 6px 10px; }
.tuning-edit .build-btn { padding: 6px 12px; }

/* Planet screen: defense and attack power */
.power { margin: 10px 0; }
.power-row { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; }
.power-row b { font-family: var(--f-display); font-size: 18px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.power p { margin: 2px 0 0; }
a[data-privacy] { color: var(--signal); }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink); font: inherit; cursor: pointer; text-decoration: underline dotted var(--ink-dim); text-underline-offset: 3px; }
/* Admin: chat moderation */
.mod-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.mod-actions .build-btn { padding: 6px 10px; font-size: 13px; }
.mod-text { overflow-wrap: anywhere; }
#mod-words-text { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
/* Reading and accepting the privacy policy */
.privacy-gate { position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; gap: 10px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--void); }
.privacy-gate[hidden] { display: none; }
.privacy-gate .screen-title { margin: 0; }
.privacy-gate p { margin: 0; }
#privacy-frame { flex: 1; min-height: 0; width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--void); }

/* --- Season 2: the neon title, its sunset and the glowing grid --- */
.neon, .waitroom h1.neon, .topbar-title .name.neon {
  font-family: var(--f-neon); font-weight: 400; letter-spacing: 0.02em; line-height: 1.05; text-transform: uppercase;
  background: linear-gradient(180deg, #e7d6ff, #b48cff 45%, #f28a4b); -webkit-background-clip: text; background-clip: text;
  color: transparent; filter: drop-shadow(0 0 10px rgba(180, 140, 255, 0.55));
}
.neon-sun {
  width: 120px; height: 60px; border-radius: 120px 120px 0 0; margin: 0 auto -4px; opacity: 0.9;
  background: repeating-linear-gradient(180deg, #f28a4b 0 7px, transparent 7px 10px), linear-gradient(180deg, #ffd27a, #f28a4b, #e0457b);
  background-blend-mode: multiply;
}
.neon-grid {
  position: fixed; left: -20%; right: -20%; bottom: 0; height: 34%; pointer-events: none; z-index: 0; opacity: 0.6;
  background-image: linear-gradient(rgba(180, 140, 255, 0.35) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(180, 140, 255, 0.35) 1px, transparent 1px);
  background-size: 34px 22px; transform: perspective(240px) rotateX(58deg); transform-origin: bottom;
}
.waitroom, .loading { background: linear-gradient(180deg, var(--void) 0%, #0f0b22 55%, #1b0f2a 100%); }
.waitroom .setup-inner, .loading > * { position: relative; z-index: 1; }
.waitroom .setup-inner { text-align: center; }
/* "Space Strider IV" is the big neon line, "Season 2" the smaller one under it. */
.series.neon { display: block; letter-spacing: 0.02em; margin-bottom: 4px; font-size: clamp(20px, 7.4vw, 32px); }
.waitroom h1.neon, .loading h1 .neon:not(.series) { font-size: clamp(17px, 5.4vw, 24px); letter-spacing: 0.04em; }
.setup .series.neon { font-size: clamp(18px, 6vw, 24px); }
.season-tag { font-size: clamp(13px, 4vw, 17px); margin-top: 2px; }
.topbar-title .series.neon { font-size: clamp(13px, 3.9vw, 19px); margin: 0; white-space: nowrap; }
.topbar-title .name.neon { font-size: 13px; letter-spacing: 0.04em; filter: none; }

/* The bell: the bot's messages inside the game. */
.bell-btn { position: relative; font-size: 18px; }
.bell-btn .badge { position: absolute; top: -6px; right: -8px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .bell-btn { background: var(--hull); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.inbox { display: grid; gap: 8px; }
.inbox-item { background: var(--hull); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.inbox-item.unread { border-color: var(--signal); }
.inbox-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.inbox-when { margin-top: 4px; font-size: 12px; color: var(--ink-dim); }

/* The little ? buttons and their popup (one part of the Guide). */
.help-btn {
  display: inline-grid; place-items: center; width: 20px; height: 20px; padding: 0; margin-left: 4px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--hull-2); color: var(--signal);
  font: 700 12px/1 var(--f-body); letter-spacing: 0; text-transform: none; vertical-align: middle; cursor: pointer;
}
body.no-help .help-btn, body.no-help .legend-help { display: none; }
.resources-wrap { position: relative; }
.resources-wrap > .help-btn { position: absolute; top: -9px; right: -6px; margin: 0; }
.allegiance .help-btn { width: 16px; height: 16px; font-size: 10px; margin-left: 2px; }
.legend-help { margin-right: 2px; }
.legend-help .help-btn { margin: 0; }
.help-pop {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(6, 4, 14, 0.6);
}
.help-pop[hidden] { display: none; }
.help-card {
  position: relative; width: 100%; max-width: 560px; max-height: 78vh; display: flex; flex-direction: column; gap: 10px;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--hull);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0;
}
.help-title { margin: 0 40px 0 0; font-family: var(--f-display); font-size: 20px; }
.help-body { overflow-y: auto; min-height: 0; flex: 1; border: 0; padding: 0; background: none; border-radius: 0; }
.help-body > p:first-child { margin-top: 0; }
.fold > summary > .help-btn { margin-left: 8px; margin-right: auto; }
.head-right { gap: 4px; }
.head-right .icon-btn { padding: 2px 5px; }

/* Admin: battles feed */
.battle-won { color: var(--signal); }
.battle-lost { color: var(--ink-dim); }
#battles-back { margin: 4px 0 12px; }

/* Admin statistics: last 24 hours */
.day-awards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.day-award { padding-block: 8px; }
.day-table-wrap { overflow-x: auto; margin-top: 10px; }
.day-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.day-table th { text-align: left; font-weight: 500; color: var(--ink-dim); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.day-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.day-table tbody tr { cursor: pointer; }
.day-table tbody tr:hover td { background: var(--hull-2); }
