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

html,
body {
  height: 100%;
}

:root {
  --bg: #0d1117;
  --paper: #161b22;
  --paper-strong: #21262d;
  --ink: #e6edf3;
  --muted: #8b949e;
  --line: #30363d;
  --accent: #e3b341;
  --accent-soft: rgba(227, 179, 65, 0.12);
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-gold: #d29922;
  --panel-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
}

body {
  min-height: 100dvh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  overflow: hidden;
  background: var(--bg);
}

.deck {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 10px;
  gap: 10px;
  overflow: hidden;
}

.topbar,
.story-panel,
.visual-stage,
.deck-nav {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
}

.topbar {
  border-radius: 22px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.topbar-left {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  margin-top: 4px;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--ink);
}

.deck-kicker,
.story-step,
.counter-label,
.swatch-label,
.metric-label,
.toolbar-label,
.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--accent);
}

.deck-title,
.story-title,
.card-title,
.vector-title,
.pixel-card-title {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.03em;
}

.deck-title {
  font-size: clamp(1.25rem, 2.1vw, 1.8rem);
  line-height: 1;
  margin-top: 2px;
}

.counter {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--muted);
}

.counter-value {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--accent-gold);
  line-height: 1;
}

.deck-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(232px, 0.6fr) minmax(0, 1.7fr);
  gap: 10px;
  min-height: 0;
}

.story-panel {
  border-radius: 24px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.story-title {
  font-size: clamp(1.48rem, 2.15vw, 2rem);
  line-height: 0.96;
}

.story-lead {
  color: #c9d1d9;
  font-size: 0.88rem;
  line-height: 1.42;
}

.story-points {
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.story-points li {
  font-size: 0.82rem;
  line-height: 1.34;
  color: #c9d1d9;
}

.story-prompt {
  margin-top: auto;
  border: 1px dashed #484f58;
  background: rgba(13, 17, 23, 0.42);
  border-radius: 20px;
  padding: 16px 18px;
  font-size: 0.98rem;
  line-height: 1.6;
  color: #c9d1d9;
}

.story-prompt strong {
  color: var(--accent);
}

.visual-panel {
  min-height: 0;
}

.visual-stage {
  height: 100%;
  min-height: 0;
  border-radius: 24px;
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  scrollbar-gutter: stable;
}

.visual-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(88, 166, 255, 0.08), transparent 34%),
    radial-gradient(circle at bottom right, rgba(210, 153, 34, 0.08), transparent 32%);
  pointer-events: none;
}

.scene {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: none;
  flex-direction: column;
  gap: 12px;
  overflow: visible;
  animation: fadeIn 0.3s ease;
}

.scene.active-step {
  display: flex;
}

.scene-grid,
.pixel-grid,
.detail-grid,
.metrics-grid,
.toggle-grid,
.preset-grid,
.color-stage,
.audio-grid-layout,
.voice-grid-layout,
.digit-grid-layout,
.sensor-pose-layout,
.text-token-layout,
.text-detail-grid {
  display: grid;
  gap: 10px;
}

.scene-grid-swatch,
.pixel-grid,
.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

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

.toggle-grid,
.preset-grid {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

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

.audio-grid-layout {
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.82fr);
  align-items: stretch;
}

.voice-grid-layout {
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.82fr);
  align-items: stretch;
}

.digit-grid-layout {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.9fr) minmax(0, 1.15fr);
  align-items: start;
}

.sensor-pose-layout {
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.82fr);
  align-items: start;
}

.text-token-layout,
.text-detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.color-stage-challenge {
  align-items: stretch;
}

.swatch-card,
.metric-card,
.pixel-card,
.vector-card,
.control-card,
.note-card,
.gray-tick {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--paper-strong);
  padding: 14px;
}

.swatch {
  aspect-ratio: auto;
  width: 100%;
  height: clamp(130px, 22vh, 210px);
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #0a0e14;
}

.swatch-meta,
.metric-value,
#draw-flat-vector,
#digit-flat-vector {
  font-family: "SFMono-Regular", Consolas, monospace;
}

.swatch-meta {
  margin-top: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--muted);
}

.card-title,
.pixel-card-title,
.vector-title {
  font-size: 1rem;
  margin-bottom: 10px;
}

.card-subtitle {
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.challenge-card {
  border-radius: 16px;
  border: 1px dashed #484f58;
  background: rgba(13, 17, 23, 0.42);
  padding: 12px 14px;
}

.mission-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(38px, 1fr));
  gap: 8px;
}

.mission-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #0d1117;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  padding: 8px 10px;
  text-align: center;
}

