:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #0d0d0d;
  --ink: #f5f5f5;
  --muted: #a8f0a8;
  --accent: #ff4a4a;
  --line: #e8e8e8;
  --shadow: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 28rem),
    var(--bg);
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

.crt-shell {
  width: min(72rem, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.top-panel,
.terminal,
.choices,
.inventory-panel {
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.88);
  box-shadow: 0 0 1.4rem var(--shadow), inset 0 0 2rem rgba(255, 255, 255, 0.04);
}

.top-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  text-transform: uppercase;
}

.kicker {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: clamp(0.78rem, 2vw, 0.95rem);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0.06em;
}

h1 {
  font-size: clamp(1.35rem, 6vw, 3rem);
}

h2 {
  color: var(--muted);
  font-size: clamp(1.1rem, 4vw, 1.55rem);
}

.status-lights {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 5.5rem;
  border: 1px dashed var(--line);
  padding: 0.45rem 0.65rem;
  text-align: center;
  color: var(--muted);
}

.read-toggle {
  border: 1px solid var(--line);
  background: #000;
  color: var(--muted);
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.read-toggle[aria-pressed="true"] {
  background: var(--muted);
  color: #000;
}

.read-toggle:focus-visible {
  outline: 3px solid var(--muted);
  outline-offset: 2px;
}

.scene-picture {
  margin: 0 0 1rem;
}

.scene-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  background: #000;
  box-shadow: 0 0 1rem rgba(255, 74, 74, 0.18);
}

figcaption {
  border-top: 1px dashed var(--line);
  margin-top: 1rem;
  padding-top: 0.75rem;
  color: var(--muted);
}

.terminal {
  display: flex;
  flex-direction: column;
  min-height: 24rem;
  padding: 1rem;
}

.scene-panel {
  margin-bottom: 1rem;
}

.story-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.story-log p {
  margin: 0.75rem 0;
}

.system-message {
  color: var(--muted);
}

.story-pre {
  margin: 0.75rem 0;
  font-family: inherit;
  font-size: clamp(0.7rem, 2.4vw, 0.95rem);
  line-height: 1.2;
  white-space: pre;
  overflow-x: auto;
  color: var(--ink);
  text-shadow: 0 0 0.35rem rgba(255, 255, 255, 0.35);
}

.command-form {
  border-top: 1px dashed var(--line);
  margin-top: 1rem;
  padding-top: 0.8rem;
}

.command-form label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.prompt-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
}

input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #000;
  color: var(--ink);
  padding: 0.7rem;
}

button {
  border: 2px solid var(--line);
  background: #111;
  color: var(--ink);
  padding: 0.7rem 0.85rem;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}

button:hover,
button:focus-visible {
  background: var(--ink);
  color: #000;
  outline: 3px solid var(--muted);
  outline-offset: 2px;
}

button:disabled {
  border-style: dashed;
  color: #8b8b8b;
  cursor: not-allowed;
}

.choices {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
  padding: 1rem;
}

.choice-button::first-letter {
  color: var(--accent);
}

.inventory-panel {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
}

.notebook-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  padding: 0.4rem 0;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

.notebook-toggle:hover,
.notebook-toggle:focus-visible {
  background: transparent;
  color: var(--ink);
  outline: 2px solid var(--muted);
  outline-offset: 2px;
}

.inventory-panel ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
  margin: 0.6rem 0 0.2rem;
  list-style: none;
}

.inventory-panel li {
  border: 1px dashed var(--line);
  padding: 0.35rem 0.55rem;
  color: var(--muted);
}

@media (min-width: 900px) {
  .crt-shell {
    display: grid;
    grid-template-columns: minmax(30rem, 1fr) minmax(14rem, 0.38fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "top       top"
      "terminal  choices"
      "inventory inventory";
    gap: 1rem;
    height: 100vh;
    min-height: 0;
    overflow-y: auto;
  }

  .top-panel {
    grid-area: top;
    margin-bottom: 0;
  }

  .terminal {
    grid-area: terminal;
    min-height: 0;
    overflow: hidden;
  }

  .scene-panel {
    margin-bottom: 0;
  }

  .scene-picture {
    display: grid;
    grid-template-columns: minmax(16rem, 0.58fr) minmax(14rem, 0.42fr);
    gap: 1rem;
    align-items: end;
  }

  .scene-picture figcaption {
    margin-top: 0;
    min-height: 100%;
    border-top: 0;
    border-left: 1px dashed var(--line);
    padding: 0 0 0 1rem;
  }

  .choices {
    grid-area: choices;
    margin-top: 0;
    align-content: start;
    overflow-y: auto;
  }

  .inventory-panel {
    grid-area: inventory;
    margin-top: 0;
    padding-block: 0.3rem;
  }

  /* Notebook collapsed by default at laptop widths */
  .inventory-panel ul {
    display: none;
  }

  .inventory-panel.is-open ul {
    display: flex;
  }

  /* Header compacts after first player action */
  .crt-shell.is-playing .kicker {
    display: none;
  }

  .crt-shell.is-playing h1 {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
  }

  .crt-shell.is-playing .top-panel {
    padding-block: 0.3rem;
  }

  .story-log {
    padding-right: 0.5rem;
  }
}

@media (max-width: 760px) {
  .crt-shell {
    padding-inline: 0.65rem;
  }

  .top-panel {
    display: block;
  }

  .status-lights {
    margin-top: 0.75rem;
    text-align: left;
  }

  .terminal {
    margin-bottom: 0.85rem;
  }

  figcaption {
    font-size: 0.92rem;
  }

  .prompt-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .prompt-row button {
    grid-column: 1 / -1;
    text-align: center;
  }
}

.crt-shell::after {
  pointer-events: none;
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.035),
    rgba(255, 255, 255, 0.035) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: screen;
  animation: scanline-flicker 4s steps(2, end) infinite;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fade-in 0.3s ease-out both;
}

@keyframes flash-update {
  0%   { background: var(--muted); color: #000; }
  60%  { background: var(--muted); color: #000; }
  100% { background: transparent; color: var(--muted); }
}

.flash-update {
  animation: flash-update 0.8s ease-out both;
}

@keyframes art-pulse {
  0%   { filter: brightness(1.55) saturate(1.35); }
  100% { filter: brightness(1) saturate(1); }
}

.art-pulse {
  animation: art-pulse 0.55s ease-out both;
}

@keyframes scanline-flicker {
  0%,
  100% {
    opacity: 0.22;
  }

  50% {
    opacity: 0.12;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
