:root {
  --paper: #f5efe2;
  --paper-2: #efe7d6;
  --ink: #1b1712;
  --ink-soft: #574d3f;
  --line: #d8cdb4;
  --accent: #c8442e;      /* terracotta */
  --accent-2: #2f6b4f;    /* moosgrün (richtig) */
  --wrong: #c8442e;
  --card: #fffdf7;
  --shadow: 0 2px 0 var(--line), 0 14px 30px -18px rgba(27,23,18,.5);
  --radius: 14px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Spectral', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141210;
    --paper-2: #1c1813;
    --ink: #f2e9d8;
    --ink-soft: #b3a78f;
    --line: #342d22;
    --accent: #e2765b;
    --accent-2: #7bb98f;
    --card: #1f1a14;
    --shadow: 0 2px 0 var(--line), 0 18px 34px -20px rgba(0,0,0,.7);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  background:
    radial-gradient(120% 80% at 100% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%),
    var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
#app { max-width: 720px; margin: 0 auto; padding: 20px 18px 90px; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 900; line-height: 1.05; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(2rem, 7vw, 3rem); font-variation-settings: 'opsz' 120; }
h2 { font-size: 1.5rem; font-weight: 600; }
p { line-height: 1.55; }
a { color: var(--accent); }
button { font-family: inherit; cursor: pointer; }

/* --- header --- */
.top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; gap: 12px; }
.brand { font-family: var(--font-display); font-weight: 900; font-size: 1.35rem; letter-spacing: -.02em; }
.brand em { color: var(--accent); font-style: italic; }
.muted { color: var(--ink-soft); }
.small { font-size: .82rem; }

/* --- buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1.5px solid var(--ink); background: var(--ink); color: var(--paper);
  padding: 12px 18px; border-radius: 999px; font-size: 1rem; font-weight: 500;
  transition: transform .08s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 7px 12px; font-size: .85rem; }

/* --- cards --- */
.card {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.mod { display: block; text-align: left; width: 100%; background: var(--card);
  border: 1.5px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 14px; color: inherit;
  transition: transform .1s ease, border-color .15s ease; }
.mod:hover { transform: translateY(-2px); border-color: var(--accent); }
.mod .row { display: flex; justify-content: space-between; align-items: baseline; }
.mod h2 { font-family: var(--font-display); font-weight: 900; }
.bar { height: 8px; border-radius: 999px; background: var(--paper-2); overflow: hidden; margin-top: 12px; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), color-mix(in srgb, var(--accent-2) 60%, var(--accent))); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { font-size: .78rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper-2); color: var(--ink-soft); }
.chip.due { color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* --- forms --- */
label { display: block; font-size: .82rem; color: var(--ink-soft); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
input, textarea {
  width: 100%; font-family: var(--font-body); font-size: 1rem; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }

/* --- quiz --- */
.qmeta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.progress-line { height: 4px; background: var(--paper-2); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.progress-line > span { display: block; height: 100%; background: var(--accent); transition: width .3s ease; }
.qtext { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; line-height: 1.25; margin: 6px 0 20px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px; color: inherit; font-size: 1.02rem;
  transition: border-color .12s ease, background .12s ease;
}
.opt:hover { border-color: var(--accent); }
.opt .key { font-family: var(--font-display); font-weight: 900; width: 26px; height: 26px; flex: none;
  display: grid; place-items: center; border: 1.5px solid var(--line); border-radius: 8px; font-size: .9rem; }
.opt.sel { border-color: var(--ink); }
.opt.sel .key { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.opt.correct { border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 12%, var(--card)); }
.opt.correct .key { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.opt.wrong { border-color: var(--wrong); background: color-mix(in srgb, var(--wrong) 12%, var(--card)); }
.opt.wrong .key { background: var(--wrong); color: #fff; border-color: var(--wrong); }
.opt:disabled { cursor: default; }

.verdict { border-radius: 12px; padding: 16px; margin: 16px 0; border: 1.5px solid var(--line); background: var(--paper-2); }
.verdict.ok { border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 10%, var(--card)); }
.verdict.no { border-color: var(--wrong); background: color-mix(in srgb, var(--wrong) 10%, var(--card)); }
.verdict h3 { font-size: 1.05rem; margin-bottom: 6px; }
.score-pill { font-family: var(--font-display); font-weight: 900; }

.center { text-align: center; }
.stack { display: grid; gap: 10px; }
.spacer { height: 8px; }
.err { color: var(--wrong); font-size: .9rem; margin-top: 8px; }
.link { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 0; font-size: .95rem; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.fade { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --- KI-Tutor chat --- */
.tutor { margin-top: 6px; }
.askrow { display: flex; gap: 8px; margin-top: 10px; }
.askrow input { flex: 1; }
#asklog { max-height: 320px; overflow-y: auto; }
.bubble { padding: 10px 14px; border-radius: 14px; font-size: .95rem; line-height: 1.5; max-width: 90%; white-space: pre-wrap; }
.bubble.u { align-self: flex-end; background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; margin-left: auto; }
.bubble.a { align-self: flex-start; background: var(--paper-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.load { color: var(--ink-soft); font-style: italic; }

.bignum { font-family: var(--font-display); font-weight: 900; font-size: 3rem; line-height: 1; color: var(--accent); }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; }
.statgrid .n { font-family: var(--font-display); font-weight: 900; font-size: 1.6rem; }
