/* ==========================================================================
   INSPECTOR'S DILEMMA — Authentic Indie Pixel × CRT Aesthetic
   Zero AI-dashboard small-caps monospace! Unified Pixelify Sans + VT323
   bitmap typography, animated pixel-art data centers, and 4 international
   lab directors.
   ========================================================================== */

:root {
  --void: #06060a;
  --panel: #0b0d13;
  --panel-alt: #10131c;
  --white: #f2efe9;
  --gray: #9aa0ac;
  --dim: #3d4352;
  --amber: #ffb627;
  --red: #ff2e4c;
  --cyan: #38d9ff;
  --mint: #2ee6a6;
  --violet: #b46bff;

  --font-display: 'Silkscreen', 'Pixelify Sans', monospace;
  --font-ui: 'Pixelify Sans', 'VT323', monospace;
  --font-crt: 'VT323', 'Pixelify Sans', monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--void);
  color: var(--white);
  font-family: var(--font-ui);
  font-size: 14px;
  overflow-x: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#crt-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.14) 0px,
      rgba(0, 0, 0, 0.14) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(circle at center, transparent 62%, rgba(0, 0, 0, 0.45) 100%);
}

/* Utility Colors */
.c-white { color: var(--white); }
.c-gray { color: var(--gray); }
.c-amber { color: var(--amber); }
.c-red { color: var(--red); }
.c-cyan { color: var(--cyan); }
.c-mint { color: var(--mint); }
.c-violet { color: var(--violet); }
.hidden { display: none !important; }

/* Undertale Shake Text & Screen Shake */
@keyframes ut-shake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(1px, -1px); }
  50%  { transform: translate(-1px, 1px); }
  75%  { transform: translate(1px, 1px); }
  100% { transform: translate(-1px, -1px); }
}

.ut-shake {
  display: inline-block;
  animation: ut-shake 0.09s infinite;
}

@keyframes screen-slam {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-5px, 3px); }
  40%  { transform: translate(5px, -3px); }
  60%  { transform: translate(-3px, 2px); }
  80%  { transform: translate(2px, -1px); }
  100% { transform: translate(0, 0); }
}

.shake-shell {
  animation: screen-slam 0.28s ease-out;
}

@keyframes stamp-pop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(2.1) rotate(-9deg); }
  22%  { opacity: 1; transform: translate(-50%, -50%) scale(1.0) rotate(-6deg); }
  78%  { opacity: 1; transform: translate(-50%, -50%) scale(1.0) rotate(-6deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95) rotate(-6deg); }
}

/* ==========================================================================
   SCREENS
   ========================================================================== */
.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
  padding: 12px 16px;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ==========================================================================
   TITLE SCREEN
   ========================================================================== */
.title-cabinet {
  width: 100%;
  max-width: 660px;
  border: 3px solid var(--white);
  background: var(--panel);
  padding: 26px 28px 22px;
  text-align: center;
  box-shadow: 0 0 0 3px var(--void), 0 0 0 5px var(--dim);
}

.title-kicker {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--gray);
  margin-bottom: 8px;
}

.title-logo {
  font-family: var(--font-display);
  font-size: clamp(26px, 4.5vw, 40px);
  letter-spacing: 2px;
  color: var(--white);
  text-shadow: 3px 3px 0 rgba(255, 46, 76, 0.55);
  margin-bottom: 6px;
}

.title-sub {
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  color: var(--amber);
  margin-bottom: 16px;
}

.title-art-frame {
  border: 2px solid var(--white);
  background: var(--void);
  padding: 4px;
  margin-bottom: 18px;
}

#title-art-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.title-hook {
  font-family: var(--font-crt);
  font-size: 25px;
  line-height: 1.24;
  color: var(--white);
  margin-bottom: 22px;
}

.title-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.title-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  font-family: var(--font-crt);
  font-size: 18px;
  color: var(--gray);
}

/* ==========================================================================
   UNDERTALE-INSPIRED CHUNKY COMMAND BUTTONS
   ========================================================================== */
.ut-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--void);
  color: var(--amber);
  border: 2px solid var(--amber);
  padding: 9px 16px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.08s, color 0.08s, transform 0.06s;
}

.ut-btn small {
  font-family: var(--font-crt);
  font-size: 17px;
  font-weight: 400;
  opacity: 0.85;
}

.ut-btn .soul-mark {
  display: inline-block;
  transition: transform 0.1s;
}

.ut-btn:hover:not(:disabled),
.ut-btn:focus-visible:not(:disabled) {
  background: var(--amber);
  color: var(--void);
  outline: none;
}

