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

[hidden] {
  display: none !important;
}

/* ── STARFIELD CANVAS ───────────────────────────────────────────────────── */

#starfield {
  height: 100vh;
  left: 0;
  pointer-events: none;
  position: fixed;
  top: 0;
  width: 100vw;
  z-index: -1;
}

/* ── ROOT LAYOUT ────────────────────────────────────────────────────────────
   #app is centered via margin: auto regardless of the sidebar.
   .narrative-sidebar is position:fixed to the right of the centered game —
   it is a sibling (not a child) of #app, so the blackout filter on #app
   does NOT affect it.
   ────────────────────────────────────────────────────────────────────────── */

body {
  background: #000;
  color: #00ff88;
  font-family: 'Courier New', Courier, monospace;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Simple wrapper — no flex needed; #app self-centers. */
#layout-root {
  height: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin: 0 auto;    /* game panel always centered in the viewport */
  max-width: 680px;
  width: 100%;
}

/* ── STICKY TOP ─────────────────────────────────────────────────────────── */

.sticky-top {
  background: #000;
  border-bottom: 1px solid #1a4430;
  flex-shrink: 0;
  z-index: 50;
}

/* ── GAME HEADER ─────────────────────────────────────────────────────────── */

.game-header {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 16px 14px;
}

.header-title-row {
  align-items: baseline;
  display: flex;
  gap: 14px;
}

.title {
  font-size: 1.6rem;
  font-weight: normal;
  letter-spacing: 0.3em;
}

.subtitle {
  color: #2a6644;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
}

.counter {
  font-size: 2.6rem;
  letter-spacing: 0.08em;
  text-align: center;
  text-shadow: 0 0 18px rgba(0, 255, 136, 0.22);
}

/* §D — Burst flash: brief glow when a pulse burst fires */
.pulse-burst-flash {
  animation: burst-flash 0.3s ease-out forwards;
}

@keyframes burst-flash {
  0%   { text-shadow: 0 0 40px rgba(0, 255, 136, 0.9), 0 0 80px rgba(0, 255, 136, 0.5); }
  100% { text-shadow: 0 0 18px rgba(0, 255, 136, 0.22); }
}

/* Production + entropy on the same row — entropy only visible when revealed */
.header-status-row {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;       /* never wrap — row is always exactly one line tall */
  gap: 0 20px;
  height: 1.4em;           /* fixed height — text changes never resize the header */
  justify-content: center;
  overflow: hidden;
  width: 100%;
}

.production {
  color: #00ff88;
  flex-shrink: 0;          /* production value never gets squeezed */
  font-size: 0.95rem;
  letter-spacing: 0.1em;
}

.entropy-status {
  color: #78c99c;
  flex-shrink: 1;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  min-width: 0;            /* allow shrinking inside flex */
  overflow: hidden;
  pointer-events: none;
  text-overflow: ellipsis;
  white-space: nowrap;     /* never wrap to a second line */
}

