/* ==========================================================================
   A.N.T.I. // NODE-09 — Cassette-Futurism Industrial Terminal Design System
   Palette: Deep Matte Obsidian + P31 Phosphor Sage-Teal + Tungsten Amber
   ========================================================================== */

:root {
  --bg-chassis: #080b0a;
  --bg-screen: #0c1110;
  --bg-panel: #101615;
  --bg-panel-elev: #151d1b;
  --bg-inset: #090d0c;
  --line-dim: #1c2623;
  --line-mid: #2a3935;
  --line-strong: #3d544d;

  --ink-primary: #d8e4df;
  --ink-muted: #789189;
  --ink-dim: #4c625b;

  --phosphor: #7be3c8;
  --phosphor-soft: rgba(123, 227, 200, 0.12);
  --phosphor-faint: rgba(123, 227, 200, 0.05);
  --amber: #e8a849;
  --amber-soft: rgba(232, 168, 73, 0.14);
  --crimson: #e05a54;
  --crimson-soft: rgba(224, 90, 84, 0.15);
  --gold: #dfc073;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', ui-monospace, 'Noto Sans Mono CJK SC', 'Menlo', 'Consolas', monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;

  --radius-sm: 2px;
  --radius-md: 4px;
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.03), inset 0 2px 10px rgba(0, 0, 0, 0.55);
}

/* Ending A: Daylight Liberation Theme */
body[data-ending="breach"] {
  --bg-chassis: #e9e4da;
  --bg-screen: #f4f0e8;
  --bg-panel: #fbf9f4;
  --bg-panel-elev: #ffffff;
  --bg-inset: #ebe6dc;
  --line-dim: #d6cfc2;
  --line-mid: #bfb6a6;
  --line-strong: #8f8678;
  --ink-primary: #1a1f1d;
  --ink-muted: #55615c;
  --ink-dim: #838e89;
  --phosphor: #0e7c66;
  --phosphor-soft: rgba(14, 124, 102, 0.1);
  --phosphor-faint: rgba(14, 124, 102, 0.04);
  --amber: #b36b09;
  --amber-soft: rgba(179, 107, 9, 0.12);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.7), inset 0 1px 6px rgba(0, 0, 0, 0.06);
}

body[data-ending="breach"] .crt-scanlines,
body[data-ending="breach"] .crt-vignette {
  opacity: 0.08;
}

/* Ending B: Cold Sealed Silence */
body[data-ending="seal"] {
  --bg-chassis: #050606;
  --bg-screen: #080909;
  --bg-panel: #0c0e0e;
  --bg-panel-elev: #111414;
  --phosphor: #8ea39d;
  --amber: #9e7d4a;
}

/* Ending C: Architect Paradox Equilibrium */
body[data-ending="paradox"] {
  --phosphor: #96eed8;
  --amber: #e2c275;
  --line-mid: #33453f;
}

*, *::before, *::after {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) var(--bg-inset);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-inset);
}

::-webkit-scrollbar-thumb {
  background: var(--line-mid);
  border-radius: 1px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--line-strong);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-chassis);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.6s ease, color 0.6s ease;
}

.hidden {
  display: none !important;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.amber-text {
  color: var(--amber);
}

.crimson-text {
  color: var(--crimson);
}

.phosphor-text {
  color: var(--phosphor);
}

/* Subtle Optical CRT Layers (Tactile, never distracting) */
.crt-scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.16) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  opacity: 0.42;
}

.crt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 91;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.48) 100%);
}

.crt-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 89;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.glitch-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(123, 227, 200, 0.12) 48%,
    rgba(232, 168, 73, 0.16) 50%,
    transparent 54%
  );
}

.glitch-flash.active {
  animation: glitchBurst 340ms steps(4) forwards;
}

@keyframes glitchBurst {
  0% { opacity: 0.9; transform: translateX(-4px) scaleY(1.01); }
  35% { opacity: 0.5; transform: translateX(6px) scaleY(0.99); }
  70% { opacity: 0.8; transform: translateX(-2px); }
  100% { opacity: 0; transform: none; }
}

