/* Stock Academy — single stylesheet, no build step.
   Design language: native-app feel. Shape system: cards 16px, controls 12px,
   chips/tabs pill. One accent (brand teal). Press feedback on everything
   tappable. Mobile-first with a bottom tab bar; desktop gets top nav. */

/* Theme tokens via light-dark(): the JS theme control forces a mode by
   setting documentElement.style.colorScheme; default follows the system. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f2f5f7, #0e1216);
  --surface: light-dark(#ffffff, #171d24);
  --surface-2: light-dark(#e9eef2, #212a33);
  --text: light-dark(#16212b, #e8edf2);
  --text-muted: light-dark(#5c6b7a, #93a3b2);
  --border: light-dark(#dee5eb, #2b3641);
  --accent: light-dark(#0f7d68, #3cc0a3);
  --accent-strong: light-dark(#0a6152, #6fd7bf);
  --accent-soft: light-dark(#dcf1ea, #17342c);
  --warn: light-dark(#9a5b00, #e0a94f);
  --warn-soft: light-dark(#f9efdd, #32281a);
  --danger: light-dark(#b23b3b, #e08080);
  --danger-soft: light-dark(#f9e7e7, #362022);
  --info: light-dark(#2f5cad, #86a8e0);
  --info-soft: light-dark(#e7eefb, #1f2938);
  --radius-card: 16px;
  --radius-ctrl: 12px;
  --shadow-card: 0 1px 2px light-dark(rgba(23, 37, 50, 0.05), rgba(0, 0, 0, 0.3)), 0 4px 16px light-dark(rgba(23, 37, 50, 0.06), rgba(0, 0, 0, 0.28));
  --shadow-float: 0 8px 28px light-dark(rgba(23, 37, 50, 0.16), rgba(0, 0, 0, 0.5));
  --tab-bar-h: 62px;
  --max-width: 860px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }

.skip-link {
  position: absolute;
  left: -9999px;
  background: var(--surface);
  padding: 0.5rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

svg.icon {
  width: 1.25em;
  height: 1.25em;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.25em;
  flex: none;
}

/* ---------- Top bar ---------- */
/* Sticky lives on #site-header: a sticky child that exactly fills its parent
   has no room to stick and silently scrolls away. */
#site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.6rem 1rem;
  padding-top: calc(0.6rem + env(safe-area-inset-top));
  padding-left: calc(1rem + env(safe-area-inset-left));
  padding-right: calc(1rem + env(safe-area-inset-right));
}
.nav-bar .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
  margin-right: 0.25rem;
  min-height: 44px;
}
.nav-bar .brand .icon { color: var(--accent); width: 1.35em; height: 1.35em; }
.nav-links { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.45rem 0.85rem;
  min-height: 44px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text); }
.nav-links a:active { transform: scale(0.96); }
.nav-links a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }

.game-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
  padding: 0.3rem 0.8rem;
  min-height: 44px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.game-chip:hover { color: var(--text); background: var(--accent-soft); }
.game-chip .sep { color: var(--text-muted); font-weight: 400; }

/* Segmented control (e.g. checklist switcher) — works on all viewports */
.seg-tabs {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.25rem;
  margin-bottom: 0.5rem;
}
.seg-tabs a, .seg-tabs button {
  text-decoration: none;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--text-muted);
  padding: 0.4rem 0.9rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-tabs button:hover { background: var(--surface); color: var(--text); }
.seg-tabs a.active, .seg-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }

/* ---------- Bottom tab bar (mobile) ---------- */
.tab-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 0.25rem 0.25rem calc(0.25rem + env(safe-area-inset-bottom));
}
.tab-bar-inner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 520px;
  margin: 0 auto;
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 0.3rem 0.2rem;
  border-radius: var(--radius-ctrl);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.tab-item .icon { width: 22px; height: 22px; }
.tab-item:active { transform: scale(0.94); }
.tab-item.active { color: var(--accent-strong); background: var(--accent-soft); }
.tab-item:hover { color: var(--accent-strong); }

.disclaimer-strip {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 0.3rem 1rem 0;
}
.disclaimer-strip a { color: inherit; font-weight: 600; }

