:root {
  --bg: #0e1626;
  --bg-raised: #16203a;
  --ink: #efe7d6;
  --ink-dim: #9aa3b8;
  --gold: #c9a44c;
  --pass: #5fb37a;
  --fail: #d2706a;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, monospace;

  /* Gamification v2 art tokens (ADR-027). --gold-soft is the engraved highlight; the eight
     --biome-* accents mirror backend/db/seed.py STAGES colours 1:1 (used to recolour the medallion
     emblems and seal the world map). */
  --gold-soft: #e6cd86;
  --biome-the-grove: #4e8d6e;
  --biome-the-marble-caverns: #5b8fb0;
  --biome-the-forge: #c08a3e;
  --biome-the-archive: #8a8474;
  --biome-the-spires: #4f9c91;
  --biome-the-aether: #8a6fb0;
  --biome-the-observatory: #a8556a;
  --biome-the-summit: #6a74b0;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --motion-celebrate: 900ms;
  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(120% 100% at 50% 0%, #1a2742 0%, var(--bg) 60%) fixed;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(201, 164, 76, 0.25);
}

.brand {
  font-family: var(--serif);
  font-size: 1.4rem;
  letter-spacing: 0.04em;
  color: var(--gold);
}

#app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.view[hidden] {
  display: none;
}

h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2rem, 1rem + 4vw, 3.2rem);
  margin: 0 0 1.5rem;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1.2rem;
  background: var(--gold);
  color: #1a1205;
  font-weight: 600;
  transition:
    transform 150ms cubic-bezier(0.16, 1, 0.3, 1),
    filter 150ms;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(201, 164, 76, 0.4);
}

button.ghost:hover {
  background: rgba(201, 164, 76, 0.12);
}

/* Login */
.login-card {
  max-width: 380px;
  margin: 8vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-raised);
  padding: 2rem;
  border-radius: var(--radius);
  border: 1px solid rgba(201, 164, 76, 0.2);
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--ink-dim);
  font-size: 0.9rem;
}

.login-card input {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid rgba(154, 163, 184, 0.4);
  background: #0c1322;
  color: var(--ink);
}

.error {
  color: var(--fail);
  margin: 0;
}

/* World */
.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.biome-card {
  position: relative;
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 1.4rem 1.4rem 1.2rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-top: 3px solid var(--accent, var(--gold));
  overflow: hidden;
}

.biome-card.open {
  cursor: pointer;
  transition:
    transform 200ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 200ms;
}

.biome-card.open:hover,
.biome-card.open:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  outline: none;
}

.biome-index {
  position: absolute;
  top: 0.6rem;
  right: 1rem;
  font-family: var(--serif);
  font-size: 2.4rem;
  color: var(--accent, var(--gold));
  opacity: 0.25;
}

.biome-card h2 {
  font-family: var(--serif);
  margin: 0.2rem 0 0.1rem;
  font-size: 1.4rem;
}

.biome-title {
  margin: 0;
  color: var(--ink-dim);
  font-size: 0.85rem;
}

.biome-boss {
  margin: 0.8rem 0 0.2rem;
  font-size: 0.8rem;
  color: var(--accent, var(--gold));
  min-height: 1rem;
}

