#v2-top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  /* Grow into the notch / status-bar area on phones (viewport-fit=cover) so the
     bar's content still sits below it. No-op where the inset is 0. */
  height: calc(44px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(10, 10, 15, 0.92);
  border-bottom: 1px solid var(--neon-muted);
  backdrop-filter: blur(8px);
  font-family: var(--font-body);
  font-size: 13px;
  z-index: 10;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  /* Keep clear of a side notch in landscape. */
  padding: 0 calc(16px + env(safe-area-inset-right, 0px)) 0 calc(16px + env(safe-area-inset-left, 0px));
  height: 44px;
}
/* The resource/stat readouts cluster. Grouped so it can shrink and scroll
   horizontally on narrow screens while the MENU button stays pinned and
   reachable (see the mobile breakpoint below). */
.topbar-stats {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}
.topbar-res {
  display: inline-flex;
  align-items: center;
}
/* The section header and per-row resource names exist only for the phone stats
   menu; the inline desktop bar stays a tight icon+value strip. */
.topbar-stats-head { display: none; }
.topbar-res-name { display: none; }
/* Mobile-only toggle that pops the resource/stat box out of the bar. Hidden on
   desktop, where the stats sit inline (shown at the ≤640px breakpoint below). */
.topbar-stats-toggle {
  display: none;
  width: auto;
  gap: 4px;
  align-items: center;
}
.topbar-stats-glance {
  color: var(--neon-primary);
  font-weight: 600;
  font-size: 12px;
}
.topbar-res b {
  color: var(--neon-primary);
  font-weight: 600;
  margin-left: 2px;
}
/* Per-resource icon tints now come from the global .ll-icon[data-res=…] rule in
   main.css (icon() stamps the data-res key), so every gold/food/wood/gems glyph
   reads the same here and everywhere else. The value text stays cyan. */
