:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3ede3;
  --line: #e4ddd0;
  --line-strong: #cfc5b4;
  --text: #1c1917;
  --muted: #665e55;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #e6f5f3;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --indigo: #3730a3;
  --indigo-soft: #e0e7ff;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.num {
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top bar: strictly 56px so primary content begins ~72px from viewport top */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  min-height: 44px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-accent {
  color: var(--accent);
}

.primary-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 140ms ease-out, color 140ms ease-out;
}

.nav-tab.is-active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
}

.stat-pill .icon {
  width: 16px;
  height: 16px;
  color: var(--amber);
}

.lang-toggle {
  min-height: 44px;
  min-width: 48px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 140ms ease-out, border-color 140ms ease-out;
}

.lang-toggle.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Main container */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  min-width: 0;
}

/* Active Hero Mission Card */
.mission-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.mission-copy {
  min-width: 0;
  max-width: 62ch;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.01em;
  margin-bottom: 4px;
}

.hero-title {
  margin: 0 0 4px;
  font-size: 1.375rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.hero-sub {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

.fr-note {
  margin: 4px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 120ms ease-out, background-color 140ms ease-out;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
}

/* Section heading */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 12px;
}

.section-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
}

.section-meta {
  font-size: 0.8125rem;
  color: var(--muted);
}

/* 6 Curriculum Track Cards Grid */
.tracks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 14px;
}

.track-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  width: 100%;
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 140ms ease-out, border-color 140ms ease-out;
}

.track-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-bottom: 10px;
}

.domain-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}

.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  font-variant-numeric: tabular-nums;
}

.track-preview {
  width: 100%;
  aspect-ratio: 120 / 68;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.track-art {
  width: 100%;
  height: 100%;
  display: block;
}

.track-name {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-sub {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0 0 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mastery-row {
  margin-top: auto;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mastery-bar {
  flex: 1;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.mastery-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 180ms ease-out;
}

.mastery-label {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Exercise Studio View */
.exercise-shell {
  max-width: 680px;
  margin: 0 auto;
}

.exercise-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.progress-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.p-dot {
  width: 22px;
  height: 8px;
  border-radius: 999px;
  background: var(--line);
}

.p-dot.is-current {
  background: var(--amber);
}

.p-dot.is-done {
  background: var(--accent);
}

.exercise-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.passage-box {
  background: var(--bg);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 16px;
  font-size: 1rem;
  line-height: 1.6;
  max-width: 65ch;
}

.prompt-text {
  margin: 0 0 6px;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.4;
  max-width: 65ch;
}

.geo-stage {
  width: 100%;
  max-width: 380px;
  aspect-ratio: 260 / 155;
  margin: 14px auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.geo-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Interactive Zahlenmauer */
.pyramid-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
}

.pyramid-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.brick-static,
.brick-input {
  width: 78px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.brick-static {
  background: var(--surface-2);
  border: 1.5px solid var(--line-strong);
  color: var(--text);
}

.brick-input {
  background: var(--amber-soft);
  border: 2px solid var(--amber);
  color: var(--text);
  text-align: center;
  padding: 0 4px;
}

.brick-input.is-ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.brick-input.is-err {
  background: var(--danger-soft);
  border-color: var(--danger);
}

/* Number answer input + unit */
.answer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 6px;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

.num-input {
  width: 170px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.unit-label {
  font-weight: 700;
  color: var(--muted);
}

/* Multiple choice options */
.choices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 6px;
}

.choice-btn {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  text-align: left;
  border-radius: 10px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.96875rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 120ms ease-out, background-color 120ms ease-out;
}

.choice-key {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.choice-btn.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.choice-btn.is-selected .choice-key {
  background: var(--accent);
  color: #ffffff;
}

.choice-btn.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.choice-btn.is-wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Action bar & progressive disclosure hint */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.feedback-banner {
  margin-top: 14px;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  font-size: 0.9375rem;
}

.feedback-banner.is-ok {
  background: var(--ok-soft);
  border-left-color: var(--ok);
}

.feedback-banner.is-hint {
  background: var(--amber-soft);
  border-left-color: var(--amber);
}

.feedback-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  margin-bottom: 4px;
}

/* Geschichten-Atelier & Eltern views */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.chip-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.chip-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.story-slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.story-slot {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
}

.slot-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 4px;
}

.word-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 10px 0;
}

.word-pill {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 0.875rem;
  font-weight: 600;
}

/* ZAP1 Grade Calculator & Roadmap */
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.calc-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc-field label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.calc-select {
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

.zap-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--ok);
  background: var(--ok-soft);
  margin-top: 12px;
}

.zap-result.is-below {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.roadmap-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.roadmap-row:last-child {
  border-bottom: none;
}

/* Undo Toast */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--text);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.toast-undo {
  min-height: 36px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
  color: #fef3c7;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Mobile bottom bar */
.mobile-nav {
  display: none;
}

@media (hover: hover) {
  .track-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
  }
  .btn:hover {
    background: var(--surface-2);
  }
  .btn-primary:hover {
    background: var(--accent-hover);
  }
  .choice-btn:hover {
    border-color: var(--accent);
  }
}

@media (max-width: 720px) {
  .desktop-nav {
    display: none;
  }
  .app-main {
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }
  .mission-hero {
    flex-direction: column;
    align-items: stretch;
  }
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-tab {
    min-height: 56px;
    border: none;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
  }
  .mobile-tab.is-active {
    color: var(--accent);
  }
  .toast {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
