/* MathTrail – Styles */
:root {
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #f0eff7;
  --text: #1b1a2e;
  --muted: #62607a;
  --border: #e3e1ef;
  --grid: #ecebf4;
  --accent: #5b3cc4;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --bad: #c2410c;
  --shadow: 0 1px 2px rgba(20, 18, 50, .06), 0 4px 16px rgba(20, 18, 50, .05);
  --radius: 14px;
  --maxw: 1100px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12111c; --surface: #1c1b2a; --surface-2: #252336; --text: #ecebf6; --muted: #a3a1bb;
    --border: #322f48; --grid: #262439; --accent: #9b82ff; --accent-ink: #12111c; --ok: #4ade80; --bad: #fb923c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12111c; --surface: #1c1b2a; --surface-2: #252336; --text: #ecebf6; --muted: #a3a1bb;
  --border: #322f48; --grid: #262439; --accent: #9b82ff; --accent-ink: #12111c; --ok: #4ade80; --bad: #fb923c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 130px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: clamp(1.45rem, 3.5vw, 2rem); }
button { font: inherit; color: inherit; }
svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ---------- Kopf & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, calc((100% - var(--maxw)) / 2)); background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 1.15rem; white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo svg { width: 30px; height: 30px; stroke: none; }
.logo b { color: var(--accent); }
.search { flex: 1; position: relative; max-width: 520px; margin-left: auto; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input {
  width: 100%; padding: 9px 12px 9px 36px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px; outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--surface); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 50%; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); }

