/* =====================================================================================================
   Space Race client stylesheet
   -----------------------------------------------------------------------------------------------------
   Layout containers (index.html, fixed positions, all overlays over the full-screen #galaxy svg):
     #galaxy          full screen svg                     #top-left       turn + Score / New game buttons
     #command-list    top center, single scrollable line  #resources      top right, 3 rows (M, AP, Fleet)
    #top-bar         single non-wrapping row: #top-left (turn + Score), #messaging (hamburger),
    #top-right       #home-bar (Home button) and #resources; the two wrappers are display:contents
     #under-commands  below command list (centered)       #step-text      top center progression text
     #action-left     above selection, left               #action-right   above selection, right
     #selection       bottom 25% of the screen            #center-msg    toast in the middle
     #popup-layer     modal container
   Visibility helpers:
     .hidden          display:none (use on any element)
     .overlay         generic translucent panel look (already applied to layout containers)
     body.mode-<mode> set by main.js on every render: mode-default, mode-finished, mode-activation,
                      mode-progression, mode-deployment, mode-bombardment, mode-annihilation, mode-gameover
   Buttons:
     .btn             generic button (<button class="btn">)     .btn.primary   highlighted main action
     .btn.danger      red action                                .btn.small     compact button
     .btn.success     green action (e.g. vote given)            .btn.active    toggled on state
     .btn:disabled    greyed out, not clickable
     .icon-btn        small square text button, e.g. "+" / "-"  .remove-x      red "x" for removing entries
   Popups (inside #popup-layer):
     .popup-backdrop  full screen dim layer (click-catcher)     .popup         centered dialog box
     .popup h2/.popup-title   title          .popup-body   scrollable content   .popup-buttons  bottom bar
     .popup.wide      wider dialog (score table, battle report)
   Tabs:
     .tabs > .tab (.tab.active)               tab strip; content below is up to the module
   Lists / rows:
     .list            vertical scrollable box              .list-item     row inside (flex, space-between)
     .list-item.selected  highlighted choice               .list-item.clickable  hover/cursor
     .disabled        greyed entry (opacity + no pointer)  .queued        italic "queued" entries
     .indent          indented sub row (cargo lines)       .muted         secondary grey text
     .row             horizontal flex row with gap         .col           vertical flex column
     .spacer          flex:1 filler                        .right         text-align right / margin-left auto
     .error / .warn / .ok   red / orange / green text      .bad           red number (over budget)
   Player colors:
     .pc              inline player colored text: set style="color: <player color>" (adds text shadow)
     .swatch          small colored square: set style="background: <color>"
   Inputs:
     .num-input       small number box, with .icon-btn +/- around it
     .qty             wrapper row for "- [n] +"
   Tables:
     table.grid       compact table (score table, battle report); th/td; .num right aligned
   Command list:
     .cmd-entry       one command entry in #command-list    .cmd-entry.error  invalid command (red border)
     .cmd-entry .remove-x
   Selection view helpers:
     .sel-grid        two column grid for selection views   .sel-box   bordered scrollable sub box
     .sel-header      header line                           .pbox      html planet view box container
   Tooltip (long press / hover):
     .tooltip         absolutely positioned tooltip box (module positions it)
   Galaxy svg classes (galaxy.js): .hex, .hex.activated, .hex.current, .hex.path, .hex.selected, .hex.home,
     .storm, .sys-name, .ship-row, .planet-grp, .sb-text, .move-arrow, .anim-arrow
   ===================================================================================================== */

:root {
  --bg: #05070f;
  --panel: rgba(12, 18, 34, 0.86);
  --panel-solid: #0e1528;
  --panel-border: rgba(110, 150, 220, 0.35);
  --text: #dfe7f5;
  --muted: #8592ab;
  --accent: #4fa3ff;
  --accent-2: #7cc4ff;
  --danger: #ff5a5f;
  --danger-muted: #d96b6b;
  --warn: #ffb347;
  --ok: #5fd35f;
  --sel-h: 25vh;
  --gap: 6px;
  --radius: 6px;
  --font: 14px;
}

* { box-sizing: border-box; }

.tier-sup { font-size: 0.7em; vertical-align: super; line-height: 0; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

button, input, select { font: inherit; color: inherit; }

/* --------------------------------------------------------------------------------- galaxy svg */
#galaxy {
  position: fixed; inset: 0; width: 100vw; height: 100vh; display: block;
  background: radial-gradient(ellipse at 50% 45%, #111a36 0%, #070a17 55%, #03040a 100%);
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
}
#galaxy.dragging { cursor: grabbing; }
#galaxy text { font-family: "Segoe UI", Roboto, Arial, sans-serif; pointer-events: none; }
#galaxy .hit { cursor: pointer; }

#galaxy .hex { fill: rgba(20, 32, 64, 0.35); stroke: rgba(120, 160, 230, 0.35); stroke-width: 1.5; }
#galaxy .hex.home { fill: rgba(40, 40, 70, 0.45); }
#galaxy .hex.center-sys { fill: rgba(60, 40, 80, 0.40); }
/* activated/current: stroke + tint are set inline to the accented player color (galaxy.js);
   these values are fallbacks for spectators / missing colors. */
#galaxy .hex.activated { stroke: #ffd24a; stroke-width: 3.5; }
#galaxy .hex.path { stroke: #4fe0ff; stroke-width: 4; fill: rgba(40, 150, 200, 0.18); }
#galaxy .hex.selected { stroke: #ffffff; stroke-width: 3; }
#galaxy .hex.current { stroke: #ffe066; stroke-width: 6; fill: rgba(255, 210, 60, 0.12); }
#galaxy .hex.hl-deploy { stroke: #6cff9a; stroke-width: 6; fill: rgba(80, 255, 140, 0.10); }
#galaxy .hex.hl-tutorial { stroke: #ff4d4d; stroke-width: 6; fill: rgba(255, 80, 80, 0.10); }
#galaxy .hex.hl-bomb { stroke: #ff9a4d; stroke-width: 6; fill: rgba(255, 150, 70, 0.12); }
#galaxy .hex.hl-ann { stroke: #ff5a5a; stroke-width: 6; fill: rgba(255, 80, 80, 0.14); }
#galaxy .hex.hl-retreat { stroke: #ff7ad9; stroke-width: 6; fill: rgba(255, 110, 200, 0.14);
  animation: retreat-pulse 1.1s ease-in-out infinite; }
