:root {
  --bg: #ffffff;
  --fg: #2b2f38;
  --fg-soft: #5c6270;
  --fg-muted: #9ea4b0;
  --hairline: rgba(28, 34, 46, 0.11);
  --surface: rgba(255, 255, 255, 0.94);
  --surface-hover: rgba(28, 34, 46, 0.055);
  --track: #ebebef;
  --track-fill: rgba(43, 47, 56, 0.14);
  --tick: rgba(43, 47, 56, 0.18);
  --thumb-bg: #ffffff;
  --thumb-border: rgba(28, 34, 46, 0.22);
  --thumb-shadow: 0 1px 3px rgba(15, 20, 30, 0.14), 0 0.5px 1px rgba(15, 20, 30, 0.08);
  --seg-bg: #e4e6ec;
  --seg-fill: #545966;
  --pill-bg: rgba(28, 34, 46, 0.045);
  --pill-active-bg: rgba(28, 34, 46, 0.08);
  --menu-shadow: 0 10px 30px rgba(15, 22, 36, 0.12), 0 1px 3px rgba(15, 22, 36, 0.06);
  --toast-bg: rgba(28, 34, 46, 0.84);
  --toast-fg: #f7f9fc;
}

body[data-theme="dark"] {
  --fg: #edf1f8;
  --fg-soft: #adb6c8;
  --fg-muted: #6e788e;
  --hairline: rgba(226, 234, 250, 0.14);
  --surface: rgba(22, 28, 44, 0.94);
  --surface-hover: rgba(226, 234, 250, 0.09);
  --track: rgba(226, 234, 250, 0.13);
  --track-fill: rgba(235, 210, 155, 0.26);
  --tick: rgba(226, 234, 250, 0.24);
  --thumb-bg: #eef2fa;
  --thumb-border: rgba(255, 255, 255, 0.4);
  --thumb-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  --seg-bg: rgba(226, 234, 250, 0.18);
  --seg-fill: #d8dfee;
  --pill-bg: rgba(226, 234, 250, 0.07);
  --pill-active-bg: rgba(226, 234, 250, 0.15);
  --menu-shadow: 0 14px 36px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
  --toast-bg: rgba(235, 241, 252, 0.9);
  --toast-fg: #141926;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  transition: background-color 0.35s ease, color 0.35s ease;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 12px;
}

/* ── Top Bar ──────────────────────────────────────────────────────── */

.top-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 20;
}

.scene-picker {
  position: relative;
}

.scene-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.25s ease;
}

.scene-trigger:hover {
  background: var(--surface-hover);
}

.scene-trigger .chevron {
  color: var(--fg-muted);
  transition: transform 0.18s ease, color 0.15s ease;
}

.scene-trigger[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
  color: var(--fg);
}

.scene-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 224px;
  padding: 5px;
  border-radius: 11px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  box-shadow: var(--menu-shadow);
  backdrop-filter: blur(12px);
  z-index: 50;
}

.scene-menu[hidden] {
  display: none;
}

.scene-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 450;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.scene-option:hover {
  background: var(--surface-hover);
}

.scene-option.active {
  background: var(--pill-active-bg);
  font-weight: 600;
}

.scene-option-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scene-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 4px;
  border: 1px solid var(--hairline);
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-muted);
}

.scene-option.active .scene-key {
  color: var(--fg);
  border-color: var(--fg-muted);
}

.scene-option-time {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
}

/* 5-Scenario Progress Segments */
.scene-segments {
  display: flex;
  align-items: center;
  gap: 5px;
}

.scene-segment {
  position: relative;
  width: 24px;
  height: 12px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.scene-segment-track {
  position: relative;
  width: 100%;
  height: 2.5px;
  border-radius: 99px;
  background: var(--seg-bg);
  overflow: hidden;
  transition: height 0.14s ease, background-color 0.25s ease;
}

.scene-segment:hover .scene-segment-track {
  height: 3.5px;
}

.scene-segment-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 99px;
  background: var(--seg-fill);
  transition: background-color 0.25s ease;
}

/* ── Center Canvas Viewport ───────────────────────────────────────── */

.diorama-viewport {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

#diorama-canvas {
  display: block;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
  touch-action: none;
}

#diorama-canvas.interactive-hover {
  cursor: pointer;
}

.interact-toast {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
}

.interact-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Bottom Transport Bar ─────────────────────────────────────────── */

.bottom-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 20;
}

.transport-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--fg-soft);
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--fg);
}

#btn-play .icon-play {
  display: none;
}

#btn-play.paused .icon-pause {
  display: none;
}

