/* ============================================================
   Pixel Galaxy v1.0 — design system
   One set of tokens, one panel style, one button style, one
   popup style, used on every screen. Plain CSS, no libraries.
   Tokens extend the original 4-colour palette (--bg/--hi/--mid/--fg).
   ============================================================ */
:root{
  --bg:#e6f4ff; --hi:#9ec5ee; --mid:#2a4f9a; --fg:#070b1f;
  color-scheme:light; box-sizing:border-box;
  /* v1.0 tokens */
  --panel:#e6f4ff; --panel-2:#d3e8fb; --ink:#070b1f; --ink-2:#33415e;
  --accent:#2a4f9a; --accent-2:#4fc3f7; --good:#2d7a46; --warn:#e0584a;
  --gold:#ffe066; --glass:rgba(230,244,255,.88); --glass-dark:rgba(7,11,31,.72);
  --radius:10px; --radius-sm:6px;
  --shadow:4px 4px 0 var(--mid); --shadow-sm:2px 2px 0 var(--mid);
  --hud-h:56px; --dock-h:64px; --tray-h:0px;
  --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px;
  --fs-title:20px; --fs-h:15px; --fs-body:14px; --fs-sm:12px;
  --lh:1.5; --lh-tight:1.3;
  padding-top:env(safe-area-inset-top,0px); padding-bottom:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    --bg:#070b1f; --hi:#1a2a63; --mid:#4fc3f7; --fg:#e6f4ff; color-scheme:dark;
    --panel:#0d1430; --panel-2:#16204a; --ink:#e6f4ff; --ink-2:#aab4c9;
    --accent:#4fc3f7; --glass:rgba(13,20,48,.88);
  }
}
:root[data-theme="dark"]{
  --bg:#070b1f; --hi:#1a2a63; --mid:#4fc3f7; --fg:#e6f4ff; color-scheme:dark;
  --panel:#0d1430; --panel-2:#16204a; --ink:#e6f4ff; --ink-2:#aab4c9;
  --accent:#4fc3f7; --glass:rgba(13,20,48,.88);
}
html{scroll-padding-top:env(safe-area-inset-top,0px)}
body{margin:0;background:var(--bg);color:var(--fg);font:var(--fs-body)/var(--lh) "Courier New",ui-monospace,monospace}
main{margin:0;padding:0;max-width:none}
h1{font-size:var(--fs-title);margin:4px 0 10px;letter-spacing:2px;line-height:var(--lh-tight)}
h2{font-size:var(--fs-h);margin:0 0 6px;line-height:var(--lh-tight);letter-spacing:1px}
small{opacity:.85;font-size:var(--fs-sm);line-height:var(--lh)}
[hidden]{display:none!important}
body{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
html{overscroll-behavior-y:none}
button{user-select:none;-webkit-user-select:none}

/* --- panels & rows: one card style everywhere --- */
.box,.card{border:3px solid var(--fg);border-radius:var(--radius);padding:var(--sp-3);margin-bottom:var(--sp-3);box-shadow:var(--shadow);background:var(--panel)}
.row{display:flex;justify-content:space-between;align-items:center;gap:var(--sp-2);padding:10px 0;border-bottom:1px solid var(--hi)}
.row:last-child{border-bottom:0}
.row>div{min-width:0}
.empty{display:block;padding:var(--sp-3);text-align:center;color:var(--ink-2);font-size:var(--fs-sm)}

/* --- buttons: one style, press feedback, 44px targets --- */
button{font:inherit;font-weight:bold;background:var(--fg);color:var(--bg);border:0;border-radius:var(--radius-sm);padding:8px 12px;min-height:44px;min-width:44px;cursor:pointer;transition:transform .12s ease,opacity .12s ease,background .12s ease}
button:active{transform:scale(.96)}
button:disabled{opacity:.35;cursor:default;transform:none}
button.mini{font-size:12px;padding:4px 8px;min-height:28px;min-width:0} /* v3.3: compact button for the raid quest's "Empire ›" link */
button.mini.on{background:var(--fg);color:var(--bg);border-color:var(--fg)} /* v3.8: the selected stance button reads as pressed (it used to look identical to the others) */
button:focus-visible{outline:3px solid var(--mid);outline-offset:2px}
button.secondary{background:none;color:var(--fg);border:2px solid var(--fg)}
.row>button{flex-shrink:0;white-space:nowrap} /* v3.1.3: a long "Requires…" line used to squeeze the Research button to "Resear…" on narrow screens — the button keeps its width and the text wraps instead */
.row>.bg{flex-shrink:0} /* v3.1.4: the Fleet ship-button grid is a nested flex child, so the v3.1.3 .row>button rule never reached it — the grid shrank under the long ship text and the one-word "Build"/"Scrap" buttons clipped to "Buil"/"Scra" (they can't wrap). The grid keeps its width now; the ship text wraps instead */

/* --- progress bars --- */
.pbar{height:10px;border:2px solid var(--fg);border-radius:5px;margin:6px 0;background:var(--hi);overflow:hidden}
.pbar div{height:100%;width:0;background:var(--mid);transition:width .3s ease}

/* ============================================================
   HUD — one slim glass strip. Translucent, so the map shows
   through at the edges; the camera safe area keeps map content
   out from under it (see game.js measureUI / safeCy).
   ============================================================ */
#top{position:fixed;top:0;left:0;right:0;z-index:15;padding:calc(4px + env(safe-area-inset-top,0px)) 8px 0;pointer-events:none}
#top .hud{pointer-events:auto;display:flex;align-items:center;gap:6px;margin:0;padding:4px 8px;background:var(--glass);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border:3px solid var(--fg);border-radius:var(--radius);box-shadow:var(--shadow-sm)} /* v3.2.1: NEVER give this bar a min-height tied to --hud-h again. measureUI() reads .hud offsetHeight (which includes its 4px padding + 3px border) and writes it into --hud-h every 250ms — with min-height feeding it back, the bar grew ~14px per tick until it covered the whole screen and ate every tap (cloud-browser diagnostic, v3.2). The bar's height is its content height now. */
#top .brand{font-weight:bold;letter-spacing:1px;font-size:13px;white-space:nowrap}
#menubtn{min-width:44px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg)}
#top .hudbtns{display:flex;gap:4px}
#top .hudbtns button{min-width:44px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg)}
#snd{min-height:36px}
@media (max-width:520px){#top .brand{display:none}}
/* v3.1.3 narrow HUD (live v3.1.2, phone): Hide + Sound ate ~140px of
   the bar, squeezing the four pills to ~40px — names truncated to
   EN…/ME…/CR…/CR… and amounts/rates clipped off. Both buttons
   already live in the hamburger menu, so they leave the HUD here;
   the pills then get ~73px each at 390px and the rate wraps under
   the amount instead of clipping. The storage chip also collided
   with the "Drag to pan" hint at this width ("…upgrade the
   Command…" bleeding through) — it hides here; storage lives in
   the HUD pills, tap the strip for details. */
@media (max-width:560px){
  #top .hudbtns{display:none}
  .res{gap:3px}
  .res .pill{padding:2px 3px 3px}
  .res .pill .pline{flex-wrap:wrap}
  .res .pill .rate{font-size:10px}
  .mapchip.capchip{display:none}
}

/* Resource chips: icon + amount + rate on ONE line, storage as a
   thin bar underneath. Tap the strip to expand storage detail. */
.res{flex:1;display:grid;grid-template-columns:repeat(4,1fr);gap:4px;min-width:0;cursor:pointer}
.res .pill{border:2px solid var(--fg);border-radius:var(--radius-sm);padding:3px 4px 4px;background:var(--panel);display:flex;flex-direction:column;align-items:stretch;line-height:var(--lh-tight);overflow:hidden;min-width:0}
.res .pill .rlabel{font-size:10px;line-height:1.2;color:var(--ink-2);letter-spacing:.5px;text-transform:uppercase;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.res .pill .pline{display:flex;align-items:center;gap:3px;white-space:nowrap;overflow:hidden}
.res .pill .ric{font-size:13px;line-height:1}
.res .pill b{font-size:14px;line-height:1.2;overflow:hidden;text-overflow:ellipsis}
.res .pill .rate{font-size:11px;line-height:1.2;color:var(--ink-2);white-space:nowrap}
.res .pill .sbar{height:4px;border:1px solid var(--fg);border-radius:2px;margin-top:3px;background:var(--hi);overflow:hidden}
.res .pill .sbar i{display:block;height:100%;width:0;background:var(--mid);transition:width .3s ease}
.res .pill .cap{display:none;font-size:11px;line-height:1.2;color:var(--ink-2);margin-top:2px;white-space:nowrap}
.res.expanded .pill .cap{display:block}
.res #inc{display:none;font-size:11px;line-height:1.5;color:var(--ink-2);margin-top:6px}
.res.expanded #inc{display:block} /* v3.3: income breakdown, only when the resource bar is expanded */
.res .dot-energy{color:#b8860b}.res .dot-metal{color:#7c849c}.res .dot-crystal{color:#2a9dc4}.res .dot-credits{color:#d07000}

/* ============================================================
   Slide-in menu + immersive mode
   ============================================================ */
#menubk{position:fixed;inset:0;z-index:30;background:rgba(7,11,31,.6);border:0}
#menu{position:fixed;top:0;left:0;bottom:0;z-index:31;width:min(320px,86vw);background:var(--panel);border-right:3px solid var(--fg);box-shadow:6px 0 0 var(--mid);padding:calc(12px + env(safe-area-inset-top,0px)) 12px 12px;transform:translateX(-102%);transition:transform .22s ease;display:flex;flex-direction:column;gap:6px}
#menu.open{transform:translateX(0)}
.menuhead{display:flex;justify-content:space-between;align-items:center}
.menu-title{font-size:var(--fs-title);font-weight:bold;letter-spacing:2px}
.menu-sub{font-size:var(--fs-sm);color:var(--ink-2);margin:0 0 6px}
.mitem{display:flex;align-items:center;gap:10px;width:100%;text-align:left;background:var(--panel-2);color:var(--fg);border:2px solid var(--fg);border-radius:var(--radius-sm);padding:10px 12px;min-height:48px}
.mitem .ic{font-size:17px}
.mitem .chev{margin-left:auto;opacity:.6}
.mitem.danger{border-color:var(--warn);color:var(--warn)}
.menu-foot{margin-top:auto;font-size:var(--fs-sm);color:var(--ink-2)}
#mclose{min-width:44px;background:none;color:var(--fg);border:2px solid var(--fg)}
#uishow{position:fixed;left:10px;top:calc(10px + env(safe-area-inset-top,0px));z-index:25;width:44px;height:44px;border-radius:50%;background:var(--glass);color:var(--fg);border:2px solid var(--fg);box-shadow:var(--shadow-sm)}
/* Immersive mode: hide every piece of chrome, keep only #uishow. */
body.ui-hidden #top,body.ui-hidden #tabs,body.ui-hidden .mapctl,body.ui-hidden #mm,body.ui-hidden .mapchip{opacity:0;pointer-events:none}
body.ui-hidden #uishow{display:block}
#top,#tabs,.mapctl,#mm,.mapchip{transition:opacity .2s ease}

/* --- toasts --- */
#toasts{position:fixed;left:0;right:0;bottom:calc(84px + env(safe-area-inset-bottom,0px));z-index:15;display:flex;flex-direction:column;align-items:center;gap:6px;pointer-events:none}
.toast{background:var(--fg);color:var(--bg);padding:8px 12px;max-width:min(92vw,520px);border:2px solid var(--mid);border-radius:var(--radius-sm);font-weight:bold;animation:toastIn .18s ease}
/* v3.4 RAID WARNING — a red banner under the HUD, visible on every
   tab while a raid is incoming. It is NOT a popup, so the player can
   still tap through to reinforce the garrison. */
#raidwarn{position:fixed;top:calc(var(--hud-h) + 10px + env(safe-area-inset-top,0px));left:8px;right:8px;z-index:14;background:#7a1f1f;color:#fff;border:3px solid #ff6a5e;border-radius:var(--radius-sm);padding:8px 10px;font-size:13px;line-height:1.5;box-shadow:var(--shadow-sm)}
#raidwarn button{margin-left:6px;background:#ff6a5e;color:#fff;border-color:#fff}
#raidwarn button:disabled{opacity:.45}
/* v3.4 SAVE EXPORT/IMPORT — the save text is long, so the textareas
   span the modal and use a small monospace font. */
#savetxt,#imptxt{width:100%;box-sizing:border-box;font-family:monospace;font-size:11px;min-height:90px;margin:6px 0;background:var(--bg);color:var(--fg);border:2px solid var(--fg);border-radius:var(--radius-sm);padding:6px}
@keyframes toastIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}

/* --- v1.5 activity tray: every timed job, visible on every screen ---
   Slim rows above the dock; the tray counts toward the safe-area inset
   (game.js measureUI), so map content never hides under it. Hidden
   when nothing is running. Same tokens / progress-bar style / 44px
   tap targets as the rest of the v1.0 design system. */
#activity{position:fixed;left:8px;right:8px;bottom:calc(var(--dock-h) + 12px + env(safe-area-inset-bottom,0px));z-index:14;display:flex;flex-direction:column;gap:6px;pointer-events:none}
.actjob{pointer-events:auto;display:flex;align-items:center;gap:8px;width:100%;min-height:44px;padding:6px 10px;background:var(--glass);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);color:var(--fg);border:2px solid var(--fg);border-radius:var(--radius-sm);box-shadow:var(--shadow-sm);text-align:left}
.actjob .actic{font-size:16px}
.actjob .actname{font-size:var(--fs-sm);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:0 1 auto}
.actjob .actbar{flex:1 1 60px;height:10px;border:2px solid var(--fg);border-radius:5px;background:var(--hi);overflow:hidden;min-width:48px}
.actjob .actbar i{display:block;height:100%;width:0;background:var(--mid)}
.actjob .acttime{font-size:var(--fs-sm);white-space:nowrap}
/* v3.2: Hobbit-style collapsible tray. The summary row is the only
   thing visible by default; the job list expands above it and is
   capped at 2 rows + a peek of the third (146px) so it scrolls
   instead of eating the screen. */
.traysum{pointer-events:auto;display:flex;align-items:center;gap:8px;width:100%;min-height:44px;padding:6px 10px;background:var(--glass);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);color:var(--fg);border:2px solid var(--fg);border-radius:var(--radius-sm);box-shadow:var(--shadow-sm);text-align:left}
.traysum .traychev{font-size:14px}
.traylist{pointer-events:auto;display:flex;flex-direction:column;gap:6px;max-height:146px;overflow-y:auto}
body.ui-hidden #activity{opacity:0;pointer-events:none}

/* --- popups: one centred card style, fade/scale in --- */
#bbox,#hbox,#rbox,#pop,#end,#savebox,#impbox{position:fixed;inset:0;z-index:20;background:rgba(7,11,31,.8);display:flex;align-items:center;justify-content:center;padding:16px} /* v3.8: #savebox/#impbox were missing from this rule, so Export/Import rendered invisibly behind the map canvas */
.bpanel{background:var(--panel);width:100%;max-width:440px;max-height:80vh;overflow-y:auto;margin:0;animation:popIn .18s ease}
/* v3.2 battle report card: big canvas, header lines, result banner. */
.bpanel #bt{width:100%;height:auto;display:block;image-rendering:pixelated}
.bsub{font-size:var(--fs-sm);color:var(--ink-2);margin:2px 0 8px}
.bfleets,.bpow{font-size:var(--fs-sm);margin:8px 0 0}
.bresult{margin:10px 0}
.bresult .bwin{font-size:20px;font-weight:700;color:#ffe066;margin-bottom:6px}
.bresult .blose{font-size:20px;font-weight:700;color:#ff6b6b;margin-bottom:6px}
@keyframes popIn{from{opacity:0;transform:scale(.96) translateY(6px)}to{opacity:1;transform:none}}
#hlog .row{display:block;font-size:13px}
#pop{z-index:20}
#pop-panel{text-align:left}
.pophead{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-bottom:6px}
.pophead h2{margin:0;font-size:17px;letter-spacing:1px}
#pop-x{min-width:48px;min-height:48px;padding:4px 12px;background:none;color:var(--fg);border:2px solid var(--fg)}
#pop-hero{width:96px;height:96px;margin:0 auto 10px;border:3px solid var(--fg);border-radius:var(--radius-sm);background:#0a0e2a;image-rendering:pixelated}
#pop-body{margin-bottom:10px}
#pop-body .stat{display:flex;justify-content:space-between;gap:8px;padding:4px 0;border-bottom:1px solid var(--hi);font-size:var(--fs-sm)}
#pop-body .stat:last-child{border-bottom:0}
#pop-actions{display:flex;flex-direction:column;gap:6px}
#pop-actions button{min-width:0;width:100%;min-height:48px} /* v1.4: touch targets >=48px */

/* --- page headers (menu pages) --- */
.pagehead{display:flex;align-items:baseline;gap:10px;margin:4px 0 10px}
.pagehead h2{margin:0;font-size:var(--fs-title);letter-spacing:1px}
.pagehead .page-sub{font-size:var(--fs-sm);color:var(--ink-2)}
.pagehead button{min-width:44px;min-height:36px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg)}
#shero,#bhero{width:160px;height:160px;margin:0 auto 12px;border:3px solid var(--fg);background:#0a0e2a}
#bhero{background:#c98a5a}

/* --- bottom dock: slim floating glass icon dock --- */
#tabs{position:fixed;left:50%;transform:translateX(-50%);bottom:calc(8px + env(safe-area-inset-bottom,0px));z-index:10;display:flex;gap:2px;width:min(560px,calc(100vw - 16px));background:var(--glass);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border:3px solid var(--fg);border-radius:var(--radius);box-shadow:var(--shadow);padding:4px}
#tabs button{flex:1 1 0;min-width:0;min-height:52px;padding:4px 2px;background:none;color:var(--fg);border:2px solid transparent;border-radius:var(--radius-sm);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;font-size:11px;position:relative}
#tabs button .ic{font-size:17px;line-height:1}
#tabs button.on{background:var(--fg);color:var(--bg)}
#tabs button:active{transform:scale(.95)}
#tabs .badge{position:absolute;top:2px;right:6px;min-width:18px;height:18px;line-height:18px;background:#e0584a;color:#fff;border:2px solid var(--fg);border-radius:9px;font-size:11px;text-align:center;padding:0 3px}
.emp-row{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:10px 0;border-bottom:1px solid var(--hi)}
.emp-row:last-child{border-bottom:0}
.emp-row button{min-width:0;min-height:44px;padding:4px 10px}

/* ============================================================
   Maps — full screen. The canvas IS the screen on Galaxy /
   Station; HUD + dock float over it as glass. The camera safe
   area (game.js) keeps map content out from under them.
   ============================================================ */
section[data-pg="map"],section[data-pg="station"]{position:fixed;inset:0;z-index:1}
section[data-pg="station"] .mapwrap{background:#c98a5a}
section[data-pg="fleet"],section[data-pg="research"],section[data-pg="quests"],section[data-pg="empire"],section[data-pg="log"]{max-width:560px;margin:0 auto;padding:calc(var(--hud-h) + 20px + env(safe-area-inset-top,0px)) 12px calc(var(--dock-h) + 24px)}
.mapwrap{position:absolute;inset:0;border:0;margin:0;background:#0a0e2a}
.mapwrap #cv,.mapwrap #st{border:0;margin:0;display:block;touch-action:none;width:100vw;height:100dvh;max-width:none;image-rendering:pixelated;image-rendering:crisp-edges}
canvas{image-rendering:pixelated;image-rendering:crisp-edges}
#mm{position:fixed;top:calc(var(--hud-h) + 16px + env(safe-area-inset-top,0px));right:8px;width:96px;height:120px;border:2px solid var(--fg);border-radius:var(--radius-sm);margin:0;background:#0a0e2a;cursor:pointer;z-index:2} /* v3.3: bigger — it was ~70px and too small to read or tap reliably */
/* v1.7: the minimap is FIXED to the viewport, not absolute inside the
   map wrap — at ~1100px wide and below it was clipped by the right
   edge of the screen (live v1.6), which only happens if its
   containing block is wider than the viewport. Fixed + right:8px
   makes it inside the viewport by construction. It also shrinks at
   narrow widths so it never crowds the hint chip, and it is never
   half-clipped: full minimap or (below 360px) a small one. */
@media (max-width:700px){#mm{width:72px;height:90px}}
@media (max-width:420px){#mm{width:60px;height:75px}}
.mapctl{position:absolute;left:6px;bottom:calc(var(--dock-h) + var(--tray-h,0px) + 16px + env(safe-area-inset-bottom,0px));display:flex;gap:4px;z-index:2} /* v3.1.5: the tray used to cover these buttons — both were anchored at dock-h, and the tray (dock-h+12px, ~56px tall) painted over them whenever a job ran. The controls now lift by the live tray height */
.mapctl button{min-width:44px;min-height:44px;padding:4px 10px;background:var(--glass);color:var(--fg);border:2px solid var(--fg);border-radius:var(--radius-sm)}
.mapctl button.on{background:var(--fg);color:var(--bg)} /* v2.5: sector toggle — the active sector reads as pressed, same as the dock tabs */
.mapchip{position:absolute;z-index:2;background:var(--glass);color:var(--fg);border:2px solid var(--fg);border-radius:var(--radius-sm);padding:4px 8px;font-size:12px}
.mapchip.hint{top:calc(var(--hud-h) + 16px + env(safe-area-inset-top,0px));left:8px;max-width:60vw}
.mapchip.capchip{top:calc(var(--hud-h) + 16px + env(safe-area-inset-top,0px));right:8px}
.mapchip.bqchip{left:8px;bottom:calc(var(--dock-h) + var(--tray-h,0px) + 70px + env(safe-area-inset-bottom,0px));max-width:60vw} /* v3.2.1: the one-builder status line — baseUI() is dead (v0.9.2 removed #binfo), so this chip is the line's home; it lifts with the tray like the map controls */
/* v3.4 NEXT STEP — one line naming the current bottleneck. On the
   Station tab it sits above the builder chip; on the Galaxy tab it
   sits under the hint. Same text, both tabs. */
.mapchip.nextchip{left:8px;bottom:calc(var(--dock-h) + var(--tray-h,0px) + 102px + env(safe-area-inset-bottom,0px));max-width:60vw;background:#1a2a4a;color:#cfe0ff;border-color:#6a8fd0}
#nextstep-g{top:calc(var(--hud-h) + 52px + env(safe-area-inset-top,0px));bottom:auto;max-width:60vw}
.mapchip.mvcancel{right:8px;bottom:calc(var(--dock-h) + var(--tray-h,0px) + 70px + env(safe-area-inset-bottom,0px));cursor:pointer;font:inherit} /* v3.2.2: Cancel for Move/Place mode — the mode had no exit (no button, Escape ignored it) and persisted until reload; shown only while S.mv or S.place is set */ /* v3.2.3: this selector was misspelled in v3.2.2 (one wrong letter), so the chip got no positioning and never rendered bottom-right — the class name must match index.html exactly */
#sec-note{left:6px;bottom:calc(var(--dock-h) + var(--tray-h,0px) + 68px + env(safe-area-inset-bottom,0px));max-width:72vw} /* v2.9: sits just above the map controls, only while viewing Sector 2 without Jump Drive. v3.5.3: the bottom offset now includes --tray-h (it didn't) — when a job ran, the tray lifted the Sector 1/2 buttons up into the note and the note covered the Sector 1 button so the player couldn't return to Sector 1. The note now lifts with the tray and always sits 8px above the buttons. */
#tech .row.locked,#tech .row.done{opacity:.55} /* v2.9: locked/done tech rows stay visible but greyed */
#pagefoot{max-width:560px;margin:0 auto;padding:calc(var(--hud-h) + 20px) 12px calc(var(--dock-h) + var(--tray-h,0px) + 24px)} /* v3.2.7: bottom padding now includes --tray-h — without it, the fixed jobs tray covered the last row of scrollable lists (Research/Crew/Empire) until the player scrolled */
body:has(section[data-pg="map"]:not([hidden])) #pagefoot,body:has(section[data-pg="station"]:not([hidden])) #pagefoot{display:none}
#log{min-height:2.8em;margin:0 0 12px}
#reset{background:none;color:var(--fg);border:2px solid var(--fg);min-height:36px;font-weight:normal}
.ttl{display:flex;justify-content:space-between;align-items:center;gap:8px}
.bg{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.bg button{min-width:0;padding:6px 8px;min-height:48px} /* v1.4: popup Place buttons >=48px */

/* --- v1.3 tutorial: overlay card, map visible behind it. The wrapper
   never blocks the map (pointer-events none); only the card is clickable. */
#tut{position:fixed;left:0;right:0;bottom:calc(var(--dock-h) + 24px);z-index:18;display:flex;justify-content:center;padding:0 16px;pointer-events:none}
#tut .tutcard{pointer-events:auto;width:100%;max-width:440px;margin:0;animation:popIn .18s ease}
.tuthead{display:flex;justify-content:space-between;align-items:center;gap:8px}
.tuthead h2{margin:0}
#tut-skip{min-width:0;min-height:36px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg)}
#tut-col{min-width:0;min-height:36px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg);font-size:18px;line-height:1}
#tut-body{margin:8px 0}
#tut-dots{display:flex;gap:6px;justify-content:center;margin:6px 0 10px}
#tut-dots .dot{width:9px;height:9px;border-radius:50%;border:2px solid var(--fg);background:transparent}
#tut-dots .dot.on{background:var(--fg)}
.tutbtns button{min-height:44px}
.tutbtns{grid-template-columns:1fr 1fr 1fr}
#tut-step{display:block;text-align:center;font-size:12px;opacity:.75;margin:2px 0 0}
#tut.mini .tutcard{padding:10px 12px}
#tut.mini #tut-body{font-size:14px;margin:6px 0}
#tut.mini #tut-dots{margin:4px 0 6px}
/* --- v3.1: while a game popup is open, the tutorial card collapses
     to a slim bar (title + step + Skip). The popup (z 20) sits above
     the card (z 18) and used to cover its top half (live v3.0,
     steps 6/7). Shrinking the card can only reduce the overlap,
     never cover a popup button; tutLayout() removes the class when
     the popup closes and the card expands again. --- */
#tut.pop-open #tut-body,#tut.pop-open #tut-dots,#tut.pop-open .tutbtns,#tut.collapsed #tut-body,#tut.collapsed #tut-dots,#tut.collapsed .tutbtns{display:none}
#tut.pop-open .tutcard,#tut.collapsed .tutcard{padding:6px 12px}
#tut.pop-open #tut-step,#tut.collapsed #tut-step{margin:0}
/* --- v3.9.35: online tutorial card — same overlay card as single
     player, online ids. Same collapse rules (popup/card open, or the
     chevron): slim bar with the body, dots and buttons hidden. --- */
#o-tut{position:fixed;left:0;right:0;bottom:calc(var(--dock-h) + 24px);z-index:18;display:flex;justify-content:center;padding:0 16px;pointer-events:none}
#o-tut .tutcard{pointer-events:auto;width:100%;max-width:440px;margin:0;animation:popIn .18s ease}
#o-tut-skip{min-width:0;min-height:36px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg)}
#o-tut-col{min-width:0;min-height:36px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg);font-size:18px;line-height:1}
#o-tut-body{margin:8px 0}
#o-tut-dots{display:flex;gap:6px;justify-content:center;margin:6px 0 10px}
#o-tut-dots .dot{width:9px;height:9px;border-radius:50%;border:2px solid var(--fg);background:transparent}
#o-tut-dots .dot.on{background:var(--fg)}
#o-tut-step{display:block;text-align:center;font-size:12px;opacity:.75;margin:2px 0 0}
#o-tut.mini .tutcard{padding:10px 12px}
#o-tut.mini #o-tut-body{font-size:14px;margin:6px 0}
#o-tut.mini #o-tut-dots{margin:4px 0 6px}
#o-tut.pop-open #o-tut-body,#o-tut.pop-open #o-tut-dots,#o-tut.pop-open .tutbtns,#o-tut.collapsed #o-tut-body,#o-tut.collapsed #o-tut-dots,#o-tut.collapsed .tutbtns{display:none}
#o-tut.pop-open .tutcard,#o-tut.collapsed .tutcard{padding:6px 12px}
#o-tut.pop-open #o-tut-step,#o-tut.collapsed #o-tut-step{margin:0}
/* --- v3.2.5: the tutorial card is collapsible (Jayden, phone, step 10:
     the full card covered most of the Galaxy map, so he could not see
     or tap the Pirate Outpost while following the step). The chevron
     in the title row toggles .collapsed: slim bar (title + step +
     Skip + expand chevron) with the body, dots and buttons hidden, so
     the map stays visible while the player acts. The choice persists
     in localStorage; on a narrow screen (<=560px) a step starts
     collapsed unless the player already chose expanded. --- */
@media (max-width:560px){#tut .tutcard{padding:12px}#tut-body{max-height:26vh;overflow-y:auto}}
/* --- v3.0 tutorial highlight: pulsing gold ring on the real UI
     element the step is about, so the eye goes there first. --- */
.tut-hl{outline:3px solid #ffd84a!important;outline-offset:2px;border-radius:8px;box-shadow:0 0 0 6px rgba(255,216,74,.25),0 0 18px rgba(255,216,74,.6);animation:tutPulse 1.2s ease-in-out infinite}
@keyframes tutPulse{50%{box-shadow:0 0 0 10px rgba(255,216,74,.12),0 0 26px rgba(255,216,74,.85)}}

/* v3.4 TAB GRAPHICS — Fleet ship sprites, commander portraits
   and tech icons, quest icons. These make the four tabs read at a
   glance instead of as bare text rows. */
.shipimg{image-rendering:pixelated;vertical-align:middle;margin-right:6px;background:#0a0e2a;border:2px solid var(--mid);border-radius:4px}
.cmdav{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:50%;font-weight:bold;font-size:16px;color:#fff;margin-right:8px;vertical-align:middle;border:2px solid var(--fg)}
.cmdav-fleet{background:#a33}
.cmdav-econ{background:#3a7}
.cmdav-build{background:#36a}
.techic{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:6px;background:var(--mid);font-size:15px;margin-right:8px;vertical-align:middle}
.questic{font-size:18px;margin-right:6px;vertical-align:middle}
.row.claimable{border-color:#ffb02e;box-shadow:0 0 0 2px rgba(255,176,46,.35)}

/* v3.5 RESEARCH TREE — the 18 techs as a tree: lanes by family, depth
   rows, SVG connectors. #tech scrolls sideways on a phone so each 156px
   lane stays readable. Nodes keep the #tr-/#tc-/#tb- ids so update()
   works unchanged. */
#tech{overflow-x:auto;padding-bottom:6px}
.techtree{display:grid;grid-template-columns:repeat(7,172px);grid-template-rows:30px repeat(5,190px);row-gap:14px;column-gap:16px;position:relative;min-width:max-content}
#techsvg,#o-techsvg{position:absolute;inset:0;pointer-events:none;z-index:0}
.techlane{grid-row:1;display:flex;align-items:center;justify-content:center;gap:6px;font-size:12px;font-weight:bold;letter-spacing:.5px;border-bottom:2px solid var(--fg);padding-bottom:4px;white-space:nowrap}
#tech .treenode,#o-techtree .treenode{position:relative;z-index:1;flex-direction:column;align-items:stretch;justify-content:flex-start;gap:3px;padding:6px 8px;border:2px solid var(--fg);border-radius:var(--radius-sm);background:var(--panel);font-size:11px;line-height:1.3;overflow:hidden}
#tech .treenode .tn-head,#o-techtree .treenode .tn-head{display:flex;align-items:center;gap:4px;flex-wrap:wrap}
#tech .treenode .tn-head b,#o-techtree .treenode .tn-head b{font-size:12px}
#tech .treenode .techic,#o-techtree .treenode .techic{width:22px;height:22px;font-size:12px;margin-right:0;flex-shrink:0}
#tech .treenode small,#o-techtree .treenode small{display:block}
#tech .treenode button,#o-techtree .treenode button{margin-top:auto;min-height:28px;font-size:12px;padding:4px 8px}
.techlink{fill:none;stroke:var(--fg);stroke-width:2;opacity:.3}
.techlink.done{stroke:#ffb02e;opacity:1}

/* v3.9.0 ONLINE MODE + MODE SELECT — the shared galaxy. #modesel is a
   full-screen overlay (same pattern as the other modals). #online is a
   full-screen column: ribbon, galaxy, activity tray, tab dock — the same
   shell as single player (#top / #activity / #tabs). v3.9.20: the old
   per-overlay top bars ("Back to galaxy" + resource line) and the bottom
   #o-bar are gone; every online view shares the ribbon and the tabs. */
#modesel{position:fixed;inset:0;z-index:30;background:rgba(7,11,31,.88);display:flex;align-items:center;justify-content:center;padding:16px}
#modesel .bpanel{text-align:center}
#modesel .bg{display:flex;flex-direction:column;gap:8px;margin:12px 0}
#online{position:fixed;inset:0;z-index:10;display:flex;flex-direction:column;background:var(--bg);color:var(--fg);overflow-x:hidden}
#online *{box-sizing:border-box}
#o-top{padding:calc(4px + env(safe-area-inset-top, 0px)) 8px 0}
#o-top .hud{display:flex;align-items:center;gap:6px;margin:0;padding:4px 8px;background:var(--glass);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border:3px solid var(--fg);border-radius:var(--radius);box-shadow:var(--shadow-sm)}
#o-top .brand{font-weight:bold;letter-spacing:1px;font-size:13px;white-space:nowrap}
#o-menubtn{min-width:44px;padding:4px 10px;background:none;color:var(--fg);border:2px solid var(--fg)}
@media (max-width:520px){#o-top .brand{display:none}}
#o-menubk{position:fixed;inset:0;z-index:30;background:rgba(7,11,31,.6);border:0}
#o-menu{position:fixed;top:0;left:0;bottom:0;z-index:31;width:min(320px,86vw);background:var(--panel);border-right:3px solid var(--fg);box-shadow:6px 0 0 var(--mid);padding:calc(12px + env(safe-area-inset-top,0px)) 12px 12px;transform:translateX(-102%);transition:transform .22s ease;display:flex;flex-direction:column;gap:6px}
#o-menu.open{transform:translateX(0)}
#o-main{position:relative;flex:1 1 auto;min-height:0;display:flex;flex-direction:column;overflow:hidden}
#ocv{flex:1 1 auto;width:100%;min-height:0;touch-action:none;display:block;background:#0a0e2a}
#o-activity{margin:6px 8px 0;display:flex;flex-direction:column;gap:6px}
#o-activity .trayrow{background:var(--panel);border:2px solid var(--fg);border-radius:var(--radius-sm);padding:6px 10px;font-size:12px}
#o-tabs{display:flex;gap:2px;width:100%;background:var(--glass);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border-top:3px solid var(--fg);padding:4px 8px calc(4px + env(safe-area-inset-bottom,0px))}
#o-tabs button{flex:1 1 0;min-width:0;min-height:52px;padding:4px 2px;background:none;color:var(--fg);border:2px solid transparent;border-radius:var(--radius-sm);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;font-size:11px;position:relative}
#o-tabs button .ic{font-size:17px;line-height:1}
#o-tabs button.on{background:var(--fg);color:var(--bg)}
#o-tabs button:active{transform:scale(.95)}
#o-tabs button .qbadge{position:absolute;top:2px;right:6px;min-width:16px;height:16px;padding:0 4px;border-radius:8px;background:var(--warn);color:#fff;font-size:10px;line-height:16px;text-align:center;font-weight:700}
#o-panel{border-top:2px solid var(--fg);background:var(--panel);padding:10px 12px;max-height:38vh;overflow-y:auto;overflow-x:hidden}
#o-panel .ocard h2{margin:0 0 4px;font-size:17px;letter-spacing:1px}
#o-panel .ocard small{font-size:12px;line-height:1.5}
#o-panel input{width:100%;font:inherit;padding:10px;border:2px solid var(--fg);border-radius:var(--radius-sm);background:var(--bg);color:var(--fg);margin:8px 0}
.obtn{font:inherit;font-weight:bold;background:var(--fg);color:var(--bg);border:0;border-radius:var(--radius-sm);padding:10px 14px;min-height:44px;cursor:pointer}
.obtn.big{min-height:52px;font-size:16px}
.obtn.ghost{background:none;color:var(--fg);border:2px solid var(--fg)}
.obtn.sel{outline:3px solid var(--accent,#6ee7f5);outline-offset:1px} /* v3.9.27: selected production toggle */
#o-toast{position:fixed;left:50%;bottom:120px;transform:translateX(-50%);z-index:25;background:var(--fg);color:var(--bg);padding:10px 14px;border-radius:var(--radius-sm);font-weight:bold;font-size:13px;max-width:90vw;text-align:center;box-shadow:var(--shadow)}
/* v3.9.14 STATION — an overlay over the galaxy view inside #o-main,
   same layout as #online: canvas, chips, popup. */
#o-station{position:absolute;inset:0;z-index:15;display:flex;flex-direction:column;background:var(--bg);color:var(--fg);overflow-x:hidden}
#o-station *{box-sizing:border-box}
/* v3.9.16: the station canvas fills the space like single player's
   .mapwrap #st (100vw x 100dvh); chips float over it, and the popup
   (#o-st-pop) mirrors the single-player #pop exactly. */
#o-st-wrap{position:relative;flex:1 1 auto;min-height:0;overflow:hidden}
#ostcv{position:absolute;inset:0;width:100%;height:100%;touch-action:none;display:block;image-rendering:pixelated;image-rendering:crisp-edges}
#o-st-wrap .mapchip.hint{top:8px;left:8px;max-width:60vw}
#o-st-wrap .mapchip.capchip{display:block;top:8px;right:8px}
#o-st-wrap .mapchip.bqchip{left:8px;bottom:8px;max-width:60vw}
#o-st-wrap .mapchip.mvcancel{right:8px;bottom:8px;cursor:pointer;font:inherit}
/* v3.9.38: #o-st-pop is position:absolute inside #o-main (it was
   position:fixed, so the panel centred in the full viewport and its top
   — the pinned header with the X — ended up behind the ribbon on a tall
   popup on Jayden's phone). Same pattern as #o-fleet / #o-research, so
   the header + X are always visible within the main area. */
#o-st-pop{position:absolute;inset:0;z-index:20;background:rgba(7,11,31,.8);display:flex;align-items:center;justify-content:center;padding:16px}
#o-st-pop-panel{text-align:left}
#o-st-pop-x{min-width:48px;min-height:48px;padding:4px 12px;background:none;color:var(--fg);border:2px solid var(--fg)}
/* v3.9.38: the online system card is a centered popup like single-player
   #pop (Jayden: the bottom sheet took half the screen and cut the Crystal
   button off). Full-screen dimming overlay, centered panel, header with
   the system name + X, scrollable body — the card's own actions (Attack,
   setprod, garrison, Close) live inside the body. */
#o-syspop{position:fixed;inset:0;z-index:20;background:rgba(7,11,31,.8);display:flex;align-items:center;justify-content:center;padding:16px}
#o-syspop-panel{text-align:left;width:100%;max-width:480px;display:flex;flex-direction:column;max-height:85vh;max-height:85dvh;overflow:hidden}
#o-syspop-x{min-width:48px;min-height:48px;padding:4px 12px;background:none;color:var(--fg);border:2px solid var(--fg)}
/* v3.9.38: the Battle report must be tappable from every tab — the Fleet /
   Research / Quests overlays (z-index 15) cover the panel the report used
   to live in. #o-outcome is a top banner above them (same geometry as
   #raidwarn, z-index 25 like the toast). */
#o-outcome{position:fixed;top:calc(var(--hud-h) + 10px + env(safe-area-inset-top,0px));left:8px;right:8px;z-index:25}
#o-outcome .ocard{margin:0}
/* v3.9.38: the production picker is a compact 2x2 grid of small buttons
   (the old full-width obtns pushed Crystal off the bottom of the sheet).
   The label spans the full row; the four resource buttons fill the 2x2. */
#o-syspop-body .prodpick{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin:6px 0}
#o-syspop-body .prodpick-label{grid-column:1 / -1}
#o-syspop-body .prodpick .obtn{min-height:36px;padding:6px 8px;font-size:13px}
/* v3.9.18 (Phase 2): the Fleet view mirrors the single-player Fleet tab.
   An overlay inside #o-main like the station: a scrollable panel with
   the power breakdown, ship rows, and the shipyard queue. */
#o-fleet{position:absolute;inset:0;z-index:15;display:flex;flex-direction:column;background:var(--bg);color:var(--fg);overflow-x:hidden}
#o-fleet *{box-sizing:border-box}
#o-fl-body{flex:1;overflow-y:auto;padding:12px}
#o-fl-body .ocard{margin:0 auto 12px;max-width:640px}
#o-fl-body .shiprow{display:flex;justify-content:space-between;gap:10px;padding:10px 0;border-bottom:1px solid var(--hi)}
#o-fl-body .shiprow:last-child{border-bottom:0}
#o-fl-body .shiprow .bg{display:flex;flex-direction:column;gap:6px;align-items:stretch}
#o-fl-body .shiprow .bg button{min-width:64px}
#o-fl-body .pbar{height:8px;background:var(--hi);border-radius:4px;overflow:hidden;margin-top:6px}
#o-fl-body .pbar div{height:100%;background:var(--ac,#ffd84a);width:0%}
#o-research{position:absolute;inset:0;z-index:15;display:flex;flex-direction:column;background:var(--bg);color:var(--fg);overflow-x:hidden}
#o-quests{position:absolute;inset:0;z-index:15;display:flex;flex-direction:column;background:var(--bg);color:var(--fg);overflow-x:hidden}
#o-quests *{box-sizing:border-box}
#o-q-body{flex:1;overflow-y:auto;padding:12px}
#o-q-body .ocard{margin:0 auto 12px;max-width:640px}
#o-research *{box-sizing:border-box}
#o-res-body,#o-cr-body{flex:1;overflow-y:auto;padding:12px}
#o-res-body .ocard,#o-cr-body .ocard{margin:0 auto 12px;max-width:640px}
#o-res-body .techtree-wrap{overflow-x:auto;padding-bottom:4px}
#o-res-body .ocard.otree-card{max-width:none} /* v3.9.21: the tree spans the full body width like single-player #tech (scrolls sideways on a phone); the 640px cap is for the status card only */
#o-res-body .pbar{height:8px;background:var(--hi);border-radius:4px;overflow:hidden;margin-top:6px}
#o-res-body .pbar div{height:100%;background:var(--ac,#ffd84a);width:0%}
#o-st-pop-hero{width:96px;height:96px;margin:0 auto 10px;border:3px solid var(--fg);border-radius:var(--radius-sm);background:#0a0e2a;image-rendering:pixelated}
#o-st-pop-body{margin-bottom:10px}
#o-st-pop-body .stat{display:flex;justify-content:space-between;gap:8px;padding:4px 0;border-bottom:1px solid var(--hi);font-size:var(--fs-sm)}
#o-st-pop-body .stat:last-child{border-bottom:0}
#o-st-pop-actions{display:flex;flex-direction:column;gap:6px}
#o-st-pop-actions button{min-width:0;width:100%;min-height:48px}
/* v3.9.26: popup panels are flex columns — the header (with the close
   button) and the actions stay pinned; only the body scrolls. Before,
   the whole panel scrolled as one unit, so on a phone the close button
   scrolled off the top once the build list was longer than the screen. */
#pop-panel,#o-st-pop-panel{display:flex;flex-direction:column;max-height:calc(100vh - 32px);max-height:calc(100dvh - 32px);overflow:hidden}
#pop-panel>.pophead,#o-st-pop-panel>.pophead,#o-syspop-panel>.pophead,#pop-hero,#o-st-pop-hero,#pop-actions,#o-st-pop-actions{flex-shrink:0}
#pop-body,#o-st-pop-body,#o-syspop-body{flex:1 1 auto;min-height:0;overflow-y:auto}