.biome-status {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.biome-card:not(.open) .biome-status {
  color: var(--ink-dim);
  font-style: italic;
}

/* A faint, themeable "realm sigil" — placeholder atmosphere recoloured per biome (CC0, in-repo). */
.biome-sigil {
  position: absolute;
  top: 50%;
  right: -22px;
  width: 140px;
  height: 140px;
  transform: translateY(-50%);
  color: var(--accent, var(--gold));
  opacity: 0.1;
  pointer-events: none;
}

.biome-progress {
  margin: 0.7rem 0 0;
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left;
  transform: scaleX(calc(var(--pct, 0) / 100)); /* compositor-friendly fill */
  background: var(--accent, var(--gold));
  transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

.biome-card.complete {
  border-top-color: var(--pass);
}

.biome-card.complete .progress-fill {
  background: var(--pass);
}

.biome-check {
  position: absolute;
  top: 0.6rem;
  left: 1rem;
  color: var(--pass);
  font-size: 1.1rem;
  opacity: 0;
}

.biome-card.complete .biome-check {
  opacity: 1;
}

.module-progress {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.module-progress li {
  padding: 0.15rem 0;
}

.module-progress li.done {
  color: var(--pass);
}

/* A multi-module biome card is a container, not one big button — its module rows are the targets. */
.biome-card.open.has-modules {
  cursor: default;
}

.module-progress li.openable {
  cursor: pointer;
  margin: 0 -0.4rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  transition: background 150ms;
}

.module-progress li.openable:hover {
  background: rgba(255, 255, 255, 0.07);
}

.module-progress li.openable:focus-visible {
  background: rgba(255, 255, 255, 0.07);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- Sealed (locked) realms (ADR-027): shown but non-interactive; the lock is stated in TEXT. --- */
.biome-card.sealed {
  opacity: 0.72;
  border-top-color: var(--ink-dim);
}
.biome-card.sealed .biome-index { color: var(--ink-dim); }
.biome-card.sealed .biome-sigil { filter: grayscale(1); opacity: 0.05; }
.biome-card.sealed .biome-boss,
.biome-card.sealed .biome-status {
  color: var(--ink-dim);
  font-style: italic;
}

/* The final boss (advances the biome) reads a touch stronger than a mini-boss in the module list. */
.module-progress li.boss.final {
  color: var(--gold-soft);
  font-weight: 600;
}

/* --- Quiet boss-clear celebration: one compositor-friendly transform pulse when a boss is newly
   cleared. Reduced-motion strips it below. Uses the shipped --motion-celebrate/--ease-out-back. --- */
@keyframes boss-cleared {
  0% { transform: scale(1); }
  35% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.biome-card.celebrate {
  animation: boss-cleared var(--motion-celebrate) var(--ease-out-back);
}

/* Lesson */
.lesson-body {
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 1.5rem 1.8rem;
  margin: 1rem 0 1.5rem;
  line-height: 1.6;
}

.lesson-body h2 {
  font-family: var(--serif);
}

.exercise {
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 1.5rem 1.8rem;
}

.exercise-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.exercise-progress {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
}

.exercise-nav button:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
  filter: none;
}

.exercise h2 {
  font-family: var(--serif);
  margin-top: 0;
}

#code-editor {
  width: 100%;
  min-height: 180px;
  font-family: var(--mono);
  font-size: 0.95rem;
  background: #0c1322;
  color: var(--ink);
  border: 1px solid rgba(154, 163, 184, 0.35);
  border-radius: 10px;
  padding: 1rem;
  resize: vertical;
}

code {
  font-family: var(--mono);
  background: rgba(201, 164, 76, 0.14);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
}

pre {
  background: #0c1322;
  padding: 1rem;
  border-radius: 10px;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1rem 0;
}

.status {
  color: var(--ink-dim);
}

.status.pass {
  color: var(--pass);
}

.status.fail {
  color: var(--fail);
}

.results {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.88rem;
}

.results li {
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.results li.pass {
  color: var(--pass);
}

.results li.fail {
  color: var(--fail);
}

/* Feedback (advisory, grounded-hybrid — ADR-012) */
.feedback {
  margin-top: 1.5rem;
  padding: 1.2rem 1.4rem;
  background: rgba(201, 164, 76, 0.07);
  border: 1px solid rgba(201, 164, 76, 0.22);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
}

.feedback[hidden] {
  display: none;
}

.feedback-heading {
  margin: 0 0 0.6rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--gold);
}

.feedback-source {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-dim);
  font-weight: 400;
}

.feedback-body {
  line-height: 1.55;
}

.feedback-body p:first-child {
  margin-top: 0;
}

.feedback-body p:last-child {
  margin-bottom: 0;
}

/* --- Dashboard ("Your Ledger") — an editorial bento atlas of derived progress + mastery ------- */
.topbar-actions {
  display: flex;
  gap: 0.6rem;
}

.world-ledger-cta {
  margin: 1.5rem 0 0;
  text-align: center;
}

.dashboard .dash-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dashboard .dash-head h1 {
  margin: 0;
}

/* Headings focused programmatically on a view switch (for AT) shouldn't flash a ring at the mouse
   user who didn't tab there — the move is for announcement, not a visible focus indicator. */
:is(h1, h2)[tabindex="-1"]:focus {
  outline: none;
}

.dash-bento {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); /* review | wider heat-map */
}

@media (max-width: 760px) {
  .dash-bento {
    grid-template-columns: minmax(0, 1fr); /* stack narrow; minmax(0,…) lets wide viz shrink, not blow out */
  }
}

.dash-panel {
  background: var(--bg-raised);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-top: 3px solid var(--panel-accent, var(--gold)); /* a semantic per-panel accent */
  padding: 1.4rem 1.5rem;
  min-width: 0; /* a grid item defaults to min-width:auto — let wide content (heat-map) shrink to fit */
}

.dash-overview {
  --panel-accent: var(--gold); /* charted progress — the brand/achievement accent */
  margin-bottom: 1.25rem;
}

.dash-review {
  --panel-accent: var(--ink-dim); /* scheduled / cool — set apart from achievement gold */
}

.dash-mastery {
  --panel-accent: var(--pass); /* the mastery map; lifted forward as the data-viz centrepiece */
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.dash-panel-title {
  font-family: var(--serif);
  margin: 0 0 0.8rem;
  font-size: 1.2rem;
}

.dash-panel-sub {
  margin: -0.4rem 0 1rem;
  color: var(--ink-dim);
  font-size: 0.82rem;
}

.overview-headline {
  margin: 0 0 0.8rem;
  font-family: var(--mono);
  font-size: clamp(1.6rem, 1rem + 2vw, 2.1rem); /* the hero metric outweighs its section label */
  color: var(--gold);
  letter-spacing: 0.01em;
}

/* Reuse the world map's --pct progress fill; recolour it on completion. */
.dash-overview .progress-bar.complete .progress-fill {
  background: var(--pass);
}

.module-progress li.boss {
  color: var(--gold);
}

/* A sealed stage row in the Ledger's per-stage rollup (state is also in the '· sealed' text). */
.module-progress li.sealed {
  color: var(--ink-dim);
  font-style: italic;
}

/* Review queue */
.review-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.review-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.review-when {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-dim);
  white-space: nowrap;
}

/* Mastery / weakness heat-map */
.heatmap-svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin-bottom: 0.9rem;
}