.mission-pill.active {
  background: rgba(210, 153, 34, 0.16);
  border-color: rgba(210, 153, 34, 0.45);
  color: #ffd866;
}

.mission-pill.done {
  background: rgba(63, 185, 80, 0.16);
  border-color: rgba(63, 185, 80, 0.35);
  color: #56d364;
}

.mission-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  margin-top: 4px;
}

.mission-instruction {
  margin-top: 6px;
  color: #c9d1d9;
  font-size: 0.9rem;
  line-height: 1.4;
}

.mission-feedback {
  min-height: 24px;
  margin: 8px 0 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--muted);
}

.mission-feedback.success {
  color: #56d364;
}

.mission-feedback.pending {
  color: #d29922;
}

.note-card {
  color: #c9d1d9;
  line-height: 1.55;
}

.channel-toggle,
.preset-btn,
.btn-primary,
.digit-btn,
.nav-btn {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--paper-strong);
  padding: 12px 14px;
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent-gold);
  color: #0d1117;
  border-color: rgba(210, 153, 34, 0.3);
}

.wide-btn {
  width: 100%;
}

.channel-red.active {
  background: rgba(248, 81, 73, 0.12);
  border-color: rgba(248, 81, 73, 0.4);
}

.channel-green.active {
  background: rgba(63, 185, 80, 0.12);
  border-color: rgba(63, 185, 80, 0.4);
}

.channel-blue.active {
  background: rgba(88, 166, 255, 0.12);
  border-color: rgba(88, 166, 255, 0.4);
}

.digit-btn.active {
  background: rgba(88, 166, 255, 0.12);
  border-color: rgba(88, 166, 255, 0.4);
}

.slider-row,
.toolbar-slider {
  display: grid;
  grid-template-columns: 92px 1fr 72px;
  align-items: center;
  gap: 10px;
  color: #c9d1d9;
}

.toolbar-slider span,
.slider-row span {
  font-size: 0.95rem;
}

input[type="range"] {
  accent-color: var(--accent-blue);
}

.metric-value {
  font-size: 0.95rem;
  word-break: break-word;
}

.metric-hint,
.pixel-card-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

#gray-gradient {
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, #000 0%, #fff 100%);
  margin-bottom: 14px;
}

.gray-control-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gray-targets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.gray-targets .digit-btn {
  padding: 8px 10px;
  font-size: 0.8rem;
}

.gray-challenge-card {
  padding: 10px 12px;
}

#gray-ticks {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.gray-tick {
  text-align: center;
  font-size: 0.8rem;
}

.gray-swatch {
  background: linear-gradient(135deg, #222, #ddd);
}

.draw-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.toolbar-group {
  display: grid;
  gap: 10px;
}

#digit-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#draw-resolution-buttons,
#sensor-scenario-buttons,
#text-preset-buttons,
#digit-resolution-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#text-preset-buttons .digit-btn {
  flex: 1 1 180px;
}

#draw-input-canvas,
#draw-pixel-canvas,
#draw-canvas,
#draw-preview,
#digit-source-canvas,
#digit-pixel-canvas,
#sensor-chart-canvas,
#pose-canvas,
#audio-grid-canvas,
#voice-grid-canvas {
  width: min(100%, 226px);
  aspect-ratio: 1 / 1;
  max-height: min(24vh, 226px);
  display: block;
  border-radius: 18px;
  background: #0a0e14;
  border: 1px solid var(--line);
  touch-action: none;
  margin-inline: auto;
}

#audio-grid-canvas {
  width: 100%;
  aspect-ratio: auto;
  height: clamp(210px, 31vh, 270px);
  max-height: none;
  cursor: crosshair;
}

#voice-grid-canvas {
  width: 100%;
  aspect-ratio: auto;
  height: clamp(210px, 31vh, 270px);
  max-height: none;
}

#sensor-chart-canvas,
#pose-canvas {
  width: 100%;
  aspect-ratio: auto;
  height: clamp(220px, 32vh, 290px);
  max-height: none;
}

#pose-canvas {
  cursor: grab;
}

.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.voice-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audio-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.audio-preset-btn {
  flex: 1 1 110px;
}

.audio-editor-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sensor-card,
.pose-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.text-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.token-input {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0a0e14;
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
  line-height: 1.45;
}

.token-chip-list,
.token-context-window {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.token-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.18);
  color: #c9d1d9;
}

.token-chip-index,
.token-chip-id {
  font-size: 0.74rem;
  color: var(--muted);
}

