:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #f0f7f6;
  --surface-alt: #fff6e8;
  --text: #13283a;
  --muted: #627483;
  --line: #d9e3ea;
  --brand: #0f8a7a;
  --brand-strong: #07675c;
  --accent: #f59e3d;
  --accent-strong: #c56f12;
  --blue: #4568f0;
  --danger: #cc3847;
  --success: #16855b;
  --shadow: 0 18px 48px rgba(18, 40, 58, 0.12);
  --shadow-soft: 0 10px 30px rgba(18, 40, 58, 0.09);
  --radius: 8px;
  --sidebar: 252px;
  --topbar: 76px;
  --content: 1160px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1418;
  --surface: #121d22;
  --surface-strong: #132c2d;
  --surface-alt: #261f16;
  --text: #eef6f6;
  --muted: #a5b6bd;
  --line: #28404a;
  --brand: #5bd0bd;
  --brand-strong: #8be4d7;
  --accent: #f5b45f;
  --accent-strong: #ffd18c;
  --blue: #9eafff;
  --danger: #ff7c88;
  --success: #62d8a4;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 4%, rgba(15, 138, 122, 0.12), transparent 30%),
    radial-gradient(circle at 86% 10%, rgba(245, 158, 61, 0.13), transparent 28%),
    var(--bg);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand), white 20%);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: -80px;
  z-index: 20;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  transition: top 160ms ease;
}

.skip-link:focus {
  top: 14px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: var(--topbar) minmax(calc(100vh - var(--topbar)), auto);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg), transparent 6%);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  color: white;
  background: linear-gradient(135deg, var(--brand), var(--blue));
  box-shadow: var(--shadow-soft);
}

.brand-mark svg,
.icon-button svg,
.nav-item svg,
.segmented-btn svg,
.inline-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  font-size: 1rem;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  min-width: 190px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

[data-mode="story"] .segmented-btn[data-mode-value="story"],
[data-mode="game"] .segmented-btn[data-mode-value="game"] {
  color: white;
  background: var(--brand);
  box-shadow: 0 8px 18px rgba(15, 138, 122, 0.18);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  transition: transform 160ms ease, border-color 160ms ease;
}

.icon-button:hover,
.nav-item:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.sidebar {
  position: sticky;
  top: var(--topbar);
  align-self: start;
  height: calc(100vh - var(--topbar));
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg), var(--surface) 48%);
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-weight: 750;
  transition: transform 160ms ease, color 160ms ease, background 160ms ease;
}

.nav-item[aria-current="page"] {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.main {
  min-width: 0;
  padding: clamp(18px, 3vw, 36px);
}

.view {
  width: min(100%, var(--content));
  margin: 0 auto;
}

.view-stack {
  display: grid;
  gap: 24px;
}

.hero-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 460px);
  gap: 24px;
  align-items: stretch;
  padding: clamp(22px, 4vw, 38px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--surface), var(--brand) 7%), color-mix(in srgb, var(--surface), var(--accent) 7%));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero-content {
  display: grid;
  align-content: center;
  gap: 18px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--brand-strong);
  background: color-mix(in srgb, var(--surface), var(--brand) 8%);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 880px;
  margin-bottom: 0;
  font-size: clamp(2.1rem, 4.3vw, 4.2rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.45rem, 2.3vw, 2.1rem);
  line-height: 1.12;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

p {
  color: var(--muted);
  line-height: 1.66;
}

.hero-copy {
  max-width: 700px;
  font-size: 1.05rem;
}

.hero-art {
  min-height: 310px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}

.hero-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.toolbar,
.section-heading,
.detail-header,
.card-row,
.quiz-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.toolbar {
  flex-wrap: wrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-button {
  border: 1px solid var(--brand);
  color: white;
  background: var(--brand);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
}

.ghost-button {
  border: 1px solid transparent;
  color: var(--brand-strong);
  background: transparent;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: default;
  opacity: 0.62;
  transform: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card,
.lesson-card,
.module-card,
.reference-card,
.revision-card,
.quiz-card,
.example-card,
.badge-card,
.answer-row,
.source-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.stat-card {
  min-height: 122px;
  padding: 18px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1;
}

.stat-card span,
.meta,
.fineprint {
  color: var(--muted);
  font-size: 0.86rem;
}

.fineprint {
  margin-bottom: 0;
}

.progress-shell {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line), transparent 30%);
}

.progress-fill {
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 520ms cubic-bezier(.2, .7, .2, 1);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
}

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), var(--surface-strong) 24%);
}

.panel h2,
.panel h3 {
  margin-bottom: 12px;
}

.module-stack {
  display: grid;
  gap: 18px;
}

.module-card {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.module-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.module-index {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: white;
  background: var(--blue);
  font-weight: 900;
}

.lesson-grid,
.quiz-grid,
.reference-grid,
.revision-grid,
.badge-grid,
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.lesson-card,
.quiz-card,
.reference-card,
.revision-card,
.source-card {
  display: grid;
  gap: 12px;
  min-height: 214px;
  padding: 18px;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.lesson-card:hover,
.quiz-card:hover,
.reference-card:hover,
.revision-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--brand), var(--line) 50%);
}

