/* ===================================================================
   CyberZork - Responsive Stylesheet
   All phases implemented: viewport fix, mobile layout, sidebar toggle,
   touch targets, accessibility, font loading, performance
   =================================================================== */

:root {
  --bg: #07111a;
  --panel: rgba(9, 20, 31, 0.94);
  --panel-strong: rgba(8, 18, 29, 0.99);
  --line: rgba(116, 243, 255, 0.28);
  --line-strong: rgba(116, 243, 255, 0.55);
  --text: #f0feff;
  --muted: #c0dce8;
  --cyan: #74f3ff;
  --teal: #2dd4bf;
  --amber: #ffbf69;
  --rose: #ff7aa2;
  --danger: #ff6c8c;
  --warn: #ffd166;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, monospace;
  --display: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

@media (min-width: 1251px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--mono);
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.2), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 122, 162, 0.18), transparent 26%),
    linear-gradient(180deg, #09131d 0%, #050b12 100%);
}

/* Phase 3: Focus-visible styles (WCAG 2.4.7) */
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

.command-form input:focus-visible {
  outline-offset: -2px;
  border-color: var(--cyan);
}

/* Phase 7: Reduced motion (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .background-grid {
    opacity: 0;
  }

  .terminal-panel::after {
    display: none !important;
  }
}

/* ===================================================================
   CRT SCANLINE OVERLAY
   Pure CSS — never blocks interaction
   =================================================================== */

.terminal-panel {
  position: relative;
}

.terminal-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  pointer-events: none;
  z-index: 10;
  mix-blend-mode: multiply;
}

body.crt-off .terminal-panel::after {
  display: none;
}

/* ===================================================================
   NEON GLOW EFFECTS
   =================================================================== */

.app-header h1 {
  text-shadow:
    0 0 8px rgba(116, 243, 255, 0.55),
    0 0 24px rgba(116, 243, 255, 0.25);
}

#location-title {
  text-shadow:
    0 0 8px rgba(116, 243, 255, 0.45),
    0 0 20px rgba(116, 243, 255, 0.18);
  transition: text-shadow 300ms ease;
  color: var(--cyan);
}

.command-form input:focus-visible {
  box-shadow:
    0 0 8px rgba(116, 243, 255, 0.2),
    inset 0 0 4px rgba(116, 243, 255, 0.05);
}

.ops-tab.active {
  box-shadow: 0 0 6px rgba(116, 243, 255, 0.12);
}

.utility-launcher.active {
  box-shadow: 0 0 6px rgba(116, 243, 255, 0.12);
}

/* Pulsing glow on current minimap node */
@keyframes node-pulse {
  0%, 100% { r: 5.5; opacity: 0.3; }
  50% { r: 7; opacity: 0.6; }
}

.mini-map-node.current .mini-map-pulse {
  animation: node-pulse 2.4s ease-in-out infinite;
}

/* ===================================================================
   ROOM TRANSITION ANIMATION
   =================================================================== */

@keyframes room-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ansi-art {
  animation: room-enter 350ms ease-out;
}

/* ===================================================================
   TRANSCRIPT ENTRY ANIMATION
   =================================================================== */

@keyframes entry-slide {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.entry {
  animation: entry-slide 200ms ease-out;
}

/* ===================================================================
   GLITCH EFFECT (applied via JS class)
   =================================================================== */

@keyframes glitch-skew {
  0% { transform: skewX(0deg); }
  20% { transform: skewX(-2deg); }
  40% { transform: skewX(1.5deg); }
  60% { transform: skewX(-1deg); }
  80% { transform: skewX(0.5deg); }
  100% { transform: skewX(0deg); }
}

@keyframes glitch-clip {
  0% { clip-path: inset(0 0 100% 0); }
  10% { clip-path: inset(40% 0 20% 0); }
  20% { clip-path: inset(10% 0 60% 0); }
  30% { clip-path: inset(80% 0 5% 0); }
  40% { clip-path: inset(20% 0 40% 0); }
  50% { clip-path: inset(50% 0 10% 0); }
  60% { clip-path: inset(5% 0 80% 0); }
  70% { clip-path: inset(60% 0 15% 0); }
  80% { clip-path: inset(25% 0 50% 0); }
  90% { clip-path: inset(70% 0 5% 0); }
  100% { clip-path: inset(0 0 100% 0); }
}

.glitch-active {
  animation: glitch-skew 250ms linear;
}

.glitch-active::before {
  content: "";
  position: absolute;
  inset: 0;
  background: inherit;
  animation: glitch-clip 250ms steps(5) forwards;
  mix-blend-mode: screen;
  opacity: 0.4;
  z-index: 11;
  pointer-events: none;
}

/* ===================================================================
   TYPEWRITER CURSOR
   =================================================================== */

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.typewriter-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.1em;
  background: var(--cyan);
  vertical-align: text-bottom;
  animation: blink-cursor 800ms step-end infinite;
  margin-left: 1px;
}

