/* Design-Tokens und Grundlayout. Views ergänzen eigene Klassen mit Präfix. */
:root {
  --bg: #f6f4ef;
  --bg-elev: #fffdf8;
  --fg: #1f1d1a;
  --muted: #6d675e;
  --border: #e3ddd2;
  --card: #fffdf8;
  --accent: #2f5d8a;
  --accent-soft: #e3ecf5;
  --ok: #2e7d4f;
  --warn: #b7791f;
  --bad: #b23b3b;
  --new: #2f5d8a;
  --learning: #b7791f;
  --review: #2e7d4f;
  --hl-yellow: #fbe8a6;
  --hl-blue: #cfe3f7;
  --hl-green: #d3efd6;
  --hl-pink: #f6d3e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", system-ui, sans-serif;
  --font-read: "Iowan Old Style", "Charter", Georgia, "Songti SC", serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17171a; --bg-elev: #1f1f23; --fg: #e9e6df; --muted: #a39d93; --border: #33333a;
    --card: #1f1f23; --accent: #7fb0e0; --accent-soft: #233446;
    --ok: #6cc08b; --warn: #e0b157; --bad: #e57d7d;
    --new: #7fb0e0; --learning: #e0b157; --review: #6cc08b;
    --hl-yellow: #5a4d1c; --hl-blue: #1f3d5a; --hl-green: #1f4a2b; --hl-pink: #5a2840;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17171a; --bg-elev: #1f1f23; --fg: #e9e6df; --muted: #a39d93; --border: #33333a;
  --card: #1f1f23; --accent: #7fb0e0; --accent-soft: #233446;
  --ok: #6cc08b; --warn: #e0b157; --bad: #e57d7d;
  --new: #7fb0e0; --learning: #e0b157; --review: #6cc08b;
  --hl-yellow: #5a4d1c; --hl-blue: #1f3d5a; --hl-green: #1f4a2b; --hl-pink: #5a2840;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
pre, code { font-family: var(--mono); font-size: .9em; }

.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px;
  padding: 16px 10px; border-right: 1px solid var(--border); background: var(--bg-elev); }
.sidebar .brand { font-weight: 700; font-size: 1.1rem; padding: 4px 10px 14px; }
.sidebar a { padding: 7px 10px; border-radius: 8px; color: var(--fg); text-decoration: none; }
.sidebar a:hover { background: var(--accent-soft); }
.sidebar a.active { background: var(--accent); color: var(--bg-elev); }
.nav-foot { margin-top: auto; padding: 10px; }
.view { padding: 24px 32px; min-width: 0; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .brand, .nav-foot { display: none; }
  .view { padding: 16px; }
}

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel.error { border-color: var(--bad); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack > * + * { margin-top: 10px; }

.btn { font: inherit; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--fg); cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg-elev); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; color: var(--fg); background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; border: 1px solid var(--border); color: var(--muted); }
.badge.new { color: var(--new); border-color: var(--new); }
.badge.learning, .badge.relearning { color: var(--learning); border-color: var(--learning); }
.badge.review { color: var(--review); border-color: var(--review); }
.counts { display: flex; gap: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.counts .n { color: var(--new); } .counts .l { color: var(--learning); } .counts .r { color: var(--review); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px; width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 6px; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 8px 18px 14px; overflow: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 18px 16px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 8px; max-width: 380px; box-shadow: var(--shadow); }
.toast-error { background: var(--bad); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }

.spinner { display: flex; gap: 8px; align-items: center; color: var(--muted); padding: 10px 0; }
.spinner .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%,100% { opacity: .25 } 50% { opacity: 1 } }

.md { line-height: 1.6; }
.md p { margin: 0 0 .8em; }
.md pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow: auto; }
.md blockquote { margin: 0 0 .8em; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--border); padding: 4px 8px; }
.katex-display { overflow-x: auto; overflow-y: hidden; }