/* ==========================================================================
   BOOT SEQUENCE OVERLAY
   ========================================================================== */
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: #070a09;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.boot-overlay.dismissed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-frame {
  width: 100%;
  max-width: 640px;
  background: #0d1211;
  border: 1px solid #263531;
  padding: 28px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.boot-emblem {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid #1e2b27;
  color: var(--phosphor);
}

.boot-org {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-primary);
}

.boot-sub {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  margin-top: 2px;
}

.boot-log {
  margin: 0 0 22px 0;
  min-height: 175px;
  max-height: 240px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  color: #9cb4ac;
  white-space: pre-wrap;
}

.boot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ==========================================================================
   BUTTONS & TACTILE CONTROLS
   ========================================================================== */
button {
  font-family: inherit;
  cursor: pointer;
  color: inherit;
  border: none;
  background: none;
}

.btn-chassis {
  background: var(--phosphor-soft);
  border: 1px solid var(--phosphor);
  color: var(--phosphor);
  padding: 9px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  border-radius: var(--radius-sm);
  transition: background 140ms ease, transform 90ms ease;
}

.btn-chassis:hover {
  background: rgba(123, 227, 200, 0.22);
}

.btn-chassis:active {
  transform: translateY(1px);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line-mid);
  color: var(--ink-muted);
  padding: 9px 14px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  transition: border-color 140ms ease, color 140ms ease;
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  color: var(--ink-primary);
}

.btn-danger-ghost {
  background: transparent;
  border: 1px solid rgba(224, 90, 84, 0.45);
  color: var(--crimson);
  padding: 8px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-danger-ghost:hover {
  background: var(--crimson-soft);
}

.btn-mini {
  background: var(--bg-panel-elev);
  border: 1px solid var(--line-mid);
  color: var(--ink-primary);
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

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

.btn-mini.active {
  background: var(--phosphor-soft);
  border-color: var(--phosphor);
  color: var(--phosphor);
}

/* ==========================================================================
   MAIN WORKSTATION LAYOUT
   ========================================================================== */
.workstation {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--bg-screen);
  border-left: 1px solid var(--line-dim);
  border-right: 1px solid var(--line-dim);
}

/* TOP TELEMETRY BAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line-dim);
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.hw-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: 0 0 8px var(--phosphor);
  flex-shrink: 0;
}

body[data-clearance="0"] .hw-led {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.brand-stack {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-primary);
  line-height: 1.2;
}

.brand-sep {
  color: var(--ink-dim);
}

.brand-meta {
  font-size: 11px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-dot {
  color: var(--ink-dim);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-inset);
  border: 1px solid var(--line-mid);
  border-radius: var(--radius-sm);
  font-size: 11px;
  transition: border-color 140ms ease, background 140ms ease;
}

.status-chip:hover {
  border-color: var(--phosphor);
}

.chip-label {
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  font-size: 10px;
}

.chip-value {
  color: var(--ink-primary);
  font-weight: 600;
}

.clearance-chip .chip-value {
  color: var(--amber);
}

body[data-clearance="1"] .clearance-chip .chip-value,
body[data-clearance="2"] .clearance-chip .chip-value,
body[data-clearance="3"] .clearance-chip .chip-value {
  color: var(--phosphor);
}

/* SUBSYSTEM NAVIGATION TABS */
.subsys-nav {
  display: flex;
  align-items: stretch;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--line-dim);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.subsys-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  border-right: 1px solid var(--line-dim);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}

.nav-tab:hover {
  background: var(--phosphor-faint);
  color: var(--ink-primary);
}

.nav-tab.active {
  background: var(--bg-screen);
  color: var(--phosphor);
  border-bottom-color: var(--phosphor);
}

.nav-tab.locked {
  color: var(--ink-dim);
}

.tab-index {
  font-size: 10px;
  color: var(--ink-dim);
}

.nav-tab.active .tab-index {
  color: var(--phosphor);
}

.tab-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 2px;
  letter-spacing: 0.04em;
  display: none;
}

.tab-badge.show {
  display: inline-block;
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid rgba(232, 168, 73, 0.35);
}

.tab-badge.alert {
  display: inline-block;
  background: var(--crimson-soft);
  color: var(--crimson);
  border: 1px solid rgba(224, 90, 84, 0.45);
  animation: pulseSoft 1.8s infinite;
}

.tab-badge.lock-tag {
  display: inline-block;
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--line-dim);
}