body.typewriter-off .typewriter-cursor {
  display: none;
}

/* ===================================================================
   ENDING THEMES
   Distinct finale treatment for each release path
   =================================================================== */

@keyframes ending-public-surge {
  0%, 100% { box-shadow: 0 0 0 rgba(116, 243, 255, 0); }
  50% { box-shadow: 0 0 28px rgba(116, 243, 255, 0.18); }
}

@keyframes ending-audit-scan {
  0% { background-position: 0 0; }
  100% { background-position: 0 32px; }
}

@keyframes ending-ghost-drift {
  0%, 100% { opacity: 0.92; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

@keyframes ending-blackout-flicker {
  0%, 100% { filter: brightness(1); }
  20% { filter: brightness(0.84); }
  40% { filter: brightness(1.05); }
  60% { filter: brightness(0.78); }
  80% { filter: brightness(1.02); }
}

body.ending-theme-public .terminal-panel {
  animation: ending-public-surge 1.9s ease-in-out infinite;
}

body.ending-theme-public .ansi-art,
body.ending-theme-public .entry.ansi pre {
  color: #9ef8ff;
  text-shadow: 0 0 18px rgba(116, 243, 255, 0.22);
}

body.ending-theme-audit .terminal-panel {
  background-image:
    linear-gradient(180deg, rgba(255, 191, 105, 0.06), transparent 42%),
    repeating-linear-gradient(
      180deg,
      rgba(255, 191, 105, 0.07) 0,
      rgba(255, 191, 105, 0.07) 2px,
      transparent 2px,
      transparent 8px
    );
  animation: ending-audit-scan 2.6s linear infinite;
}

body.ending-theme-audit .ansi-art,
body.ending-theme-audit .entry.ansi pre {
  color: #ffd79b;
  text-shadow: 0 0 16px rgba(255, 191, 105, 0.18);
}

body.ending-theme-ghost .terminal-panel {
  box-shadow:
    inset 0 0 32px rgba(45, 212, 191, 0.08),
    0 18px 38px rgba(0, 0, 0, 0.48);
}

body.ending-theme-ghost .ansi-art,
body.ending-theme-ghost .entry.ansi pre {
  color: #a6fff4;
  animation: ending-ghost-drift 2.4s ease-in-out infinite;
  text-shadow: 0 0 14px rgba(45, 212, 191, 0.2);
}

body.ending-theme-blackout .terminal-panel {
  animation: ending-blackout-flicker 1.3s steps(2) infinite;
  box-shadow:
    inset 0 0 36px rgba(255, 108, 140, 0.08),
    0 18px 38px rgba(0, 0, 0, 0.52);
}

body.ending-theme-blackout .ansi-art,
body.ending-theme-blackout .entry.ansi pre {
  color: #ffd29c;
  text-shadow:
    0 0 8px rgba(255, 191, 105, 0.2),
    0 0 18px rgba(255, 108, 140, 0.16);
}

.background-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(116, 243, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(116, 243, 255, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.42;
  pointer-events: none;
}

.app-shell {
  position: relative;
  max-width: 1480px;
  margin: 0 auto;
  padding: 6px 10px 10px;
}

/* Phase 1: Replace vh with dvh/svh for desktop locked mode */
@media (min-width: 1251px) {
  .app-shell {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 8px 12px;
    overflow: hidden;
  }
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: end;
  padding: 6px 12px;
  background: linear-gradient(135deg, rgba(7, 18, 29, 0.98), rgba(10, 26, 40, 0.95));
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.terminal-label {
  margin: 0 0 4px;
  color: #4de8d0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header h1,
.panel h2,
#location-title {
  margin: 0;
  font-family: var(--display);
  letter-spacing: -0.04em;
}

.app-header h1 {
  font-size: clamp(1.2rem, 2.2vw, 1.9rem);
}

#location-title {
  font-size: 1.05rem;
  line-height: 1.25;
}

.app-subtitle {
  margin: 6px 0 0;
  color: #d8f0fa;
  font-size: 0.92rem;
  line-height: 1.45;
}

.app-header-copy {
  min-width: 0;
}

.app-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: end;
}

.app-header-meta span,
.badge {
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  background: rgba(7, 18, 29, 0.75);
  color: var(--text);
  font-size: 0.72rem;
}

/* Phase 1: dvh fallback for game grid */
.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "terminal";
  gap: 10px;
  align-items: stretch;
  min-height: calc(100vh - 120px);
  min-height: calc(100dvh - 120px);
}

@media (min-width: 1251px) {
  .game-grid {
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.7fr);
    grid-template-areas: "terminal rail";
    min-height: 0;
    height: 100%;
  }
}