/* A static sparkline: cells aren't focusable (the readable list below is the keyboard/AT view), so
   they don't advertise interactivity with a lift — the native <title> still surfaces each tag on hover. */
.heatmap-svg .cell.needs-work {
  stroke: var(--fail);
  stroke-width: 1;
}

.heatmap-svg .cell.mastered {
  stroke: var(--gold);
  stroke-width: 1.5;
}

.heatmap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  font-size: 0.76rem;
  color: var(--ink-dim);
}

.legend-chip {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  margin-right: 0.35rem;
  vertical-align: -1px;
}

.heatmap-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.heatmap-list li {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap; /* the mono meta is nowrap; let it drop to a second line on a narrow panel */
  gap: 0.2rem 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.heat-chip {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  transform: translateY(1px);
}

.heat-name {
  flex: 1;
}

.heat-meta {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--ink-dim);
  white-space: nowrap;
}

.heatmap-list li.needs-work .heat-name {
  color: var(--fail);
}

.dash-empty {
  margin: 0.4rem 0 0;
  color: var(--ink-dim);
  font-style: italic;
}

/* Projected-retention panel: the aggregate forgetting-curve line + the weakest-recall list. */
.curve-svg {
  width: 100%;
  max-width: 640px; /* keep the 320x120 chart a sensible size on wide panels (no tall stretch) */
  height: auto;
  display: block;
  margin: 0.4rem 0 0.8rem;
  overflow: visible;
}
.curve-line {
  fill: none;
  stroke: var(--gold);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.curve-target {
  stroke: var(--ink-dim);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.5;
}
.curve-axis {
  fill: var(--ink-dim);
  font-family: var(--mono);
  font-size: 9px;
}
.curve-list-heading {
  margin: 0.4rem 0 0.3rem;
}
.curve-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.curve-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.curve-tag {
  color: var(--ink);
}
.curve-pct {
  font-family: var(--mono);
  color: var(--gold-soft);
  font-size: 0.85rem;
}

/* Global reduced-motion: honour the preference across the WHOLE app — near-instant transitions and
   animations (the world-map fill, the boss-clear celebration, any future motion), so nothing moves
   for those who asked it not to (WCAG 2.3.3 / web perf a11y). Supersedes the earlier targeted rules. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