/* Slightly larger glyphs so the detail survives at the 13px bar size. */
.topbar-res .ll-icon { font-size: 1.25em; margin-right: 3px; }
.topbar-sep {
  color: #2a2f38;
  font-weight: 400;
}
.topbar-dim {
  color: var(--ink-muted);
  font-size: 11px;
  margin-left: 4px;
}
.topbar-btn {
  background: transparent;
  border: 1px solid var(--neon-muted);
  color: var(--neon-primary);
  width: 30px; height: 28px;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  position: relative;
}
.topbar-btn:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--neon-primary);
}
.topbar-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 14px;
  height: 14px;
  padding: 0 2px;
  border-radius: 7px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-family: var(--font-label, Inter, sans-serif);
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  pointer-events: none;
}
.topbar-goto {
  font-family: var(--font-body);
  font-size: 12px;
  width: 80px;
  padding: 3px 6px;
  background: var(--bg-primary);
  border: 1px solid var(--neon-muted);
  border-radius: var(--border-radius-sm, 2px);
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition-fast, 200ms);
}
.topbar-goto:focus {
  border-color: var(--neon-primary);
}
.topbar-goto.invalid {
  border-color: var(--danger);
}
.topbar-goto-btn {
  font-size: 11px;
  padding: 0 8px;
  width: auto;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.topbar-fps {
  color: var(--ink-muted);
  margin-left: auto;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;   /* digits don't jitter as the count ticks */
}
/* Perf-gauge states (set by TopBar.setFps). Tokens from :root in main.css. */
.topbar-fps.fps-good { color: var(--success); }
.topbar-fps.fps-warn { color: var(--warning); }
.topbar-fps.fps-bad  { color: var(--danger); }
.topbar-legacy-link {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid var(--neon-muted);
  padding: 4px 10px;
}
.topbar-legacy-link:hover {
  color: var(--neon-primary);
  border-color: var(--neon-primary);
}

/* ── Menu dropdown (consolidated panel launchers) ───────────────────────────
   Classic-RTS system menu: one ☰ button instead of a long icon row, so the bar
   stays a clean resource strip and works at low resolution. */
.topbar-menu-toggle {
  width: auto;
  padding: 0 10px;
  margin-left: auto;            /* push menu + goto + fps to the right edge */
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  letter-spacing: 1px;
}
.topbar-menu-label { font-size: 11px; }
.topbar-menu-toggle.active {
  background: var(--neon-tint-strong, rgba(0, 212, 255, 0.18));
  border-color: var(--neon-primary);
}
.topbar-fps { margin-left: 8px; }   /* the toggle now owns the auto-margin */

.topbar-menu {
  position: absolute;
  top: calc(44px + env(safe-area-inset-top, 0px));
  right: 8px;
  min-width: 248px;
  /* Never run down over the bottom-right minimap; scroll vertically only if the
     screen is tiny. overflow-x stays hidden so a slightly-wide item can never
     promote overflow-x to `auto` and pop a horizontal scrollbar. */
  max-height: calc(100vh - 264px);
  overflow: hidden auto;
  background: rgba(13, 17, 23, 0.98);
  border: 1px solid var(--neon-muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 2px;
}
.topbar-menu-item {
  width: 100%;
  height: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.topbar-menu-item:hover { background: var(--neon-tint, rgba(0, 212, 255, 0.10)); }
.topbar-menu-item.active { background: var(--neon-tint-strong, rgba(0, 212, 255, 0.18)); }
.tmi-icon  { width: 18px; text-align: center; font-size: 14px; }
.tmi-label { flex: 1; white-space: nowrap; }
.tmi-key {
  color: var(--neon-primary);
  border: 1px solid var(--neon-muted);
  border-radius: 2px;
  padding: 0 5px;
  font-size: 10px;
}
.topbar-menu-legacy { color: var(--ink-muted, var(--ink-muted)); border-top: 1px solid var(--neon-muted); margin-top: 2px; }

/* Go-to popover — opened from the menu or the 'C' shortcut; centred under the
   bar, opaque, transient. */
.topbar-goto-pop {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(13, 17, 23, 0.98);
  border: 1px solid var(--neon-muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  font-family: var(--font-body);
}
.topbar-goto-pop .tgp-label {
  color: var(--neon-primary);
  font-size: 11px;
  letter-spacing: 1.5px;
}
.topbar-goto-pop .topbar-goto { width: 110px; }
.topbar-goto-pop .topbar-goto-btn { font-size: 11px; padding: 0 10px; text-transform: uppercase; letter-spacing: 1px; }

/* Low-resolution (tablets and down): tighten spacing, drop the secondary text +
   the MENU label, and — since the resource strip can no longer fit — let it
   scroll horizontally (swipe) while the MENU button stays pinned at the right
   edge and always tappable. */
@media (max-width: 820px) {
  .topbar-inner { gap: 10px; padding: 0 calc(8px + env(safe-area-inset-right, 0px)) 0 calc(8px + env(safe-area-inset-left, 0px)); }
  .topbar-dim { display: none; }
  .topbar-menu-label { display: none; }
  .topbar-goto { width: 62px; }
  .topbar-stats {
    flex: 1 1 auto;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;              /* Firefox: hide the scrollbar track */
    -webkit-overflow-scrolling: touch;  /* momentum scroll on iOS */
  }
  .topbar-stats::-webkit-scrollbar { display: none; }  /* WebKit */
  /* Readouts keep their natural width and scroll rather than squashing. */
  .topbar-stats > .topbar-res,
  .topbar-stats > .topbar-sep { flex: 0 0 auto; white-space: nowrap; }
  /* MENU owns its own slot at the right; the flex stats push it there, so it no
     longer needs (or wants) the auto margin. */
  .topbar-menu-toggle { margin-left: 0; flex: 0 0 auto; }
}

/* Phones: shrink the type, drop the non-essential FPS readout, and let the menu
   dropdown span edge-to-edge for easier tapping. The resource/stat strip no
   longer scrolls inside the cramped bar — instead it collapses into a pop-out
   box behind a chart-icon toggle (with the gold count as an at-a-glance value),
   freeing the bar for just the two toggles. */
@media (max-width: 640px) {
  #v2-top-bar { font-size: 12px; }
  .topbar-inner { gap: 8px; }
  .topbar-menu-toggle { height: 32px; }
  /* Keep the FPS readout visible on phones — it's the at-a-glance perf gauge,
     and mobile is exactly where frame drops bite. Pin it to the left slot
     (before the stats toggle) so it never collides with the right-edge MENU. */
  .topbar-fps { display: inline; order: -1; margin: 0 4px 0 0; font-size: 10px; }
  /* The top-right MENU is free to grow to (almost) the full viewport height and
     scroll internally, rather than being clamped well short of the bottom. */
  .topbar-menu {
    left: 8px; right: 8px; min-width: 0;
    max-height: calc(100dvh - 44px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 8px);
  }

  /* The toggle takes the left slot and pushes MENU to the right edge. Force
     width:auto here — the base .topbar-btn rule (equal specificity, later in
     source) otherwise pins it to 30px and the gold glance value spills out. */
  .topbar-stats-toggle { display: inline-flex; width: auto; height: 32px; padding: 0 10px; margin-right: auto; }

  /* The stat cluster becomes an edge-to-edge dropdown "empire" menu under the
     bar, shown only while `stats-open` is set on the root. Overrides the
     horizontal-scroll strip the ≤820px rule applies. Styled to read as a proper
     terminal panel: cyan-edged, 2px corners, internally scrollable. */
  .topbar-stats {
    position: absolute;
    top: calc(44px + env(safe-area-inset-top, 0px)); left: 8px; right: 8px;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0 0 4px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100dvh - 52px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    background: rgba(13, 17, 23, 0.98);
    border: 1px solid var(--neon-muted);
    border-radius: var(--border-radius-sm, 2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    z-index: 20;
    display: none;
  }
  #v2-top-bar.stats-open .topbar-stats { display: flex; }

  /* Section header — matches the "// QUEUE" terminal heading convention. */
  .topbar-stats-head {
    display: block;
    position: sticky;
    top: 0;
    z-index: 1;
    font-family: var(--font-heading);
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--neon-primary);
    padding: 9px 10px;
    background: rgba(13, 17, 23, 0.98);
    border-bottom: 1px solid var(--neon-muted);
  }

  /* Vertical dot separators read oddly in a stacked list — drop them. */
  .topbar-stats > .topbar-sep { display: none; }
  /* Roomy, tap-friendly rows: icon + name on the left, value + rate aligned to
     the right with a hairline divider between readouts. */
  .topbar-stats > .topbar-res {
    width: 100%;
    justify-content: flex-start;
    padding: 11px 12px;
    font-size: 14px;
    border-bottom: 1px solid var(--neon-tint, rgba(0, 212, 255, 0.10));
  }
  .topbar-stats > .topbar-res:last-of-type { border-bottom: none; }
  .topbar-res-name {
    display: inline;
    flex: 1 1 auto;
    margin-left: 8px;
    color: var(--ink);
    font-size: 14px;
  }
  /* Push the value (and the rate/detail that trail it) to the right edge. */
  .topbar-stats > .topbar-res > b { margin-left: auto; }
  /* There's room for the secondary detail (worker cap, renown) here, so bring
     the dimmed spans back that the ≤820px rule hides. */
  .topbar-stats .topbar-dim { display: inline; }

  /* The build/recruit queue, relocated into the stats menu by topBar.js. Strip
     its floating-widget chrome so it reads as the menu's final section. */
  .topbar-stats #v2-queue-panel {
    position: static;
    inset: auto;
    width: 100%;
    max-height: none;
    overflow: visible;
    background: none;
    border: none;
    border-top: 1px solid var(--neon-muted);
    box-shadow: none;
    border-radius: 0;
    padding: 10px 12px 4px;
    z-index: auto;
  }
}

/* ── Per-tick rate spans ─────────────────────────────────────────────────── */
.topbar-rate {
  font-family: var(--font-body);
  font-size: 10px;
  margin-left: 4px;
  letter-spacing: 0.5px;
  vertical-align: middle;
}
.topbar-rate.positive {
  color: var(--success, #00ff88);
}
.topbar-rate.negative {
  color: var(--danger, #ff3344);
}
.topbar-rate.dim {
  color: var(--ink-muted);
}

/* ── Maintenance warning tint ────────────────────────────────────────────── */
.topbar-res-warn b {
  color: var(--warning, #ffaa00);
}

/* ── Hover tooltip ───────────────────────────────────────────────────────── */
.topbar-tooltip {
  position: fixed;
  z-index: 9999;
  width: 240px;
  background: var(--bg-secondary, #0d1117);
  border: 1px solid var(--neon-muted, #004d66);
  border-radius: var(--border-radius-sm, 2px);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink, #e6edf3);
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
.topbar-tooltip .tt-header {
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--neon-primary, #00d4ff);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--neon-muted, #004d66);
  padding-bottom: 6px;
}
.topbar-tooltip .tt-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.topbar-tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 1.4;
}
.topbar-tooltip .tt-secondary {
  opacity: 0.8;
  padding-left: 10px;
}
.topbar-tooltip .tt-sub {
  color: var(--ink-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 6px;
  margin-bottom: 2px;
}
.topbar-tooltip .tt-note {
  color: var(--ink-muted);
  font-size: 11px;
  margin-top: 4px;
}
.topbar-tooltip .tt-warn {
  color: var(--warning, #ffaa00);
  font-size: 11px;
  margin-top: 6px;
}
/* Inherit rate colors inside tooltip */
.topbar-tooltip .topbar-rate.positive { color: var(--success, #00ff88); }
.topbar-tooltip .topbar-rate.negative { color: var(--danger, #ff3344); }
.topbar-tooltip .topbar-rate.dim      { color: var(--ink-muted); }

/* Phase-5 bind updates: a changed counter replays this tick so the number
   visibly moves the frame an action (or a pushed collection) lands. */
.bind-bump {
  display: inline-block; /* transforms don't apply to inline boxes */
  animation: bind-bump var(--transition-medium, 300ms) ease-out;
}
@keyframes bind-bump {
  0%   { transform: translateY(-2px); color: var(--neon-primary); }
  100% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .bind-bump { animation: none; }
}
