:root {
  --surface-primary: #0C0F14;
  --surface-secondary: #151921;
  --surface-elevated: #1C2230;
  --border: #2A3040;
  --text-primary: #E8EAED;
  --text-secondary: #8B93A1;
  --text-muted: #545D6E;
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --danger-muted: rgba(239, 68, 68, 0.12);
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-serif: 'Instrument Serif', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--surface-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Utilities ── */
.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
}

/* ── Classification label ── */
.classification-label {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 3px;
  margin-bottom: 24px;
}

/* ── Buttons ── */
.btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 28px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 200ms ease, opacity 200ms ease;
  letter-spacing: 0.02em;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Meta note ── */
.meta-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
  text-align: center;
}

/* ══════════════════════════════════════════
   STATE 1 — Title Screen
══════════════════════════════════════════ */
.screen-title {
  align-items: center;
  justify-content: center;
  background: var(--surface-primary);
  padding: 40px 24px;
}

.title-inner {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.scenario-heading {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: 6px;
}

.scenario-subheading {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(18px, 2.5vw, 26px);
  font-weight: 400;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.scenario-tagline {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 32px;
}

.scenario-description {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 40px;
  max-width: 460px;
}

/* ══════════════════════════════════════════
   STATE 2/3 — Simulation Screen
══════════════════════════════════════════ */
.screen-simulation {
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

.video-col {
  flex: 0 0 65%;
  display: grid;
  grid-template-rows: 1fr 54px 196px;
  border-right: 1px solid var(--border);
  overflow: hidden;
  height: 100vh;
}

.video-wrapper {
  position: relative;
  background: #000;
  overflow: hidden;
  min-height: 0;
  display: flex;
  align-items: flex-start;
}

#sim-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top;
  display: block;
}

.video-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 15, 20, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Facility Status Bar ── */
.status-bar {
  display: flex;
  height: 54px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface-secondary);
  overflow: hidden;
}

.status-metric {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 14px;
  border-right: 1px solid var(--border);
  gap: 3px;
  overflow: hidden;
  min-width: 0;
}

.status-metric:last-child { border-right: none; }

.status-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.status-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  transition: color 400ms ease;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-value[data-color="success"] { color: var(--success); }
.status-value[data-color="warning"] { color: var(--warning); }
.status-value[data-color="danger"]  { color: var(--danger); }
.status-value[data-color="muted"]   { color: var(--text-muted); }

/* ── Incident Feed ── */
.feed-container {
  display: flex;
  flex-direction: column;
  height: 196px;
  background: var(--surface-secondary);
  overflow: hidden;
}

.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 4px;
  flex-shrink: 0;
}

.feed-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.feed-indicator {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 5px;
}

.feed-indicator::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.feed-scroll-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.feed-fade-top,
.feed-fade-bottom {
  position: absolute;
  left: 0; right: 0;
  height: 24px;
  pointer-events: none;
  z-index: 1;
}

.feed-fade-top {
  top: 0;
  background: linear-gradient(to bottom, var(--surface-secondary), transparent);
}

.feed-fade-bottom {
  bottom: 0;
  background: linear-gradient(to top, var(--surface-secondary), transparent);
}