.ut-btn:hover:not(:disabled) .soul-mark {
  transform: scale(1.25);
}

.ut-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.ut-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ut-btn-lg {
  padding: 11px 22px;
  font-size: 18px;
}

.ut-btn-cyan {
  color: var(--cyan);
  border-color: var(--cyan);
}
.ut-btn-cyan:hover:not(:disabled),
.ut-btn-cyan:focus-visible:not(:disabled) {
  background: var(--cyan);
  color: var(--void);
}

.ut-btn-mint {
  color: var(--mint);
  border-color: var(--mint);
}
.ut-btn-mint:hover:not(:disabled),
.ut-btn-mint:focus-visible:not(:disabled) {
  background: var(--mint);
  color: var(--void);
}

.ut-btn-white {
  color: var(--white);
  border-color: var(--white);
}
.ut-btn-white:hover:not(:disabled),
.ut-btn-white:focus-visible:not(:disabled) {
  background: var(--white);
  color: var(--void);
}

.mini-btn {
  background: var(--void);
  color: var(--white);
  border: 1.5px solid var(--gray);
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--amber);
  color: var(--amber);
}

.badge {
  display: inline-block;
  background: var(--amber);
  color: var(--void);
  padding: 0 5px;
  font-size: 11px;
  margin-left: 3px;
}

/* ==========================================================================
   MAIN CONSOLE LAYOUT
   ========================================================================== */
#screen-game.active {
  align-items: stretch;
  padding: 9px 14px;
}

.console-shell {
  width: 100%;
  max-width: 1130px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* TOP HUD BAR */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border: 2px solid var(--white);
  background: var(--panel);
  padding: 6px 12px;
}

.hud-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.hud-label {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--gray);
  font-weight: 600;
}

.hud-val {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 17px;
  line-height: 1.1;
}

.hud-val sup {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  vertical-align: super;
  line-height: 0;
}

.hud-sub {
  font-family: var(--font-crt);
  font-size: 15px;
  line-height: 1;
  color: var(--amber);
}

.hud-epoch {
  min-width: 68px;
}

.hud-phi {
  min-width: 148px;
}

.hud-phi-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.phi-meter {
  position: relative;
  height: 10px;
  background: var(--void);
  border: 1.5px solid var(--dim);
}

.phi-fill {
  height: 100%;
  width: 100%;
  background: var(--mint);
  transition: width 0.3s ease, background 0.3s ease;
}

.phi-threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: 66.6%;
  width: 2px;
  background: var(--white);
}

.hud-pips {
  display: inline-flex;
  gap: 3px;
  font-size: 15px;
  line-height: 1.1;
}

.pip-on { color: var(--mint); }
.pip-low { color: var(--red); }
.pip-off { color: var(--dim); }

.hud-tools {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* SUB-RIBBON */
.sub-ribbon {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 3px 10px;
  background: var(--panel-alt);
  border: 1.5px solid var(--dim);
  padding: 3px 10px;
  font-family: var(--font-crt);
  font-size: 16px;
  line-height: 1.1;
}

.ribbon-key {
  color: var(--gray);
  margin-right: 4px;
}

.ribbon-val {
  font-weight: 400;
}

/* ==========================================================================
   UPPER STAGE: UNDERTALE ENCOUNTER / PROBE / VERDICT
   ========================================================================== */
.encounter-stage {
  position: relative;
  border: 3px solid var(--white);
  background: var(--void);
  padding: 10px 12px;
  min-height: 162px;
  display: flex;
  align-items: stretch;
}

.stamp-flash {
  pointer-events: none;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 40;
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 3px;
  padding: 8px 18px;
  border: 4px solid var(--red);
  color: var(--red);
  background: rgba(6, 6, 10, 0.92);
  animation: stamp-pop 0.65s ease-out forwards;
}

.stamp-flash.is-clear {
  border-color: var(--mint);
  color: var(--mint);
}

.stage-pane {
  display: none;
  width: 100%;
}

.stage-pane.active {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

/* MODE A: DIALOGUE */
.portrait-box {
  flex: 0 0 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 2px solid var(--dim);
  background: var(--void);
  padding: 4px;
}

.portrait-box canvas {
  display: block;
  width: 112px;
  height: 112px;
  image-rendering: pixelated;
}

.portrait-name {
  width: 100%;
  text-align: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--amber);
  border-top: 1px solid var(--dim);
  padding-top: 3px;
  margin-top: 3px;
  line-height: 1.1;
}

.portrait-role {
  width: 100%;
  text-align: center;
  font-family: var(--font-crt);
  font-size: 15px;
  color: var(--gray);
  line-height: 1.05;
}

.dialogue-box {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 10px;
  cursor: pointer;
}

.dialogue-text {
  font-family: var(--font-crt);
  font-size: 27px;
  line-height: 1.22;
  color: var(--white);
}

.dialogue-text::before {
  content: '* ';
  color: var(--amber);
}

.dialogue-cue {
  align-self: flex-end;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  color: var(--amber);
  animation: blink-cue 0.85s steps(2) infinite;
}

@keyframes blink-cue {
  0% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* MODE B: UNDERTALE FIRMWARE PROBE */
#stage-probe.active {
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.probe-side-portrait {
  flex: 0 0 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 2px solid var(--dim);
  padding: 4px;
}

#probe-portrait-canvas {
  display: block;
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
}

.probe-dir-tag {
  margin-top: 3px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  color: var(--amber);
}

.probe-site-tag {
  font-family: var(--font-crt);
  font-size: 16px;
  color: var(--cyan);
}

.probe-arena-wrap {
  flex: 0 1 420px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.probe-hud-top {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
}

.probe-canvas-frame {
  border: 3px solid var(--white);
  background: var(--void);
  line-height: 0;
}

#probe-canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
}

.probe-hud-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.probe-ev-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
}