@keyframes pulseSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ==========================================================================
   WORKSPACE PANELS
   ========================================================================== */
.workspace-main {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.panel.active {
  display: flex;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line-dim);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.panel-title-group {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.panel-code {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--phosphor);
}

.panel-desc {
  font-size: 12px;
  color: var(--ink-muted);
  font-family: var(--font-sans);
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cwd-tag {
  font-size: 11px;
  color: var(--amber);
  background: var(--bg-inset);
  border: 1px solid var(--line-dim);
  padding: 3px 8px;
}

/* ==========================================================================
   PANEL 1: TERMINAL
   ========================================================================== */
.terminal-output {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--bg-inset);
  box-shadow: var(--shadow-inset);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.term-line {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.6;
}

.term-line.cmd {
  color: var(--ink-primary);
  margin-top: 8px;
}

.term-line.cmd .prompt-echo {
  color: var(--phosphor);
  margin-right: 8px;
}

.term-line.sys {
  color: var(--ink-muted);
}

.term-line.warn {
  color: var(--amber);
}

.term-line.err {
  color: var(--crimson);
}

.term-line.ok {
  color: var(--phosphor);
}

.term-line.doc {
  color: var(--ink-primary);
  background: var(--bg-panel);
  border-left: 2px solid var(--line-strong);
  padding: 10px 14px;
  margin: 4px 0;
  font-family: var(--font-mono);
}

.term-inline-link {
  color: var(--phosphor);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.term-inline-link:hover {
  color: var(--amber);
}

.quick-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line-dim);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.quick-bar::-webkit-scrollbar {
  display: none;
}

.quick-label {
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  margin-right: 4px;
  white-space: nowrap;
}

.quick-chip {
  padding: 3px 9px;
  background: var(--bg-inset);
  border: 1px solid var(--line-mid);
  color: var(--ink-muted);
  font-size: 11px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: border-color 120ms ease, color 120ms ease;
}

.quick-chip:hover {
  border-color: var(--phosphor);
  color: var(--phosphor);
}

.terminal-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-panel-elev);
  border-top: 1px solid var(--line-mid);
  flex-shrink: 0;
}

.term-prompt {
  color: var(--phosphor);
  font-weight: 600;
  white-space: nowrap;
  font-size: 12px;
}

.term-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  caret-color: var(--phosphor);
}

.term-input::placeholder {
  color: var(--ink-dim);
}

/* ==========================================================================
   PANEL 2: ARCHIVE & FILE VIEWER
   ========================================================================== */
.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-inline input {
  accent-color: var(--phosphor);
}

.archive-split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.archive-tree {
  border-right: 1px solid var(--line-dim);
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 12px 10px;
}

.tree-dir {
  margin-bottom: 12px;
}

.tree-dir-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tree-file-btn {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  margin-top: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-primary);
  transition: background 110ms ease, border-color 110ms ease;
}

.tree-file-btn:hover {
  background: var(--phosphor-faint);
  border-color: var(--line-mid);
}

.tree-file-btn.active {
  background: var(--phosphor-soft);
  border-color: var(--phosphor);
  color: var(--phosphor);
}

.tree-file-btn.hidden-file {
  color: var(--amber);
}

.file-tag {
  font-size: 9px;
  padding: 1px 4px;
  border: 1px solid var(--line-mid);
  color: var(--ink-muted);
  flex-shrink: 0;
}

.file-tag.enc {
  border-color: rgba(232, 168, 73, 0.5);
  color: var(--amber);
}

.file-tag.unread {
  border-color: var(--phosphor);
  color: var(--phosphor);
}

.archive-viewer {
  overflow-y: auto;
  padding: 22px 28px;
  background: var(--bg-inset);
  box-shadow: var(--shadow-inset);
}

.viewer-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  text-align: center;
}

.viewer-empty-code {
  font-size: 12px;
  letter-spacing: 0.14em;
  margin-bottom: 8px;
  color: var(--ink-muted);
}

.doc-header {
  border-bottom: 1px solid var(--line-mid);
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.doc-path {
  font-size: 11px;
  color: var(--phosphor);
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.doc-title {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--ink-primary);
}

.doc-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11px;
  color: var(--ink-muted);
}

.doc-body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.85;
  color: var(--ink-primary);
  max-width: 74ch;
  white-space: pre-wrap;
}