/* §C — New two-zone entropy status classes */
.entropy-status-warning  { color: #fff0a6; }
.entropy-status-blackout { color: #ff4444; font-weight: bold; animation: blackout-pulse 0.8s ease-in-out infinite alternate; }
/* Keep old names as aliases so any cached renders don't break */
.entropy-status-distortion-rising { color: #fff0a6; }
.entropy-status-unstable          { color: #ff8a8a; }

/* §C — When #app is dimmed during blackout, boost the status label back to full
   visibility. Parent brightness(0.45) × child brightness(2.5) ≈ brightness(1.12),
   so the text appears slightly above normal brightness against the dark backdrop. */
.entropy-blackout #entropy-status {
  filter: brightness(2.5);
}

/* §C — Blackout overlay on #app: dims everything and adds red border */
.entropy-blackout {
  filter: brightness(0.45) saturate(0.6);
  outline: 2px solid #8b0000;
  outline-offset: -2px;
  transition: filter 0.4s ease, outline 0.4s ease;
}

@keyframes blackout-pulse {
  from { opacity: 1; }
  to   { opacity: 0.55; }
}

/* LISTEN button — primary action, full width, prominent */
.listen-btn {
  font-size: 1.1rem;
  letter-spacing: 0.2em;
  padding: 10px 40px;
  width: min(340px, calc(100vw - 32px));
}

/* First-time directional hint — fades when totalClicks > 0 */
.first-hint {
  color: #3a7a56;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  margin: 6px auto 0;
  text-align: center;
  width: min(340px, calc(100vw - 32px));
}

/* Pulse bar click-to-charge hint */
.pulse-hint {
  color: #2a6644;
  font-size: 0.68rem;
  letter-spacing: 0.10em;
  margin: 3px auto 0;
  text-align: center;
  width: min(340px, calc(100vw - 32px));
}

/* Tab explanation hint (Echo, Coherence panels) */
.tab-hint {
  color: #2a6644;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  line-height: 1.5;
  margin: 0 auto 12px;
  max-width: min(500px, calc(100vw - 32px));
  text-align: center;
}

/* §D — Pulse Burst charge bar */
.pulse-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(340px, calc(100vw - 32px));
  margin: 4px auto 0;
  background: #0a1a10;
  border: 1px solid #1a4030;
  border-radius: 2px;
  height: 12px;
  overflow: hidden;
  position: relative;
}

.pulse-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00994d, #00ff88);
  transition: width 0.15s ease;
  border-radius: 2px;
}

.pulse-bar-fill.pulse-bar-ready {
  background: linear-gradient(90deg, #00cc66, #88ffcc);
  box-shadow: 0 0 8px rgba(0, 255, 136, 0.7);
  animation: pulse-bar-glow 0.5s ease-in-out infinite alternate;
}

.pulse-bar-label {
  position: absolute;
  right: 4px;
  font-size: 0.6rem;
  color: #78c99c;
  letter-spacing: 0.05em;
  pointer-events: none;
}

@keyframes pulse-bar-glow {
  from { opacity: 0.85; }
  to   { opacity: 1; }
}

.save-status {
  color: #2a6644;
  font-size: 0.72rem;
  height: 1.1em;
  letter-spacing: 0.1em;
  text-align: center;
}

/* ── TAB BAR ─────────────────────────────────────────────────────────────── */

.tab-bar {
  border-top: 1px solid #0d2a1a;
  display: flex;
  width: 100%;
}

.tab-btn {
  background: transparent;
  border: none;
  border-top: 2px solid transparent;
  color: #4a9a6a;
  cursor: pointer;
  flex: 1;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  padding: 10px 8px;
  position: relative;
  transition: color 120ms ease, background 120ms ease;
}

.tab-btn:hover {
  background: rgba(0, 255, 136, 0.04);
  color: #78c99c;
}

.tab-active {
  border-top-color: #00ff88;
  color: #00ff88;
}

/* Notification dot — shown on ECHO/Ψ tab when upgrades are purchasable */
.tab-btn-notify::after {
  background: #fff0a6;
  border-radius: 50%;
  content: '';
  height: 5px;
  position: absolute;
  right: 6px;
  top: 6px;
  width: 5px;
}

/* Locked tab (pre-unlock) */
.tab-btn-locked {
  color: #2a5a44;
  cursor: default;
}

/* ── TAB PANELS ──────────────────────────────────────────────────────────── */

.tab-panel {
  align-items: center;
  display: flex;
  flex: 1;              /* takes all remaining height below sticky-top */
  flex-direction: column;
  gap: 4px;
  min-height: 0;        /* prevent flex from blocking overflow */
  overflow-y: auto;
  padding: 12px 0 40px;
  /* Scrollbar — bright enough to see on a black background */
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 255, 136, 0.3) transparent;
}

.tab-panel::-webkit-scrollbar        { width: 6px; }
.tab-panel::-webkit-scrollbar-track  { background: transparent; }
.tab-panel::-webkit-scrollbar-thumb  { background: rgba(0, 255, 136, 0.3); border-radius: 3px; }

.tab-panel-hidden {
  display: none !important;
}

/* Section label within a tab panel — visual divider between groups */
.panel-section-label {
  border-top: 1px solid #0d2a1a;
  color: #1a4430;
  font-size: 0.66rem;
  letter-spacing: 0.25em;
  margin-top: 10px;
  padding: 10px 24px 4px;
  text-align: left;
  width: min(600px, calc(100vw - 16px));
}

/* Tab panel heading (inside echo/coherence/system tabs) */
.tab-panel-title {
  border-bottom: 1px solid #1a4430;
  color: #78c99c;
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  padding-bottom: 10px;
  text-align: center;
  width: min(600px, calc(100vw - 16px));
}

/* ── ACHIEVEMENT PANEL ───────────────────────────────────────────────────── */

.achievement-panel {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
}

.achievement-summary {
  color: #78c99c;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  padding: 8px 24px 14px;
  text-align: center;
  width: 100%;
}

.achievement-list {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Category label within the achievement list */
.achievement-category-label {
  border-top: 1px solid #0d2a1a;
  color: #2a6644;
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  margin-top: 6px;
  padding: 8px 24px 3px;
  text-align: left;
  width: 100%;
}

/* Individual achievement row */
.achievement-row {
  border-bottom: 1px solid #0d2a1a;
  display: grid;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  gap: 3px 10px;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  letter-spacing: 0.08em;
  padding: 9px 24px;
  text-align: left;
  width: min(600px, calc(100vw - 16px));
}

.achievement-row-name   { grid-column: 1; grid-row: 1; }
.achievement-row-check  { grid-column: 2; grid-row: 1; color: #00ff88; font-size: 0.75rem; white-space: nowrap; }
.achievement-row-text   { color: #2a6644; font-size: 0.75rem; grid-column: 1 / -1; grid-row: 2; letter-spacing: 0.05em; }
.achievement-row-prog   { color: #2a6644; font-size: 0.72rem; grid-column: 1 / -1; grid-row: 3; letter-spacing: 0.04em; }

/* Unlocked state — bright, full color */
.achievement-unlocked .achievement-row-name  { color: #00ff88; }
.achievement-unlocked .achievement-row-text  { color: #78c99c; }

/* Locked state — dimmed but readable */
.achievement-locked .achievement-row-name    { color: #2a6644; }
.achievement-locked .achievement-row-text    { color: #1a4430; }
.achievement-locked .achievement-row-prog    { color: #1a4430; }

/* Secret state — near-invisible until earned */
.achievement-secret .achievement-row-name    { color: #1a4430; }
.achievement-secret .achievement-row-text    { color: #1a4430; }

/* Audio controls row in SYS tab */
.audio-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── SYSTEM PANEL ────────────────────────────────────────────────────────── */

.system-panel {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
  width: min(600px, calc(100vw - 16px));
}

.system-divider {
  border-top: 1px solid #1a4430;
  color: #78c99c;
  font-size: 0.66rem;
  letter-spacing: 0.25em;
  margin-top: 8px;
  padding-top: 14px;
  text-align: center;
  width: 100%;
}

.system-note {
  color: #2a6644;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-align: center;
}

/* ── CARRIER WAVE BUTTON ─────────────────────────────────────────────────── */

.carrier-wave-btn {
  border-color: #00c8ff;
  color: #00c8ff;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  padding: 10px 20px;
}

.carrier-wave-btn:hover:not(:disabled) { background: rgba(0, 200, 255, 0.08); }

.carrier-wave-btn:disabled {
  border-color: #1a4430;
  color: #2a6644;
  cursor: default;
}

.carrier-wave-timer {
  color: #2a6644;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-align: center;
}

/* ── LIFETIME STATS ──────────────────────────────────────────────────────── */

.stats-content {
  color: #78c99c;
  font-size: 0.76rem;
  letter-spacing: 0.07em;
  line-height: 1.7;
  text-align: center;
  width: 100%;
}

.stats-line { padding: 1px 24px; }

/* ── SAVE DATA (EXPORT / IMPORT) ─────────────────────────────────────────── */

.save-data-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.save-data-btn {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  padding: 8px 16px;
}

.import-export-status {
  color: #78c99c;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  min-height: 1.2em;
  text-align: center;
}

/* ── NARRATIVE LOG ───────────────────────────────────────────────────────── */

.narrative-log {
  border-left: 2px solid #1a4430;
  color: #78c99c;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  line-height: 1.7;
  margin-bottom: 6px;
  padding: 6px 0 6px 12px;
  pointer-events: none;
  text-align: left;
  white-space: pre-line;
  width: min(600px, calc(100vw - 16px));
}

/* ── COMMON BUTTON BASE ──────────────────────────────────────────────────── */

.btn {
  background: transparent;
  border: 1px solid #00ff88;
  color: #00ff88;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  letter-spacing: 0.15em;
  padding: 10px 32px;
  transition: background 120ms ease;
}

.btn:hover  { background: rgba(0, 255, 136, 0.08); }
.btn:active { background: rgba(0, 255, 136, 0.18); }

/* Keyboard focus ring — visible for all interactive elements */
button:focus-visible {
  outline: 1px solid rgba(0, 255, 136, 0.55);
  outline-offset: 3px;
}

/* Dev buttons — intentionally red-toned (danger/debug), but readable */
.dev-reset-btn,
.dev-boost-btn {
  border-color: #995555;
  color: #cc7777;
  font-size: 0.75rem;
  padding: 8px 18px;
}

.dev-reset-btn:hover,
.dev-boost-btn:hover {
  background: rgba(204, 119, 119, 0.1);
}

/* ── BUILDING ROWS ───────────────────────────────────────────────────────── */
/* Antenna and Building area share the same 4-column grid layout.           */
/* Unified here to avoid duplication.                                        */

.antenna-area,
.building-area {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 1px solid #0d2a1a; /* row separator always visible */
  color: #00ff88;
  column-gap: 18px;
  display: grid;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.88rem;
  grid-template-columns: minmax(140px, 1fr) minmax(80px, auto) minmax(72px, auto) minmax(44px, auto);
  letter-spacing: 0.1em;
  min-height: 1.4em;
  padding: 9px 24px;
  text-align: center;
  transition: background 120ms ease;
  width: min(600px, calc(100vw - 16px));
}

/* Lock hint — shown before first antenna is reachable */
.antenna-locked {
  color: #1a4430;
  cursor: default;
}

/* Available (affordable) */
.antenna-available,
.building-available {
  border: 1px solid #00ff88;
  color: #00ff88;
  cursor: pointer;
}

.antenna-available:hover,
.building-available:hover {
  background: rgba(0, 255, 136, 0.07);
}

/* Locked/unaffordable — keep bottom border for row rhythm */
.building-locked,
.antenna-area.building-locked {
  border-color: transparent;
  border-bottom-color: #0d2a1a;
  color: #1a4430;
  cursor: default;
}

.antenna-area:disabled,
.building-area:disabled {
  opacity: 1; /* managed by CSS classes, not opacity */
}

/* Column sub-elements */
.building-name { text-align: left; }

.building-cost {
  color: #fff0a6;
  text-align: right;
  white-space: nowrap;
}

.building-owned {
  color: #78c99c;
  text-align: right;
  white-space: nowrap;
}

.building-available .building-cost,
.antenna-available .building-cost {
  color: #fff0a6;
}

.building-available .building-owned,
.antenna-available .building-owned {
  color: #a4ffd0;
}

.building-locked .building-name,
.antenna-area.building-locked .building-name,
.building-locked .building-cost,
.antenna-area.building-locked .building-cost {
  color: #3a7a58;
}

.building-locked.building-no-owned .building-owned,
.antenna-area.building-locked.building-no-owned .building-owned {
  color: #1a4430;
}

.building-locked.building-has-owned .building-owned,
.antenna-area.building-locked.building-has-owned .building-owned {
  color: #78c99c; /* show count even when unaffordable */
}

/* Buy-quantity badge */
.building-quantity {
  border: 1px solid #1a4430;
  color: #78c99c;
  cursor: pointer;
  min-width: 44px;
  padding: 1px 5px;
  text-align: center;
  transition: background 80ms ease, border-color 80ms ease;
  white-space: nowrap;
}

.building-quantity:hover {
  background: rgba(0, 255, 136, 0.08);
  border-color: #78c99c;
}

.building-available .building-quantity,
.antenna-available .building-quantity {
  border-color: #78c99c;
  color: #a4ffd0;
}

.building-locked .building-quantity,
.antenna-area.building-locked .building-quantity {
  opacity: 0.45;
}

/* Production preview — appears on hover/focus when building is available */
.building-preview {
  color: #2a6644;
  display: none;
  font-size: 0.69rem;
  grid-column: 1 / -1;
  letter-spacing: 0.06em;
  padding-top: 3px;
  text-align: left;
}

.building-available:hover .building-preview,
.antenna-available:hover .building-preview,
.building-available:focus-within .building-preview,
.antenna-available:focus-within .building-preview,
.building-has-owned:hover .building-preview {
  display: block;
}

/* ── LISTEN BUTTON PULSE ─────────────────────────────────────────────────── */

@keyframes listen-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.35); }
  65%  { box-shadow: 0 0 0 10px rgba(0, 255, 136, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0); }
}

.listen-btn-active {
  animation: listen-pulse 2.8s ease-out infinite;
}

/* ── TIP BUTTON ──────────────────────────────────────────────────────────── */

.tip-btn {
  border-color: #c87840;
  color: #c87840;
  display: inline-block;
  letter-spacing: 0.12em;
  text-decoration: none;
}

.tip-btn:hover { background: rgba(200, 120, 64, 0.09); }

/* ── NEW GAME / RESET ────────────────────────────────────────────────────── */

.new-game-btn {
  border-color: #7a3535;
  color: #bb6666;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  padding: 8px 18px;
}
.new-game-btn:hover { background: rgba(187, 102, 102, 0.08); }

.new-game-confirm {
  border: 1px solid #7a3535;
  border-radius: 2px;
  margin-top: 10px;
  padding: 12px 14px;
}
.new-game-warning {
  color: #bb6666;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  margin: 0 0 10px;
}
.new-game-confirm-btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.new-game-confirm-btn {
  border-color: #bb3333;
  color: #dd5555;
  font-size: 0.75rem;
  letter-spacing: 0.09em;
  padding: 7px 14px;
}
.new-game-confirm-btn:hover { background: rgba(221, 85, 85, 0.12); }

/* ── UPGRADE ROWS ────────────────────────────────────────────────────────── */

/* Never let building / upgrade rows shrink inside the scrolling flex column */
.building-area,
.antenna-area,
.upgrade-area {
  flex-shrink: 0;
}

.upgrade-area {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 1px solid #0d2a1a; /* row separator */
  color: #00ff88;
  display: grid;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.84rem;
  /* Row 1: name (left) + cost (right).  Row 2: effect description. */
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 3px 12px;
  letter-spacing: 0.1em;
  min-height: 1.4em;
  padding: 10px 24px;
  text-align: left;
  transition: background 120ms ease;
  width: min(600px, calc(100vw - 16px));
}

.upgrade-name   { grid-column: 1; grid-row: 1; }
.upgrade-cost   { grid-column: 2; grid-row: 1; white-space: nowrap; }
.upgrade-effect { grid-column: 1 / -1; grid-row: 2; }

/* Affordable — full border, bright */
.upgrade-available {
  border: 1px solid #00ff88;
  cursor: pointer;
}

.upgrade-available:hover {
  background: rgba(0, 255, 136, 0.07);
}

/* Locked — row separator only, readable but de-emphasised */
.upgrade-locked {
  border-color: transparent;
  border-bottom-color: #0d2a1a;
  color: #4a8a68;
  cursor: default;
}

.upgrade-locked .upgrade-cost,
.upgrade-locked .upgrade-effect {
  color: #3a7058;
}

/* Purchased — completed, de-emphasised */
.upgrade-complete {
  border-color: transparent;
  border-bottom-color: #0d2a1a;
  color: #2a6644;
  cursor: default;
}

.upgrade-complete .upgrade-effect {
  color: #1a4430;
}

/* Purchased but still usable (e.g. entropy filters in USE state) —
   restore the green border + pointer so it reads as actionable */
.upgrade-complete.upgrade-available {
  border: 1px solid #00ff88;
  color: #00ff88;
  cursor: pointer;
}

.upgrade-complete.upgrade-available:hover {
  background: rgba(0, 255, 136, 0.07);
}

.upgrade-complete.upgrade-available .upgrade-cost {
  color: #fff0a6;
}

.upgrade-complete.upgrade-available .upgrade-effect {
  color: #78c99c;
}

/* Cost span */
.upgrade-cost   { color: #fff0a6; }
/* Effect span */
.upgrade-effect { color: #78c99c; font-size: 0.8rem; }

.upgrade-area:disabled { opacity: 1; }

/* ── UPGRADE LIST (echo + coherence tab containers) ─────────────────────── */

.upgrade-list {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* ── ECHO PANEL ──────────────────────────────────────────────────────────── */

.echo-panel,
.coherence-panel {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
}

.echo-balance,
.coherence-balance {
  color: #a4ffd0;
  font-size: 1rem;
  letter-spacing: 0.15em;
  padding: 10px 24px 14px;
  text-align: center;
  width: 100%;
}

/* Tier labels within echo / coherence upgrade lists */
.echo-tier-label,
.coherence-tier-label {
  border-top: 1px solid #0d2a1a;
  color: #2a6644;
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  margin-top: 6px;
  padding: 8px 24px 3px;
  text-align: left;
  width: 100%;
}

/* Placeholder text for locked tabs */
.tab-placeholder {
  color: #78c99c;
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  padding: 24px;
  text-align: center;
}

/* ── RESYNC INDICATOR ────────────────────────────────────────────────────── */

.resync-indicator {
  animation: resync-pulse 2s ease-in-out infinite;
  background: transparent;
  border: 1px solid #00ff88;
  color: #00ff88;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  padding: 8px 20px;
  text-align: center;
  transition: background 120ms ease;
  width: min(340px, calc(100vw - 32px));
}

.resync-indicator:hover {
  background: rgba(0, 255, 136, 0.08);
}

/* Entropy climbing — amber steady pulse */
.resync-indicator.resync-warning {
  animation: resync-warning-pulse 1.4s ease-in-out infinite;
  border-color: #c87840;
  color: #c87840;
}

.resync-indicator.resync-warning:hover {
  background: rgba(200, 120, 64, 0.08);
}

/* Entropy unsalvageable — red-orange fast pulse */
.resync-indicator.resync-urgent {
  animation: resync-urgent-pulse 0.7s ease-in-out infinite;
  border-color: #ff5020;
  color: #ff5020;
}

.resync-indicator.resync-urgent:hover {
  background: rgba(255, 80, 32, 0.08);
}

/* Fix A — approaching state: dim, non-interactive, no animation */
.resync-indicator.resync-approaching {
  animation: none;
  border-color: #1a4430;
  color: #2a6644;
  cursor: default;
  font-size: 0.72rem;
  letter-spacing: 0.10em;
  opacity: 0.75;
}

.resync-indicator.resync-approaching:hover {
  background: transparent;
}

@keyframes resync-pulse {
  0%, 100% { opacity: 1; border-color: #00ff88; }
  50%       { opacity: 0.4; border-color: #1a4430; }
}

@keyframes resync-warning-pulse {
  0%, 100% { opacity: 1; border-color: #c87840; }
  50%       { opacity: 0.45; border-color: #6a3810; }
}

@keyframes resync-urgent-pulse {
  0%, 100% { opacity: 1; border-color: #ff5020; }
  50%       { opacity: 0.25; border-color: #701800; }
}

/* ── PRESTIGE INTRO TEXT ─────────────────────────────────────────────────── */

/* Typewriter narrative shown before confirm/cancel on the first resync */
.prestige-intro-text {
  color: #78c99c;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  line-height: 1.8;
  margin-bottom: 20px;
  min-height: 7em;       /* reserves space so the modal doesn't resize mid-type */
  text-align: left;
  white-space: pre-line;
}

/* ── MUTE BUTTON ─────────────────────────────────────────────────────────── */

.mute-btn {
  border-color: #78c99c;
  color: #78c99c;
  font-size: 0.8rem;
  padding: 8px 20px;
  transition: background 120ms ease;
}

.mute-btn:hover { background: rgba(120, 201, 156, 0.1); }

.mute-btn-off {
  border-color: #995555;
  color: #cc7777;
}

.mute-btn-off:hover { background: rgba(204, 119, 119, 0.1); }

/* ── ACHIEVEMENT TOAST ───────────────────────────────────────────────────── */

.achievement-toast {
  border: 1px solid #fff0a6;
  color: #fff0a6;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  opacity: 0;
  padding: 10px 16px;
  pointer-events: none;
  position: fixed;
  right: 20px;
  top: 20px;
  transition: opacity 500ms ease;
  z-index: 600;
}

.achievement-toast-visible { opacity: 1; }

.toast-name   { display: block; font-weight: bold; }
.toast-flavor { display: block; color: #c8b86a; font-size: 0.72rem; margin-top: 3px; opacity: 0.85; }

/* ── LAST STAND OVERLAY ──────────────────────────────────────────────────── */

.last-stand-overlay {
  align-items: center;
  background: rgba(0, 0, 0, 0.92);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 200;
}

.last-stand-box {
  border: 1px solid #00ff88;
  color: #00ff88;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', Courier, monospace;
  gap: 24px;
  max-width: min(540px, calc(100vw - 32px));
  padding: 36px;
  width: 100%;
}

.last-stand-narrative {
  font-size: 0.88rem;
  letter-spacing: 0.1em;
  line-height: 1.9;
  min-height: 5.4em;
  white-space: pre-line;
}

.last-stand-bar-row {
  align-items: center;
  display: flex;
  font-size: 0.8rem;
  gap: 10px;
  letter-spacing: 0.06em;
}

.last-stand-bar-label { color: #2a6644; flex-shrink: 0; }

.last-stand-bar-fill {
  color: #00ff88;
  flex: 1;
  font-size: 0.72rem;
  letter-spacing: 0;
  overflow: hidden;
}

.last-stand-bar-pct {
  color: #78c99c;
  flex-shrink: 0;
  min-width: 62px;
  text-align: right;
}

.transmit-btn {
  background: transparent;
  border: 1px solid #ff8a8a;
  color: #ff8a8a;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  letter-spacing: 0.18em;
  padding: 14px 32px;
  text-align: center;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  user-select: none;
  -webkit-user-select: none;
  width: 100%;
}

.transmit-btn:disabled { cursor: default; opacity: 0.6; }

.transmit-holding {
  background: rgba(0, 255, 136, 0.06);
  border-color: #00ff88 !important;
  color: #00ff88 !important;
}

/* Background distortion during Last Stand */
.last-stand-distortion { animation: app-flicker 0.45s steps(2) infinite; }

@keyframes app-flicker {
  0%   { filter: none; }
  50%  { filter: hue-rotate(12deg) brightness(1.06) contrast(1.04); }
  100% { filter: none; }
}

/* ── PRESTIGE MODAL ──────────────────────────────────────────────────────── */

/* Explicitly suppress display:flex when [hidden] is set — belt-and-suspenders
   against browsers where UA [hidden]{display:none} lacks !important. */
.prestige-modal-overlay[hidden],
.last-stand-overlay[hidden] {
  display: none !important;
}

.prestige-modal-overlay {
  align-items: center;
  background: rgba(0, 0, 0, 0.96);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 100;
}

.prestige-modal {
  border: 1px solid #00ff88;
  color: #00ff88;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', Courier, monospace;
  gap: 18px;
  max-height: 90vh;
  max-width: min(540px, calc(100vw - 32px));
  overflow-y: auto;
  padding: 32px;
  width: 100%;
}

.prestige-modal-title {
  font-size: 1rem;
  letter-spacing: 0.3em;
  text-align: center;
}

.prestige-echo-preview {
  color: #a4ffd0;
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 5px;
  letter-spacing: 0.08em;
}

.prestige-upgrade-preview-title {
  color: #2a6644;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
}

.prestige-upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.prestige-upgrade-row {
  color: #1a4430;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 3px 0;
}

.prestige-upgrade-affordable { color: #78c99c; }
.prestige-upgrade-owned      { color: #2a6644; }

.prestige-warning {
  color: #ff8a8a;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-align: center;
}

.prestige-modal-buttons {
  display: flex;
  gap: 14px;
  justify-content: center;
}

/* Keep button labels on one line regardless of modal width */
.prestige-modal-buttons .btn {
  padding: 10px 20px;
  white-space: nowrap;
}

.prestige-confirm { border-color: #ff8a8a; color: #ff8a8a; }
.prestige-confirm:hover { background: rgba(255, 138, 138, 0.08); }

/* ── ENDING CHOICE MODAL ─────────────────────────────────────────────────── */

.ending-modal-overlay {
  align-items: center;
  background: rgba(0, 0, 0, 0.97);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 150;
}

.ending-modal {
  border: 1px solid #00ff88;
  color: #00ff88;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', Courier, monospace;
  gap: 18px;
  max-width: min(540px, calc(100vw - 32px));
  padding: 36px;
  width: 100%;
}

.ending-modal-title {
  font-size: 1rem;
  letter-spacing: 0.3em;
  text-align: center;
}

.ending-narrative {
  color: #78c99c;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  line-height: 1.8;
}

.ending-run-stats {
  color: #2a6644;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  line-height: 1.7;
}

.ending-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ending-btn-broadcast         { border-color: #00ff88; color: #00ff88; }
.ending-btn-broadcast:hover   { background: rgba(0, 255, 136, 0.08); }
.ending-btn-silence           { border-color: #78c99c; color: #78c99c; }
.ending-btn-silence:hover     { background: rgba(120, 201, 156, 0.06); }
.ending-btn-void              { border-color: #ff8a8a; color: #ff8a8a; }
.ending-btn-void:hover        { background: rgba(255, 138, 138, 0.08); }

.ending-void-hint {
  color: #2a6644;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  min-height: 1em;
}

/* ── SILENCE ENDING ──────────────────────────────────────────────────────── */

.silence-overlay {
  align-items: center;
  animation: silence-fade-in 3s ease forwards;
  background: #000;
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 500;
}

@keyframes silence-fade-in {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}

.silence-content {
  color: #2a6644;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', Courier, monospace;
  gap: 18px;
  max-width: min(480px, calc(100vw - 32px));
  text-align: center;
}

.silence-stats {
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  line-height: 1.9;
  opacity: 0;
  transition: opacity 1.5s ease;
}
.silence-stats.silence-stats-visible { opacity: 1; }
.silence-footer { color: #1a4430; font-size: 0.72rem; letter-spacing: 0.15em; margin-top: 8px; }

/* ── VOID ENDING ─────────────────────────────────────────────────────────── */

.void-overlay {
  align-items: center;
  background: #000;
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 500;
}

.void-overlay.void-invert { animation: void-flash 0.6s steps(3) forwards; }

@keyframes void-flash {
  0%, 100% { filter: none; background: #000; }
  33%       { filter: invert(1); background: #fff; }
  66%       { filter: invert(1) hue-rotate(180deg); }
}

.void-content {
  color: #1a4430;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', Courier, monospace;
  gap: 14px;
  max-width: min(480px, calc(100vw - 32px));
  text-align: center;
}

.void-stats {
  color: #2a6644;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  line-height: 1.9;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 1.5s ease;
}
.void-stats.void-stats-visible { opacity: 1; }
.void-footer { color: #1a4430; font-size: 0.7rem; letter-spacing: 0.2em; margin-top: 4px; }

/* ── LOOP FLASH (Keep Broadcasting brief acknowledgment) ─────────────────── */
.loop-flash {
  align-items: center;
  background: rgba(0, 0, 0, 0.92);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 600;
  animation: loop-flash-in 0.4s ease forwards;
}
.loop-flash.loop-flash-out { animation: loop-flash-fade 0.8s ease forwards; }
@keyframes loop-flash-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes loop-flash-fade { from { opacity: 1; } to { opacity: 0; } }

.loop-flash-text {
  color: #7fffd4;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  letter-spacing: 0.2em;
  line-height: 2;
  text-align: center;
}

/* ── ENDING LINE-BY-LINE REVEAL ──────────────────────────────────────────── */

/* Container used by both silence and void line sequences */
.ending-narrative-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

/* Silence variant — green */
#silence-lines .ending-reveal-line  { color: #4a9a6a; }
#silence-lines .ending-reveal-line:last-child { color: #00ff88; }

/* Void variant — deeper teal / near-white for the final lines */
.void-narrative-lines .ending-reveal-line { color: #2a6644; }
.void-narrative-lines .ending-reveal-line:last-child { color: #7fffd4; }

.ending-spacer { height: 0.9em; }

.ending-reveal-line {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  line-height: 1.7;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.ending-reveal-line-in {
  opacity: 1;
  transform: translateY(0);
}

/* Stats lines inside endings */
.ending-stat-line {
  color: #3a7a56;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  line-height: 1.9;
}

/* ── ENDING RESTART BUTTON ───────────────────────────────────────────────── */
.ending-restart-btn {
  background: transparent;
  border: 1px solid #2a6644;
  color: #4a9a6a;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  margin-top: 20px;
  padding: 10px 32px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.ending-restart-btn:hover {
  background: rgba(0, 255, 136, 0.06);
  border-color: #00ff88;
  color: #00ff88;
}
.ending-restart-btn-void {
  border-color: #1a3d2b;
  color: #2a6644;
}
.ending-restart-btn-void:hover {
  background: rgba(127, 255, 212, 0.06);
  border-color: #7fffd4;
  color: #7fffd4;
}

/* ── NARRATIVE SEEN (already read in a previous run) ─────────────────────── */
.narrative-entry-seen {
  opacity: 0.28;
}
/* The newest entry always shows full brightness even if technically "seen" */
.narrative-sidebar-entry:last-child {
  filter: brightness(1.35);
  border-left-width: 3px;
  opacity: 1 !important;
}

/* App fade-out on endings — only applies to #app contents */
.app-fading {
  opacity: 0;
  pointer-events: none;
  transition: opacity 3s ease;
}

/* ── MOBILE ───────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .antenna-area,
  .building-area {
    font-size: 0.8rem;
    grid-template-columns: 1fr auto auto;
    padding: 8px 12px;
  }

  .building-owned { display: none; } /* hidden on very small screens — count in quantity badge */

  .upgrade-area {
    font-size: 0.78rem;
    padding: 9px 12px;
  }

  .tab-btn {
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    padding: 8px 2px;
  }
}

/* ── ANTENNA FIRST-BUY CTA ─────────────────────────────────────────────── */
/* Pulses when player has signal but no antennas — "buy this first" hint */
.antenna-cta {
  animation: antenna-cta-pulse 1.4s ease-in-out infinite;
  border-color: #00ff88 !important;
}

@keyframes antenna-cta-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0); border-color: #00ff88; }
  50%       { box-shadow: 0 0 8px 3px rgba(0, 255, 136, 0.35); border-color: #a4ffd0; }
}

/* ── GLOBAL BUY QUANTITY CONTROL ────────────────────────────────────────── */
.global-qty-row {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin: 0 auto 4px;
  width: min(600px, calc(100vw - 16px));
}

.global-qty-label {
  color: #2a6644;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
}

.global-qty-btn {
  background: transparent;
  border: 1px solid #1a4430;
  color: #78c99c;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.10em;
  padding: 3px 10px;
  transition: background 80ms ease, border-color 80ms ease;
}

.global-qty-btn:hover {
  background: rgba(0, 255, 136, 0.08);
  border-color: #78c99c;
}

/* ── NARRATIVE SIDEBAR ──────────────────────────────────────────────────── */
/* In-flow flex item next to #app inside #layout-root.
   Both sidebars are position:fixed, mirroring each other around the centered game.
   Game is 680px wide → half-width = 340px → plus 16px gap = 356px from center.

   Right sidebar (#narrative-log / .narrative-sidebar):
     left: calc(50% + 356px)   — lore, whispers, fragment voices

   Left sidebar (#guidance-log / .guidance-sidebar):
     right: calc(50% + 356px)  — guidance, warnings, mechanics

   Width of each adapts so neither overflows viewport.
   Both hide below 1040px (right) / 1040px (left). */

/* ── Shared sidebar base ── */
.narrative-sidebar {
  bottom: 0;
  cursor: default;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow-y: scroll;
  padding: 24px 18px 24px 22px;
  pointer-events: auto;
  position: fixed;
  scrollbar-color: #2a6644 #0a0a0a;
  scrollbar-width: thin;
  top: 0;
  z-index: 10;
}

/* ── Right sidebar — lore entries, signal log ── */
.narrative-sidebar:not(.guidance-sidebar) {
  border-left: 2px solid #1a3d2b;
  left: calc(50% + 356px);
  width: min(650px, calc(50vw - 356px));
}

/* ── Left sidebar — guidance + warning entries ── */
.guidance-sidebar {
  border-right: 2px solid #1a3d2b;
  right: calc(50% + 356px);
  width: min(650px, calc(50vw - 356px));
}

.narrative-sidebar-title {
  color: #3a7a56;
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

/* ── Base entry style ── */
.narrative-sidebar-entry {
  border-left: 2px solid #1a3d2b;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  line-height: 1.85;
  padding: 10px 0 10px 14px;
  white-space: pre-line;
}

/* ── Guidance: bright teal — system voice, mechanics, boot/resync headers ── */
.narrative-entry-guidance {
  border-left-color: #2a7a5a;
  color: #7fffd4;            /* aquamarine — clear, operational, technical */
}

/* ── Lore: warm amber — fragment voices, whispers, deep mystery ── */
.narrative-entry-lore {
  border-left-color: #8a6a2a;
  color: #c9a86c;            /* old gold — ancient, alien, searching */
}

/* ── Warning: orange-red — entropy alerts, distortion, danger ── */
.narrative-entry-warning {
  border-left-color: #8b2a0a;
  color: #ff7040;            /* red-orange — urgent, corrosive, wrong */
}

/* Latest entry brightness is handled by the rule near .narrative-entry-seen */

/* Hide both sidebars when gutters are too narrow to be readable.
   Each gutter = 50vw - 356px; disappears when < 160px → viewport < 1032px.
   Right sidebar needs right gutter; left sidebar needs left gutter — same threshold. */
@media (max-width: 1040px) {
  .narrative-sidebar { display: none !important; }
  .guidance-sidebar  { display: none !important; }
}

/* ── ENTROPY FLUSH — BLACKOUT PULSE ────────────────────────────────────────
   During a full blackout the flush button glows red-orange to guide the player. */
@keyframes flush-urgent-pulse {
  0%, 100% { box-shadow: 0 0 0 2px #ff4400, 0 0 10px rgba(255, 68, 0, 0.5); border-color: #ff4400; }
  50%       { box-shadow: 0 0 0 3px #ff6600, 0 0 28px rgba(255, 102, 0, 0.9), 0 0 50px rgba(255, 68, 0, 0.3); border-color: #ff6600; }
}
.entropy-flush-urgent {
  animation: flush-urgent-pulse 1.1s ease-in-out infinite !important;
  color: #ff7040 !important;
}

/* ── TUTORIAL OVERLAY ───────────────────────────────────────────────────────
   Dark mask that blocks clicks on non-highlighted areas.
   The active container gets .tutorial-container-active to rise above it. */
.tutorial-overlay {
  background: rgba(0, 0, 0, 0.80);
  bottom: 0;
  left: 0;
  pointer-events: all;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 400;
}

/* Container that needs to appear above the overlay during a tutorial step */
.tutorial-container-active {
  position: relative;
  z-index: 410;
}

/* Pulsing glow on the element the player should click */
@keyframes tutorial-pulse {
  0%, 100% {
    box-shadow: 0 0 0 2px #00ff88, 0 0 10px rgba(0, 255, 136, 0.5);
  }
  50% {
    box-shadow: 0 0 0 3px #00ff88, 0 0 28px rgba(0, 255, 136, 0.85), 0 0 50px rgba(0, 255, 136, 0.3);
  }
}
.tutorial-highlight {
  animation: tutorial-pulse 1.4s ease-in-out infinite;
  position: relative;
  z-index: 411;
}

/* ── Tutorial card ── */
.tutorial-card {
  background: #000;
  border: 1px solid #00ff88;
  bottom: 24px;
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.2);
  color: #00ff88;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', Courier, monospace;
  gap: 12px;
  left: 50%;
  max-width: 480px;
  padding: 20px 24px;
  position: fixed;
  transform: translateX(-50%);
  width: calc(100vw - 32px);
  z-index: 420;
}

.tutorial-step-label {
  color: #2a7a5a;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.tutorial-body {
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  line-height: 1.75;
  white-space: pre-line;
}

.tutorial-card-footer {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-top: 4px;
}

.tutorial-got-it-btn {
  background: transparent;
  border: 1px solid #00ff88;
  color: #00ff88;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  padding: 8px 20px;
  transition: background 120ms ease;
}
.tutorial-got-it-btn:hover { background: rgba(0, 255, 136, 0.1); }

.tutorial-skip-btn {
  background: transparent;
  border: none;
  color: #1a4430;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 4px 0;
  text-decoration: underline;
  transition: color 120ms ease;
}
.tutorial-skip-btn:hover { color: #3a7a56; }