.probe-ev-bar {
  flex: 1;
  height: 10px;
  border: 1.5px solid var(--white);
  background: var(--void);
}

#probe-ev-fill {
  height: 100%;
  width: 0%;
  background: var(--amber);
}

.probe-legend {
  flex: 1;
  min-width: 190px;
  border: 1.5px solid var(--dim);
  background: var(--panel);
  padding: 8px 10px;
  font-family: var(--font-crt);
  font-size: 17px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  color: var(--white);
  border-bottom: 1px solid var(--dim);
  padding-bottom: 3px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--gray);
  line-height: 1.1;
}

.dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  flex-shrink: 0;
}
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }
.dot-cyan { background: var(--cyan); }
.dot-white { background: var(--white); }
.dot-violet { background: var(--violet); }

/* MODE C: VERDICT STAMP DILEMMA */
.verdict-report {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 8px;
}

.verdict-kicker {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  color: var(--amber);
}

.verdict-score-row {
  display: flex;
  align-items: center;
  gap: 18px;
}

.verdict-metric {
  border: 2px solid var(--white);
  padding: 6px 14px;
  text-align: center;
  min-width: 138px;
}

.vm-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--gray);
}

.vm-num {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--amber);
}

.verdict-pattern {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 17px;
  color: var(--white);
  margin-bottom: 3px;
}

.verdict-note {
  font-family: var(--font-crt);
  font-size: 19px;
  color: var(--gray);
}

.verdict-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stamp-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 14px;
  background: var(--void);
  border: 2.5px solid var(--white);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.08s, color 0.08s;
}

.stamp-btn small {
  font-family: var(--font-crt);
  font-size: 16px;
  font-weight: 400;
  opacity: 0.9;
}

.stamp-sanction {
  border-color: var(--red);
  color: var(--red);
}
.stamp-sanction:hover {
  background: var(--red);
  color: var(--void);
}

.stamp-clear {
  border-color: var(--mint);
  color: var(--mint);
}
.stamp-clear:hover {
  background: var(--mint);
  color: var(--void);
}

/* ==========================================================================
   1-LINE POWER GRAPH DECODER BAR
   ========================================================================== */
.signal-guide {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  background: var(--panel);
  border: 1.5px solid var(--dim);
  padding: 4px 12px;
  font-family: var(--font-crt);
  font-size: 17px;
  color: var(--gray);
}

.sg-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  color: var(--white);
}

.sg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.sg-item code {
  font-family: var(--font-crt);
  font-size: 18px;
  background: var(--void);
  border: 1px solid #262b3a;
  padding: 0 5px;
  line-height: 1.05;
}

/* ==========================================================================
   MIDDLE STAGE: FACILITY TELEMETRY GRID WITH PIXEL-ART DIORAMAS
   ========================================================================== */
.facility-grid {
  display: grid;
  gap: 9px;
  flex: 1;
}

.facility-grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.facility-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.fac-card {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  border: 2px solid var(--dim);
  background: var(--panel);
  padding: 8px 11px;
  cursor: pointer;
  transition: border-color 0.08s, background 0.08s;
}

.fac-card:hover {
  border-color: var(--gray);
  background: var(--panel-alt);
}

.fac-card.selected {
  border-color: var(--amber);
  box-shadow: inset 0 0 0 1px var(--amber);
  background: #131520;
}