#btn-play.paused .icon-play {
  display: block;
}

.btn-audio .icon-unmuted {
  display: none;
}

.btn-audio[aria-pressed="true"] .icon-muted {
  display: none;
}

.btn-audio[aria-pressed="true"] .icon-unmuted {
  display: block;
}

.btn-audio[aria-pressed="true"] {
  color: var(--fg);
}

#btn-story-play .icon-play {
  display: none;
}

#btn-story-play.paused .icon-pause {
  display: none;
}

#btn-story-play.paused .icon-play {
  display: block;
}

/* Scrubber */
.scrubber {
  position: relative;
  width: min(220px, 44vw);
  height: 24px;
  display: flex;
  align-items: center;
  cursor: ew-resize;
  touch-action: none;
  outline: none;
}

.scrubber-track {
  position: relative;
  width: 100%;
  height: 11px;
  border-radius: 6px;
  background: var(--track);
  transition: background-color 0.25s ease;
}

.scrubber-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 70%;
  border-radius: 6px;
  background: var(--track-fill);
  pointer-events: none;
}

.scrubber-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scrubber-tick {
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 1px;
  background: var(--tick);
  transform: translateX(-0.5px);
}

.scrubber-thumb {
  position: absolute;
  top: 50%;
  left: 70%;
  width: 20px;
  height: 15px;
  border-radius: 5px;
  border: 1px solid var(--thumb-border);
  background: var(--thumb-bg);
  box-shadow: var(--thumb-shadow);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: transform 0.1s ease, background-color 0.25s ease;
}

.scrubber:hover .scrubber-thumb,
.scrubber.dragging .scrubber-thumb {
  transform: translate(-50%, -50%) scale(1.06);
}

.scrubber:focus-visible .scrubber-thumb {
  outline: 2px solid var(--fg-soft);
  outline-offset: 1px;
}

.time-readout {
  min-width: 35px;
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--fg-soft);
  text-align: center;
  letter-spacing: 0.01em;
}

.mode-pill {
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--pill-bg);
  color: var(--fg-soft);
  font-size: 10.5px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mode-pill:hover {
  background: var(--pill-active-bg);
  color: var(--fg);
}

.mode-pill[aria-pressed="true"] {
  background: var(--pill-active-bg);
  color: var(--fg);
}

.hint-line {
  margin: 0;
  font-size: 10.5px;
  color: var(--fg-muted);
  letter-spacing: 0.01em;
  text-align: center;
  transition: color 0.3s ease;
}

/* ── Mode switching ───────────────────────────────────────────────── */

body.mode-story .sandbox-only,
body.mode-sandbox .story-only {
  display: none !important;
}

/* ── Story header ─────────────────────────────────────────────────── */

.story-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.story-chapter {
  padding: 4px 12px;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.scene-segment.locked {
  cursor: default;
  opacity: 0.45;
}

/* ── Canvas frame + story overlays ────────────────────────────────── */

.canvas-frame {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.story-fade {
  position: absolute;
  inset: 0;
  background: #0b0d12;
  opacity: 0;
  pointer-events: none;
  transition-property: opacity;
  transition-timing-function: ease;
}

.story-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  line-height: 1.2;
  text-align: center;
  color: #f3f5f9;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.9s ease, transform 0.9s ease;
  pointer-events: none;
}

.story-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.story-card[hidden] {
  display: none;
}

.card-kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #d9534f;
}

.card-title {
  font-size: clamp(22px, 4.2vw, 40px);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.card-sub {
  font-size: 13px;
  color: #a9b1c2;
  letter-spacing: 0.02em;
}

.story-end.visible {
  pointer-events: auto;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.card-btn {
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #f3f5f9;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.card-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.card-btn.primary {
  background: #f3f5f9;
  color: #141821;
  border-color: transparent;
}

.card-btn.primary:hover {
  background: #ffffff;
}

.story-pause {
  background: rgba(11, 13, 18, 0.72);
}

.story-pause.visible {
  pointer-events: auto;
}

.story-end.death .card-kicker {
  color: #ff6b6b;
}

/* ── Gameplay HUD ─────────────────────────────────────────────────── */

#diorama-canvas.aiming {
  cursor: none;
}

.hud {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px;
  line-height: 1.2;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.hud[hidden] {
  display: none;
}

.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-right {
  align-items: flex-end;
}

.hud-hearts {
  display: flex;
  gap: 4px;
}

.heart {
  width: 16px;
  height: 14px;
  background: #e5484d;
  clip-path: polygon(50% 100%, 0 45%, 0 15%, 15% 0, 35% 0, 50% 15%, 65% 0, 85% 0, 100% 15%, 100% 45%);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.35));
}

