:root {
  --bg-color: #0d1a2d;
  --surface: #183153;
  --surface-shade: #0a1424;
  --text-color: #f0f4fa;
  --text-muted: #a9b6cb;
  --accent-color: #74c0fc;
  --accent-soft: rgba(116, 192, 252, 0.14);
  --border-color: #2a4166;
  --yellow: #ffd43b;
  --yellow-shade: #e0a800;
  --navy: #183153;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg-color: #f0f1f3;
  --surface: #ffffff;
  --surface-shade: #c3c6d1;
  --text-color: #183153;
  --text-muted: #515e72;
  --accent-color: #146ebe;
  --accent-soft: #e7f5ff;
  --border-color: #dfe1e6;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg-color);
  color: var(--text-color);
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}
h1, h2, h3 { font-weight: 900; line-height: 1.2; margin: 0 0 0.6em; }
h1 { font-size: 2.4rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.15rem; }
a { color: var(--accent-color); }
.muted { color: var(--text-muted); }
.lead { font-size: 1.1rem; max-width: 70ch; }
code { background: var(--accent-soft); padding: 0.1em 0.4em; border-radius: 6px; font-size: 0.92em; }
img { max-width: 100%; height: auto; }

.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); min-height: 100vh; }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border-color);
  padding: 1.5rem 1.2rem; display: flex; flex-direction: column; gap: 1.2rem;
}
.brand { display: flex; align-items: center; gap: 0.9rem; padding-right: 3rem; }
.brand-tile {
  background: var(--yellow); color: var(--navy); font-weight: 900; font-size: 1.1rem;
  padding: 0.7rem 0.8rem; border-radius: 14px; transform: rotate(-5deg);
  box-shadow: 0 4px 0 var(--yellow-shade); flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; font-size: 0.95rem; }