.sidebar {
  position: fixed;
  inset: 50% auto auto 50%;
  width: min(480px, calc(100vw - 32px));
  max-height: min(78dvh, 820px);
  z-index: 200;
  transform: translate(-50%, -44%) scale(0.98);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  filter: drop-shadow(0 18px 48px rgba(0, 0, 0, 0.5));
  transition:
    transform 220ms ease,
    opacity 220ms ease,
    visibility 0ms 220ms;
}

.sidebar.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition:
    transform 220ms ease,
    opacity 220ms ease,
    visibility 0ms 0ms;
}

.panel {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  box-shadow: var(--shadow);
}

/* Phase 5: Consolidated .ops-panel (was 3 separate blocks) */
.ops-panel {
  padding: 18px;
  max-height: min(78dvh, 820px);
  overflow: auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  container-type: inline-size;
  background: rgba(5, 13, 22, 0.98);
}

.ops-header {
  display: grid;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.ops-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ops-tab {
  border: 1px solid var(--line-strong);
  background: rgba(116, 243, 255, 0.03);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  padding: 10px 12px;
  text-align: center;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color 100ms ease, background 100ms ease, color 100ms ease;
}

.ops-tab:hover {
  color: var(--text);
  background: rgba(116, 243, 255, 0.06);
}

.ops-tab.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(116, 243, 255, 0.10);
  font-weight: 500;
}

.ops-body {
  min-height: 0;
  overflow: auto;
}

.ops-pane {
  min-height: 0;
}

/* Phase 7: content-visibility for hidden panes */
.ops-pane[hidden] {
  content-visibility: hidden;
}

/* Phase 1: dvh fallback for terminal panel */
.terminal-panel {
  grid-area: terminal;
  container-type: inline-size;
  min-height: calc(100vh - 140px);
  min-height: calc(100dvh - 140px);
  max-height: calc(100vh - 140px);
  max-height: calc(100dvh - 140px);
  display: grid;
  grid-template-rows: 110px minmax(130px, 160px) minmax(80px, 1fr) auto;
  gap: 6px;
  padding: 8px;
  background:
    linear-gradient(180deg, rgba(6, 14, 23, 0.99), rgba(6, 14, 23, 0.96)),
    radial-gradient(circle at top, rgba(116, 243, 255, 0.1), transparent 45%);
  overflow: hidden;
}

.intel-rail {
  display: none;
}

@media (min-width: 1251px) {
  .intel-rail {
    grid-area: rail;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
    background:
      linear-gradient(180deg, rgba(6, 14, 23, 0.99), rgba(6, 14, 23, 0.96)),
      radial-gradient(circle at top, rgba(116, 243, 255, 0.08), transparent 42%);
  }
}

.terminal-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 175px) minmax(130px, 175px) minmax(170px, 240px);
  gap: 6px;
  align-items: stretch;
  overflow: hidden;
}

.terminal-card {
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid rgba(116, 243, 255, 0.32);
  background: rgba(4, 11, 19, 0.92);
  overflow: hidden;
}

.terminal-status-panel,
.terminal-actions-panel,
.mini-map-panel,
.play-panel,
.transcript-panel,
.command-panel {
  display: grid;
  align-content: start;
}

.play-panel,
.transcript-panel,
.command-panel {
  gap: 5px;
}

.play-panel {
  min-height: 80px;
  overflow: hidden;
}

.command-panel {
  background: rgba(4, 10, 18, 0.99);
  border-color: rgba(116, 243, 255, 0.40) !important;
}

.utility-launcher-panel {
  gap: 10px;
  position: relative;
  z-index: 201;
}