#galaxy .hex.hl-wormhole { stroke: #1b3a8f; stroke-width: 3.5; fill: rgba(27, 58, 143, 0.18); }
/* recap view: build activity (green) and population growth (cyan) hex borders */
#galaxy .hex.hl-build { stroke: #6cff9a; stroke-width: 5; fill: rgba(80, 255, 140, 0.10); }
#galaxy .hex.hl-growth { stroke: #4fe0ff; stroke-width: 5; fill: rgba(70, 200, 255, 0.10); }
#galaxy .hex.fog { fill: rgba(90, 96, 110, 0.3); stroke: none; }
#galaxy .retreat-edge { stroke: #ff7ad9; stroke-width: 5; stroke-dasharray: 10 8; opacity: 0.85;
  animation: retreat-pulse 1.1s ease-in-out infinite; }
@keyframes retreat-pulse { from { opacity: 0.45; } 50% { opacity: 1; } to { opacity: 0.45; } }
.popup-backdrop.bp-fade { animation: bp-fade-in 0.18s ease-out; }
.popup-backdrop.bp-fade.bp-hiding { animation: bp-fade-out 0.18s ease-in forwards; }
#galaxy .storm { fill: url(#storm-pattern); pointer-events: none; }
#galaxy .sys-name { fill: #8a93a6; font-weight: 600; }
#galaxy .sys-name.storm-name { fill: #6f88a8; }
.wormhole-spiral { opacity: 0.95; vertical-align: middle; }
#galaxy .sel-outline { fill: none; stroke: #fff; stroke-width: 1.5; stroke-dasharray: 3 2; pointer-events: none; }
#galaxy .move-arrow { font-weight: 700; }
#galaxy .anim-arrow { stroke-width: 4; fill: none; opacity: 0.9; }

/* ------------------------------------------------------------------------------ overlay panels */
.overlay {
  position: fixed; z-index: 10;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 4px 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  touch-action: pan-x pan-y;
}
.overlay:empty { display: none; }

/* The top bar is one non-wrapping flex row. On mobile the #top-left / #top-right
   wrappers are flattened (display:contents) so turn, Score, hamburger, Home and
   the resource box become direct row items and can never wrap. */
#top-bar {
  position: fixed; z-index: 10; top: 8px; left: 8px; right: 8px;
  --top-bar-h: 40px;
  display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center;
  justify-content: space-between; gap: 8px; pointer-events: none;
}
#top-bar > #top-left, #top-bar > #top-right { position: static; }

#top-left {
  display: flex; flex-direction: row; gap: 4px; align-items: center;
  padding: 0 8px; height: var(--top-bar-h); box-sizing: border-box;
  max-width: 30vw; pointer-events: auto;
}
#top-left .turn { font-weight: 700; font-size: 1.1em; white-space: nowrap; }
#top-left .sv-turn { font-weight: 700; font-size: 1.1em; white-space: nowrap; }
#top-left > .btn, #home-bar > .btn { height: var(--top-bar-h); min-height: 0; box-sizing: border-box; }

#command-list {
  /* flex item of #top-bar: fills the space between #top-left (turn + Score) and
     #top-right (hamburger / Home / resources) instead of overlapping them */
  position: static; flex: 1 1 auto; min-width: 0; pointer-events: auto;
  display: flex; flex-wrap: nowrap; gap: 6px; align-items: center;
  overflow: hidden; white-space: nowrap;
  min-height: 34px;
  background: rgba(6, 9, 18, 0.95);
}
#command-list:empty { display: flex; }
#command-list:empty::before { content: "No commands"; color: var(--muted); font-style: italic; }
body.mode-progression #command-list, body.mode-deployment #command-list, body.mode-bombardment #command-list, body.mode-annihilation #command-list, body.mode-gameover #command-list { display: none; }

#resources {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  /* min-height (not height): the box grows to fit its rows (material, AP, Fleet) and the top bar
     grows with it, while the other top-bar items keep their fixed height and stay centered */
  min-height: var(--top-bar-h); box-sizing: border-box;
}
#resources .res-row { display: flex; gap: 6px; justify-content: flex-end; }
#resources .sv-res-row { display: flex; gap: 6px; justify-content: flex-end; }
#resources .res-label { color: var(--muted); }

/* top-right row: message-board hamburger, Home button, then the resource output */
#top-right {
  display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 8px;
  margin-left: auto; pointer-events: auto;
}
/* the row children are laid out by #top-right, not by .overlay's fixed positioning */
#top-right > .overlay { position: static; right: auto; top: auto; }
#home-bar { display: flex; justify-content: flex-end; align-items: center; padding: 0; height: var(--top-bar-h); box-sizing: border-box; }

/* hamburger button sits left of the Home button */
#messaging {
  padding: 3px;
  height: var(--top-bar-h); box-sizing: border-box;
  display: flex; align-items: center;
}
#messaging .msg-toggle-wrap { display: inline-flex; }
body.mode-lobby #messaging { display: none; }

/* changelog cog button: its own box, left of the Home button (#home-bar); flattened into the
   top bar on small screens along with the rest of #top-right (see the responsive section) */