.fac-card.is-flagged {
  border-color: rgba(255, 182, 39, 0.65);
}

.fac-card.selected.is-flagged {
  border-color: var(--amber);
}

.fac-card.is-sanctioned {
  border-color: var(--red);
  opacity: 0.86;
}

.fac-card.is-cleared {
  border-color: rgba(46, 230, 166, 0.45);
  opacity: 0.84;
}

.fac-card.is-monitored {
  border-color: rgba(56, 217, 255, 0.72);
}

.fac-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.fac-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.fac-cursor {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--amber);
  visibility: hidden;
}

.fac-card.selected .fac-cursor {
  visibility: visible;
}

.fac-name {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  color: var(--white);
}

.fac-country {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 11px;
  padding: 0 5px;
  border: 1px solid var(--dim);
}

.fac-country.is-us {
  color: var(--cyan);
  border-color: rgba(56, 217, 255, 0.55);
  background: rgba(56, 217, 255, 0.1);
}

.fac-country.is-cn {
  color: var(--amber);
  border-color: rgba(255, 182, 39, 0.55);
  background: rgba(255, 182, 39, 0.1);
}

.fac-tier {
  font-family: var(--font-crt);
  font-size: 15px;
  padding: 0 5px;
  border: 1px solid var(--dim);
  color: var(--gray);
  line-height: 1.1;
}

.fac-pill {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 12px;
  padding: 1px 7px;
  white-space: nowrap;
}

@keyframes flag-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.74; }
}

.pill-flag {
  background: var(--amber);
  color: var(--void);
  animation: flag-pulse 1.2s ease-in-out infinite;
}
.pill-mon {
  background: rgba(56, 217, 255, 0.2);
  border: 1px solid var(--cyan);
  color: var(--cyan);
}
.pill-clear {
  background: rgba(46, 230, 166, 0.16);
  border: 1px solid var(--mint);
  color: var(--mint);
}
.pill-sanction {
  background: var(--red);
  color: var(--void);
}
.pill-idle {
  border: 1px solid var(--dim);
  color: var(--gray);
}

.fac-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-crt);
  font-size: 16px;
  line-height: 1.05;
  color: var(--gray);
}

.fac-director-line {
  color: var(--white);
}

/* Split Visual Row: Pixel-Art Data Center Diorama + Labeled 24h Power Graph */
.fac-visual-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.fac-diorama-wrap {
  flex: 0 0 104px;
  border: 1.5px solid var(--dim);
  background: var(--void);
  line-height: 0;
  overflow: hidden;
}

.fac-card.selected .fac-diorama-wrap {
  border-color: rgba(255, 182, 39, 0.65);
}

.fac-diorama {
  display: block;
  width: 104px;
  height: 72px;
  image-rendering: pixelated;
}

.fac-scope-wrap {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--dim);
  background: var(--void);
  line-height: 0;
}

.fac-scope {
  display: block;
  width: 100%;
  height: 72px;
}

.facility-grid.cols-3 .fac-diorama-wrap {
  flex: 0 0 84px;
}
.facility-grid.cols-3 .fac-diorama {
  width: 84px;
  height: 62px;
}
.facility-grid.cols-3 .fac-scope {
  height: 62px;
}

.fac-clues {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.clue-cell {
  background: var(--void);
  border: 1px solid #1e2230;
  padding: 3px 7px;
}

.clue-k {
  display: block;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--gray);
  line-height: 1.1;
}

.clue-v {
  font-family: var(--font-crt);
  font-size: 18px;
  line-height: 1.1;
  white-space: nowrap;
}

/* ==========================================================================
   BOTTOM COMMAND BAR
   ========================================================================== */
.command-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.command-bar .ut-btn {
  padding: 10px 10px;
  flex-direction: row;
  justify-content: center;
}

