/* SatPos lernen – calm, readable, light + dark. */

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --text: #1f2328;
  --muted: #646b73;
  --border: #dedcd5;
  --accent: #2f6f8f;
  --accent-text: #ffffff;
  --accent-soft: #e3eef3;
  --right: #2e7d4f;
  --right-soft: #e4f2e9;
  --wrong: #b3433a;
  --wrong-soft: #f8e6e4;
  --partial: #a86f12;
  --partial-soft: #f8eedb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1e2126;
    --surface-2: #262a30;
    --text: #e4e6e9;
    --muted: #9aa1a9;
    --border: #343941;
    --accent: #6fb0d0;
    --accent-text: #0e1a20;
    --accent-soft: #1d3340;
    --right: #6cc191;
    --right-soft: #1b3326;
    --wrong: #e98a80;
    --wrong-soft: #3d2220;
    --partial: #e0b260;
    --partial-soft: #3a2e17;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
}

.container {
  max-width: 50rem;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-left)) 4rem max(1rem, env(safe-area-inset-right));
}

h1, h2, h3 { line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
a { color: var(--accent); }
p { margin: .5rem 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
kbd {
  font-family: var(--mono);
  font-size: .72em;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 .3em;
  margin-left: .5em;
  opacity: .55;
}
@media (hover: none) { kbd { display: none; } }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.loading { color: var(--muted); padding: 3rem 0; text-align: center; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  min-height: 2.75rem;
  padding: .5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .95rem;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; border-color: var(--border); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.subtle { background: transparent; }
.btn.wide { width: 100%; }
.btn.grade-right { border-color: var(--right); color: var(--right); }
.btn.grade-partial { border-color: var(--partial); color: var(--partial); }
.btn.grade-wrong { border-color: var(--wrong); color: var(--wrong); }
.btn.grade-right:hover { background: var(--right-soft); }
.btn.grade-partial:hover { background: var(--partial-soft); }
.btn.grade-wrong:hover { background: var(--wrong-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions, .row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

/* ---------- Layout pieces ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}
.panel h2:first-child { margin-top: 0; }
.panel.error { border-color: var(--wrong); color: var(--wrong); }

.hero { padding: 1.5rem 0 .5rem; }
.hero .sub { color: var(--muted); margin: .25rem 0 0; }

.topbar {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .5rem 0 .75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.topbar .back { text-decoration: none; font-size: .9rem; }
.topbar h1 { font-size: 1.25rem; }
.topbar .sub { color: var(--muted); font-size: .9rem; }

.tag {
  display: inline-block;
  font-size: .78rem;
  padding: .05rem .5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
}
.tag-muted { background: var(--surface-2); color: var(--muted); }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s ease; }

/* ---------- Dashboard ---------- */

.mix h2 { margin-bottom: .2rem; }
.mix-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: .6rem;
  margin-top: .8rem;
}
.mix-item {
  display: flex;
  flex-direction: column;
  padding: .75rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
}
.mix-item:hover { border-color: var(--accent); }
.mix-item strong { hyphens: auto; overflow-wrap: anywhere; }
.mix-item span { color: var(--muted); font-size: .85rem; }
.mix-item.disabled { opacity: .5; }

.lecture {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: .75rem 0;
  box-shadow: var(--shadow);
}
.lecture.unavailable { opacity: .65; box-shadow: none; }
.lecture-head { display: flex; align-items: baseline; gap: .6rem; }
.lecture-head h3 { margin: 0; font-size: 1.1rem; }
.num {
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--accent);
  font-weight: 600;
}
.summary {
  color: var(--muted);
  font-size: .95rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: .75rem 0 .25rem; }
@media (max-width: 30rem) { .stats { grid-template-columns: 1fr; gap: .6rem; } }
.stat-label { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; margin-bottom: .25rem; }
.stat-value { color: var(--muted); }
.stat-extra { font-size: .8rem; margin-top: .2rem; }
.lecture-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.lecture-actions .btn { flex: 1 1 auto; }

.exam-history { list-style: none; padding: 0; margin: 0; }
.exam-history li {
  display: flex; flex-wrap: wrap; gap: .25rem 1rem;
  padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .92rem;
}
.exam-history li:last-child { border-bottom: 0; }

.page-footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.load-errors { margin-bottom: 1rem; font-size: .9rem; color: var(--muted); }
.load-errors summary { cursor: pointer; }

/* ---------- Lernen ---------- */

.section-nav { margin-bottom: 1rem; }
.section-select {
  width: 100%;
  font: inherit;
  font-size: .95rem;
  padding: .55rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.section-page { min-height: 50vh; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; }
.section-head h2 { margin: .25rem 0 .5rem; font-size: 1.35rem; }
.slide-links { font-size: .875rem; color: var(--muted); }
.slide-link { font-size: .875rem; white-space: nowrap; }
.points { padding-left: 1.2rem; }
.points > li { margin: .55rem 0; }
.points > li::marker { color: var(--accent); }
.subpoints { padding-left: 1.3rem; margin: .3rem 0 0; }
.subpoints > li { margin: .25rem 0; }
.lead { font-size: 1.05rem; }
.formulas h3 { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.formula {
  margin: .75rem 0;
  padding: .5rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.formula-tex { overflow-x: auto; overflow-y: hidden; }
.formula figcaption { color: var(--muted); font-size: .95rem; }
.formula figcaption p { margin: .25rem 0; }

.pager {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-top: 1.5rem;
  padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.counter { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.next-steps { margin-top: 2rem; }

/* ---------- Markdown + KaTeX ---------- */

.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { padding-left: 1.3rem; margin: .4rem 0; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .05em .3em; border-radius: 4px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: .25rem .5rem; }
.katex { font-size: 1.08em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .2rem 0; margin: .5rem 0; }

/* ---------- Setup forms ---------- */

.setup h2 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
.choice { display: flex; flex-wrap: wrap; gap: .4rem; }
.choice-item {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-size: .95rem;
}
.choice-item:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-item.disabled { opacity: .45; cursor: default; }
.choice-item input { accent-color: var(--accent); margin: 0; }
.check { display: flex; align-items: center; gap: .3rem; margin: .5rem 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
.lecture-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0 1rem; }
.lecture-picks .check { margin: .25rem 0; font-size: .95rem; }
.boxes { margin-top: .4rem; }

/* ---------- Karteikarten ---------- */

.session-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.session-head .bar { flex: 1; }
.card-status { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; font-size: .9rem; }
.flashcard {
  min-height: 15rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.5rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.flashcard.flipped { cursor: default; user-select: text; justify-content: flex-start; }
.card-side-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .5rem; }
.card-front { font-size: 1.15rem; font-weight: 500; }
.flipped .card-front { font-size: 1rem; color: var(--muted); }
.card-back { font-size: 1.05rem; }
.card-foot { margin-top: 1rem; }
.card-hint { margin-top: 1.5rem; font-size: .85rem; }
.rate-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: 1rem; }
.rate-row .wide { grid-column: 1 / -1; }

/* ---------- Quiz ---------- */

.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; margin-bottom: .6rem; }
.q-text { font-size: 1.12rem; font-weight: 500; margin-bottom: .75rem; }
.hint { color: var(--muted); font-size: .85rem; margin: -.25rem 0 .5rem; }
.options { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.option {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  width: 100%;
  min-height: 2.9rem;
  padding: .6rem .8rem;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; color: var(--text); opacity: 1; }
.option.picked { border-color: var(--accent); background: var(--accent-soft); }
.option.correct { border-color: var(--right); background: var(--right-soft); }
.option.wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.option.missed { border-color: var(--right); border-style: dashed; }
.opt-key {
  flex: none;
  min-width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .85rem;
  font-family: var(--mono);
}
.opt-text { flex: 1; padding-top: .05rem; }
.opt-mark { flex: none; font-weight: 700; }
.option.correct .opt-mark, .option.missed .opt-mark { color: var(--right); }
.option.wrong .opt-mark { color: var(--wrong); }
.tf-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.option.tf { justify-content: center; align-items: center; }
.option.tf .opt-text { flex: none; }

.open-label { display: block; font-size: .85rem; color: var(--muted); }
.open-label textarea {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .6rem .7rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}
.label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .3rem; }
.model-answer, .keypoints, .grade {
  margin-top: 1rem;
  padding: .8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.model-answer { border-left: 3px solid var(--accent); }
.keypoints ul { list-style: none; padding: 0; margin: 0; }
.keypoints li { margin: .35rem 0; }
.keypoints label { display: flex; align-items: flex-start; gap: .55rem; cursor: pointer; }
.keypoints input { margin-top: .35rem; width: 1.05rem; height: 1.05rem; flex: none; accent-color: var(--right); }
.grade-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
@media (max-width: 24rem) { .grade-row .btn { padding: .5rem .3rem; } }

.feedback {
  margin-top: 1rem;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.feedback-head { font-weight: 600; margin-bottom: .3rem; }
.feedback.right { border-color: var(--right); background: var(--right-soft); }
.feedback.right .feedback-head { color: var(--right); }
.feedback.wrong, .feedback.none { border-color: var(--wrong); background: var(--wrong-soft); }
.feedback.wrong .feedback-head, .feedback.none .feedback-head { color: var(--wrong); }
.feedback.partial { border-color: var(--partial); background: var(--partial-soft); }
.feedback.partial .feedback-head { color: var(--partial); }

.quiz-nav {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-top: 1.25rem;
  padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.score { font-size: 1.15rem; }
.score strong { font-size: 1.6rem; }
.result .bar { margin: .5rem 0 .75rem; }
.review h2 { margin-top: 2rem; }
.review-item {
  padding: 1rem 1.1rem;
  margin: .75rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--wrong);
  border-radius: var(--radius);
}
.review-item.right { border-left-color: var(--right); }
.review-item.partial { border-left-color: var(--partial); }
.review-item .question .model-answer,
.review-item .question .keypoints,
.review-item .question .feedback { background: var(--bg); }

/* ---------- Prüfung ---------- */

.exam-head { justify-content: space-between; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.clock.warn { color: var(--wrong); }
.dots { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }
.dot {
  min-width: 2rem;
  height: 2rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.dot.answered { background: var(--accent-soft); color: var(--text); }
.dot.current { border-color: var(--accent); border-width: 2px; color: var(--text); }

@media (max-width: 30rem) {
  body { font-size: 16px; }
  .panel, .lecture { padding: .9rem 1rem; }
  .flashcard { min-height: 13rem; padding: 1.25rem 1rem; }
  .quiz-nav .btn, .pager .btn { padding: .5rem .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