#cog-home {
  padding: 3px; height: var(--top-bar-h); box-sizing: border-box;
  display: flex; align-items: center;
}
#cog-home .cog-btn { align-self: center; }
body.mode-lobby #cog-home { display: none; }

/* hamburger button (three horizontal bars), drawn by views.renderMessaging */
.msg-toggle-wrap { position: relative; display: inline-flex; }
.msg-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 30px; cursor: pointer; border-radius: var(--radius);
  background: #1b2744; border: 1px solid #3a5388; box-sizing: border-box;
}
.msg-toggle:hover { border-color: var(--accent); }
.msg-toggle.unread { background: var(--danger); border-color: var(--danger); }
.msg-bars { display: inline-flex; flex-direction: column; justify-content: space-between; width: 20px; height: 14px; }
.msg-bar { display: block; width: 100%; height: 2px; background: var(--text); border-radius: 1px; }
.msg-toggle.unread .msg-bar { background: #fff; }
.msg-badge {
  position: absolute; top: -7px; right: -7px; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: #fff; color: var(--danger); font-size: 0.72em; font-weight: 700; line-height: 18px;
  text-align: center; pointer-events: none;
}

/* message board modal */
.msg-tabs { flex-wrap: wrap; }
.msg-tab { display: inline-flex; align-items: center; gap: 6px; }
.msg-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
.msg-list {
  display: flex; flex-direction: column; gap: 6px; min-height: 180px; max-height: 52vh;
  overflow-y: auto; padding: 6px; border: 1px solid var(--panel-border); border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.2);
}
/* full-screen board: the list fills the space left by the tabs and compose row */
.popup-body.msg-board { display: flex; flex-direction: column; overflow: hidden; }
.msg-board .msg-tabs { flex: none; }
.msg-board .msg-list { flex: 1 1 auto; max-height: none; min-height: 0; }
.msg-board .msg-compose { flex: none; }
.msg-empty { text-align: center; padding: 18px 0; }
.msg-row { display: flex; flex-direction: column; gap: 1px; max-width: 88%; }
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-meta { display: flex; align-items: baseline; gap: 6px; font-size: 0.82em; }
.msg-from { font-weight: 700; }
.msg-text { padding: 4px 8px; border-radius: 8px; background: #1b2744; white-space: pre-wrap; word-break: break-word; }
.msg-row.mine .msg-text { background: #1d5fb8; }
.msg-compose { display: flex; gap: 6px; margin-top: 8px; }
.msg-input { flex: 1 1 auto; min-width: 0; padding: 6px 8px; background: #0b1122; color: var(--text);
  border: 1px solid #3a5388; border-radius: var(--radius); }
.msg-input:focus { outline: none; border-color: var(--accent); }
@media (pointer: coarse) {
  .msg-toggle { width: 44px; height: 38px; }
  .msg-input { min-height: 40px; }
}

#under-commands {
  top: 50px; left: 50%; transform: translateX(-50%);
  max-width: min(70vw, 700px);
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
}
/* activation view: the "Activating X" line with Confirm / Deactivate and the cost is a box
   aligned to the right, under the top-right cluster (contents stay centered inside the box) */
#under-commands.sv-activation {
  left: auto; right: 8px; transform: none;
  align-items: center; text-align: center;
}

#step-text {
  top: 50px; left: 50%; transform: translateX(-50%);
  max-width: min(80vw, 800px); text-align: center; font-weight: 600; font-size: 1.1em;
}
body.mode-progression #step-text, body.mode-deployment #step-text, body.mode-bombardment #step-text, body.mode-annihilation #step-text { top: 8px; }

#action-left, #action-right {
  bottom: calc(var(--sel-h) + 6px);
  display: flex; gap: 6px; background: transparent; border: none; box-shadow: none; padding: 0;
}
#action-left { left: 8px; }
#action-right { right: 8px; }

/* Default view: "Recap" sits above "Finish" (a small vertical stack on the right) */
.sv-finish-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
/* Default view: "Council" sits above "Research" while a Galactic Council vote is held (left stack) */
.sv-research-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

/* recap view: the "Turn x recap" header (row 1) with the stage tape (row 2) below it, as one panel
   just under the top bar so the two rows can never overlap each other */