.incident-feed {
  height: 100%;
  overflow-y: auto;
  padding: 4px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.incident-feed::-webkit-scrollbar { width: 4px; }
.incident-feed::-webkit-scrollbar-track { background: transparent; }
.incident-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.feed-entry {
  display: flex;
  gap: 10px;
  font-size: 12px;
  font-family: 'DM Sans', monospace;
  line-height: 1.4;
  padding: 2px 0 2px 8px;
  border-left: 2px solid transparent;
  animation: feed-in 300ms ease forwards;
  opacity: 0;
  transform: translateY(4px);
}

@keyframes feed-in {
  to { opacity: 1; transform: translateY(0); }
}

.feed-entry.type-success { border-left-color: var(--success); }
.feed-entry.type-warning { border-left-color: var(--warning); }
.feed-entry.type-danger  { border-left-color: var(--danger); }
.feed-entry.type-neutral { border-left-color: var(--border); }

.feed-entry.critical { animation: feed-in 300ms ease forwards, pulse-entry 600ms ease 300ms; }

@keyframes pulse-entry {
  0%   { background: rgba(239, 68, 68, 0.0); }
  40%  { background: rgba(239, 68, 68, 0.15); }
  100% { background: transparent; }
}

.feed-timestamp {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.feed-source {
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.feed-message {
  color: var(--text-secondary);
}

/* ══════════════════════════════════════════
   Right panel — shared
══════════════════════════════════════════ */
.panel-col {
  flex: 0 0 35%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--surface-secondary);
}

.panel-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 24px;
  gap: 20px;
}

.panel-top { display: flex; flex-direction: column; gap: 8px; }

.phase-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Progress bar ── */
.progress-section { margin-top: 4px; }

.progress-bar-track {
  position: relative;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 400ms ease;
}

.progress-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.progress-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-marker span {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-marker.done {
  background: var(--accent);
  border-color: var(--accent);
}

.progress-marker.done span { color: #fff; }
.progress-marker.active { border-color: var(--accent); }
.progress-marker.active span { color: var(--accent); }

/* ── Score row ── */
.score-row {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

.score-display,
.decisions-remaining {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.score-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ── Playing standby ── */
.panel-standby {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.standby-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

.standby-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse-dot 3s ease-in-out infinite;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════
   STATE 3 — Decision Panel
══════════════════════════════════════════ */
.decision-title {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 20px;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.3;
}

.decision-context {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  border-left: 2px solid var(--border);
  padding-left: 12px;
  font-style: italic;
}

/* ── Timer ── */
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
}

.timer-display {
  font-size: 48px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1;
  transition: color 300ms ease;
  letter-spacing: -0.02em;
}

.timer-display.warn  { color: var(--warning); }
.timer-display.urgent { color: var(--danger); }

.timer-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Options list ── */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.option-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-primary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 200ms ease, border-left-color 200ms ease;
  opacity: 0;
  animation: option-in 200ms ease forwards;
  text-align: left;
  width: 100%;
  font-family: var(--font-sans);
}

.option-card:nth-child(1) { animation-delay: 0ms; }
.option-card:nth-child(2) { animation-delay: 80ms; }
.option-card:nth-child(3) { animation-delay: 160ms; }
.option-card:nth-child(4) { animation-delay: 240ms; }

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

.option-card:hover {
  background: var(--surface-elevated);
  border-left-color: var(--accent);
}

.option-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.option-card.selected {
  background: rgba(59, 130, 246, 0.08);
  border-left-color: var(--accent);
  border-color: rgba(59, 130, 246, 0.3);
}

.option-card.result-optimal  { border-left-color: var(--success); background: rgba(34, 197, 94, 0.08); }
.option-card.result-acceptable { border-left-color: var(--warning); background: rgba(245, 158, 11, 0.08); }
.option-card.result-suboptimal { border-left-color: var(--danger); background: var(--danger-muted); }

.option-letter {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-top: 1px;
  transition: background 200ms ease, color 200ms ease;
}

.option-card.selected .option-letter { background: var(--accent); color: #fff; }
.option-card.result-optimal .option-letter  { background: var(--success); color: #fff; }
.option-card.result-acceptable .option-letter { background: var(--warning); color: #fff; }
.option-card.result-suboptimal .option-letter { background: var(--danger); color: #fff; }

.option-content { flex: 1; }

.option-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

.option-result-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
  display: none;
}

.option-card.result-optimal .option-result-label  { display: block; color: var(--success); }
.option-card.result-acceptable .option-result-label { display: block; color: var(--warning); }
.option-card.result-suboptimal .option-result-label { display: block; color: var(--danger); }

/* ── Show Answers ── */
.show-answers-row {
  display: flex;
  justify-content: center;
  padding: 24px 0;
}

.btn-show-answers { width: 100%; }

/* ── Confirm + Feedback ── */
.confirm-row { padding-top: 4px; }

.btn-confirm { width: 100%; }

.feedback-row {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

.feedback-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ══════════════════════════════════════════
   STATE 4 — Debrief
══════════════════════════════════════════ */
.screen-debrief {
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px;
  overflow-y: auto;
}

.debrief-inner {
  max-width: 820px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.debrief-header { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }

.debrief-heading {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 400;
  color: var(--text-primary);
}

.debrief-subhead {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* ── Score block ── */
.debrief-score-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 28px 32px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.final-score {
  font-size: 56px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.performance-band {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 480px;
  line-height: 1.5;
}

/* ── Decision timeline ── */
.debrief-timeline {
  overflow-x: auto;
  padding-bottom: 4px;
}

.timeline-nodes {
  display: flex;
  gap: 0;
  min-width: max-content;
}

.timeline-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 160px;
  padding: 0 16px;
  position: relative;
}

.timeline-node + .timeline-node::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  width: 100%;
  height: 1px;
  background: var(--border);
  z-index: 0;
  left: -50%;
  width: 100%;
}

.timeline-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-secondary);
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timeline-dot.optimal    { background: var(--success); border-color: var(--success); }
.timeline-dot.acceptable { background: var(--warning); border-color: var(--warning); }
.timeline-dot.suboptimal { background: var(--danger); border-color: var(--danger); }
.timeline-dot.timeout    { background: var(--surface-elevated); border-color: var(--danger); }

.timeline-dot-inner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

.timeline-phase {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

.timeline-choice {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 130px;
  line-height: 1.3;
}

.timeline-points {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timeline-points.optimal    { color: var(--success); }
.timeline-points.acceptable { color: var(--warning); }
.timeline-points.suboptimal, .timeline-points.timeout { color: var(--danger); }

/* ── Decision review cards ── */
.debrief-decisions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.debrief-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.debrief-card {
  padding: 20px 24px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
}

.debrief-card.optimal    { border-left-color: var(--success); }
.debrief-card.acceptable { border-left-color: var(--warning); }
.debrief-card.suboptimal { border-left-color: var(--danger); }
.debrief-card.timeout    { border-left-color: var(--danger); }

.debrief-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 16px;
}

.debrief-card-phase {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.debrief-card-points {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.debrief-card-points.optimal    { color: var(--success); }
.debrief-card-points.acceptable { color: var(--warning); }
.debrief-card-points.suboptimal,
.debrief-card-points.timeout    { color: var(--danger); }

.debrief-card-body { display: flex; flex-direction: column; gap: 8px; }

.debrief-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.debrief-row-label {
  font-weight: 600;
  color: var(--text-muted);
  min-width: 100px;
  flex-shrink: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-top: 1px;
}

.debrief-row-value { color: var(--text-secondary); }

.debrief-row.explain .debrief-row-value {
  color: var(--text-primary);
  font-style: italic;
}

/* ── Debrief feed ── */
.debrief-feed-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.debrief-feed {
  max-height: 280px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  height: auto;
}

.debrief-gap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.debrief-gap::before,
.debrief-gap::after {
  content: '';
  flex: 1;
  border-top: 1px dashed var(--border);
}

/* ── Footer ── */
.debrief-footer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding-bottom: 24px;
}

.debrief-footer .meta-note { text-align: left; }

/* ══════════════════════════════════════════
   Responsive
══════════════════════════════════════════ */
@media (max-width: 900px) {
  .screen-simulation {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }

  .video-col {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .video-wrapper {
    aspect-ratio: 16 / 9;
    height: auto;
  }

  .status-bar { height: auto; }
  .status-metric { padding: 10px 12px; }
  .feed-container { height: auto; max-height: 180px; }

  .panel-col {
    flex: 0 0 auto;
  }
}