.nav {
  position: sticky; top: 59px; z-index: 19; display: flex; gap: 4px; justify-content: center;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 4px 16px;
}
.nav a { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px; color: var(--muted); font-weight: 500; position: relative; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.on { color: var(--accent); background: var(--surface-2); }
.nav i { font-style: normal; font-size: 11px; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 6px; line-height: 17px; }

main { flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 20px 16px 40px; outline: none; }
.footer { text-align: center; color: var(--muted); font-size: 14px; padding: 18px 16px 24px; }

@media (max-width: 720px) {
  .logo span { display: none; }
  .nav {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; justify-content: space-around;
    border-top: 1px solid var(--border); border-bottom: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .nav a { flex-direction: column; gap: 1px; padding: 6px 4px; font-size: 11px; flex: 1; text-align: center; }
  .nav a svg { width: 22px; height: 22px; }
  .nav i { position: absolute; top: 2px; right: calc(50% - 22px); }
  body { padding-bottom: 64px; }
  html { scroll-padding-top: 70px; }
}

/* ---------- Bausteine ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px;
  border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font-weight: 600; cursor: pointer; text-decoration: none !important; font-size: 15px;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--surface-2); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.badge { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 14px; color: var(--text); text-decoration: none !important;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cat-icon {
  --c: var(--accent); flex: none; display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 12px;
  background: color-mix(in srgb, var(--c) 15%, transparent); color: var(--c); font-weight: 700; font-size: 17px;
  font-family: "KaTeX_Main", "Times New Roman", serif; letter-spacing: -.02em; white-space: nowrap;
}
.cat-icon.sm { width: 24px; height: 24px; border-radius: 6px; font-size: 11px; margin-right: 6px; vertical-align: middle; }
.cat-icon.lg { width: 64px; height: 64px; font-size: 22px; border-radius: 16px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.section-title { font-size: 1.2rem; margin: 28px 0 12px; }
.section-title small { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 6px; }

/* ---------- Startseite ---------- */
.hero { padding: 18px 0 6px; }
.hero .lead { color: var(--muted); margin: 0 0 16px; max-width: 60ch; }
.hero-search { display: flex; gap: 8px; max-width: 640px; }
.hero-search input {
  flex: 1; min-width: 0; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; box-shadow: var(--shadow); outline: none;
}
.hero-search input:focus { border-color: var(--accent); }
.hero-search button { padding: 0 18px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 22px; }
.qa { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--text); display: flex; flex-direction: column; }
.qa:hover { border-color: var(--accent); text-decoration: none; }
.qa span { color: var(--muted); font-size: 13px; }
@media (max-width: 720px) { .quick { grid-template-columns: 1fr 1fr; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
@media (max-width: 400px) { .grid { grid-template-columns: 1fr; } }
.cat-card {
  display: flex; gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.cat-card:hover { text-decoration: none; border-color: var(--c); transform: translateY(-2px); }
.cat-card h3 { font-size: 1.05rem; margin-bottom: 4px; }
.cat-card p { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.cat-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.count { font-size: 13px; color: var(--muted); margin-left: auto; }

/* ---------- Kategorieseite ---------- */
.page-head { margin-bottom: 16px; }
.page-head > p { color: var(--muted); margin: 0; }
.back { display: inline-flex; align-items: center; gap: 2px; font-size: 14px; margin-bottom: 10px; color: var(--muted); }
.back svg { width: 1em; height: 1em; }
.page-title { display: flex; gap: 16px; align-items: flex-start; }
.page-title p { margin: 0 0 8px; color: var(--muted); }
.toc { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px; margin-bottom: 8px; scrollbar-width: thin; }
.toc a { flex: none; font-size: 13px; padding: 5px 11px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.toc a:hover { border-color: var(--accent); text-decoration: none; }
.cat-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.cat-links a { display: inline-flex; align-items: center; padding: 6px 12px 6px 6px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 14px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: 14px; align-items: start; }
.fcard {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--c);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.fcard.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 45%, transparent); } 100% { box-shadow: var(--shadow); } }
.fcard-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 8px; }
.fcard-head h3 { flex: 1; font-size: 1.05rem; margin: 2px 0 0; min-width: 0; }
.fcard-cat { width: 100%; font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; }
.star { background: none; border: 0; padding: 4px; cursor: pointer; color: var(--muted); border-radius: 8px; line-height: 0; }
.star:hover { background: var(--surface-2); }
.star svg { width: 22px; height: 22px; }
.star.on { color: #eab308; }
.star.on svg { fill: #eab308; }
.formula {
  margin: 10px 0; padding: 4px 10px; background: var(--surface-2); border-radius: 10px;
  overflow-x: auto; overflow-y: hidden; font-size: 1.05rem;
}
.formula .katex-display { margin: .7em 0; }
.expl { margin: 8px 0; }
.expl .katex, .vars .katex, .ex-steps .katex, .ex-task .katex { font-size: 1.05em; }
.vars { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; font-size: 14px; }
.vars dt { text-align: right; }
.vars dd { margin: 0; color: var(--muted); }
.tips { margin: 8px 0; padding: 8px 12px 8px 30px; background: color-mix(in srgb, #eab308 12%, transparent); border-radius: 10px; font-size: 14px; }
.example { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; }
.example summary { cursor: pointer; font-weight: 600; color: var(--c); width: fit-content; }
.ex-task { margin: 8px 0 4px; }
.ex-steps { margin: 4px 0; padding-left: 22px; }
.ex-steps li { margin: 3px 0; overflow-x: auto; }
.ex-result { margin: 6px 0 0; font-weight: 500; }
.ex-result > span { color: var(--muted); font-weight: 400; }
.katex { overflow-wrap: normal; }
.expl, .ex-steps li, .ex-result, .task-q, .solution li { overflow-x: auto; overflow-y: hidden; }

/* ---------- Auswahl-Listen ---------- */
.choose { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.choose-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.choose-item:hover { border-color: var(--accent); text-decoration: none; }
.choose-item .cat-icon { width: 40px; height: 40px; font-size: 15px; }
.choose-item b { flex: 1; font-weight: 600; font-size: 15px; }
.choose-item small { color: var(--muted); }
.stat { color: var(--ok) !important; font-size: 12px; white-space: nowrap; }

/* ---------- Karteikarten ---------- */
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.progress div { height: 100%; background: var(--accent); transition: width .3s; }
.flash-wrap { max-width: 640px; margin: 0 auto; }
.flashcard {
  width: 100%; min-height: 260px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px;
  padding: 24px 20px; background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--c);
  border-radius: 18px; box-shadow: var(--shadow); cursor: pointer; text-align: center;
}
.flashcard.open { cursor: default; }
.fc-front { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.fc-front h2 { font-size: 1.5rem; margin: 0; }
.fc-cat { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; margin-bottom: 8px; }
.fc-back { width: 100%; text-align: left; }
.fc-back .formula { text-align: center; }
.fc-actions, .fc-reveal { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.fc-actions .btn, .fc-reveal .btn { min-width: 140px; }

/* ---------- Üben ---------- */
.task {
  max-width: 720px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--c);
  border-radius: 18px; padding: 18px 20px; box-shadow: var(--shadow);
}
.task-q { font-size: 1.1rem; margin-bottom: 16px; }
.answers { display: flex; flex-wrap: wrap; gap: 12px; }
.answer { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.answer input {
  width: 130px; padding: 9px 12px; font: inherit; border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface-2); color: var(--text); outline: none;
}
.answer input:focus { border-color: var(--accent); }
.answer > .unit { font-weight: 400; color: var(--muted); }
input.right { border-color: var(--ok) !important; }
input.wrong { border-color: var(--bad) !important; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 2px solid var(--border); border-radius: 12px; cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice input { accent-color: var(--accent); width: 18px; height: 18px; }
.choice.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.feedback p { margin: 14px 0 0; font-weight: 600; }
.feedback .ok { color: var(--ok); }
.feedback .bad { color: var(--bad); }
.feedback .warn { color: var(--muted); font-weight: 400; }
.solution { margin-top: 16px; padding: 12px 16px; background: var(--surface-2); border-radius: 12px; }
.solution h3 { font-size: 1rem; }
.solution ol { margin: 0; padding-left: 22px; }
.solution li { margin: 6px 0; }

/* ---------- Plotter ---------- */
.plotter { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .plotter { grid-template-columns: 1fr; } }
.plot-box { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.plot-box canvas { display: block; width: 100%; aspect-ratio: 1 / 1; max-height: 70vh; }
.zoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 18px; }
.plot-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.plot-tex { overflow-x: auto; min-height: 3em; }
.sliders { display: grid; gap: 12px; margin: 8px 0; }
.slider > span { display: flex; align-items: baseline; gap: 6px; font-size: 14px; }
.slider output { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.slider input { width: 100%; accent-color: var(--accent); }
.plot-info { padding-left: 20px; font-size: 14px; }
.plot-info li { margin: 4px 0; }

/* ---------- Sonstiges ---------- */
.prose { max-width: 70ch; }
.prose li { margin: 4px 0; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; transition: .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 720px) { #toast { bottom: 84px; } }
@media print {
  .topbar, .nav, .footer, .actions, .toc, .star, .back { display: none !important; }
  .fcard { break-inside: avoid; box-shadow: none; }
  details.example { display: block; }
}