.heart.empty {
  background: rgba(30, 32, 40, 0.35);
}

.hud-goal,
.hud-ammo,
.hud-kills {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(16, 18, 24, 0.62);
  color: #f3f5f9;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.hud-goal::before {
  content: '→ ';
  color: #60d678;
}

.hud-ammo {
  font-size: 14px;
}

.hud-ammo.low {
  color: #ffb4a8;
}

.hud-kills {
  font-weight: 500;
  color: #c9cfdb;
}

/* ── Minimal in-game HUD (overrides) ─────────────────────────────── */

.hud .heart {
  width: 11px;
  height: 10px;
}

.hud-right {
  position: absolute;
  left: 14px;
  bottom: 12px;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}

.hud .hud-ammo {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0;
  background: none;
  border-radius: 0;
}

.hud .hud-ammo[hidden] {
  display: none;
}

.hud .pip {
  width: 3px;
  height: 10px;
  border-radius: 1px;
  background: #f2cf72;
  box-shadow: 0 0 0 1px rgba(10, 10, 14, 0.45);
}

.hud .pip.empty {
  background: rgba(255, 255, 255, 0.16);
}

.hud .hud-ammo.reloading .pip {
  animation: pip-blink 0.5s steps(2) infinite;
}

@keyframes pip-blink {
  50% { opacity: 0.25; }
}

.hud .reserve {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.hud .hud-stamina {
  width: 56px;
  height: 3px;
}

.story-title {
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  text-align: center;
  font-size: clamp(26px, 6vw, 56px);
  font-weight: 800;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: #ffffff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 0 22px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: scale(1.04);
  transition: opacity 0.5s ease, transform 2.4s ease;
  pointer-events: none;
}

.story-title.visible {
  opacity: 1;
  transform: scale(1);
}

.hud-tag {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(150, 18, 28, 0.82);
  color: #fff1f1;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.hud-stamina {
  width: 92px;
  height: 5px;
  border-radius: 99px;
  background: rgba(16, 18, 24, 0.5);
  overflow: hidden;
}

.hud-stamina-fill {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: #8fd9a0;
  transition: width 0.1s linear;
}

.hud-stamina.low .hud-stamina-fill {
  background: #f0a35e;
}

.hud-timer {
  padding: 4px 10px;
  border-radius: 7px;
  background: rgba(16, 18, 24, 0.7);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-timer.urgent {
  color: #ffd27a;
}

.hud-goal[hidden],
.hud-ammo[hidden],
.hud-kills[hidden],
.hud-timer[hidden] {
  display: none;
}

.story-caption {
  position: absolute;
  left: 50%;
  bottom: 54px;
  max-width: min(80%, 560px);
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(10, 12, 18, 0.74);
  color: #f3f5f9;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  transition: opacity 0.45s ease, transform 0.45s ease;
  pointer-events: none;
}

.story-caption.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hud-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 12px;
  max-width: calc(100% - 24px);
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(16, 18, 24, 0.7);
  color: #dfe4ee;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}

.hud-hint b {
  color: #ffffff;
  font-weight: 650;
}

.hud-hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Story transport ──────────────────────────────────────────────── */

.story-progress {
  position: relative;
  width: min(220px, 40vw);
  height: 6px;
  border-radius: 99px;
  background: var(--track);
  overflow: hidden;
}

.story-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 99px;
  background: var(--seg-fill);
}

/* ── Start screen ─────────────────────────────────────────────────── */

.start-screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(250, 250, 252, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.6s ease;
}

.start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  text-align: center;
}

.start-kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #c4413c;
}

.start-title {
  margin: 0;
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #1d2129;
}

.start-text {
  margin: 0 0 6px;
  font-size: 14px;
  line-height: 1.5;
  color: #5c6270;
}

.start-btn {
  height: 42px;
  min-width: 160px;
  padding: 0 22px;
  border: none;
  border-radius: 10px;
  background: #1d2129;
  color: #ffffff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.start-btn:hover {
  background: #000000;
  transform: translateY(-1px);
}

.start-links {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9ea4b0;
  font-size: 12.5px;
}

.start-link {
  border: none;
  background: none;
  padding: 4px 2px;
  color: #5c6270;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.start-link:hover {
  color: #1d2129;
}

@media (max-width: 520px) {
  .stage {
    padding: 14px 10px 14px;
  }
  .story-progress {
    width: 30vw;
  }
  .transport-row {
    gap: 8px;
  }
  .hint-line {
    font-size: 9.5px;
  }
}