/* ---------- Layout ---------- */
#app { display: block; min-height: 60vh; }
#app:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}
#site-footer {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
#site-footer p { max-width: var(--max-width); margin: 0 auto; }

h1 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0.5rem 0 1rem;
}
h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; margin: 1.75rem 0 0.5rem; }
h3 { font-size: 1.05rem; font-weight: 600; margin: 1.25rem 0 0.4rem; }
.prose p { margin: 0.6rem 0; }
.muted { color: var(--text-muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.25rem;
  margin: 0.75rem 0;
}
.card h2, .card h3 { margin-top: 0.25rem; }
.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.card-link:hover { border-color: var(--accent); color: inherit; transform: translateY(-2px); box-shadow: var(--shadow-float); }
.card-link:active { transform: scale(0.98); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}
.card-grid .card { margin: 0; }

.list-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0.25rem;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { transform: scale(0.99); }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .icon.chevron { color: var(--text-muted); }

/* ---------- Progress ---------- */
.progress-track {
  background: var(--surface-2);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.progress-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ---------- Lesson content ---------- */
.lesson-meta { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.breadcrumb { font-size: 0.9rem; margin-bottom: 0.25rem; }
.breadcrumb a { text-decoration: none; }

.callout {
  border-left: 4px solid var(--info);
  background: var(--info-soft);
  border-radius: var(--radius-ctrl);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}
.callout .callout-title { font-weight: 700; display: block; margin-bottom: 0.25rem; }
.callout.sweden-eu { border-left-color: var(--info); }
.callout.warning { border-left-color: var(--warn); background: var(--warn-soft); }
.callout.disclaimer { border-left-color: var(--danger); background: var(--danger-soft); font-size: 0.9rem; }
.callout.tip { border-left-color: var(--accent); background: var(--accent-soft); }

.key-term {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-ctrl);
  padding: 0.6rem 1rem;
  margin: 1rem 0;
}
.key-term dt { font-weight: 700; color: var(--accent-strong); }
.key-term dd { margin: 0.2rem 0 0; }
.key-term a { font-size: 0.85rem; }

.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.lesson-nav a {
  text-decoration: none;
  max-width: 45%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-weight: 600;
}

/* ---------- Quiz ---------- */
.quiz { margin-top: 2rem; }
.quiz fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
}
.quiz legend { font-weight: 600; padding: 0 0.4rem; }
.quiz label {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.5rem 0.4rem;
  min-height: 44px;
  border-radius: var(--radius-ctrl);
  cursor: pointer;
  transition: background 0.15s ease;
}
.quiz label:hover { background: var(--surface-2); }
.quiz .explanation { font-size: 0.9rem; margin-top: 0.5rem; padding: 0.5rem 0.75rem; border-radius: var(--radius-ctrl); }
.quiz .explanation.correct { background: var(--accent-soft); color: var(--accent-strong); }
.quiz .explanation.incorrect { background: var(--danger-soft); color: var(--danger); }
.quiz-result { font-weight: 700; margin: 1rem 0; }
.quiz-result.pass { color: var(--accent-strong); }
.quiz-result.fail { color: var(--danger); }

/* ---------- Buttons & forms ---------- */
button, .btn {
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: light-dark(#ffffff, #0c1a16);
  border: none;
  border-radius: var(--radius-ctrl);
  padding: 0.6rem 1.2rem;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.12s ease;
}
button:hover, .btn:hover { background: var(--accent-strong); color: light-dark(#ffffff, #0c1a16); }
button:active, .btn:active { transform: scale(0.97); }
button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--border); color: var(--text); }
/* --danger is a light salmon in dark mode; white text fails AA on it. */
button.danger { background: var(--danger); color: light-dark(#ffffff, #2a1113); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

form.stacked { display: grid; gap: 0.75rem; max-width: 480px; }
form.stacked label { display: grid; gap: 0.25rem; font-size: 0.9rem; font-weight: 600; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font: inherit;
  padding: 0.55rem 0.75rem;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
textarea { min-height: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field-error { color: var(--danger); font-size: 0.85rem; font-weight: 400; }

/* ---------- Checklists ---------- */
.checklist-item {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.5rem 0.6rem;
  min-height: 48px;
  border-radius: var(--radius-ctrl);
  transition: background 0.15s ease;
}
.checklist-item:hover { background: var(--surface-2); }
.checklist-item input { transform: scale(1.35); accent-color: var(--mc, var(--accent)); flex: none; }
.checklist-item.done { background: var(--mc-soft, var(--accent-soft)); }
.checklist-item.done:hover { background: var(--mc-soft, var(--accent-soft)); }
.checklist-item.done label { text-decoration: line-through; color: var(--text-muted); }
.checklist-item label {
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  flex: 1;
}
.module-chip.sm { font-size: 0.75rem; padding: 0.15rem 0.6rem; min-height: 26px; }

/* ---------- Journal ---------- */
.entry-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.entry-head .icon-tile { width: 38px; height: 38px; border-radius: 12px; }
.entry-head .icon-tile .icon { width: 19px; height: 19px; }
.entry-head .entry-title { flex: 1; min-width: 0; font-weight: 700; }
.entry-head .pl-big { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.status-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.status-pill.open { background: var(--accent-soft); color: var(--accent-strong); }
.thesis-quote {
  border-left: 3px solid var(--accent-soft);
  padding: 0.2rem 0 0.2rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}
.entry-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.6rem; }
.entry-actions button { min-height: 40px; padding: 0.4rem 1rem; font-size: 0.9rem; }
.hidden { display: none !important; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  font-size: 0.92rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th { background: var(--surface-2); }
.pl-pos { color: var(--accent-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.pl-neg { color: var(--danger); font-weight: 600; font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block;
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 0.78rem;
  padding: 0.05rem 0.55rem;
  margin-right: 0.25rem;
  color: var(--text-muted);
}

/* ---------- Glossary ---------- */
.glossary-search { margin-bottom: 1rem; max-width: 380px; }
.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}
.term-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.term-card.highlight { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-card); }
.term-card .term-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.term-card .term-head .icon-tile { width: 38px; height: 38px; border-radius: 12px; }
.term-card .term-head .icon-tile .icon { width: 19px; height: 19px; }
.term-card .term-name { font-weight: 700; line-height: 1.3; }
.term-card .term-def { margin: 0; font-size: 0.9rem; color: var(--text-muted); line-height: 1.55; }
.term-card .term-links { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: auto; }
.term-card .term-links .module-chip { font-size: 0.75rem; padding: 0.2rem 0.6rem; min-height: 28px; }

/* ---------- Misc ---------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  margin: 1rem 0;
}
.render-error { color: var(--danger); }
.badge-done { color: var(--accent-strong); font-weight: 600; }

/* ---------- Delight: view transitions, confetti, toasts, badges ---------- */
#app > * { animation: fade-up 0.25s ease both; }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; overflow: hidden; }
.confetti span {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall 1.8s ease-in forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(105vh) translateX(var(--drift, 0)) rotate(var(--spin, 360deg)); opacity: 0.7; }
}

.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + var(--tab-bar-h) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  padding: 0.6rem 1rem;
  font-weight: 600;
  animation: toast-in 0.25s ease both;
}
.toast.leaving { transition: opacity 0.4s ease, transform 0.4s ease; opacity: 0; transform: translateY(8px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.quiz .explanation { animation: pop-in 0.2s ease both; }
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}
.quiz fieldset.answered-incorrect { animation: head-shake 0.3s ease; }
@keyframes head-shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.hero-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}
.hero-row .card { margin: 0; }
.stat-big { font-size: 1.4rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.stat-sub { font-size: 0.85rem; color: var(--text-muted); }
.streak-flame { font-size: 1.4rem; }

/* Compact one-line stat strip (dashboard) */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.stat-strip .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 0.55rem 0.5rem;
  text-align: center;
  text-decoration: none;
  color: inherit;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.stat-strip a.stat { transition: transform 0.12s ease, border-color 0.15s ease; }
.stat-strip a.stat:hover { border-color: var(--accent); }
.stat-strip a.stat:active { transform: scale(0.96); }
.stat-strip .stat .icon { width: 18px; height: 18px; margin: 0 auto; color: var(--accent); }
.stat-strip .num { font-size: 1.15rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.stat-strip .lbl { font-size: 0.68rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-strip .mini-track { background: var(--surface-2); border-radius: 999px; height: 4px; overflow: hidden; margin: 3px auto 0; width: 80%; }
.stat-strip .mini-fill { background: var(--accent); height: 100%; border-radius: 999px; }

/* One-line quick navigation tiles */
.quick-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.quick-tiles a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: 68px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.quick-tiles a .icon { width: 22px; height: 22px; color: var(--accent); }
.quick-tiles a:hover { border-color: var(--accent); color: var(--text); }
.quick-tiles a:active { transform: scale(0.96); }

/* Achievements medallion grid */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 0.75rem 0.5rem;
  margin-top: 0.5rem;
}
.medal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
}
.medal .medal-disc {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--accent-soft) 60%, var(--surface)), var(--accent-soft));
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-card);
}
.medal .medal-name {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}
.medal.locked .medal-disc {
  background: var(--surface-2);
  border-color: var(--border);
  filter: grayscale(1);
  opacity: 0.55;
}
.medal.locked .medal-name { color: var(--text-muted); }

/* Lesson diagrams */
figure.diagram {
  margin: 1.25rem 0;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
figure.diagram svg { display: block; width: 100%; height: auto; }
figure.diagram figcaption {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  min-height: 32px;
  margin: 0.15rem 0.25rem 0.15rem 0;
  font-size: 0.85rem;
  font-weight: 500;
}
.badge-chip.locked { opacity: 0.45; filter: grayscale(1); }
.badge-chip .badge-emoji { font-size: 1rem; }

.widget {
  background: linear-gradient(180deg, var(--accent-soft), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.widget h3:first-child { margin-top: 0; }
.widget-title {
  font-weight: 700;
  color: var(--accent-strong);
  margin: 1.25rem 0 0.35rem;
  letter-spacing: -0.01em;
}
.widget input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 44px; }
.widget .stat-tiles { display: flex; gap: 0.75rem; flex-wrap: wrap; margin: 0.75rem 0; }
.widget .stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  padding: 0.5rem 1rem;
  min-width: 110px;
}

/* ---------- Module identity colors (content color-coding only) ---------- */
.mc-1 { --mc: light-dark(#0f7d68, #3cc0a3); --mc-soft: light-dark(#dcf1ea, #17342c); }
.mc-2 { --mc: light-dark(#4338ca, #a5b4fc); --mc-soft: light-dark(#e5e3fb, #232152); }
.mc-3 { --mc: light-dark(#92510a, #fbbf24); --mc-soft: light-dark(#fdeed3, #3a2c12); }
.mc-4 { --mc: light-dark(#0369a1, #7dd3fc); --mc-soft: light-dark(#dbeffb, #0c2d3f); }
.mc-5 { --mc: light-dark(#6d28d9, #c4b5fd); --mc-soft: light-dark(#ece2fc, #2e1f52); }
.mc-6 { --mc: light-dark(#be123c, #fda4af); --mc-soft: light-dark(#fbdfe6, #3f1220); }
.mc-7 { --mc: light-dark(#15803d, #86efac); --mc-soft: light-dark(#dcf3e3, #12341d); }
.mc-8 { --mc: light-dark(#c2410c, #fdba74); --mc-soft: light-dark(#fde6d8, #3b1f0e); }
.mc-9 { --mc: light-dark(#a21caf, #f0abfc); --mc-soft: light-dark(#f8e0fa, #3a1240); }
.mc-10 { --mc: light-dark(#0e7490, #67e8f9); --mc-soft: light-dark(#d9f2f8, #0d3038); }

.icon-tile {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--mc-soft, var(--accent-soft));
  color: var(--mc, var(--accent));
}
.icon-tile .icon { width: 22px; height: 22px; }

.module-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.module-head .module-title { flex: 1; min-width: 0; }
.module-head h2 { margin: 0; }
.module-head .goal { font-size: 0.85rem; color: var(--text-muted); margin: 0.1rem 0 0; }

.module-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: var(--mc-soft, var(--accent-soft));
  color: var(--mc, var(--accent-strong));
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}
.module-chip .icon { width: 15px; height: 15px; }

/* ---------- Progress rings ---------- */
.ring-track { stroke: var(--surface-2); }
.ring-fill { stroke: var(--mc, var(--accent)); transition: stroke-dashoffset 0.4s ease; }
.ring-text { fill: var(--text); font-weight: 700; }

/* ---------- Lesson rows (numbered) ---------- */
.lesson-rows { margin-top: 0.5rem; }
.lesson-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.6rem;
  min-height: 48px;
  border-radius: var(--radius-ctrl);
  text-decoration: none;
  color: inherit;
}
.lesson-row:hover { background: var(--surface-2); }
.lesson-row:active { transform: scale(0.99); }
.lesson-row .lesson-num {
  width: 26px;
  flex: none;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--mc, var(--accent));
  opacity: 0.85;
}
.lesson-row .lesson-title { flex: 1; min-width: 0; }
.lesson-row .lesson-mins { font-size: 0.8rem; color: var(--text-muted); flex: none; }
.lesson-row .badge-done .icon { width: 18px; height: 18px; }
.lesson-row.current {
  background: var(--mc-soft, var(--accent-soft));
  font-weight: 600;
}
.lesson-row.current .lesson-mins { color: var(--mc, var(--accent-strong)); font-weight: 700; }

/* ---------- Gradient hero ---------- */
.hero-gradient {
  background: linear-gradient(135deg, light-dark(#0f7d68, #0d4a3c), light-dark(#0a5644, #123028));
  color: light-dark(#ffffff, #e8edf2);
  border: none;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1.1rem 1.25rem;
  margin: 0.75rem 0;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.hero-gradient .hero-main { flex: 1; min-width: 0; }
.hero-gradient h1 { margin: 0 0 0.2rem; color: inherit; }
.hero-gradient p { margin: 0; opacity: 0.85; font-size: 0.9rem; }
.hero-gradient .ring-track { stroke: rgba(255, 255, 255, 0.25); }
.hero-gradient .ring-fill { stroke: #ffffff; }
.hero-gradient .ring-text { fill: #ffffff; }

/* ---------- First-run welcome ---------- */
.welcome-hero {
  background: linear-gradient(160deg, #0f7d68, #0a5644 60%, #084234);
  color: #fff;
  border-radius: var(--radius-card);
  margin: 1rem 0;
  padding: 2.5rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.welcome-hero .welcome-mark {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-hero .welcome-mark .icon { width: 44px; height: 44px; color: #fff; }
.welcome-hero h1 { color: #fff; margin: 0; }
.welcome-hero p { margin: 0; opacity: 0.88; max-width: 40ch; }
.welcome-hero input {
  max-width: 280px;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  color: #16212b;
  border: none;
}
.btn.inverse {
  background: #ffffff;
  color: #0a5644;
  font-weight: 700;
}
.btn.inverse:hover { background: #e8f5f1; color: #0a5644; }
.welcome-hero .btn.inverse { padding: 0.7rem 1.8rem; }
.welcome-hero .ghost-link { color: rgba(255, 255, 255, 0.85); font-size: 0.88rem; }

/* ---------- Module-complete celebration ---------- */
.celebrate-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(10, 16, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.celebrate-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  padding: 2rem 1.75rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  animation: pop-in 0.25s ease both;
}
.celebrate-card .trophy-disc {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--warn-soft);
  color: var(--warn);
  display: flex;
  align-items: center;
  justify-content: center;
}
.celebrate-card .trophy-disc .icon { width: 44px; height: 44px; }
.celebrate-card h2 { margin: 0; }
.celebrate-card p { margin: 0; color: var(--text-muted); }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  #app > *, .toast, .quiz .explanation,
  .quiz fieldset.answered-incorrect, .confetti span, .celebrate-card { animation: none; }
  .ring-fill { transition: none; }
  .card-link, .card-link:hover, .card-link:active,
  .tab-item:active, .nav-links a:active, button:active, .btn:active,
  .progress-fill, .toast.leaving { transition: none; transform: none; }
  html { scroll-behavior: auto; }
}

/* ---------- Mobile/tablet: app shell ---------- */
@media (max-width: 900px) {
  html { scroll-padding-bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom)); }
  .nav-links { display: none; }
  .tab-bar { display: block; }
  #app { padding-bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom)); }
  #site-footer { padding-bottom: calc(var(--tab-bar-h) + 1rem + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.6rem; }
  .page { padding-top: 1rem; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav a { max-width: 100%; }
}