.recap-line { flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 90vw; }
.recap-chip {
  padding: 1px 7px; border-radius: 10px; font-size: 0.85em; cursor: pointer;
  background: rgba(30, 38, 60, 0.8); border: 1px solid var(--panel-border); color: var(--muted);
}
.recap-chip.shown { color: #cdd6f4; }
.recap-chip.current { background: #1d5fb8; border-color: #4fa3ff; color: #fff; font-weight: 600; }
/* recap view: the Exploration tab (the viewer's own discoveries), tinged like an unexplored star */
.recap-chip.explore { border-color: #4aa8ff; color: #9ccbff; }
.recap-chip.explore.current { color: #fff; }
.recap-exploration { max-height: 40vh; overflow-y: auto; }
/* recap view: the Asteroid field tab (the viewer's own stopped moves), tinged like an asteroid field */
.recap-chip.asteroid { border-color: #a9764a; color: #d8a877; }
.recap-chip.asteroid.current { color: #fff; }
.recap-asteroid { max-height: 40vh; overflow-y: auto; }
/* recap view: the battle-report buttons row under the stage tape */
.recap-reports { flex-wrap: wrap; justify-content: center; gap: 6px; }
.recap-reports .btn { padding: 1px 8px; min-height: 0; font-size: 0.82em; }
.recap-reports .btn.report-won { background: rgba(46, 160, 67, 0.5); border-color: #3fb950; }
.recap-reports .btn.report-lost { background: rgba(200, 50, 50, 0.5); border-color: #e05252; }
body.mode-recap #step-text { display: none; }
#under-commands.recap-panel {
  top: 54px; bottom: auto; left: 50%; right: auto; transform: translateX(-50%);
  max-width: min(92vw, 900px);
  align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); padding: 6px 10px; pointer-events: auto;
}
#under-commands.recap-panel .recap-header { font-weight: 700; font-size: 1.05em; white-space: nowrap; }

/* recap view: large horizontally-centered arrows on the left/right to step through the stages */
.recap-arrow {
  position: fixed; top: 50%; transform: translateY(-50%);
  z-index: 60; width: 54px; height: 84px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.6em; line-height: 1; color: #fff; cursor: pointer;
  background: rgba(20, 24, 40, 0.85); border: 1px solid var(--accent);
  border-radius: 10px; user-select: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  transition: opacity 0.12s ease-out;
}
.recap-arrow:hover { background: rgba(36, 52, 90, 0.95); }
.recap-arrow:active { transform: translateY(-50%) scale(0.96); }
#recap-arrow-left { left: 10px; }
#recap-arrow-right { right: 10px; }
.recap-arrow.disabled { opacity: 0.3; pointer-events: none; }
@media (pointer: coarse) {
  .recap-arrow { width: 46px; height: 72px; font-size: 2.2em; }
}

/* activation queue: always visible on the left (see System activation queue view) */
#action-left.sv-queue-panel {
  top: 92px; bottom: calc(var(--sel-h) + 6px);
  max-height: none;
  flex-direction: column; align-items: stretch; gap: 4px;
  width: max-content;
  min-width: 170px;
  max-width: min(300px, 60vw);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); padding: 6px 8px;
  overflow: hidden;
}
#action-left.sv-queue-panel .sv-queue-head { font-weight: 700; color: var(--accent-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* the "Queued in ..." head alone determines the panel width: entries collapse (ellipsis) to it */
#action-left.sv-queue-panel .sv-queue-box { flex: 0 1 auto; width: 0; min-width: 100%; min-height: 0; overflow-y: auto; overflow-x: hidden; font-size: 0.85em; scrollbar-width: none; -ms-overflow-style: none; }
#action-left.sv-queue-panel .sv-queue-box::-webkit-scrollbar { width: 0; height: 0; }
#action-left.sv-queue-panel .sv-queue-box .pp-group { margin: 5px 0 1px; font-size: 0.95em; overflow: hidden; }
#action-left.sv-queue-panel .sv-queue-box .pp-group:not(.pp-head-group) { white-space: nowrap; text-overflow: ellipsis; }
#action-left.sv-queue-panel .sv-queue-box .list-item { min-height: 0; padding: 1px 4px; gap: 4px; min-width: 0; }
/* cargo rows: taller with larger text for readability */
#action-left.sv-queue-panel .sv-queue-box .list-item.indent { min-height: 28px; padding: 3px 4px; gap: 8px; font-size: 1.05em; }
#action-left.sv-queue-panel .sv-queue-box .list { min-width: 0; overflow: visible; }
/* always keep at least the first 4 letters of an entry label visible when it collapses */
#action-left.sv-queue-panel .sv-queue-box .pp-qrow .pp-grow { min-width: 4ch; }
#action-left.sv-queue-panel .sv-queue-box .pp-qrow .remove-x { width: 28px; height: 28px; font-size: 1.1em; }
#action-left.sv-queue-panel .sv-queue-box .indent { padding-left: 8px; }
/* "Cargo load/cap" sub-header on each move group: larger for readability */
#action-left.sv-queue-panel .sv-queue-box .pp-head-group .pp-sub { font-size: 1.05em; padding: 2px 0; }
#action-left.sv-queue-panel .sv-queue-total {
  width: 0; min-width: 100%; box-sizing: border-box;
  border-top: 1px solid var(--panel-border); padding-top: 4px;
  font-variant-numeric: tabular-nums; color: var(--muted); text-align: right;
}
/* move-view action buttons: as thin as possible */
#action-left.sv-queue-panel .btn { padding: 1px 8px; min-height: 18px; font-size: 0.8em; line-height: 1.1; }
/* empty-queue hint: wrap into the panel width (driven by the "Queued in ..." head) so it never widens the panel */
#action-left.sv-queue-panel .pp-empty { width: 0; min-width: 100%; box-sizing: border-box; white-space: normal; overflow-wrap: anywhere; font-size: 0.85em; line-height: 1.25; }

#selection {
  left: 0; right: 0; bottom: 0; height: var(--sel-h); max-height: var(--sel-h);
  border-radius: 10px 10px 0 0; border-bottom: none;
  padding: 8px 10px; overflow: auto;
  background: rgba(10, 15, 30, 0.93);
}
#selection:empty { display: block; }
#selection:empty::before { content: "Nothing selected"; color: var(--muted); font-style: italic; }

#center-msg {
  position: fixed; z-index: 200; top: 42%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(20, 24, 40, 0.95); border: 1px solid var(--accent); color: #fff;
  padding: 10px 18px; border-radius: 8px; font-size: 1.1em; font-weight: 600;
  pointer-events: none; text-align: center; max-width: 80vw;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
  animation: toast-in 0.15s ease-out;
}
#center-msg.persistent { pointer-events: auto; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -40%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes bp-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes bp-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* ------------------------------------------------------------------------- lobby (start screen) */
#lobby {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 12px;
  background: radial-gradient(ellipse at 50% 45%, #111a36 0%, #070a17 55%, #03040a 100%);
  touch-action: pan-y;
}
#lobby .lobby-box {
  width: min(380px, 94vw); display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  background: var(--panel-solid); border: 1px solid #3a5388; border-radius: 10px;
  padding: 18px 20px; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8); text-align: center;
}
#lobby h1 { margin: 0; font-size: 1.6em; letter-spacing: 0.05em; }
#lobby .lobby-list { text-align: left; }
#lobby .lobby-list .list-item { gap: 8px; }
#lobby .lobby-status { margin-left: auto; }
#lobby .lobby-kick {
  padding: 0 8px; min-height: 24px; min-width: 24px; font-size: 0.9em;
  color: #ff6b6b; border-color: #a33; background: #2a1414; line-height: 1;
}
#lobby .lobby-kick:hover { color: #fff; background: #a33; border-color: #c55; }
#lobby .lobby-ready { font-size: 1.2em; min-height: 48px; }
#lobby .lobby-ready-box { width: min(440px, 96vw); max-height: 92vh; overflow-y: auto; }