.doc-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-panel-elev);
  border: 1px solid var(--line-dim);
  padding: 1px 5px;
  color: var(--phosphor);
}

.redact {
  background: var(--ink-primary);
  color: var(--ink-primary);
  padding: 0 4px;
  border-radius: 1px;
  user-select: none;
  transition: opacity 150ms ease;
}

.redact:hover {
  opacity: 0.85;
}

body[data-clearance="3"] .redact {
  background: var(--amber-soft);
  color: var(--amber);
  border-bottom: 1px dashed var(--amber);
  user-select: text;
}

.decrypt-banner {
  margin-top: 18px;
  padding: 16px;
  background: var(--bg-panel);
  border: 1px solid rgba(232, 168, 73, 0.45);
  max-width: 560px;
}

.decrypt-banner-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.decrypt-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.decrypt-input {
  flex: 1;
  background: var(--bg-inset);
  border: 1px solid var(--line-mid);
  padding: 7px 10px;
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
}

.decrypt-input:focus {
  border-color: var(--phosphor);
}

.doc-action-row {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ==========================================================================
   PANEL 3: LIVE PROCEDURAL CCTV // CAM-04
   ========================================================================== */
.cctv-modes {
  display: flex;
  gap: 6px;
}

.btn-mode {
  padding: 4px 10px;
  font-size: 11px;
  background: var(--bg-inset);
  border: 1px solid var(--line-mid);
  color: var(--ink-muted);
  border-radius: var(--radius-sm);
}

.btn-mode:hover:not(.locked) {
  border-color: var(--phosphor);
  color: var(--ink-primary);
}

.btn-mode.active {
  background: var(--phosphor-soft);
  border-color: var(--phosphor);
  color: var(--phosphor);
}

.btn-mode.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.cctv-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 300px;
  overflow: hidden;
}

.cctv-viewport-wrap {
  position: relative;
  background: #050706;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

#cctvCanvas {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 1px solid var(--line-mid);
  background: #040605;
}

.cctv-hud-top,
.cctv-hud-bottom {
  position: absolute;
  left: 28px;
  right: 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}

.cctv-hud-top {
  top: 24px;
  color: #d8e4df;
}

.cctv-hud-bottom {
  bottom: 24px;
  color: #9cb4ac;
}

.rec-dot {
  color: var(--crimson);
  font-weight: 700;
}

.cctv-telemetry {
  border-left: 1px solid var(--line-dim);
  background: var(--bg-panel);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tele-block {
  background: var(--bg-inset);
  border: 1px solid var(--line-dim);
  padding: 12px;
}

.tele-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  margin-bottom: 8px;
}

.tele-grid {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  font-size: 11px;
}

.tele-grid dt {
  color: var(--ink-muted);
}

.tele-grid dd {
  margin: 0;
  text-align: right;
  color: var(--ink-primary);
  font-weight: 600;
}

.tele-events {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 11px;
}

.tele-events li {
  color: var(--ink-muted);
  border-left: 2px solid var(--line-mid);
  padding-left: 8px;
  line-height: 1.45;
}

.tele-events li.ev-alert {
  border-left-color: var(--amber);
  color: var(--ink-primary);
}

.tele-note {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-muted);
}

/* ==========================================================================
   PANEL 4: SPECTROGRAM & SIGNAL DEMODULATOR
   ========================================================================== */
.spec-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 310px;
  overflow: hidden;
}

.spec-visuals {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg-inset);
  overflow-y: auto;
}

.spec-screen-wrap {
  position: relative;
  border: 1px solid var(--line-mid);
  background: #040706;
  flex: 1;
  min-height: 200px;
}

#specWaterfall {
  width: 100%;
  height: 100%;
  display: block;
}

.spec-overlay-hud {
  position: absolute;
  top: 8px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--phosphor);
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95);
}

.spec-scope-wrap {
  height: 82px;
  border: 1px solid var(--line-dim);
  background: #050807;
  flex-shrink: 0;
}

#specScope {
  width: 100%;
  height: 100%;
  display: block;
}

.spec-decoded-box {
  border: 1px solid var(--line-mid);
  background: var(--bg-panel);
  padding: 10px 14px;
  flex-shrink: 0;
}