/* ==========================================================================
   MODALS (POLICY, PARLEY, FIELD NOTES, MANUAL) WITH PIXEL ICONS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 8, 0.84);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  width: 100%;
  max-width: 750px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border: 3px solid var(--white);
  background: var(--panel);
  box-shadow: 0 0 0 4px var(--void);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--dim);
  padding: 10px 14px;
  background: var(--void);
}

.modal-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 18px;
  color: var(--amber);
}

.modal-body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.policy-row, .parley-row, .codex-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1.5px solid var(--dim);
  background: var(--void);
  padding: 10px 12px;
}

.option-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.option-icon-wrap {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--dim);
  background: var(--panel);
}

.pixel-icon {
  display: block;
  image-rendering: pixelated;
}

.policy-row .ut-btn,
.parley-row .ut-btn {
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 126px;
}

.policy-row.bought {
  border-color: var(--mint);
}

.policy-row.bought .option-icon-wrap {
  border-color: var(--mint);
}

.policy-info h4, .parley-info h4, .codex-row h4 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  color: var(--white);
  margin-bottom: 3px;
}

.policy-ref {
  font-family: var(--font-crt);
  font-size: 15px;
  font-weight: 400;
  color: var(--cyan);
  border: 1px solid rgba(56, 217, 255, 0.45);
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: middle;
}

.policy-info p, .parley-info p, .codex-row p {
  font-family: var(--font-crt);
  font-size: 19px;
  color: var(--gray);
  line-height: 1.24;
}

.codex-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.codex-row.locked {
  opacity: 0.45;
}

.codex-detail {
  color: var(--white) !important;
  border-left: 2px solid var(--amber);
  padding-left: 8px;
  margin-top: 2px;
}

.manual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.manual-card {
  border: 1.5px solid var(--dim);
  background: var(--void);
  padding: 10px 12px;
}

.manual-card h4 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  color: var(--amber);
  margin-bottom: 5px;
}

.manual-card p {
  font-family: var(--font-crt);
  font-size: 19px;
  color: var(--white);
  line-height: 1.25;
}

/* ==========================================================================
   ENDING / DECLASSIFIED SCREEN
   ========================================================================== */
#screen-ending.active {
  align-items: flex-start;
  padding: 18px 16px 32px;
}

.ending-cabinet {
  width: 100%;
  max-width: 940px;
  margin: 0 auto;
  border: 3px solid var(--white);
  background: var(--panel);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ending-code {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--amber);
}

.ending-title {
  font-family: var(--font-display);
  font-size: clamp(22px, 3.6vw, 32px);
  color: var(--white);
}

.ending-hero {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  border: 2px solid var(--dim);
  background: var(--void);
  padding: 14px;
}

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

.ending-quote {
  font-family: var(--font-crt);
  font-size: 25px;
  line-height: 1.22;
  color: var(--white);
  border-left: 3px solid var(--amber);
  padding-left: 12px;
}

.ending-epilogue {
  font-family: var(--font-crt);
  font-size: 20px;
  line-height: 1.28;
  color: var(--gray);
}

.ending-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
}

.stat-chip {
  border: 1px solid var(--dim);
  background: var(--panel);
  padding: 4px 9px;
}

.declassified-panel {
  border: 2px solid var(--dim);
  background: var(--void);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.declassified-head {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--cyan);
}

#ending-chart-canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--dim);
}

.ledger-wrap {
  overflow-x: auto;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-crt);
  font-size: 18px;
}

.ledger-table th, .ledger-table td {
  border: 1px solid #1e2330;
  padding: 4px 8px;
  text-align: left;
}

.ledger-table th {
  background: var(--panel);
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--gray);
}

.ending-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* FIELD NOTE UNLOCK TOAST */
.codex-toast {
  position: fixed;
  bottom: 72px;
  right: 18px;
  z-index: 900;
  border: 2px solid var(--amber);
  background: var(--void);
  color: var(--white);
  padding: 8px 14px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 0 0 3px var(--panel);
}

/* RESPONSIVE */
@media (max-width: 860px) {
  .console-shell {
    gap: 6px;
  }
  .hud-bar {
    padding: 6px 10px;
    gap: 7px;
  }
  .encounter-stage {
    padding: 8px 10px;
    min-height: 142px;
  }
  .fac-card {
    padding: 7px 9px;
    gap: 4px;
  }
  .fac-diorama-wrap {
    flex: 0 0 84px;
  }
  .fac-diorama {
    width: 84px;
    height: 60px;
  }
  .fac-scope {
    height: 60px;
  }
  .facility-grid.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .command-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  .command-bar .ut-btn {
    padding: 9px 8px;
  }
  .manual-grid {
    grid-template-columns: 1fr;
  }
  #stage-probe.active {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }
  .probe-side-portrait {
    flex: 0 0 88px;
  }
  #probe-portrait-canvas {
    width: 72px;
    height: 72px;
  }
  .probe-legend {
    flex: 1 1 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 6px 8px;
  }
  .legend-title {
    border-bottom: none;
    padding-bottom: 0;
    margin-right: 4px;
  }
  .ending-hero {
    flex-direction: column;
    align-items: center;
  }
}

@media (max-width: 720px) {
  .facility-grid.cols-2,
  .facility-grid.cols-3,
  .verdict-buttons {
    grid-template-columns: 1fr;
  }
}