.sensor-readouts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sensor-readout-pill {
  font-size: 0.76rem;
  line-height: 1.35;
  white-space: normal;
}

.scene[data-step="5"] {
  gap: 12px;
}

.scene[data-step="5"] .metric-value {
  min-height: 42px;
}

.scene[data-step="6"] {
  gap: 10px;
}

.scene[data-step="6"] .metric-value {
  min-height: 42px;
}

.scene[data-step="7"] {
  gap: 10px;
}

.scene[data-step="7"] #pose-vector {
  margin: 0;
  max-height: 112px;
  overflow: auto;
  font-size: 0.76rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c9d1d9;
}

.scene[data-step="8"] {
  gap: 10px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(var(--matrix-size, 8), minmax(0, 1fr));
  gap: 3px;
}

.matrix-cell {
  aspect-ratio: 1 / 1;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.38rem, 0.72vw, 0.56rem);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.vector-flow {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.flow-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.18);
  color: #79c0ff;
  font-weight: 800;
}

.flow-arrow {
  color: var(--accent-gold);
  font-weight: 900;
}

.compact-flow {
  margin-bottom: 8px;
  gap: 8px;
}

.compact-flow .flow-pill {
  padding: 8px 11px;
  font-size: 0.86rem;
}

.draw-summary-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.summary-pill {
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.18);
  color: #79c0ff;
  font-size: 0.82rem;
  font-weight: 700;
}

#draw-flat-vector,
#digit-flat-vector {
  margin: 0;
  max-height: 112px;
  overflow: auto;
  font-size: 0.76rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c9d1d9;
}

.scene[data-step="3"] {
  gap: 12px;
}

.scene[data-step="3"] .pixel-grid,
.scene[data-step="3"] .detail-grid {
  gap: 8px;
}

.scene[data-step="3"] .pixel-card,
.scene[data-step="3"] .vector-card {
  padding: 12px;
}

.scene[data-step="3"] #draw-canvas,
.scene[data-step="3"] #draw-preview {
  width: min(100%, 196px);
  max-height: min(20vh, 196px);
}

.scene[data-step="3"] #draw-flat-vector {
  max-height: 72px;
}

.scene[data-step="4"] {
  gap: 10px;
}

.scene[data-step="4"] .draw-toolbar {
  gap: 8px;
  justify-content: flex-start;
}

.scene[data-step="4"] .pixel-card,
.scene[data-step="4"] .vector-card {
  padding: 12px;
}

.scene[data-step="4"] #digit-source-canvas,
.scene[data-step="4"] #digit-pixel-canvas {
  width: min(100%, 188px);
  max-height: min(19vh, 188px);
}

.scene[data-step="4"] #digit-flat-vector {
  max-height: 84px;
}

.scene[data-step="4"] .vector-flow {
  margin-bottom: 8px;
}

.scene > :first-child {
  margin-top: 0;
}

.deck-nav {
  border-radius: 22px;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: 120px 1fr 120px;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  justify-self: start;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.nav-btn-primary {
  justify-self: end;
  background: var(--accent-gold);
  color: #0d1117;
  border-color: rgba(203, 138, 28, 0.2);
}

.progress-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 0;
  background: #30363d;
  cursor: pointer;
}

.progress-dot.active {
  background: var(--accent-gold);
}

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

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .deck {
    height: auto;
    min-height: 100dvh;
  }

  .deck-main {
    grid-template-columns: 1fr;
  }

  .visual-stage {
    min-height: 0;
    overflow: visible;
  }

  .story-panel,
  .scene {
    overflow: visible;
  }

  .scene-grid-swatch,
  .pixel-grid,
  .detail-grid,
  .metrics-grid,
  .two-cols,
  .color-stage,
  .voice-grid-layout,
  .digit-grid-layout,
  .sensor-pose-layout,
  .text-token-layout,
  .text-detail-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-slider,
  .slider-row {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  #draw-input-canvas,
  #draw-pixel-canvas,
  #draw-canvas,
  #draw-preview,
  #digit-source-canvas,
  #digit-pixel-canvas,
  #sensor-chart-canvas,
  #pose-canvas,
  #audio-grid-canvas,
  #voice-grid-canvas {
    width: 100%;
    max-height: none;
  }

  .audio-grid-layout,
  .voice-grid-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .deck {
    padding: 12px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-left {
    flex-direction: column;
    gap: 8px;
  }

  .deck-nav {
    grid-template-columns: 1fr;
  }

  .nav-btn,
  .nav-btn-primary {
    justify-self: stretch;
  }

  .flow-arrow {
    display: none;
  }
}