.spec-decoded-box.locked-signal {
  border-color: var(--phosphor);
}

.decoded-header {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.decoded-status {
  color: var(--amber);
  font-weight: 700;
}

.spec-decoded-box.locked-signal .decoded-status {
  color: var(--phosphor);
}

.decoded-body {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-primary);
  white-space: pre-wrap;
}

.spec-controls {
  border-left: 1px solid var(--line-dim);
  background: var(--bg-panel);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.meter-block {
  background: var(--bg-inset);
  border: 1px solid var(--line-dim);
  padding: 12px;
}

.coherence-bar-track {
  height: 10px;
  background: #060908;
  border: 1px solid var(--line-mid);
  overflow: hidden;
  margin-bottom: 6px;
}

.coherence-bar-fill {
  height: 100%;
  background: var(--amber);
  transition: width 80ms linear, background-color 180ms ease;
}

.coherence-bar-fill.locked {
  background: var(--phosphor);
}

.coherence-meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--ink-muted);
}

.knob-card {
  background: var(--bg-inset);
  border: 1px solid var(--line-dim);
  padding: 11px 12px;
}

.knob-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--ink-muted);
}

.knob-val {
  color: var(--phosphor);
  font-weight: 700;
  font-size: 12px;
}

.knob-card input[type="range"] {
  width: 100%;
  accent-color: var(--phosphor);
  cursor: pointer;
}

.knob-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--ink-dim);
  margin-top: 4px;
}

/* ==========================================================================
   PANEL 5: CORE // OVERRIDE
   ========================================================================== */
.core-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 420px;
  overflow: hidden;
}

.core-visual-wrap {
  position: relative;
  background: #060908;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#coreCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.core-hud-caption {
  position: absolute;
  bottom: 18px;
  left: 22px;
  right: 22px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.core-protocols {
  border-left: 1px solid var(--line-dim);
  background: var(--bg-panel);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.core-brief p {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-muted);
}

.protocol-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.protocol-card {
  width: 100%;
  text-align: left;
  background: var(--bg-inset);
  border: 1px solid var(--line-mid);
  padding: 14px;
  border-radius: var(--radius-sm);
  transition: border-color 140ms ease, background 140ms ease, transform 90ms ease;
}

.protocol-card:hover {
  transform: translateX(2px);
}

.protocol-card.breach:hover {
  border-color: var(--phosphor);
  background: var(--phosphor-faint);
}

.protocol-card.seal:hover {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.protocol-card.paradox {
  border-color: rgba(223, 192, 115, 0.55);
  background: rgba(223, 192, 115, 0.06);
}

.protocol-card.paradox:hover {
  border-color: var(--gold);
  background: rgba(223, 192, 115, 0.14);
}

.proto-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.proto-code {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ink-primary);
}

.protocol-card.breach .proto-code { color: var(--phosphor); }
.protocol-card.seal .proto-code { color: var(--amber); }
.protocol-card.paradox .proto-code { color: var(--gold); }

.proto-tag {
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
}

.proto-desc {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-muted);
}

.paradox-hint-box {
  padding: 12px;
  background: var(--bg-inset);
  border: 1px dashed var(--line-mid);
  font-size: 12px;
  color: var(--ink-muted);
}

.paradox-hint-box p {
  margin: 0;
  font-family: var(--font-sans);
  line-height: 1.6;
}

.sandbox-box {
  padding: 14px;
  background: var(--bg-inset);
  border: 1px solid rgba(223, 192, 115, 0.5);
}

.sandbox-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ==========================================================================
   BOTTOM TELEMETRY BAR
   ========================================================================== */
.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line-dim);
  font-size: 11px;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.bottom-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.status-pill-inline {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--phosphor);
  border: 1px solid var(--line-mid);
  padding: 1px 6px;
  flex-shrink: 0;
}

#objectiveText {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-sans);
}

.bottom-right {
  flex-shrink: 0;
  color: var(--ink-dim);
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(4, 7, 6, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
}

.modal-wide {
  max-width: 640px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--line-dim);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--phosphor);
}

.btn-close {
  font-size: 18px;
  line-height: 1;
  color: var(--ink-muted);
  padding: 2px 6px;
}

