*, *::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: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.14);
  --accent-gold: #e3b341;
  --accent-green: #3fb950;
  --accent-red: #f85149;
  --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,
.metric-label,
.toolbar-label,
.eyebrow,
.swatch-label {
  font-size: 0.72rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--accent-gold);
}

.deck-title,
.story-title,
.card-title,
.vector-title,
.pixel-card-title,
.mission-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 {
  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.95rem;
  line-height: 1.55;
  color: #c9d1d9;
}

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

.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.09), transparent 34%),
    radial-gradient(circle at bottom right, rgba(227, 179, 65, 0.08), transparent 32%);
  pointer-events: none;
}

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

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

.draw-toolbar,
.metrics-grid,
.detail-grid,
.token-layout,
.attention-layout,
.generation-layout,
.token-detail-grid,
.generation-detail-grid {
  display: grid;
  gap: 10px;
}

.draw-toolbar {
  grid-template-columns: repeat(auto-fit, minmax(200px, max-content));
  align-items: start;
}

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

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

.attention-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.82fr);
  align-items: start;
}

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

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

.challenge-card {
  display: grid;
  gap: 10px;
}

.wide-card {
  width: 100%;
}

.metric-value,
.generated-text,
#token-id-vector {
  font-family: "SFMono-Regular", Consolas, monospace;
}

.metric-value,
.big-readout {
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  line-height: 1.35;
}

.metric-hint,
.pixel-card-hint,
.mission-instruction,
.field-row span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.42;
}

.card-title,
.vector-title,
.pixel-card-title,
.mission-title {
  font-size: 1.08rem;
  color: #f0f6fc;
}

.token-input,
.field-input,
select.field-input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid #3a434d;
  background: rgba(13, 17, 23, 0.7);
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
  resize: vertical;
}

.token-input:focus,
.field-input:focus {
  outline: 2px solid rgba(88, 166, 255, 0.38);
  border-color: var(--accent);
}

.token-chip-list,
.context-window,
#token-preset-buttons,
#attention-target-buttons,
#generation-preset-buttons,
.generated-token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.token-chip,
.context-chip,
.preset-btn,
.attention-token-btn,
.progress-dot,
.nav-btn {
  border: 1px solid transparent;
}

.token-chip,
.context-chip {
  background: rgba(88, 166, 255, 0.1);
  color: #dce9ff;
  border-color: rgba(88, 166, 255, 0.24);
  border-radius: 999px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.token-chip.punctuation,
.context-chip.punctuation {
  background: rgba(227, 179, 65, 0.12);
  border-color: rgba(227, 179, 65, 0.3);
  color: #ffe2a8;
}

.token-chip.active,
.context-chip.active,
.attention-token-btn.active {
  background: rgba(88, 166, 255, 0.2);
  border-color: rgba(88, 166, 255, 0.6);
  box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.28) inset;
}

.token-chip.newest {
  background: rgba(63, 185, 80, 0.14);
  border-color: rgba(63, 185, 80, 0.48);
  color: #cff3d4;
}

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

.token-chip-value {
  font-weight: 700;
}

.preset-btn,
.attention-token-btn,
.nav-btn {
  appearance: none;
  background: rgba(13, 17, 23, 0.7);
  color: var(--ink);
  border-radius: 999px;
  border: 1px solid #3a434d;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.preset-btn:hover,
.attention-token-btn:hover,
.nav-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.preset-btn.active {
  background: rgba(227, 179, 65, 0.12);
  border-color: rgba(227, 179, 65, 0.55);
  color: #ffe2a8;
}

.nav-btn {
  min-height: 44px;
}

.nav-btn:disabled {
  cursor: default;
  opacity: 0.45;
}

.nav-btn-primary {
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.2), rgba(227, 179, 65, 0.16));
  border-color: rgba(88, 166, 255, 0.56);
}

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

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

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

.progress-dot.active {
  background: var(--accent-gold);
  box-shadow: 0 0 0 5px rgba(227, 179, 65, 0.12);
}

.field-row {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.generation-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.mission-feedback {
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.mission-feedback.pending {
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.24);
  color: #c9d1d9;
}

.mission-feedback.success {
  background: rgba(63, 185, 80, 0.1);
  border: 1px solid rgba(63, 185, 80, 0.36);
  color: #cff3d4;
}

.mission-feedback.error {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.35);
  color: #ffd6d2;
}

.attention-matrix {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.attention-header,
.attention-row {
  display: grid;
  grid-template-columns: 120px repeat(var(--matrix-cols, 1), minmax(34px, 1fr));
  gap: 6px;
  align-items: center;
}

.attention-corner,
.attention-col-label,
.attention-row-label {
  font-size: 0.73rem;
  color: var(--muted);
  text-align: center;
}

.attention-row-label {
  text-align: left;
  padding-right: 4px;
}

.attention-cell {
  min-height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(88, 166, 255, 0.12);
  background: rgba(13, 17, 23, 0.5);
  position: relative;
  overflow: hidden;
}

.attention-cell::after {
  content: attr(data-label);
  position: absolute;
  inset: auto 0 3px 0;
  text-align: center;
  font-size: 0.6rem;
  color: rgba(230, 237, 243, 0.82);
}

.attention-cell.masked {
  opacity: 0.22;
  border-style: dashed;
}

.attention-cell.selected {
  border-color: rgba(227, 179, 65, 0.8);
  box-shadow: 0 0 0 1px rgba(227, 179, 65, 0.3) inset;
}

.attention-bar-list,
.candidate-list {
  display: grid;
  gap: 8px;
}

.attention-bar,
.candidate-item {
  border-radius: 14px;
  border: 1px solid #353d47;
  background: rgba(13, 17, 23, 0.55);
  overflow: hidden;
}

.attention-bar-head,
.candidate-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px 0;
  font-size: 0.8rem;
}

.attention-bar-track,
.candidate-track {
  height: 10px;
  border-radius: 999px;
  margin: 8px 12px 12px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.attention-bar-fill,
.candidate-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(88, 166, 255, 0.5), rgba(227, 179, 65, 0.9));
}

.generated-text,
#token-id-vector {
  margin-top: 12px;
  min-height: 72px;
  border-radius: 16px;
  border: 1px solid #353d47;
  background: rgba(13, 17, 23, 0.66);
  padding: 14px;
  white-space: pre-wrap;
  line-height: 1.55;
  color: #eaf2ff;
}

.context-window {
  min-height: 84px;
  align-content: start;
}

.empty-state {
  color: var(--muted);
  font-size: 0.86rem;
}

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

@media (max-width: 1080px) {
  .deck-main {
    grid-template-columns: 1fr;
  }

  .story-panel {
    max-height: 240px;
  }
}

@media (max-width: 880px) {
  .token-layout,
  .generation-layout,
  .token-detail-grid,
  .generation-detail-grid,
  .attention-layout,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .attention-header,
  .attention-row {
    grid-template-columns: 92px repeat(var(--matrix-cols, 1), minmax(30px, 1fr));
  }
}

@media (max-width: 640px) {
  .deck {
    padding: 8px;
  }

  .topbar,
  .deck-nav,
  .story-panel,
  .visual-stage {
    border-radius: 18px;
  }

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

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

  .topbar-left {
    flex-direction: column;
  }

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

  .nav-btn {
    width: 100%;
  }

  .attention-header,
  .attention-row {
    grid-template-columns: 76px repeat(var(--matrix-cols, 1), minmax(28px, 1fr));
  }
}
