/* --- Variables --- */
:root {
  --bg: #0c0c0e;
  --bg-card: #141418;
  --border: #2a2a30;
  --text: #e8e6e3;
  --text-muted: #8a8884;
  --accent: #7dd3fc;
  --accent-dim: rgba(125, 211, 252, 0.25);
  --success: #86efac;
  --error: #fca5a5;
  --font-serif: "Instrument Serif", Georgia, serif;
  --font-sans: "Outfit", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
  --space: clamp(1rem, 4vw, 2.5rem);
  --radius: 12px;
}

/* --- Reset & base --- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; height: 100%; }
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* --- Slide system: one slide at a time, Next only --- */
.slide-container {
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.slide-track {
  display: flex;
  flex-direction: column;
  transition: transform 0.4s ease-out;
  will-change: transform;
}

.slide {
  height: 100vh;
  min-height: 100vh;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1.5rem;
}

.slide-inner {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space) 1.25rem;
  overflow-y: auto;
}

/* Let panel shrink inside slides so Next button stays visible */
.slide-inner .panel {
  min-height: 0;
}

.next-wrap {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem 0;
  margin-top: auto;
}

/* Fixed bar at bottom so Next is always visible */
/* Hide in-slide next wraps; we use global bar instead */
.slide .next-wrap {
  display: none;
}

/* Global Next bar: fixed to viewport, outside transformed track */
.global-next-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem 1.25rem 1.5rem;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
}

.next-btn {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  padding: 0.65rem 1.5rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.2s;
}

.next-btn:hover { opacity: 0.9; }

.next-btn.next-reveal {
  font-size: 1.05rem;
  padding: 0.75rem 1.75rem;
}

.next-wrap-reveal .next-btn { display: none; }

/* --- Layout --- */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Panels --- */
.panel {
  min-height: 100vh;
  padding: var(--space) 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 640px) {
  .panel { padding-left: 2rem; padding-right: 2rem; }
}

/* --- Hero --- */
.hero {
  text-align: center;
  padding-top: 4rem;
  padding-bottom: 4rem;
}

.hero-inner {
  max-width: 42rem;
  margin: 0 auto;
}

.hero-label {
  font-family: var(--font-mono);
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.75rem, 10vw, 5rem);
  font-weight: 400;
  line-height: 1.1;
  margin: 0 0 1rem;
  color: var(--text);
}

.hero-sub {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  color: var(--text-muted);
  margin: 0;
}

/* --- Story cards --- */
.story .card {
  max-width: 36rem;
  width: 100%;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.5rem, 4vw, 2.5rem);
}

.card-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  display: block;
  margin-bottom: 1rem;
}

.story-copy {
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  line-height: 1.7;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.section-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.card-with-image .story-copy { margin-bottom: 1rem; }

.timeline-image {
  margin: 0 0 1.25rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.timeline-image img {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .timeline-image img { max-width: 400px; }
}

.story-copy.expecting {
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  color: var(--accent);
  margin-top: 0.5rem;
}

/* --- Phase panels (red herring, misleading, ML fail) --- */
.phase-panel .card { max-width: 36rem; width: 100%; }

.phase-card .puzzle-title {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  margin: 0 0 1rem;
}

.dashboard-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.timeline-image.grayscale img { filter: grayscale(1); opacity: 0.9; }

.dashboard-stats { flex: 1; min-width: 180px; }

.stat {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin: 0 0 0.35rem;
}

.stat .muted { color: var(--text-muted); font-weight: 400; }

.confusion-matrix { margin: 1rem 0; }

.matrix-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.matrix-table {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  border-collapse: collapse;
  width: 100%;
  max-width: 200px;
}

.matrix-table th, .matrix-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: center;
}

.matrix-table th { color: var(--text-muted); font-weight: 500; }

.plot-placeholder { margin: 1rem 0; }

.plot-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.plot-curve {
  height: 80px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  position: relative;
  overflow: hidden;
}

.plot-curve.oscillating::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, #ec4899 20%, #3b82f6 50%, #ec4899 80%, transparent 100%);
  animation: oscillate 2.5s ease-in-out infinite;
}

@keyframes oscillate {
  0%, 100% { opacity: 0.6; transform: translateY(0) scaleX(0.8); }
  50% { opacity: 1; transform: translateY(-15px) scaleX(1); }
}

.plot-caption {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 0;
}

.clues-list { margin-top: 0.5rem; }

