:root {
  --bg: #0f1115;
  --bg2: #151821;
  --card: #181c26;
  --card2: #1f2430;
  --line: #2a3040;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #7aa2ff;
  --accent2: #a879ff;
  --good: #3ecf8e;
  --mid: #f0b429;
  --bad: #ff6b6b;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 0.3rem; line-height: 1.25; }
h2 { font-size: 1.25rem; margin: 1.2rem 0 0.6rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.5rem; }
p { margin: 0.4rem 0; }
code, .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 0.92em; }
code { background: var(--card2); padding: 1px 5px; border-radius: 5px; }
mark { background: rgba(122, 162, 255, 0.25); color: inherit; border-radius: 4px; padding: 0 3px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }

/* Layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--bg2); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); padding: 0 8px; }
.brand img { width: 32px; height: 32px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--text); padding: 9px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
.sidebar nav a:hover { background: var(--card); }
.sidebar nav a.active { background: linear-gradient(90deg, rgba(122, 162, 255, 0.18), rgba(168, 121, 255, 0.1)); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 0 8px; word-break: break-all; }
main { min-width: 0; padding: 26px clamp(14px, 3vw, 40px) 90px; max-width: 1150px; width: 100%; }
.bottom-nav { display: none; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  main { padding: 16px 14px 96px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: rgba(21, 24, 33, 0.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 50; }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; color: var(--muted); font-size: 1.2rem; gap: 1px; }
  .bottom-nav a small { font-size: 0.68rem; }
  .bottom-nav a.active { color: var(--accent); }
  h1 { font-size: 1.35rem; }
}

/* Bausteine der Oberfläche */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head { margin: 18px 0 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }
.row.end { justify-content: flex-end; }
.row.nowrap { flex-wrap: nowrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.cards-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; display: block; color: inherit; }
a.card:hover { border-color: var(--accent); transform: translateY(-1px); transition: 0.15s; }
.grid .card { margin-bottom: 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: inherit; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.link-stat:hover { border-color: var(--accent); }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.chip.good { color: var(--good); border-color: rgba(62, 207, 142, 0.4); }
.chip.mid { color: var(--mid); border-color: rgba(240, 180, 41, 0.4); }
.chip.bad, .chip.warn { color: var(--bad); border-color: rgba(255, 107, 107, 0.4); }
.chip.accent { color: var(--accent2); border-color: rgba(168, 121, 255, 0.4); }
.good { color: var(--good); }
.mid { color: var(--mid); }
.bad { color: var(--bad); }
.empty { text-align: center; padding: 40px 16px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Buttons & Formulare */
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; background: var(--card2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font: inherit; cursor: pointer; text-align: center; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #0b0d12; font-weight: 600; }
.btn.danger { background: rgba(255, 107, 107, 0.15); border-color: rgba(255, 107, 107, 0.5); color: var(--bad); }
.btn.good { background: rgba(62, 207, 142, 0.15); border-color: rgba(62, 207, 142, 0.5); color: var(--good); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn.big { padding: 12px 22px; font-size: 1.05rem; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 1rem; }
.icon-btn:hover:not(:disabled) { background: var(--card2); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
input, select, textarea { width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(122, 162, 255, 0.45); border-color: var(--accent); }
input[type='checkbox'] { width: auto; accent-color: var(--accent); transform: scale(1.15); }
.row > select, .row > input { width: auto; }
textarea { resize: vertical; }
label { display: block; margin: 8px 0; }
label > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; gap: 8px; align-items: center; }
.form label { margin: 10px 0; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 18px; scrollbar-width: thin; }
.tabs a { padding: 9px 13px; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); border-color: var(--accent); }

/* Listen */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.list-item { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color: inherit; margin: 0; }
.list.compact .list-item { padding: 8px 10px; }
.card .list-item { background: var(--card2); }
.exam-card h3 { margin: 10px 0 2px; }
.stats-mini { display: flex; gap: 12px; color: var(--muted); font-size: 0.82rem; margin-top: 10px; flex-wrap: wrap; }
.topic .objectives { margin: 10px 0 6px; padding-left: 0; list-style: none; }
.objectives li { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.objectives li::before { content: '🎯'; font-size: 0.8rem; }
.objectives li:last-child::before { content: ''; }
.objectives-box ul { margin: 6px 0 0; }
.proposal-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; cursor: pointer; }
.proposal-item ul { margin: 4px 0 0; padding-left: 18px; font-size: 0.9rem; }
.q-item .md p { margin: 0; }
.mc-preview { margin: 6px 0 0; padding-left: 22px; font-size: 0.9rem; color: var(--muted); }
.mc-preview li.right { color: var(--good); font-weight: 600; }
.mc-preview li.wrong { color: var(--bad); }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details.card > summary { margin-bottom: 4px; }
details[open].card > summary { margin-bottom: 12px; }

/* Balken & Diagramme */
.bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 8px; flex: 1; min-width: 60px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s; }
.bar-fill.good { background: var(--good); }
.bar-fill.mid { background: var(--mid); }
.bar-fill.bad { background: var(--bad); }
.obj-stat { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.obj-stat .bar { margin: 0; max-width: 180px; }
.week { display: flex; gap: 8px; align-items: flex-end; height: 140px; }
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.week-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.week-bar { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 3px; opacity: 0.85; }
.week-bar.good { background: var(--good); }
.spark { display: flex; gap: 3px; align-items: flex-end; height: 80px; }
.spark-bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-width: 4px; }
.spark-bar.good { background: var(--good); }
.spark-bar.mid { background: var(--mid); }
.spark-bar.bad { background: var(--bad); }
.countdown { display: flex; gap: 14px; align-items: center; padding: 8px 0; color: inherit; border-bottom: 1px solid var(--line); }
.countdown:last-child { border: 0; }
.cd-days { min-width: 58px; text-align: center; font-size: 1.5rem; font-weight: 700; background: var(--card2); border-radius: 12px; padding: 4px; line-height: 1.1; }
.cd-days small { display: block; font-size: 0.7rem; color: var(--muted); font-weight: 400; }
.cd-days.warn { color: var(--bad); }
.quick { margin-top: 6px; }
.warn-card { border-color: rgba(240, 180, 41, 0.5); }

/* Lernplan */
.plan-day { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.plan-day.today { background: rgba(122, 162, 255, 0.07); border-radius: 10px; padding: 10px; }
.plan-day.past { opacity: 0.6; }
.plan-date { min-width: 120px; font-weight: 600; font-size: 0.9rem; padding-top: 6px; }
.plan-item { display: flex; gap: 10px; align-items: center; margin: 4px 0; }

/* Material */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; background: var(--card); margin-bottom: 14px; }
.dropzone.over { border-color: var(--accent); background: rgba(122, 162, 255, 0.07); }
.upload-progress .row { margin: 6px 0; }
.preview { max-height: 45vh; overflow: auto; background: var(--bg2); border-radius: 10px; padding: 12px; margin: 10px 0; }

/* Markdown */
.md p { margin: 0.45rem 0; }
.md ul, .md ol { margin: 0.4rem 0; padding-left: 1.3rem; }
.md h3, .md h4, .md h5 { margin: 0.8rem 0 0.3rem; }
.tablewrap { overflow-x: auto; margin: 8px 0; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
th { background: var(--card2); }

/* Lernseite */
.blocks { display: flex; flex-direction: column; gap: 14px; margin-bottom: 14px; }
.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.block-title { margin-bottom: 8px; }
.callout { border-left: 4px solid var(--accent); }
.callout.merke { border-left-color: var(--accent2); background: linear-gradient(90deg, rgba(168, 121, 255, 0.09), var(--card) 60%); }
.callout.warnung { border-left-color: var(--bad); }
.callout.tipp { border-left-color: var(--good); }
.callout-head { font-weight: 700; margin-bottom: 4px; }
.accordion details { border-top: 1px solid var(--line); padding: 8px 0; }
.accordion summary { font-weight: 600; }
.accordion summary::before { content: '▸ '; color: var(--accent); }
.accordion details[open] summary::before { content: '▾ '; }
.example .steps li { margin: 6px 0; }
.fade-in { animation: fade 0.3s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.exercise { border-color: rgba(122, 162, 255, 0.35); }
.result { margin-top: 8px; font-weight: 600; }
.cloze-text { line-height: 2.2; }
.gap { display: inline-block; width: auto; padding: 2px 6px; margin: 0 3px; border-radius: 6px; }
input.right, .gap.right { border-color: var(--good); background: rgba(62, 207, 142, 0.1); }
input.wrong, .gap.wrong { border-color: var(--bad); background: rgba(255, 107, 107, 0.1); }
.gap.shown { border-style: dashed; }
.match-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; padding: 6px; border-radius: 8px; }
.match-row.right { background: rgba(62, 207, 142, 0.1); }
.match-row.wrong { background: rgba(255, 107, 107, 0.1); }
.match-left { font-weight: 600; }
@media (max-width: 560px) { .match-row { grid-template-columns: 1fr; gap: 4px; } }
.order-list { padding-left: 1.5rem; }
.order-item { display: flex; align-items: center; gap: 6px; background: var(--card2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin: 6px 0; }
.order-item.right { border-color: var(--good); }
.order-item.wrong { border-color: var(--bad); }
.flipgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.flipcard { position: relative; min-height: 120px; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font: inherit; cursor: pointer; padding: 14px; perspective: 600px; }
.flipcard .back { display: none; font-size: 0.9rem; text-align: left; }
.flipcard .front { font-weight: 600; }
.flipcard.flipped { border-color: var(--accent2); background: rgba(168, 121, 255, 0.08); }
.flipcard.flipped .front { display: none; }
.flipcard.flipped .back { display: block; }
.diagram { overflow-x: auto; text-align: center; background: var(--bg2); border-radius: 10px; padding: 12px; }
.diagram svg { max-width: 100%; height: auto; }
pre.code { text-align: left; white-space: pre-wrap; font-size: 0.8rem; color: var(--muted); }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.quiz-opt { display: flex; gap: 10px; align-items: center; text-align: left; background: var(--card2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; cursor: pointer; }
.quiz-opt:hover { border-color: var(--accent); }
.quiz-opt.sel { border-color: var(--accent); background: rgba(122, 162, 255, 0.12); }
.quiz-opt.right { border-color: var(--good); background: rgba(62, 207, 142, 0.14); }
.quiz-opt.wrong { border-color: var(--bad); background: rgba(255, 107, 107, 0.14); }
.opt-letter { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--bg2); font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.explain input { margin-bottom: 8px; }
.explain-out:not(:empty) { margin-top: 12px; padding: 12px; background: var(--bg2); border-radius: 10px; }
.pager { margin-top: 10px; }

/* Üben */
.question .q-prompt { font-size: 1.05rem; margin: 10px 0; }
.feedback:not(:empty) { margin-top: 12px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); }
.feedback.right { border-color: var(--good); background: rgba(62, 207, 142, 0.08); }
.feedback.mid { border-color: var(--mid); background: rgba(240, 180, 41, 0.08); }
.feedback.wrong { border-color: var(--bad); background: rgba(255, 107, 107, 0.08); }
.fb-head { font-weight: 700; margin-bottom: 4px; }
.big-score { font-size: 3rem; font-weight: 800; }
.result-item.right { border-left: 4px solid var(--good); }
.result-item.mid { border-left: 4px solid var(--mid); }
.result-item.wrong { border-left: 4px solid var(--bad); }
.sticky-head { position: sticky; top: 0; background: var(--bg); z-index: 5; padding: 6px 0; }
.timer { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--card); padding: 4px 12px; border-radius: 10px; border: 1px solid var(--line); }
.timer.warn { color: var(--bad); border-color: var(--bad); }
.sim-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.nav-dot { width: 34px; height: 34px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); color: var(--muted); cursor: pointer; font: inherit; }
.nav-dot.done { background: rgba(122, 162, 255, 0.18); color: var(--text); }
.nav-dot.cur { border-color: var(--accent2); outline: 2px solid var(--accent2); }
.srs-card { max-width: 640px; margin: 0 auto; text-align: center; padding: 26px; }
.srs-front { font-size: 1.25rem; font-weight: 600; margin: 20px 0; }
.srs-back { text-align: left; }
.srs-rate { margin-top: 16px; }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 260px); min-height: 400px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.msg.user { align-self: flex-end; background: rgba(122, 162, 255, 0.15); border-color: rgba(122, 162, 255, 0.35); }
.chat-input { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }

/* Lernzettel */
.cheatsheet { background: #fff; color: #111; border-radius: var(--radius); padding: 24px; }
.cheatsheet .muted { color: #555; }
.cs-grid { columns: 2 300px; column-gap: 24px; margin-top: 12px; }
.cs-grid section { break-inside: avoid; margin-bottom: 14px; }
.cs-grid h3 { color: #3b4cca; border-bottom: 2px solid #dde; padding-bottom: 2px; }
.cs-grid ul { margin: 4px 0; padding-left: 18px; font-size: 0.9rem; }
.cheatsheet code { background: #eef; }

/* Dialoge & Hinweise */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 100; padding: 14px; animation: fade 0.15s; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 16px; width: min(640px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 14px 18px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
#toasts { position: fixed; bottom: 90px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(400px, calc(100vw - 32px)); }
.toast { background: var(--card2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); transition: 0.4s; }
.toast.ok { border-left-color: var(--good); }
.toast.error { border-left-color: var(--bad); }
.toast.out { opacity: 0; transform: translateX(20px); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 30% 20%, rgba(122, 162, 255, 0.12), transparent 50%), radial-gradient(circle at 70% 80%, rgba(168, 121, 255, 0.1), transparent 50%); }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 36px 30px; text-align: center; max-width: 400px; box-shadow: var(--shadow); }
.login-logo { width: 80px; height: 80px; margin-bottom: 8px; }
.login-card .btn { margin-top: 18px; background: #fff; color: #222; }
.avatar { width: 48px; height: 48px; border-radius: 50%; }
.share-card { max-width: 560px; margin: 40px auto; }
body.offline .btn.primary { filter: saturate(0.6); }

@media print {
  body { background: #fff; }
  .sidebar, .bottom-nav, .tabs, .page-head, .no-print, #toasts { display: none !important; }
  .layout { display: block; }
  main { padding: 0; max-width: none; }
  .cheatsheet { padding: 0; border-radius: 0; }
  .cs-grid { columns: 2; font-size: 10.5pt; }
}

/* Arbeitsblatt lösen */
.ws-task.right { border-left: 4px solid var(--good); }
.ws-task.mid { border-left: 4px solid var(--mid); }
.ws-task.wrong { border-left: 4px solid var(--bad); }
.ws-task textarea { margin: 8px 0; }
.solution { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: rgba(62, 207, 142, 0.06); border: 1px dashed rgba(62, 207, 142, 0.45); }
.my-answer { margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: var(--bg2); }
.ws-chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.print-only { display: none; }
@media print {
  .print-only { display: block; }
  .ws-task { break-inside: avoid; border: 1px solid #ccc; background: #fff; color: #111; }
  .solution { background: #f3fbf6; }
  .chip { color: #444; }
}