.theme-toggle {
  position: absolute; top: 1.3rem; right: 1.2rem; width: 42px; height: 42px;
  border-radius: 999px; border: 2px solid var(--border-color); background: transparent;
  color: var(--text-color); cursor: pointer; display: grid; place-items: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover { background: var(--accent-soft); border-color: var(--accent-color); }
.sidebar { position: sticky; }
.nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.8rem;
  border-radius: 12px; text-decoration: none; color: var(--text-color);
  font-weight: 800; font-size: 0.95rem; transition: background 0.15s ease, color 0.15s ease;
}
.nav-link .ico { flex: none; }
.nav-link:hover { background: var(--accent-soft); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-color); }
.nav-link.done b::after { content: " \2713"; color: #a9e34b; }

/* Main */
.main { padding: 2.5rem clamp(1.2rem, 4vw, 3.5rem) 3rem; min-width: 0; }
.crumb { margin: 0 0 0.5rem; color: var(--text-muted); font-weight: 700; font-size: 0.9rem; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-bottom: 0.8rem; }
.stars { font-weight: 900; color: var(--yellow); letter-spacing: 0.1em; }
.block { border-top: 2px dashed var(--border-color); padding-top: 1.6rem; margin-top: 2rem; }
.block ul, .block ol { padding-left: 1.3rem; }
.block li { margin-bottom: 0.4rem; }
ul.check { list-style: none; padding-left: 0; }
ul.check label { display: flex; gap: 0.7rem; align-items: flex-start; cursor: pointer; }
ul.check input { margin-top: 0.35rem; accent-color: var(--accent-color); width: 1.1rem; height: 1.1rem; flex: none; }
ul.check li:not(:has(input))::before { content: "\2713"; color: var(--accent-color); font-weight: 900; margin-right: 0.6rem; }

/* Badges */
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 900; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 0.25rem 0.7rem; border-radius: 8px; color: var(--navy);
}
.badge-yellow { background: #ffd43b; }
.badge-green { background: #a9e34b; }
.badge-pink { background: #ffc9c9; }
.badge-blue { background: #74c0fc; }
.badge-off { background: var(--border-color); color: var(--text-muted); }

/* Cards */
.card {
  position: relative; display: block; background: var(--surface); color: var(--text-color);
  border-radius: 16px; padding: 1.7rem 1.1rem 1.1rem; text-decoration: none;
  box-shadow: 0 5px 0 var(--surface-shade);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
a.card:hover { transform: translateY(-4px); box-shadow: 0 9px 0 var(--surface-shade); }
.card .badge { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); }
.card h3 { margin-bottom: 0.3rem; }
.card p { margin: 0 0 0.5rem; color: var(--text-muted); font-size: 0.9rem; }
.card-off { opacity: 0.6; box-shadow: 0 5px 0 var(--surface-shade); }
.done-mark { display: none; font-weight: 900; color: #a9e34b; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; }
.card.done .done-mark { display: block; }
.card.done { outline: 2px solid #a9e34b; }

/* Raster */
.raster-head, .raster-row { display: grid; grid-template-columns: 150px repeat(4, minmax(0, 1fr)); gap: 1.4rem 1.2rem; align-items: stretch; }
.raster-head { margin-bottom: 1.4rem; text-align: center; color: var(--text-muted); }
.raster-row { margin-bottom: 1.6rem; }
.raster-label { display: flex; flex-direction: column; justify-content: center; }
.raster-label b { font-size: 2rem; font-weight: 900; color: var(--accent-color); line-height: 1; }
.raster-label span { font-size: 0.8rem; color: var(--text-muted); font-weight: 700; }
.progress { height: 14px; background: var(--surface); border-radius: 999px; overflow: hidden; margin: 1.2rem 0 0.4rem; box-shadow: 0 3px 0 var(--surface-shade); }
.progress-bar { height: 100%; width: 0; background: var(--yellow); transition: width 0.3s ease; }
.order { columns: 2 260px; }
.order a { font-weight: 700; }

/* Buttons und Links */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1.5rem; margin-top: 2.4rem; }
.btn {
  background: var(--yellow); color: var(--navy); font: inherit; font-weight: 900; border: 0;
  border-radius: 12px; padding: 0.8rem 1.4rem; cursor: pointer;
  box-shadow: 0 5px 0 var(--yellow-shade); transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(2px); box-shadow: 0 3px 0 var(--yellow-shade); }
.btn.is-done { background: #a9e34b; box-shadow: 0 5px 0 #7fb62e; }
.btn-sec {
  display: inline-block; text-decoration: none; color: inherit; font-weight: 800;
  border: 2px solid currentColor; border-radius: 999px; padding: 0.4rem 1.1rem;
}
.btn-sec:hover { color: var(--accent-color); }
.more { font-weight: 800; text-decoration: underline; text-underline-offset: 5px; }
.more .arrow { display: inline-block; transition: transform 0.15s ease; }
.more:hover .arrow { transform: translateX(4px); }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; }

/* Inhalte */
.diagram {
  background: var(--surface); border-radius: 16px; padding: 1rem; margin: 1rem 0 0.4rem;
  box-shadow: 0 5px 0 var(--surface-shade); overflow-x: auto; text-align: center;
}
.diagram pre.mermaid { margin: 0; background: none; }
.caption { margin: 0.6rem 0 1rem; font-size: 0.95rem; }
.note { background: var(--accent-soft); border-radius: 12px; padding: 0.7rem 1rem; font-weight: 700; }
.tbl-wrap, .block { overflow-wrap: anywhere; }
.tbl { border-collapse: collapse; width: 100%; margin: 1rem 0; display: block; overflow-x: auto; }
.tbl th, .tbl td { border-bottom: 1px solid var(--border-color); padding: 0.55rem 0.8rem; text-align: left; vertical-align: top; }
.tbl th { font-weight: 900; }
.code { background: var(--surface); border-radius: 12px; padding: 1rem; overflow-x: auto; font-size: 0.9rem; }
.code code { background: none; padding: 0; }
.figure { margin: 1rem 0; }
.figure img { border-radius: 12px; background: #fff; }
.footer { margin-top: 3rem; padding-top: 1.2rem; border-top: 2px dashed var(--border-color); color: var(--text-muted); font-size: 0.9rem; }

.tabbar { display: none; }
.ico { flex: none; }

@media (max-width: 1200px) {
  .raster-head, .raster-row { grid-template-columns: 110px repeat(4, minmax(0, 1fr)); gap: 1.4rem 0.8rem; }
  .card { padding: 1.5rem 0.8rem 0.9rem; }
  .card p { display: none; }
}
@media (max-width: 900px) {
  .layout { display: block; }
  .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--border-color); padding: 1rem 1.2rem; }
  .sidebar .nav { display: none; }
  .theme-toggle { top: 0.9rem; }
  body { padding-bottom: 84px; }
  h1 { font-size: 1.9rem; }
  h2 { font-size: 1.6rem; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
    padding: 0.4rem 0.2rem; border-radius: 12px; text-decoration: none; color: var(--text-color);
    font-size: 0.72rem; font-weight: 800;
  }
  .tabbar a:active, .tabbar a:hover { background: var(--accent-soft); color: var(--accent-color); }
  .raster-head { display: none; }
  .raster-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; margin-bottom: 1.2rem; }
  .raster-label { grid-column: 1 / -1; flex-direction: row; align-items: baseline; gap: 0.7rem; }
  /* Handy: Raster kompakt, nur Kuerzel wie M1, M2 ... */
  .raster-row .card { padding: 0.9rem 0.3rem; text-align: center; min-height: 64px; display: grid; place-items: center; border-radius: 14px; }
  .raster-row .card .badge { position: static; transform: none; font-size: 1.15rem; letter-spacing: 0.04em; padding: 0.3rem 0.7rem; }
  .raster-row .card h3, .raster-row .card p, .raster-row .card .stars, .raster-row .card .quiz-score, .raster-row .card .muted, .raster-row .card .done-mark { display: none; }
  .raster-row a.card:hover { transform: none; }
  .raster-row .card.done { outline-offset: 0; }
}
@media (max-width: 680px) {
  .main { padding-top: 1.5rem; }
  .meta { gap: 0.4rem; }
  .actions { flex-direction: column; align-items: stretch; gap: 1rem; }
  .actions .btn { width: 100%; }
  .pager { gap: 0.5rem; }
  .btn-sec { padding: 0.4rem 0.9rem; font-size: 0.95rem; }
  .block { margin-top: 1.6rem; padding-top: 1.3rem; }
  .code { font-size: 0.8rem; }
  .tbl { font-size: 0.88rem; }
  .tbl th, .tbl td { padding: 0.45rem 0.55rem; overflow-wrap: normal; word-break: normal; min-width: 7rem; }
  /* Diagramme lesbar halten: breiter als der Bildschirm, seitlich wischen */
  .diagram { text-align: left; padding: 0.8rem 0.6rem; }
  .diagram::before { content: "90  seitlich wischen  92"; display: block; text-align: center; color: var(--text-muted); font-size: 0.75rem; font-weight: 800; margin-bottom: 0.4rem; }
  .diagram pre.mermaid svg { min-width: 560px; max-width: none !important; }
  .quiz { padding: 1rem; }
  .quiz-q { font-size: 1.15rem; }
  .quiz-opt { padding: 0.75rem 0.85rem; }
  .quiz-feedback .btn { width: 100%; }
}
@media (max-width: 380px) {
  h1 { font-size: 1.6rem; }
  .brand-text { font-size: 0.85rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
  a.card:hover, .btn:hover { transform: none; }
}

/* Quiz */
.quiz { background: var(--surface); border-radius: 16px; padding: 1.4rem; box-shadow: 0 5px 0 var(--surface-shade); max-width: 760px; }
.quiz-bar { height: 14px; background: var(--bg-color); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.quiz-bar-fill { height: 100%; background: #a9e34b; border-radius: 999px; transition: width 0.3s ease; }
.quiz-head { display: flex; justify-content: space-between; font-weight: 800; font-size: 0.9rem; }
.quiz-streak { color: var(--yellow); }
.quiz-q { font-size: 1.35rem; margin: 0.6rem 0 1rem; }
.quiz-best { font-weight: 800; color: var(--yellow); }
.quiz-opts { display: grid; gap: 0.7rem; }
.quiz-opt {
  font: inherit; font-weight: 800; text-align: left; color: var(--text-color); cursor: pointer;
  background: var(--bg-color); border: 2px solid var(--border-color); border-radius: 12px;
  padding: 0.8rem 1rem; box-shadow: 0 4px 0 var(--surface-shade);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent-color); transform: translateY(-2px); box-shadow: 0 6px 0 var(--surface-shade); }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.is-right { background: #a9e34b; border-color: #7fb62e; color: #183153; }
.quiz-opt.is-wrong { background: #ffc9c9; border-color: #e07a7a; color: #183153; }
.quiz-feedback { margin-top: 1.1rem; border-radius: 12px; padding: 1rem; }
.quiz-feedback.ok { background: rgba(169, 227, 75, 0.18); }
.quiz-feedback.bad { background: rgba(255, 201, 201, 0.18); }
.quiz-feedback p { margin: 0.3rem 0 0.9rem; }
.quiz-score { display: block; font-size: 0.8rem; font-weight: 800; color: var(--accent-color); }

/* Trennung Lernteil und Quiz */
.nav-title { margin: 1rem 0 0.2rem 0.8rem; font-size: 0.72rem; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0 0.4rem; }
.chip { text-decoration: none; font-weight: 800; font-size: 0.85rem; color: var(--text-color); border: 2px solid var(--border-color); border-radius: 999px; padding: 0.15rem 0.7rem; transition: background 0.15s ease, border-color 0.15s ease; }
.chip:hover { background: var(--accent-soft); border-color: var(--accent-color); }
.chip.active { background: var(--accent-color); border-color: var(--accent-color); color: var(--navy); }
.tag-learn, .tag-quiz { display: inline-block; font-size: 0.72rem; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; padding: 0.15rem 0.6rem; border-radius: 8px; color: var(--navy); margin-right: 0.4rem; }
.tag-learn { background: #74c0fc; }
.tag-quiz { background: #ffd43b; }
.part { margin-top: 2.5rem; padding: 1.6rem clamp(0.8rem, 2vw, 1.8rem) 1.2rem; border-radius: 20px; border: 2px dashed var(--border-color); }
.part-quiz { border-color: var(--yellow); }
.part-learn { border-color: var(--accent-color); }
.part-head { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.part-head h2 { margin: 0; }
.btn-link { display: inline-block; text-decoration: none; }
.btn-sec.done-btn { font: inherit; font-weight: 800; background: transparent; color: var(--text-color); cursor: pointer; }
.btn-sec.done-btn.is-done { background: #a9e34b; border-color: #a9e34b; color: var(--navy); }
.quiz-cta { text-align: left; }
.card.perfect { outline: 2px solid var(--yellow); }
@media (max-width: 900px) {
  .part { padding: 1.2rem 0.7rem 0.8rem; margin-top: 2rem; }
  .part-head h2 { font-size: 1.4rem; }
}

/* Papier-Markierung im Raster */
.paper-tag { display: inline-flex; align-items: center; gap: 0.3rem; margin-top: 0.4rem; background: #ffc9c9; color: #183153; font-size: 0.72rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; padding: 0.2rem 0.6rem; border-radius: 8px; }
.paper-tag .ico { width: 14px; height: 14px; }
.paper-legend { margin-top: 0; vertical-align: middle; }
@media (max-width: 900px) {
  .raster-row .card .paper-tag { display: flex; position: absolute; top: -8px; right: -6px; margin: 0; padding: 0.2rem; border-radius: 999px; }
  .raster-row .card .paper-tag span { display: none; }
}