/* lobby color picker (choose your player color) */
#lobby .lobby-colors { display: flex; flex-direction: column; gap: 6px; align-items: center; }
#lobby .lobby-color-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#lobby .lobby-color {
  width: 28px; height: 28px; min-width: 28px; padding: 0; border-radius: 6px;
  border: 2px solid var(--panel-border); cursor: pointer; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
#lobby .lobby-color:hover { border-color: var(--accent); }
#lobby .lobby-color.taken { opacity: 0.35; cursor: not-allowed; }
#lobby .lobby-color.taken:hover { border-color: var(--panel-border); }
#lobby .lobby-color.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* lobby "All" message board (in-game ready screen) */
#lobby .lobby-chat {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  border-top: 1px solid var(--panel-border); padding-top: 10px;
}
#lobby .lobby-chat-title { text-transform: uppercase; letter-spacing: 0.06em; text-align: center; }
#lobby .lobby-chat-list {
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
  max-height: 180px; min-height: 48px; padding: 4px 2px;
  background: #0b1122; border: 1px solid var(--panel-border); border-radius: 8px;
}
#lobby .lobby-chat-empty { text-align: center; padding: 12px 0; }
#lobby .lobby-chat-row { display: flex; gap: 6px; align-items: baseline; font-size: 0.92em; }
#lobby .lobby-chat-row.mine { justify-content: flex-end; }
#lobby .lobby-chat-from { color: var(--accent); font-weight: 700; flex: none; }
#lobby .lobby-chat-row.mine .lobby-chat-from { color: #9fd0ff; }
#lobby .lobby-chat-text { white-space: pre-wrap; word-break: break-word; }
#lobby .lobby-chat-compose { display: flex; gap: 6px; }
#lobby .lobby-chat-input {
  flex: 1 1 auto; min-width: 0; padding: 6px 8px; min-height: 34px;
  background: #0b1122; color: var(--text); border: 1px solid var(--panel-border); border-radius: 8px;
}
#lobby .lobby-chat-input:focus { outline: none; border-color: var(--accent); }
#lobby .lobby-name { text-align: center; padding: 6px 8px; min-height: 32px; }
#lobby .lobby-name-row { display: flex; align-items: center; gap: 8px; text-align: left; }
#lobby .lobby-name-row input { flex: 1 1 auto; min-width: 0; }
body.mode-lobby .overlay { display: none !important; }
body.mode-home .overlay { display: none !important; }