.card-title {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 850;
  line-height: 1.3;
}

.pill-row,
.meta-row,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface), var(--bg) 46%);
  font-size: 0.78rem;
  font-weight: 800;
}

.pill.success {
  color: var(--success);
  background: color-mix(in srgb, var(--surface), var(--success) 10%);
}

.pill.warning {
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--surface), var(--accent) 14%);
}

.pill.brand {
  color: var(--brand-strong);
  background: color-mix(in srgb, var(--surface), var(--brand) 12%);
}

.pill.danger {
  color: var(--danger);
  background: color-mix(in srgb, var(--surface), var(--danger) 10%);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line);
}

.status-dot.complete {
  background: var(--success);
}

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

.detail-header {
  align-items: flex-start;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, color-mix(in srgb, var(--surface), var(--brand) 6%), var(--surface));
}

.detail-header h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.lesson-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
}

.lesson-article {
  display: grid;
  gap: 18px;
}

.lesson-section,
.quiz-question {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.lesson-section p:last-child {
  margin-bottom: 0;
}

.visual-card {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), var(--surface-strong) 50%);
}

.concept-map {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.concept-node {
  display: grid;
  place-items: center;
  min-height: 72px;
  padding: 10px;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  font-weight: 850;
}

.concept-node.accent {
  color: #1d2b36;
  background: #ffcf78;
  border-color: #e3a33f;
}

[data-theme="dark"] .concept-node.accent {
  color: #1b1407;
}

.example-card {
  padding: 18px;
}

.code-block {
  overflow: auto;
  margin: 12px 0 0;
  padding: 14px;
  border-radius: var(--radius);
  color: #eef6f6;
  background: #101820;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.58;
}

.side-stack {
  position: sticky;
  top: calc(var(--topbar) + 18px);
  display: grid;
  gap: 14px;
}

.list-clean {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-clean li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--muted);
  line-height: 1.55;
}

.list-clean li::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 8px;
  border-radius: 50%;
  background: var(--brand);
}

.answer-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.answer-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px;
  cursor: pointer;
}

.answer-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.answer-row.correct {
  border-color: color-mix(in srgb, var(--success), var(--line) 35%);
  background: color-mix(in srgb, var(--surface), var(--success) 10%);
}

.answer-row.incorrect {
  border-color: color-mix(in srgb, var(--danger), var(--line) 35%);
  background: color-mix(in srgb, var(--surface), var(--danger) 8%);
}

.feedback {
  margin-top: 12px;
  padding: 12px;
  border-left: 4px solid var(--brand);
  background: color-mix(in srgb, var(--surface), var(--brand) 8%);
  color: var(--muted);
  line-height: 1.55;
}

.filter-control {
  display: grid;
  gap: 5px;
}

.filter-control label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.filter-control input,
.filter-control select {
  min-height: 42px;
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  padding: 0 12px;
}

.flashcard {
  display: grid;
  gap: 12px;
  min-height: 220px;
}

.flash-answer {
  display: none;
  padding: 12px;
  border-radius: var(--radius);
  color: var(--text);
  background: color-mix(in srgb, var(--surface), var(--brand) 9%);
  line-height: 1.58;
}

.flashcard[data-open="true"] .flash-answer {
  display: block;
}

.badge-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  min-height: 150px;
}

.badge-card.locked {
  opacity: 0.58;
}

.badge-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-alt);
  font-weight: 900;
}

.chart-bars {
  display: grid;
  gap: 10px;
}

.chart-row {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.empty-state,
.loading-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 30px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.loader {
  width: 38px;
  height: 38px;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: grid;
  gap: 10px;
  max-width: min(420px, calc(100vw - 36px));
}

.toast {
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  background: var(--accent);
}

.hidden {
  display: none !important;
}

[data-mode="story"] .game-only {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.motion-enter {
  animation: rise-in 360ms cubic-bezier(.2, .7, .2, 1) both;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: var(--topbar);
    z-index: 9;
    height: auto;
    padding: 10px 14px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }

  .hero-band,
  .content-grid,
  .lesson-layout {
    grid-template-columns: 1fr;
  }

  .side-stack {
    position: static;
  }

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

@media (max-width: 680px) {
  :root {
    --topbar: auto;
  }

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

  .topbar-actions,
  .segmented {
    width: 100%;
  }

  .topbar-actions {
    align-items: stretch;
  }

  .segmented {
    min-width: 0;
  }

  .main {
    padding: 16px;
  }

  .hero-band {
    padding: 18px;
  }

  .hero-art {
    min-height: 230px;
  }

  .stats-grid,
  .lesson-grid,
  .quiz-grid,
  .reference-grid,
  .revision-grid,
  .badge-grid,
  .source-grid {
    grid-template-columns: 1fr;
  }

  .detail-header,
  .toolbar,
  .section-heading,
  .quiz-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .filter-control,
  .filter-control input,
  .filter-control select,
  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .concept-map {
    grid-template-columns: 1fr;
  }

  .chart-row {
    grid-template-columns: 88px minmax(0, 1fr) 38px;
  }
}