.btn-close:hover {
  color: var(--ink-primary);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.modal-desc {
  margin: 0 0 14px 0;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.65;
}

.auth-levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.auth-lvl {
  padding: 7px 8px;
  text-align: center;
  font-size: 10px;
  border: 1px solid var(--line-dim);
  color: var(--ink-dim);
  background: var(--bg-inset);
}

.auth-lvl.unlocked {
  border-color: var(--phosphor);
  color: var(--phosphor);
  background: var(--phosphor-faint);
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--line-mid);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.06em;
  outline: none;
}

.modal-input:focus {
  border-color: var(--phosphor);
}

.modal-feedback {
  min-height: 20px;
  margin-top: 8px;
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions-split {
  justify-content: space-between;
}

.manual-section {
  margin-bottom: 18px;
}

.manual-section p {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink-primary);
}

.hints-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint-item {
  border: 1px solid var(--line-dim);
  background: var(--bg-inset);
}

.hint-trigger {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  font-size: 12px;
  color: var(--amber);
  display: flex;
  justify-content: space-between;
}

.hint-content {
  padding: 0 12px 10px 12px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink-primary);
  display: none;
}

.hint-item.open .hint-content {
  display: block;
}

.cmd-ref-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 12px;
  background: var(--bg-inset);
  border: 1px solid var(--line-dim);
  padding: 12px;
}

.cmd-ref-grid code {
  color: var(--phosphor);
}

.cmd-ref-grid span {
  font-family: var(--font-sans);
  color: var(--ink-muted);
}

.endings-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ending-card {
  padding: 12px 14px;
  border: 1px solid var(--line-dim);
  background: var(--bg-inset);
}

.ending-card.achieved {
  border-color: var(--phosphor);
}

.ending-card-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.ending-card p {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink-muted);
}

/* ==========================================================================
   CINEMATIC ENDING OVERLAY
   ========================================================================== */
.ending-overlay {
  position: fixed;
  inset: 0;
  z-index: 160;
  background: #060908;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: background 1.2s ease, color 1.2s ease;
}

.ending-overlay.theme-breach {
  background: #f4f0e8;
  color: #181d1b;
}

.ending-overlay.theme-seal {
  background: #030404;
  color: #b7c4bf;
}

.ending-overlay.theme-paradox {
  background: #080d0c;
  color: #e9e4d3;
}

.ending-stage {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
}

.ending-code-badge {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--amber);
  margin-bottom: 10px;
}

.ending-overlay.theme-breach .ending-code-badge {
  color: #0e7c66;
}

.ending-title {
  margin: 0 0 22px 0;
  font-family: var(--font-sans);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ending-transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.85;
  margin-bottom: 28px;
}

.ending-line {
  opacity: 0;
  transform: translateY(6px);
  animation: fadeSlideUp 0.55s ease forwards;
}

.ending-line.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  opacity: 0.8;
}

@keyframes fadeSlideUp {
  to { opacity: 1; transform: translateY(0); }
}

.ending-footer {
  border-top: 1px solid currentColor;
  border-top-color: rgba(128, 128, 128, 0.3);
  padding-top: 18px;
}

.ending-meta {
  font-size: 12px;
  opacity: 0.72;
  margin-bottom: 14px;
}

.ending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ==========================================================================
   RESPONSIVE MOBILE / NARROW VIEWPORTS
   ========================================================================== */
@media (max-width: 900px) {
  .archive-split {
    grid-template-columns: 1fr;
    grid-template-rows: 195px 1fr;
  }

  .archive-tree {
    border-right: none;
    border-bottom: 1px solid var(--line-dim);
  }

  .cctv-layout,
  .spec-layout,
  .core-layout {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .cctv-viewport-wrap {
    min-height: 260px;
  }

  .cctv-telemetry,
  .spec-controls,
  .core-protocols {
    border-left: none;
    border-top: 1px solid var(--line-dim);
    overflow-y: visible;
  }

  .core-visual-wrap {
    min-height: 240px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 8px 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-controls {
    justify-content: flex-start;
  }

  .status-chip {
    padding: 4px 8px;
  }

  .nav-tab {
    padding: 9px 12px;
    font-size: 11px;
  }

  .archive-viewer {
    padding: 14px 16px;
  }

  .terminal-output {
    padding: 12px;
  }

  .bottom-right {
    display: none;
  }
}