.utility-launchers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.utility-launcher {
  border: 1px solid rgba(116, 243, 255, 0.34);
  background: rgba(116, 243, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: border-color 120ms ease, background 120ms ease;
}

.utility-launcher.active,
.utility-launcher:hover {
  border-color: var(--cyan);
  background: rgba(116, 243, 255, 0.12);
  color: var(--cyan);
}

.utility-launcher-copy {
  margin: 0;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.55;
  opacity: 0.88;
}

.utility-launcher-copy kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid rgba(116, 243, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
}

.intel-section {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  border: 1px solid rgba(116, 243, 255, 0.32);
  background: rgba(4, 11, 19, 0.92);
  overflow: hidden;
  transition: flex 200ms ease;
}

.intel-section.expanded {
  flex: 1 1 0;
  min-height: 80px;
  overflow: hidden;
}

.intel-chevron {
  color: var(--cyan);
  font-size: 0.7rem;
  flex-shrink: 0;
  transition: transform 200ms ease;
  margin-left: auto;
  padding-left: 8px;
}

.intel-section.expanded .intel-chevron {
  transform: rotate(180deg);
}

.intel-section:not(.expanded) .intel-body {
  display: none;
}

.intel-heading {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
  min-height: 38px;
  flex-shrink: 0;
}

.intel-heading-inner {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.intel-heading:hover {
  background: rgba(116, 243, 255, 0.06);
}

.intel-heading h2 {
  font-size: 1rem;
  color: var(--text);
  margin: 0;
}

.intel-body {
  min-height: 0;
  overflow: auto;
  padding: 4px 14px 14px;
}

.scene-layout {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.mini-map-panel {
  padding: 6px 8px !important;
  overflow: hidden;
}

.mini-map {
  display: grid;
  gap: 3px;
}

.mini-map-svg {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  max-height: 120px;
  display: block;
  border: 1px solid rgba(116, 243, 255, 0.30);
  background:
    radial-gradient(circle at center, rgba(116, 243, 255, 0.08), transparent 58%),
    linear-gradient(180deg, rgba(3, 10, 18, 0.96), rgba(3, 10, 18, 0.90));
}

.mini-map-link {
  stroke-linecap: round;
  stroke-width: 1.35;
}

.mini-map-link.hidden {
  stroke: rgba(116, 243, 255, 0.22);
  stroke-dasharray: 2.4 3;
}

.mini-map-link.discovered {
  stroke: rgba(45, 212, 191, 0.75);
}

.mini-map-node {
  color: var(--muted);
}

.mini-map-pulse {
  fill: rgba(116, 243, 255, 0.04);
  stroke: transparent;
}

.mini-map-core {
  fill: rgba(116, 243, 255, 0.30);
  stroke: rgba(116, 243, 255, 0.55);
  stroke-width: 1;
  filter: url(#mini-glow);
}

.mini-map-node.visited .mini-map-core {
  fill: rgba(45, 212, 191, 0.40);
  stroke: rgba(45, 212, 191, 0.80);
}

.mini-map-node.current .mini-map-pulse {
  fill: rgba(116, 243, 255, 0.18);
  stroke: rgba(116, 243, 255, 0.35);
  stroke-width: 0.7;
}

.mini-map-node.current .mini-map-core {
  fill: rgba(116, 243, 255, 1.0);
  stroke: rgba(220, 247, 255, 1.0);
}

.mini-map-node.unknown .mini-map-core {
  fill: rgba(142, 185, 200, 0.18);
  stroke: rgba(142, 185, 200, 0.40);
}

.mini-map-label {
  fill: currentColor;
  font-family: var(--mono);
  font-size: 5px;
  letter-spacing: 0.18em;
  text-anchor: middle;
  font-weight: 600;
}

.mini-map-node.visited,
.mini-map-node.current {
  color: #d7fffb;
}

.mini-map-node.unknown {
  color: rgba(184, 216, 232, 0.60);
}

.mini-map-caption {
  margin: 0;
  color: var(--text);
  font-size: 0.82rem;
  text-align: center;
  opacity: 0.9;
}

@media (min-width: 1251px) {
  .terminal-panel {
    min-height: 0;
    max-height: none;
    height: 100%;
  }
}

.terminal-header,
.oracle-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.oracle-header {
  margin-bottom: 16px;
}

.location-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin: 2px 0;
}

.location-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

.terminal-status-panel .location-subtitle {
  display: none;
}

.button-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.secondary-button,
.command-form button,
.chip-button,
#oracle-button,
.compass-button {
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(13, 31, 45, 0.98), rgba(8, 20, 32, 0.96));
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.secondary-button:hover,
.command-form button:hover,
.chip-button:hover,
#oracle-button:hover,
.compass-button:hover {
  border-color: var(--cyan);
  background: linear-gradient(135deg, rgba(18, 42, 60, 0.98), rgba(12, 28, 44, 0.96));
  box-shadow: 0 0 10px rgba(116, 243, 255, 0.14);
}

.command-form button {
  color: var(--cyan);
  border-color: var(--cyan);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.command-form button:hover {
  background: rgba(116, 243, 255, 0.12);
  box-shadow: 0 0 12px rgba(116, 243, 255, 0.22);
}

.secondary-button,
.compass-button {
  padding: 7px 10px;
  font-size: 0.80rem;
}

.compass-button[disabled] {
  opacity: 0.30;
  cursor: default;
  color: rgba(184, 216, 232, 0.40);
  border-color: rgba(116, 243, 255, 0.14);
}

.nav-strip {
  display: grid;
  gap: 10px;
}

.ansi-art {
  margin: 0;
  padding: 4px 6px;
  border: 1px solid rgba(116, 243, 255, 0.26);
  background: linear-gradient(180deg, rgba(3, 10, 18, 0.96), rgba(3, 10, 18, 0.90));
  color: #c8feff;
  font-family: var(--mono);
  font-size: 0.58rem;
  line-height: 1.2;
  white-space: pre;
  overflow: auto;
  max-block-size: 100px;
}

.compass {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.transcript {
  overflow: auto;
  padding-right: 6px;
  display: grid;
  gap: 6px;
  min-height: 0;
  min-block-size: 220px;
  scrollbar-width: thin;
  scrollbar-color: rgba(116, 243, 255, 0.30) rgba(0, 0, 0, 0.20);
}

.transcript::-webkit-scrollbar {
  width: 4px;
}

.transcript::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.20);
}

.transcript::-webkit-scrollbar-thumb {
  background: rgba(116, 243, 255, 0.30);
  border-radius: 2px;
}

.transcript::-webkit-scrollbar-thumb:hover {
  background: rgba(116, 243, 255, 0.55);
}

.intel-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(116, 243, 255, 0.25) rgba(0, 0, 0, 0.15);
  flex: 1;
  min-height: 0;
}

.transcript-panel {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.entry {
  padding: 5px 10px;
  border-left: 3px solid transparent;
  background: rgba(116, 243, 255, 0.03);
}

.entry.system {
  border-left-color: var(--cyan);
  color: var(--text);
}

.entry.player {
  border-left-color: var(--rose);
  color: #ffdce8;
  background: rgba(255, 122, 162, 0.04);
}

.entry.oracle {
  border-left-color: var(--amber);
  color: #ffefd0;
  background: rgba(255, 191, 105, 0.05);
}

.entry p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 0.88rem;
}

.entry pre {
  margin: 0;
  white-space: pre;
  font-family: var(--mono);
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.55;
}

.entry.story {
  border-left-color: var(--teal);
  background: rgba(45, 212, 191, 0.07);
  color: #d8fff9;
}

.command-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.command-form input,
.oracle-form select,
.oracle-form textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(3, 9, 16, 0.96);
  color: var(--text);
  font: inherit;
}

.command-form input::placeholder {
  color: rgba(184, 216, 232, 0.50);
}

.oracle-form textarea::placeholder {
  color: rgba(184, 216, 232, 0.45);
  font-size: 0.88rem;
  line-height: 1.5;
}

.command-form input {
  padding: 10px 14px;
}

.command-form button {
  padding: 10px 18px;
}

.command-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.static-chips {
  margin-top: 4px;
}

.chip-button {
  padding: 6px 10px;
  font-size: 0.80rem;
  color: var(--muted);
  border-color: rgba(116, 243, 255, 0.30);
  white-space: nowrap;
}

.chip-button:hover {
  color: var(--text) !important;
  border-color: var(--cyan) !important;
}

/* Button SVG icons — inherit color, never shrink */
.secondary-button svg,
.chip-button svg,
.utility-launcher svg,
.ops-tab svg,
#oracle-button svg,
.compass-button svg {
  flex-shrink: 0;
  color: inherit;
  stroke: currentColor;
}

.status-list,
.inventory-list,
.objective-list,
.map-list {
  display: grid;
  gap: 2px;
}

.stat-card,
.inventory-item,
.objective-item,
.map-node {
  padding: 5px 0;
  border: none;
  background: transparent;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.stat-card + .stat-card,
.inventory-item + .inventory-item,
.objective-item + .objective-item,
.map-node + .map-node {
  border-top: 1px solid rgba(116, 243, 255, 0.10);
}

.stat-card.warn strong {
  color: rgba(255, 209, 102, 0.95);
}

.stat-card.danger strong {
  color: rgba(255, 108, 140, 0.95);
}

.map-node.current strong {
  color: var(--cyan);
}

.map-node.visited strong {
  color: var(--teal);
}

.map-node.unknown {
  opacity: 0.65;
}

.stat-card strong,
.inventory-item strong,
.objective-item strong,
.map-node strong {
  display: block;
  margin-bottom: 0;
  color: #ffffff;
  font-weight: 600;
  flex-shrink: 0;
}

.stat-card,
.inventory-item,
.objective-item,
.map-node {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.notes-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
}

.notes-list li {
  color: var(--text);
  line-height: 1.65;
  font-size: 0.92rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.oracle-status {
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  background: rgba(116, 243, 255, 0.06);
}

.oracle-copy {
  margin-top: 0;
  color: var(--text);
  line-height: 1.65;
  font-size: 0.9rem;
}

.oracle-form {
  display: grid;
  gap: 12px;
}

.oracle-form select,
.oracle-form textarea,
#oracle-button {
  padding: 12px 14px;
}

.oracle-output {
  min-height: 180px;
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed rgba(255, 191, 105, 0.50);
  background: rgba(255, 191, 105, 0.07);
  color: #ffefd0;
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 0.9rem;
}

/* ===================================================================
   SETTINGS PANEL
   =================================================================== */

.settings-group {
  padding: 16px 0;
  border-bottom: 1px solid var(--line-strong);
}

.settings-group:first-child {
  padding-top: 0;
}

.settings-group:last-child {
  border-bottom: none;
}

.settings-group h2 {
  font-size: 1.05rem;
  color: var(--text);
  margin: 4px 0 10px;
}

.settings-group p.muted {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
  margin: 0 0 10px;
}

.key-input-wrapper {
  position: relative;
  display: flex;
  gap: 0;
}

.key-input-wrapper input {
  flex: 1;
  width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(3, 9, 16, 0.96);
  color: var(--text);
  font: inherit;
  padding: 12px 44px 12px 14px;
}

.key-toggle-btn {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  font-size: 1rem;
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
}

.key-toggle-btn:hover {
  color: var(--cyan);
  opacity: 1;
}

.key-validation {
  min-height: 1.4em;
  font-size: 0.8rem;
  margin: 6px 0;
  line-height: 1.4;
}

.key-validation.valid {
  color: var(--teal);
}

.key-validation.invalid {
  color: var(--rose);
}

.settings-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.82rem;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.connection-dot.online {
  background: var(--teal);
  box-shadow: 0 0 6px rgba(45, 212, 191, 0.5);
}

.connection-dot.offline {
  background: var(--rose);
  box-shadow: 0 0 6px rgba(255, 122, 162, 0.3);
}

.connection-dot.checking {
  background: var(--amber);
  box-shadow: 0 0 6px rgba(255, 191, 105, 0.3);
  animation: blink-cursor 1s step-end infinite;
}

.key-status-text {
  color: var(--text);
  font-size: 0.84rem;
}

.settings-group select {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(3, 9, 16, 0.96);
  color: var(--text);
  font: inherit;
  padding: 10px 14px;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.toggle-row label {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--cyan);
  cursor: pointer;
}

/* ===================================================================
   COMMAND AUTOCOMPLETE
   =================================================================== */

.command-form {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 4px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  background: rgba(5, 13, 22, 0.99);
  z-index: 50;
  display: none;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
}

.autocomplete-list.visible {
  display: block;
}

.autocomplete-item {
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid rgba(116, 243, 255, 0.08);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: rgba(116, 243, 255, 0.10);
  color: var(--cyan);
}

.autocomplete-item .match-highlight {
  color: var(--cyan);
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Phase 2: Sidebar toggle button (hidden on desktop) */
.sidebar-toggle {
  display: none;
}

/* Phase 2: Sidebar backdrop (hidden by default) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(45, 212, 191, 0.08), transparent 45%),
    rgba(1, 6, 11, 0.76);
  backdrop-filter: blur(8px);
  z-index: 199;
}

.sidebar-backdrop.active {
  display: block;
}

/* Phase 2: Sidebar close button inside panel */
.sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

.sidebar-close:hover {
  border-color: var(--cyan);
  color: var(--text);
}

/* ===================================================================
   RESPONSIVE BREAKPOINTS
   Ordered from largest to smallest, with bounded ranges where needed
   =================================================================== */

/* --- Desktop short screens (height constrained) --- */

@media (max-height: 940px) and (min-width: 1251px) {
  .app-header h1 {
    font-size: clamp(1.9rem, 3vw, 2.6rem);
  }

  .eyebrow,
  .terminal-label {
    margin-bottom: 4px;
  }

  .oracle-header {
    margin-bottom: 10px;
  }

  .command-form input,
  .command-form button,
  .oracle-form select,
  .oracle-form textarea,
  #oracle-button {
    padding: 10px 12px;
  }

  .chip-button {
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .oracle-output {
    min-height: 120px;
  }
}

@media (max-height: 820px) {
  .app-header {
    padding: 5px 12px;
  }

  .app-header h1 {
    font-size: clamp(1.1rem, 2vw, 1.6rem);
  }
}

@media (max-height: 820px) and (min-width: 1251px) {
  .app-shell {
    gap: 6px;
    padding: 6px 10px;
  }

  .game-grid {
    gap: 6px;
  }

  .app-subtitle {
    display: none;
  }

  .terminal-panel {
    padding: 6px;
    grid-template-rows: 110px minmax(110px, 140px) minmax(80px, 1fr) auto;
  }

  .intel-rail {
    gap: 4px;
    padding: 6px;
  }
}

/* --- Tablet landscape: 1025px - 1250px --- */

@media (min-width: 1025px) and (max-width: 1250px) {
  .game-grid {
    grid-template-columns: minmax(0, 1fr);
    min-height: auto;
    gap: 14px;
  }

  .terminal-panel {
    min-height: 62vh;
    min-height: 62dvh;
    max-height: none;
    grid-template-rows: auto minmax(90px, auto) minmax(140px, 1fr) auto;
  }

  .command-panel {
    position: sticky;
    bottom: 0;
    z-index: 3;
  }

  .transcript {
    max-height: clamp(220px, 36vh, 420px);
  }

  .intel-rail {
    display: none;
  }
}

/* --- Tablet portrait and below: <=1024px --- */
/* Phase 1 & 2: Single-column layout + sidebar toggle */

@media (max-width: 1024px) {
  .game-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "terminal";
    min-height: auto;
    gap: 14px;
  }

  .terminal-panel {
    max-height: none;
    min-height: auto;
  }

  .intel-rail {
    display: none;
  }

  /* Phase 1: Reorder so command input and transcript come first */
  .command-panel { order: 1; }
  .transcript-panel { order: 2; }
  .terminal-topbar { order: 3; }
  .play-panel { order: 4; }

  .transcript {
    max-height: clamp(220px, 40svh, 400px);
  }

  /* Phase 2: Sidebar becomes a slide-over panel */
  .sidebar {
    top: 0;
    left: auto;
    right: 0;
    bottom: 0;
    inset: 0 0 0 auto;
    width: min(380px, 88vw);
    z-index: 200;
    max-height: none;
    transform: translateX(100%);
    transition: transform 300ms ease, visibility 0ms 300ms;
    opacity: 1;
    pointer-events: auto;
    visibility: hidden;
    overflow-y: auto;
    padding: 16px;
    background: var(--panel-strong);
    border-left: 1px solid var(--line);
    will-change: transform;
  }

  .sidebar.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 300ms ease, visibility 0ms 0ms;
  }

  /* Phase 2: Show the toggle button — inline in app-header */
  .sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--cyan);
    background: transparent;
    color: var(--cyan);
    font: inherit;
    font-size: 0.80rem;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .sidebar-toggle:hover {
    border-color: var(--text);
    color: var(--text);
  }

  /* App-header becomes a row with toggle on the right */
  .app-header {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .app-header-copy {
    flex: 1 1 auto;
    min-width: 0;
  }

  .app-header-meta {
    display: none;
  }

  /* Phase 2: Close button inside sidebar */
  .utility-launcher-panel {
    display: none;
  }
}

/* --- Small tablet / large phone: <=860px --- */

@media (max-width: 860px) {
  .app-shell {
    display: grid;
    gap: 14px;
  }

  .app-header {
    flex-direction: column;
    align-items: start;
    padding: 12px 14px;
  }

  .app-subtitle {
    display: none;
  }

  .app-header-meta {
    justify-content: start;
  }

  .ops-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  /* Phase 6: Compass 3x2 grid for better touch targets */
  .compass {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .transcript {
    max-height: clamp(220px, 38svh, 380px);
  }
}

/* --- Mobile: <=720px --- */

@media (max-width: 720px) {
  .app-shell {
    padding: 10px 8px 20px;
  }

  .app-header {
    padding: 10px 12px;
  }

  .app-header h1 {
    font-size: clamp(1.6rem, 5vw, 2.2rem);
  }

  .app-header-meta {
    display: none;
  }

  .terminal-panel {
    padding: 8px;
    grid-template-rows: auto auto minmax(120px, 1fr) auto auto;
    gap: 6px;
  }

  /* Phase 1: Reorder for mobile - input first, status second */
  .command-panel { order: 1; }
  .terminal-topbar { order: 2; }
  .transcript-panel { order: 3; }
  .play-panel { order: 4; }

  /* Phase 6: Compact terminal topbar */
  .terminal-topbar {
    gap: 6px;
    grid-template-columns: minmax(0, 1fr);
  }

  .terminal-actions-panel .terminal-label {
    display: none;
  }

  .terminal-status-panel {
    gap: 6px;
  }

  .terminal-status-panel .location-row {
    gap: 4px;
  }

  .utility-launcher-copy {
    font-size: 0.74rem;
  }

  /* Keep 2x2 grid on mobile — 4-col is too narrow */
  .button-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .mini-map-panel .terminal-label {
    display: none;
  }

  .mini-map-svg {
    aspect-ratio: 6 / 1.15;
    max-height: 60px;
  }

  .ops-panel {
    padding: 14px;
  }

  .ops-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Phase 3: Keep command form inline on mobile for better UX */
  .command-form {
    grid-template-columns: 1fr auto;
  }

  .command-form input {
    padding: 12px 14px;
    font-size: 0.9rem;
  }

  .command-form button {
    padding: 12px 16px;
    min-height: 48px;
  }

  .oracle-header {
    flex-direction: column;
  }

  .location-row {
    gap: 6px;
  }

  #location-title {
    font-size: 1.6rem;
  }

  .location-subtitle {
    margin-top: 4px;
    font-size: 0.85rem;
  }

  /* Phase 3: Touch-target-safe button sizes (WCAG 2.5.8 / 2.5.5) */
  .secondary-button {
    padding: 10px 10px;
    min-height: 44px;
    font-size: 0.78rem;
  }

  /* Phase 6: ANSI art - horizontal scroll, don't break structure */
  .ansi-art {
    font-size: 0.52rem;
    padding: 5px 6px;
    white-space: pre;
    overflow-x: auto;
    overflow-wrap: normal;
    -webkit-overflow-scrolling: touch;
    max-block-size: 80px;
  }

  .entry pre {
    font-size: 0.6rem;
    line-height: 1.15;
    white-space: pre;
    overflow-x: auto;
  }

  /* Phase 1: Much larger transcript on mobile */
  .transcript {
    max-height: clamp(200px, 40svh, 360px);
    min-block-size: 180px;
  }

  .entry {
    padding: 8px 10px;
  }

  /* Phase 3: Touch-target-safe chip buttons */
  .chip-button {
    padding: 10px 14px;
    font-size: 0.8rem;
    min-height: 44px;
    flex: 0 0 auto;
  }

  .terminal-card {
    padding: 10px 12px;
  }

  .static-chips {
    margin-top: 8px;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  /* Phase 3: Touch-target-safe compass buttons */
  .compass {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .compass-button {
    min-height: 44px;
    min-width: 44px;
    font-size: 0.9rem;
  }

  /* Phase 3: Touch-target-safe ops tabs */
  .ops-tab {
    min-height: 44px;
  }

  /* Phase 6: Oracle mobile optimization */
  .oracle-form textarea {
    max-height: 80px;
  }

  .oracle-output {
    min-height: 100px;
  }

  /* Phase 7: Lighter background grid on mobile */
  .background-grid {
    opacity: 0.2;
    background-size: 64px 64px;
  }
}

/* --- Ultra-compact mobile: <=400px --- */

@media (max-width: 400px) {
  .app-shell {
    padding: 8px 6px 16px;
  }

  .app-header {
    padding: 8px 10px;
  }

  .app-header h1 {
    font-size: 1.4rem;
  }

  .eyebrow {
    font-size: 0.62rem;
  }

  /* Phase 6: Hide ANSI art on very small screens - illegible anyway */
  .ansi-art {
    display: none;
  }

  .terminal-card {
    padding: 8px 10px;
  }

  #location-title {
    font-size: 1.3rem;
  }

  .badge {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .button-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .command-form input {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .chip-button {
    padding: 8px 10px;
    font-size: 0.75rem;
    min-height: 44px;
  }
}

/* ===================================================================
   CONTAINER QUERIES
   =================================================================== */

@container (max-width: 700px) {
  .terminal-topbar {
    grid-template-columns: minmax(0, 1fr) minmax(140px, 190px);
  }

  .utility-launcher-panel {
    display: none;
  }

  .scene-layout {
    grid-template-columns: 1fr;
  }
}

@container (max-width: 500px) {
  .terminal-topbar {
    grid-template-columns: 1fr;
  }
}

/* Phase 5: Container query for ops panel */
@container (max-width: 280px) {
  .ops-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