/* home page (three-tab lobby) */
#lobby .lobby-home { width: min(440px, 96vw); max-height: 92vh; overflow-y: auto; text-align: left; }
#lobby .lobby-home h1 { text-align: center; }
#lobby .lobby-home .lobby-name-row { text-align: left; }
#lobby .lobby-login { width: min(360px, 94vw); text-align: left; }
#lobby .lobby-login h1 { text-align: center; }
#lobby .lobby-login .lobby-name-row { text-align: left; }
.lobby-version { text-align: center; margin-top: -4px; margin-bottom: 4px; }
.lobby-login-actions { justify-content: center; gap: 8px; margin-top: 4px; }
.lobby-user-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border-bottom: 1px solid var(--panel-border); padding-bottom: 8px;
}
.lobby-user-name { font-size: 1.05em; color: #fff; }
.lobby-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--panel-border); }
.lobby-tab {
  padding: 6px 10px; cursor: pointer; color: var(--muted); font-size: 0.92em;
  border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0;
}
.lobby-tab:hover { color: var(--text); }
.lobby-tab.active { color: #fff; background: #1b2744; border-color: var(--panel-border); }
.game-section { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.game-section-title { border-bottom: 1px solid var(--panel-border); padding-bottom: 2px; }
.game-row { gap: 8px; }
.game-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-needed {
  flex: none; padding: 1px 6px; border-radius: 4px;
  background: #7a1616; border: 1px solid #c33; color: #fff;
  font-size: 0.8em; font-weight: bold; white-space: nowrap;
}
.game-meta { flex: none; font-variant-numeric: tabular-nums; }
.game-actions { flex: none; gap: 4px; flex-wrap: nowrap; }
.game-empty { padding: 8px 6px; text-align: center; font-style: italic; }
.lobby-footer { justify-content: flex-end; margin-top: 2px; }

#popup-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
#popup-layer > * { pointer-events: auto; }

/* ----------------------------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 14px; min-height: 32px;
  background: #1b2744; color: var(--text);
  border: 1px solid #3a5388; border-radius: var(--radius);
  cursor: pointer; white-space: nowrap; user-select: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.btn:hover { background: #24345a; border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: #1d5fb8; border-color: #4fa3ff; color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2470d6; }
.btn.danger { background: #6a1f25; border-color: #ff5a5f; }
.btn.danger:hover { background: #862a31; }
.btn.success { background: #1f6f3a; border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.success:hover { background: #278a48; }
.btn.active { background: #2b4d86; border-color: var(--accent-2); color: #fff; }
.btn.small { padding: 2px 8px; min-height: 24px; font-size: 0.9em; }
.btn:disabled, .btn.disabled {
  opacity: 0.4; cursor: not-allowed; pointer-events: none; box-shadow: none; transform: none;
}
.btn.link { background: none; border: none; box-shadow: none; color: var(--accent-2); text-decoration: underline; padding: 2px 4px; min-height: 0; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0; line-height: 1;
  background: #1b2744; border: 1px solid #3a5388; border-radius: 4px; cursor: pointer; font-weight: 700;
  flex: none;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.remove-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; padding: 0; margin-left: 4px;
  background: none; border: none; color: var(--danger); font-weight: 700; cursor: pointer; line-height: 1;
}
.remove-x:hover { color: #ff9095; }

/* ------------------------------------------------------------------------------------ popups */
.popup-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 12px;
  z-index: 100;
}
.popup-backdrop.fullscreen { padding: 0; }
.popup {
  background: var(--panel-solid); border: 1px solid #3a5388; border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
  width: min(460px, 94vw); max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
  touch-action: pan-y;
}
.popup.wide { width: min(760px, 96vw); }
.popup.fullscreen { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; border-radius: 0; border: none; }
.popup h2, .popup .popup-title {
  margin: 0; padding: 10px 14px; font-size: 1.1em; border-bottom: 1px solid var(--panel-border);
}
.popup .popup-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.popup .popup-title-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popup .popup-title-left { flex: 0 0 auto; display: flex; align-items: center; }
.popup .popup-title-right { flex: 0 0 auto; }
.popup .pp-res { display: flex; flex-direction: column; gap: 1px; font-size: 0.85em; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.popup .pp-effect { font-size: 0.9em; padding: 2px 0; }
.popup .popup-body { padding: 10px 14px; overflow-y: auto; flex: 1 1 auto; }
.popup > p { margin: 8px 14px; }
.popup-buttons {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--panel-border); background: rgba(0, 0, 0, 0.2);
}
.popup-buttons .summary { margin-right: auto; align-self: center; color: var(--muted); }

/* -------------------------------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--panel-border); margin-bottom: 8px; }
.tab {
  padding: 6px 12px; cursor: pointer; border: 1px solid transparent; border-bottom: none;
  border-radius: 6px 6px 0 0; color: var(--muted); background: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: #fff; background: #1b2744; border-color: var(--panel-border); }

/* ------------------------------------------------------------------------------------- lists */
.list {
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 4px; overflow-y: auto; background: rgba(0, 0, 0, 0.2);
}
.list-item {
  display: flex; align-items: center; gap: 6px; justify-content: space-between;
  padding: 4px 6px; border-radius: 4px; border: 1px solid transparent;
}
.list-item.clickable, .list-item[data-click] { cursor: pointer; }
.list-item.clickable:hover { background: rgba(80, 120, 200, 0.15); }
.list-item.selected { background: rgba(79, 163, 255, 0.22); border-color: var(--accent); }
.list-item.disabled:hover { background: none; }
.disabled { opacity: 0.4; cursor: not-allowed !important; }
.queued { font-style: italic; opacity: 0.85; }
.indent { padding-left: 18px; font-size: 0.92em; color: var(--muted); }

.row { display: flex; flex-direction: row; gap: var(--gap); align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.spacer { flex: 1 1 auto; }
.right { text-align: right; margin-left: auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
.sv-label { display: inline-flex; align-items: center; gap: 4px; }
.sv-toggle { min-width: 20px; min-height: 20px; padding: 0 5px; font-size: 0.9em; line-height: 1; }
.small { font-size: 0.88em; }
.bold { font-weight: 700; }
.error, .bad { color: var(--danger); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }

.pc { font-weight: 600; text-shadow: 0 0 2px rgba(0, 0, 0, 0.9); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

/* ------------------------------------------------------------------------------------ inputs */
.num-input {
  width: 48px; text-align: center; padding: 3px 4px;
  background: #0a1122; border: 1px solid #3a5388; border-radius: 4px;
  -moz-appearance: textfield; appearance: textfield;
}
.num-input::-webkit-outer-spin-button, .num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num-input.invalid { border-color: var(--danger); }
.qty { display: inline-flex; align-items: center; gap: 4px; }
select, input[type="text"] {
  background: #0a1122; border: 1px solid #3a5388; border-radius: 4px; padding: 3px 6px;
}
input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ------------------------------------------------------------------------------------ tables */
table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 3px 6px; border-bottom: 1px solid rgba(110, 150, 220, 0.18); text-align: left; }
table.grid th { color: var(--muted); font-weight: 600; }
table.grid .num, table.grid td.num, table.grid th.num { text-align: right; }
table.grid tr.total td { font-weight: 700; border-top: 1px solid var(--panel-border); }

/* ------------------------------------------------------------------------------ command list */
.cmd-entry {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  padding: 3px 6px 3px 8px; border-radius: 4px; background: #16213d; border: 1px solid #2d426e;
  cursor: pointer; font-size: 0.92em;
}
.cmd-entry:hover { border-color: var(--accent); }
.cmd-entry.error { border-color: var(--danger); color: #ffc3c5; }
.cmd-entry.editing { border-color: #ffd24a; background: #2d2a14; }
body.mode-finished .cmd-entry { cursor: default; }

/* --------------------------------------------------------------------------- selection views */
.sel-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; height: 100%; }
.sel-box {
  border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 4px 6px; overflow-y: auto; min-height: 0; background: rgba(0, 0, 0, 0.2);
}
.sel-header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 600; margin-bottom: 4px; }
.sel-header .title { font-size: 1.05em; }

/* HTML planet view box (views.js planetBox) */
.pbox { display: inline-flex; align-items: flex-start; gap: 4px; padding: 4px; border-radius: 6px; cursor: pointer; }
.pbox:hover { background: rgba(80, 120, 200, 0.15); }
.pbox .tower { display: flex; flex-direction: column-reverse; gap: 2px; align-self: center; }
.pbox .tower span { width: 8px; height: 8px; border: 1px solid #778; display: block; }
.pbox .circle {
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid currentColor;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9em;
  background: rgba(0, 0, 0, 0.35);
}
.pbox .land { display: flex; flex-direction: column; font-size: 0.85em; font-weight: 700; }
.pbox .bld { font-size: 0.8em; text-align: center; }

/* ---------------------------------------------------------------------------------- tooltip */
.tooltip {
  position: fixed; z-index: 300; max-width: 260px; pointer-events: none;
  background: #1a2238; border: 1px solid var(--accent); border-radius: 4px; padding: 4px 8px; font-size: 0.9em;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

/* ---------------------------------------------------------------- in-game rules wiki */
/* full-screen panel over everything (incl. popups and the changelog), opened by the selection-view "i" buttons */
#wiki-layer { position: fixed; inset: 0; z-index: 540; pointer-events: none; }
.wiki-panel {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 0%, #101a34 0%, #070b17 60%, #04060d 100%);
  pointer-events: auto; overflow: hidden;
}
.wiki-header {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 8px 12px; border-top: 1px solid var(--panel-border); background: var(--panel-solid);
}
.wiki-header .wiki-title { font-weight: 700; font-size: 1.1em; }
.wiki-header .wiki-spacer { flex: 1 1 auto; }
.wiki-header .wiki-nav { padding: 0 10px; min-width: 34px; font-size: 1.1em; line-height: 1; }
.wiki-search-row { position: relative; flex: none; display: flex; margin: 8px 12px; }
.wiki-search {
  flex: 1 1 auto; padding: 6px 10px;
  background: #0a1122; border: 1px solid #3a5388; border-radius: var(--radius); color: var(--text);
}
.wiki-search:focus { outline: none; border-color: var(--accent); }
.wiki-results {
  position: absolute; bottom: 100%; left: 0; right: 0; z-index: 5; margin-bottom: 2px;
  max-height: 40vh; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--panel-border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}
.wiki-result { padding: 6px 10px; cursor: pointer; }
.wiki-result:hover, .wiki-result:focus { background: rgba(80, 120, 200, 0.25); outline: none; }
.wiki-result.muted { cursor: default; }
.wiki-crumb {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 6px 12px; border-bottom: 1px solid var(--panel-border); color: var(--muted); font-size: 0.9em;
}
.wiki-crumb:empty { display: none; }
.wiki-crumb .wiki-view-name { color: var(--accent-2); font-weight: 600; }
.wiki-body { flex: 1 1 auto; overflow-y: auto; padding: 12px 16px 40px; line-height: 1.5; }
.wiki-body h2 { font-size: 1.25em; margin: 4px 0 8px; border-bottom: 1px solid var(--panel-border); padding-bottom: 3px; }
.wiki-body h2.wiki-page-title { font-size: 1.45em; color: #fff; }
.wiki-body h3 { font-size: 1.1em; margin: 12px 0 4px; }
.wiki-body h4, .wiki-body h5, .wiki-body h6 { font-size: 1em; margin: 10px 0 3px; }
.wiki-p { margin: 6px 0; }
.wiki-list { margin: 4px 0 4px 0; padding-left: 22px; }
.wiki-list.wiki-nested { margin: 2px 0; }
.wiki-list li { margin: 2px 0; }
.wiki-cont { margin: 3px 0 3px 4px; }
.wiki-link { color: var(--accent-2); cursor: pointer; text-decoration: underline dotted; }
.wiki-link:hover { color: #fff; text-decoration: underline solid; }
.wiki-link.missing { color: var(--muted); cursor: help; }
/* sv-info buttons (see selection views) */
.sv-info-btn { padding: 0 7px; min-width: 22px; min-height: 22px; font-weight: 700; line-height: 1; }
@media (pointer: coarse) { .sv-info-btn { min-width: 30px; min-height: 28px; } }

/* ------------------------------------------------------------------- cog menu (gear button) */
/* Shared by the home page (top-right of the lobby box) and the top bar (#cog-home, left of the
   Home button). The button opens a dropdown menu whose elements appear below it. */
.cog-menu { position: relative; display: inline-flex; }
#lobby .lobby-home { position: relative; }
#lobby .lobby-home .cog-menu { position: absolute; top: 14px; right: 14px; }
.cog-btn { padding: 0 8px; min-width: 28px; min-height: 28px; font-size: 1.15em; line-height: 1; }
.cog-menu.open .cog-btn { border-color: var(--accent); }
.cog-menu-list {
  position: absolute; top: 100%; right: 0; margin-top: 4px; z-index: 20; min-width: 140px;
  display: flex; flex-direction: column; padding: 4px;
  background: var(--panel-solid); border: 1px solid #3a5388; border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}
.cog-menu-item {
  text-align: left; padding: 8px 10px; cursor: pointer; color: var(--text);
  background: none; border: none; border-radius: var(--radius); font: inherit;
}
.cog-menu-item:hover { background: rgba(80, 120, 200, 0.25); }
.cog-menu.drop-up .cog-menu-list { top: auto; bottom: 100%; margin-top: 0; margin-bottom: 4px; }

/* ------------------------------------------------------------------------- changelog */
#changelog-layer { position: fixed; inset: 0; z-index: 520; pointer-events: none; }
/* battle calculator (full-screen page, below #popup-layer so the battle report opens on top) */
#battlecalc-layer { position: fixed; inset: 0; z-index: 90; pointer-events: none; }
.changelog-panel {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 0%, #101a34 0%, #070b17 60%, #04060d 100%);
  pointer-events: auto; overflow: hidden;
}
.changelog-body { flex: 1 1 auto; overflow-y: auto; padding: 20px 22px 28px; line-height: 1.5; }
.changelog-body h2.changelog-title {
  font-size: 1.5em; color: #fff; margin: 4px 0 12px;
  border-bottom: 1px solid var(--panel-border); padding-bottom: 6px;
}
.changelog-body h3, .changelog-body h4, .changelog-body h5, .changelog-body h6 { margin: 12px 0 4px; }
.changelog-footer {
  display: flex; align-items: center; gap: 10px; flex: none; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--panel-border); background: var(--panel-solid);
}
.changelog-nav { min-width: 84px; }
.changelog-nav:disabled { opacity: 0.35; pointer-events: none; }
.changelog-position { flex: 1 1 auto; text-align: center; }
.changelog-close { margin-left: auto; }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 6px; }
::-webkit-scrollbar-thumb { background: #2d426e; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------------------- responsive */
@media (max-width: 700px) {
  :root { --font: 13px; --sel-h: 25vh; }
  /* the top bar is one panel forced onto a single row: turn, Score,
     hamburger, Home, resource box. The wrappers are flattened. */
  #top-bar { gap: 4px; --top-bar-h: 30px; flex-wrap: nowrap; align-items: center; padding: 3px 6px;
    background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); }
  #top-bar > #top-left, #top-bar > #top-right { display: contents; }
  #top-bar .overlay { position: static; right: auto; top: auto; background: none; border: none; border-radius: 0; box-shadow: none; }
  #top-left > * { pointer-events: auto; }
  #top-left .sv-turn { font-size: 0.88em; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #top-left > .btn, #home-bar > .btn { padding: 0 7px; font-size: 0.88em; flex: none; min-height: 0; }
  #top-left > .btn, #home-bar > .btn, #messaging, #cog-home { height: var(--top-bar-h); }
  #resources { min-height: var(--top-bar-h); }
  #messaging, #cog-home { padding: 0 2px; }
  #top-bar .msg-toggle { width: 34px; height: var(--top-bar-h); }
  #resources { padding: 0; font-size: 0.86em; }
  #top-bar #command-list { position: fixed; top: auto; bottom: auto; left: 8px; right: 8px; transform: none; width: auto; flex: none; pointer-events: auto; top: 56px;
    background: rgba(6, 9, 18, 0.95); border: 1px solid var(--panel-border); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); }
  #under-commands { top: 104px; max-width: 94vw; }
  #step-text { top: 64px; max-width: 94vw; font-size: 1em; }
  body.mode-progression #step-text, body.mode-deployment #step-text, body.mode-bombardment #step-text, body.mode-annihilation #step-text { top: 64px; }
  .sel-grid { grid-template-columns: minmax(0, 1fr); height: auto; max-height: 100%; overflow-y: auto; }
  .btn { padding: 6px 10px; }
  .popup { width: 96vw; max-height: 92vh; }
  .popup.fullscreen { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; }
  #action-left.sv-queue-panel { max-width: 60vw; }
}
@media (max-height: 500px) and (orientation: landscape) {
  :root { --sel-h: 32vh; --font: 12px; }
}

/* ------------------------------------------------------------------------------- tutorial */
/* The tutorial overlay: full-screen, transparent to clicks except the centered popup (click gating
   is done in JS). A red rectangle and an arrow point at the explained control. */
#tutorial-layer { position: fixed; inset: 0; z-index: 110; pointer-events: none; }
.tut-rect { position: fixed; border: 2px solid #ff4d4d; border-radius: 6px; pointer-events: none;
  box-shadow: 0 0 0 2000px rgba(2, 4, 10, 0.55); }
.tut-arrow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* The box shrinks to its text and its position is computed in JS (tutorial.js `place()`) so it never
   covers the element it explains; the CSS only styles the panel and caps its width. */
.tut-popup { position: fixed; pointer-events: auto;
  width: fit-content; min-width: 0; max-width: min(420px, 92vw); max-height: 76vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.7); padding: 12px 14px; z-index: 115; }
/* A compact box: used for popOver steps and on small screens, where the repositioning is tighter. */
.tut-popup.tut-popup-compact { max-width: min(300px, 92vw); padding: 10px 12px; font-size: 0.92em; }
/* When a game modal is open (research / battle strategy / tier unlock) the box stops catching clicks so
   the modal's buttons stay clickable even if the box sits behind them. */
body.tut-modal .tut-popup { pointer-events: none; }
/* the box itself lets clicks through to the modal, but its own "Ok" button must stay clickable */
body.tut-modal .tut-popup .tut-ok { pointer-events: auto; }
/* while a modal is open the modal already dims the screen: do not dim it again with the marker */
body.tut-modal .tut-rect { box-shadow: none; }
.tut-text { display: flex; flex-direction: column; gap: 8px; }
/* shrink-wrapped box: let each line use its natural width instead of stretching to the container, and
   cap it with the same max-width as the popup so long text still wraps (no cyclic 100% dependency). */
.tut-popup .tut-text { width: max-content; max-width: min(420px, 92vw); }
.tut-popup.tut-popup-compact .tut-text { max-width: min(300px, 92vw); }
.tut-text .tut-line:first-child { font-weight: bold; font-size: 1.08em; }
.tut-text .tut-line { line-height: 1.4; }
.tut-actions { margin-top: 12px; display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.tut-wait { flex: 1; text-align: left; }
/* while the tutorial runs, the map cursor hints interaction is limited to the explained element */
body.tutorial-active #galaxy { cursor: default; }
.tut-home { min-width: 84px; }
.lobby-tutorial-btn { border-color: var(--accent); }

@media (max-width: 700px) {
  /* smaller panel on phones; its position is still computed in JS */
  .tut-popup { padding: 10px 12px; font-size: 0.94em; }
}