.clue-item {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.clue-item:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.clue-label {
  font-size: 0.8rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.25rem;
}

.clue-value {
  font-size: 1rem;
  margin: 0;
  color: var(--text);
}

.clue-item.playlist .clue-value { display: inline; }

.clue-item.playlist .fade-to {
  opacity: 0;
  margin-left: 0.5rem;
}

.pipeline-list { margin: 0.5rem 0; }

.pipeline-item {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin: 0 0 0.35rem;
  color: var(--text-muted);
}

.ml-loop { margin: 1rem 0; padding-left: 0.5rem; border-left: 2px solid var(--border); }

.ml-epoch {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 0.35rem 0;
  color: var(--text);
  opacity: 0;
}

.model-fail {
  font-weight: 500;
  color: var(--accent);
  margin: 1rem 0 0;
  opacity: 0;
  display: none;
}

.model-fail.pause { margin-top: 0.5rem; color: var(--text-muted); opacity: 0; }

.reveal-title { font-size: clamp(2rem, 6vw, 3.5rem); margin-bottom: 0.5rem; }

.reveal-text.final { font-size: 1.5rem; color: var(--text); }

/* --- Game (dino-style runner, blue/pink coins) --- */
.game-panel .card { max-width: 480px; }

.game-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.game-coins {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.coin-count.blue { color: #3b82f6; font-weight: 600; }
.coin-count.pink { color: #ec4899; font-weight: 600; }

.game-viewport {
  position: relative;
  width: 100%;
  max-width: 440px;
  height: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 auto;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.game-world {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 9000px;
  will-change: transform;
}

.game-ground-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  background: var(--border);
}

.game-obstacles, .game-coins-layer { position: absolute; left: 0; top: 0; right: 0; bottom: 0; pointer-events: none; }

.game-obstacle {
  position: absolute;
  bottom: 14px;
  width: 20px;
  height: 36px;
  background: var(--text-muted);
  border-radius: 4px;
  clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
}

.game-coin {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  bottom: 28px;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.3);
}

.game-coin.blue { background: linear-gradient(135deg, #60a5fa, #3b82f6); }
.game-coin.pink { background: linear-gradient(135deg, #f472b6, #ec4899); }

.game-coin.collected { opacity: 0; pointer-events: none; transition: opacity 0.15s ease; }

.game-finish {
  position: absolute;
  bottom: 0;
  width: 4px;
  top: 0;
  background: linear-gradient(180deg, transparent, var(--accent), transparent);
  left: 8800px;
}

.game-player {
  position: absolute;
  left: 56px;
  bottom: 14px;
  width: 28px;
  height: 36px;
  background: var(--accent);
  border-radius: 6px;
  transition: none;
  pointer-events: none;
  z-index: 2;
}

.game-status-wrap {
  min-height: 5rem;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.game-status {
  font-size: 0.9rem;
  margin: 0;
  color: var(--text-muted);
  min-height: 1.4em;
  height: 2.8em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.game-status:empty { height: 2.8em; }

.game-status.complete { color: var(--success); }
.game-status.fail { color: var(--error, #ef4444); }

.game-try-again {
  margin-top: 0.5rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.game-try-again:hover { background: var(--accent); color: var(--bg); }

.game-try-again.hidden {
  visibility: hidden;
  pointer-events: none;
}

/* --- Puzzle cards --- */
.puzzle-panel .card {
  max-width: 32rem;
  width: 100%;
}

.puzzle-card .puzzle-title {
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 400;
  margin: 0 0 0.5rem;
}

.puzzle-desc {
  color: var(--text-muted);
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
}

.binary-block {
  display: block;
  font-family: var(--font-mono);
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  color: var(--accent);
  word-break: break-all;
}

.input-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.puzzle-input {
  flex: 1;
  min-width: 120px;
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.puzzle-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.check-btn {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.check-btn:hover { opacity: 0.9; }

.puzzle-feedback {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  min-height: 1.4em;
}

.puzzle-feedback.success { color: var(--success); }
.puzzle-feedback.error { color: var(--error); }


.puzzle-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

/* Crossword */
.crossword-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(8, 2rem);
  grid-template-rows: repeat(5, 2rem);
  gap: 0;
  font-family: var(--font-mono);
}

.crossword-grid-9 {
  grid-template-columns: repeat(9, 2rem);
}

.crossword-cell {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  text-transform: uppercase;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

.crossword-cell:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.crossword-cell.filled { border-color: var(--accent); }
.crossword-cell.correct { border-color: var(--success); color: var(--success); }
.crossword-cell.wrong { border-color: var(--error); color: var(--error); }

.crossword-block {
  width: 1.75rem;
  height: 1.75rem;
  background: var(--border);
  border-radius: 2px;
}

.crossword-clues {
  flex: 1;
  min-width: 200px;
}

.clues-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 0.35rem;
}

.clues-title:not(:first-child) { margin-top: 1rem; }

.clues-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.6;
}

.crossword-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.crossword-actions .puzzle-feedback { margin: 0; }

/* --- Reveal panel --- */
.reveal-panel {
  position: relative;
  z-index: 10;
  padding-top: 4rem;
  padding-bottom: 4rem;
}

/* Final reveal celebration: pink balloons + fireworks */
.reveal-celebration {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.reveal-balloon {
  position: absolute;
  bottom: -90px;
  width: 56px;
  height: 68px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: linear-gradient(135deg, #fce7f3 0%, #fbcfe8 40%, #f9a8d4 70%, #ec4899 100%);
  box-shadow: inset -6px -6px 16px rgba(255,255,255,0.4), inset 3px 3px 10px rgba(236,72,153,0.3);
  animation: balloon-float 18s ease-in forwards;
  opacity: 0.9;
}

.reveal-balloon::before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  height: 18px;
  background: linear-gradient(to bottom, #ec4899, transparent);
  border-radius: 1px;
}

.reveal-firework {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: firework-fade 1.2s ease-out forwards;
  box-shadow: 0 0 6px currentColor;
}

@keyframes balloon-float {
  0% {
    transform: translateY(0) translateX(0) scale(0.85);
    opacity: 0.95;
  }
  100% {
    transform: translateY(-120vh) translateX(var(--drift, 0)) scale(1);
    opacity: 0.75;
  }
}

@keyframes firework-fade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.reveal-card {
  text-align: center;
  max-width: 28rem;
}

.reveal-text {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin: 0 0 1.5rem;
}

.reveal-btn-wrap {
  position: relative;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reveal-btn {
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  padding: 0.75rem 2rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s, left 0.2s ease, top 0.2s ease;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.reveal-btn:hover:not(:disabled) {
  transform: scale(1.03);
}

.reveal-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.reveal-btn.dodging {
  cursor: pointer;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 24rem;
  width: 100%;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 0 0 0.75rem;
}

.modal-body {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
  line-height: 1.6;
}

.modal-close {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  padding: 0.6rem 1.25rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}

.modal-close:hover { opacity: 0.9; }

/* --- A11y --- */
.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;
}
