:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --ink: #1d1f23;
  --muted: #6b6f76;
  --line: #e4e0d6;
  --accent: #f2a900;
  --accent-strong: #d99400;
  --accent-ink: #1d1f23;
  --accent-soft: #fff3cc;
  --ok: #23874d;
  --ok-soft: #e1f4e8;
  --bad: #c9392c;
  --bad-soft: #fbe5e2;
  --warn: #b86e00;
  --info: #2f6fd6;
  --shadow: 0 1px 2px rgba(29, 31, 35, .06), 0 4px 16px rgba(29, 31, 35, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131518;
    --surface: #1c1f23;
    --surface-2: #24282d;
    --ink: #ecebe7;
    --muted: #9ba0a8;
    --line: #2e3338;
    --accent-soft: #3a2f12;
    --ok: #4cc27c;
    --ok-soft: #173424;
    --bad: #ff7a6b;
    --bad-soft: #3d1d1a;
    --warn: #f0a23a;
    --info: #7aa7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.hazard {
  height: 5px;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 12px, #1d1f23 12px 24px);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 750; letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
.topstats { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.pill.accent { background: var(--accent-soft); border-color: transparent; }

.app { max-width: 980px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- Generic ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px;
}
h1, h2, h3 { line-height: 1.2; letter-spacing: -.015em; margin: 0 0 .4em; }
h1 { font-size: clamp(24px, 4vw, 30px); }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 15px;
  text-decoration: none; transition: transform .08s ease, background .15s ease;
  min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
label.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .5s ease; }
.bar.ok > span { background: var(--ok); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.due { background: var(--accent-soft); color: var(--warn); }
.badge.hot { background: var(--bad-soft); color: var(--bad); }
.badge.good { background: var(--ok-soft); color: var(--ok); }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login { min-height: 70dvh; display: grid; place-items: center; }
.login .card { width: min(400px, 100%); text-align: center; padding: 28px 22px; }
.login img { margin-bottom: 8px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }

/* ---------- Dashboard ---------- */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
}
.hero p { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.stat { padding: 14px; }
.stat .big { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat .lbl { font-size: 13px; color: var(--muted); }
.week { display: flex; gap: 4px; align-items: flex-end; height: 34px; margin-top: 8px; }
.week span { flex: 1; background: var(--surface-2); border-radius: 4px; min-height: 4px; }
.week span.on { background: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.module-card { display: grid; gap: 10px; text-decoration: none; cursor: pointer; transition: transform .12s ease, border-color .12s; }
.module-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.module-card .name { font-weight: 750; font-size: 17px; }
.module-card .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.add-card { border-style: dashed; display: grid; place-items: center; min-height: 140px; color: var(--muted); cursor: pointer; box-shadow: none; }
.add-card:hover { border-color: var(--accent); color: var(--ink); }

.list { display: grid; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow-wrap: anywhere; }

/* ---------- Module ---------- */
.module-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.module-head h1 { margin: 0; }
.back { text-decoration: none; color: var(--muted); font-size: 14px; }
.tabs {
  display: flex; gap: 4px; padding: 4px; border-radius: 999px;
  background: var(--surface-2); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  flex: 1; text-align: center; padding: 8px 12px; border-radius: 999px;
  text-decoration: none; font-weight: 650; font-size: 14px; white-space: nowrap; color: var(--muted);
}
.tabs a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: calc(100dvh - 250px); }
.chat-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 600;
}
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chat-tools select { width: auto; max-width: 100%; flex: 1 1 220px; border-radius: 999px; padding: 7px 12px; font-size: 14px; }
.messages { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 12px; }
.msg { display: flex; gap: 10px; align-items: flex-start; max-width: 100%; }
.msg .avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px; background: var(--accent-soft);
}
.msg .bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 10px 14px; min-width: 0; max-width: 100%; overflow-wrap: anywhere;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble {
  background: var(--ink); color: var(--bg); border-color: var(--ink);
  border-radius: var(--radius) 4px var(--radius) var(--radius); white-space: pre-wrap;
}
.msg .who { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.sources { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.source {
  font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2);
  text-decoration: none; color: var(--muted); font-weight: 600;
}
.source:hover { color: var(--ink); }
.typing span { display: inline-block; width: 7px; height: 7px; margin-right: 3px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer {
  position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 180px; border-radius: 20px; padding: 11px 16px; line-height: 1.4; }
.composer .btn { flex: none; width: 46px; height: 46px; padding: 0; }
.starter { text-align: center; padding: 24px 8px; }
.starter .avatar-big { font-size: 44px; }
.starter .chips { justify-content: center; margin-top: 14px; }

/* Markdown in Bubbles */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .5em 0; }
.md ul, .md ol { margin: .4em 0; padding-left: 1.3em; }
.md li { margin: .15em 0; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: .5em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md blockquote { margin: .5em 0; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.md h1, .md h2, .md h3 { font-size: 1.05em; margin: .8em 0 .3em; }

/* ---------- Quiz ---------- */
.quiz { max-width: 680px; margin: 0 auto; }
.quiz-progress { display: flex; gap: 6px; margin-bottom: 14px; }
.quiz-progress span { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); }
.quiz-progress span.cur { background: var(--ink); }
.quiz-progress span.ok { background: var(--ok); }
.quiz-progress span.bad { background: var(--bad); }
.question { font-size: 18px; font-weight: 650; margin-bottom: 16px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 13px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 15px; width: 100%;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option .letter {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; background: var(--surface-2);
}
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.correct .letter { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .letter { background: var(--bad); color: #fff; }
.option:disabled { cursor: default; }
.feedback { margin-top: 14px; padding: 14px; border-radius: var(--radius-sm); }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback strong { display: block; margin-bottom: 4px; }
.result { text-align: center; padding: 28px 18px; }
.result .score { font-size: 56px; font-weight: 850; letter-spacing: -.03em; line-height: 1; }
.loading-quiz { text-align: center; padding: 48px 16px; }

/* ---------- Themen ---------- */
.doc-group { margin-bottom: 22px; }
.chapter { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px; }
.topic-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 14px; }
.topic-row .bar { grid-column: 1 / -1; height: 5px; }
.topic-row > div:first-child { min-width: 0; }
.topic-row .acts { display: flex; gap: 6px; }
.topic-row .acts .btn { white-space: nowrap; }
.section-head > :last-child { white-space: nowrap; }

/* ---------- Dateien ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Toasts / Confetti ---------- */
.toasts { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s ease; }
.toast.error { background: var(--bad); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; }

.banner { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-weight: 600; margin-bottom: 16px; }

@media (max-width: 640px) {
  .app { padding: 14px 16px 32px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:first-child { grid-column: 1 / -1; }
  .topstats .pill.hide-sm { display: none; }
  .brand span { font-size: 15px; }
  .chat { min-height: calc(100dvh - 220px); }
  .card { padding: 14px; }
  .topic-row { padding: 12px; gap: 8px; }
  .topic-row .acts .btn { padding: 6px 10px; min-height: 36px; }
  .tabs a { padding: 8px 6px; font-size: 13px; }
  .stat .big { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
