/* Python Lernhandbuch – Gestaltung */

:root {
  --bg: #f7f7f5;
  --flaeche: #ffffff;
  --flaeche-2: #f0f0ec;
  --text: #1d1f23;
  --gedimmt: #5d636d;
  --linie: #dcdcd6;
  --akzent: #2f64c4;
  --akzent-text: #ffffff;
  --akzent-sanft: #e7eefb;
  --ok: #1f8a4c;
  --ok-sanft: #e4f4ea;
  --warn: #b5560b;
  --warn-sanft: #fcefe3;
  --fehler: #c0392b;
  --code-bg: #f4f4f1;
  --radius: 10px;
  --schatten: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

[data-theme="dunkel"] {
  --bg: #15171b;
  --flaeche: #1d2025;
  --flaeche-2: #252930;
  --text: #e6e7ea;
  --gedimmt: #9ba1ab;
  --linie: #343943;
  --akzent: #6d9cf0;
  --akzent-text: #0e1420;
  --akzent-sanft: #1f2a40;
  --ok: #4cc27f;
  --ok-sanft: #183326;
  --warn: #f0a052;
  --warn-sanft: #3a2a19;
  --fehler: #f07a6c;
  --code-bg: #0f1115;
  --schatten: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--akzent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 1.6em 0 .6em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin-top: .2em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--flaeche-2); padding: .1em .35em; border-radius: 4px; }
pre code { background: none; padding: 0; }
input, textarea, button { font: inherit; color: inherit; }
input, textarea {
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 8px; padding: .5em .7em; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--akzent); outline-offset: 1px; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; background: var(--flaeche); border-bottom: 1px solid var(--linie);
}
.marke { display: flex; align-items: center; gap: .55rem; font-weight: 650; color: var(--text); text-decoration: none; }
.marke-logo {
  display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 7px;
  background: var(--akzent); color: var(--akzent-text); font: 700 .85rem var(--mono);
}
.topbar-nav { display: flex; align-items: center; gap: .8rem; }
.topnav-link { color: var(--gedimmt); text-decoration: none; }
.topnav-link:hover { color: var(--text); }

/* ---------- Knöpfe ---------- */
.btn, .btn-klein {
  display: inline-flex; align-items: center; gap: .4em; cursor: pointer; text-decoration: none;
  background: var(--akzent); color: var(--akzent-text); border: 1px solid var(--akzent);
  border-radius: 8px; padding: .6em 1.1em; font-weight: 600; line-height: 1.2;
}
.btn-klein { padding: .35em .75em; font-size: .88rem; }
.btn.sekundaer, .btn-klein.sekundaer { background: transparent; color: var(--text); border-color: var(--linie); }
.btn:hover, .btn-klein:hover { filter: brightness(1.07); }
.btn:disabled, .btn-klein:disabled { opacity: .6; cursor: wait; }
.btn-klein.gefahr { background: transparent; color: var(--fehler); border-color: var(--fehler); }
.btn-link { background: none; border: none; color: var(--gedimmt); text-decoration: underline; cursor: pointer; padding: .3em; }
.btn-icon { background: none; border: 1px solid var(--linie); border-radius: 8px; width: 2.1rem; height: 2.1rem; cursor: pointer; font-size: 1.15rem; line-height: 1; }

/* ---------- Grundlayout ---------- */
.seite { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.seitenleiste {
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px); overflow-y: auto;
  padding: 1.2rem 1rem 2rem; border-right: 1px solid var(--linie); background: var(--flaeche);
}
.inhalt { padding: 1.5rem clamp(1rem, 4vw, 3rem) 4rem; max-width: 860px; width: 100%; }
.inhalt.breit { max-width: 1400px; }
.zurueck { font-size: .9rem; color: var(--gedimmt); text-decoration: none; }
.sl-titel { font-size: 1.02rem; margin: .8rem 0 .6rem; }
.sl-titel a { color: var(--text); text-decoration: none; }
.sl-umschalter { display: none; margin-bottom: 1rem; }
.sl-nachbarn { display: flex; justify-content: space-between; margin-top: 1.2rem; font-size: .9rem; }
.sl-nachbarn a { text-decoration: none; }

.schritte { list-style: none; padding: 0; margin: .8rem 0; counter-reset: s; }
.schritte li { position: relative; padding-left: 1.7rem; margin: .1rem 0; font-size: .92rem; }
.schritte li::before {
  content: ""; position: absolute; left: .35rem; top: .55em; width: .65rem; height: .65rem;
  border-radius: 50%; border: 2px solid var(--linie); background: var(--flaeche);
}
.schritte li.erledigt::before { background: var(--ok); border-color: var(--ok); }
.schritte li.gesehen::before { border-color: var(--ok); }
.schritte li.sonder { margin-top: .4rem; font-weight: 600; }
.schritte li a { display: block; padding: .25rem .45rem; border-radius: 6px; color: var(--text); text-decoration: none; }
.schritte li a:hover { background: var(--flaeche-2); }
.schritte li.aktiv a { background: var(--akzent-sanft); color: var(--akzent); }

/* ---------- Fortschritt ---------- */
.fortschritt { display: block; height: 8px; border-radius: 99px; background: var(--flaeche-2); overflow: hidden; }
.fortschritt.klein { height: 5px; }
.fortschritt-balken { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.ring {
  --wert: 0; width: 120px; height: 120px; border-radius: 50%; margin: 0 auto .4rem;
  background: conic-gradient(var(--ok) calc(var(--wert) * 1%), var(--flaeche-2) 0);
  display: grid; place-items: center;
}
.ring span {
  display: grid; place-items: center; width: 92px; height: 92px; border-radius: 50%;
  background: var(--flaeche); font-weight: 700; font-size: 1.4rem;
}

/* ---------- Startseite ---------- */
.held { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 2rem; align-items: center; margin: 1rem 0 2rem; }
.held h1 { font-size: clamp(1.7rem, 3.5vw, 2.4rem); }
.held-karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 1.3rem; text-align: center; box-shadow: var(--schatten); }
.kicker { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 650; color: var(--akzent); margin: 0 0 .3rem; }
.lead { font-size: 1.08rem; color: var(--gedimmt); max-width: 62ch; }
.gedimmt { color: var(--gedimmt); }
.klein { font-size: .85rem; }
.zeile { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.zeile input { flex: 1; min-width: 0; }
.rechts { text-align: right; }

.kapitel-raster { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
.kapitel-karte {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr auto; gap: .35rem .8rem;
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 1rem;
  color: var(--text); text-decoration: none; box-shadow: var(--schatten); transition: border-color .15s, transform .15s;
}
.kapitel-karte:hover { border-color: var(--akzent); transform: translateY(-1px); }
.kapitel-karte.fertig { border-color: var(--ok); }
.kk-nummer {
  grid-row: span 2; display: grid; place-items: center; width: 2.3rem; height: 2.3rem; border-radius: 8px;
  background: var(--akzent-sanft); color: var(--akzent); font-weight: 700;
}
.kapitel-karte.fertig .kk-nummer { background: var(--ok-sanft); color: var(--ok); }
.kk-titel { font-weight: 600; line-height: 1.35; }
.kk-meta { display: flex; flex-wrap: wrap; gap: .25rem .7rem; font-size: .8rem; color: var(--gedimmt); }
.kk-meta .ok { color: var(--ok); font-weight: 600; }
.kapitel-karte .fortschritt { grid-column: 1 / -1; margin-top: .4rem; }

.zwei-spalten { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2.5rem; }
.lerncode { word-break: break-all; user-select: all; }

/* ---------- Karten und Hinweise ---------- */
.karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1.2rem 0; box-shadow: var(--schatten); }
.karte > h2:first-child { margin-top: .2rem; }
details.karte > summary { cursor: pointer; font-weight: 600; }
details.karte[open] > summary { margin-bottom: .6rem; }
.hinweis { border-radius: var(--radius); padding: .8rem 1rem; margin: 1rem 0; background: var(--akzent-sanft); border: 1px solid transparent; }
.hinweis.erfolg { background: var(--ok-sanft); border-color: var(--ok); }
.hinweis.warnung { background: var(--warn-sanft); border-color: var(--warn); }
.hinweis > :first-child { margin-top: 0; }
.hinweis > :last-child { margin-bottom: 0; }
.tipp { font-size: .9rem; color: var(--gedimmt); border-top: 1px dashed var(--linie); padding-top: .8rem; margin-top: 2rem; }
.abzeichen { font-size: .8rem; vertical-align: middle; background: var(--ok-sanft); color: var(--ok); border-radius: 99px; padding: .2em .7em; font-weight: 600; }
.abzeichen.sekundaer { background: var(--akzent-sanft); color: var(--akzent); }
.status-liste { list-style: none; padding: 0; }
.status-liste li { padding: .2rem 0; }
.status-liste li.ok { color: var(--ok); }
.inhaltsliste li.erledigt { color: var(--ok); }
.inhaltsliste li.erledigt a::after { content: " ✓"; }

/* ---------- Prosa aus dem Handbuch ---------- */
.prosa { overflow-wrap: break-word; }
.prosa > :first-child { margin-top: 0; }
.prosa table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .92rem; display: block; overflow-x: auto; }
.prosa th, .prosa td { border-bottom: 1px solid var(--linie); padding: .45rem .6rem; text-align: left; vertical-align: top; }
.prosa th { background: var(--flaeche-2); font-weight: 600; }
.prosa ul, .prosa ol { padding-left: 1.4rem; }
.prosa li { margin: .25rem 0; }
.prosa blockquote { margin: 1rem 0; padding: .3rem 1rem; border-left: 3px solid var(--akzent); color: var(--gedimmt); }

.codeblock { margin: 1rem 0; border: 1px solid var(--linie); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); }
.codeblock-kopf {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .3rem .4rem .3rem .8rem; font: .75rem var(--mono); color: var(--gedimmt); border-bottom: 1px solid var(--linie);
}
.codeblock pre, pre.datei, .ausgabe-box pre, .spiel-ausgabe {
  margin: 0; padding: .8rem 1rem; overflow-x: auto; font: .88rem/1.55 var(--mono); tab-size: 4;
}
.highlight, [data-theme="dunkel"] .highlight { background: transparent !important; }
pre.datei { background: var(--code-bg); border: 1px solid var(--linie); border-radius: 8px; max-height: 260px; }
.spiel-code {
  display: block; width: 100%; border: none; border-radius: 0; background: var(--code-bg);
  font: .88rem/1.55 var(--mono); padding: .8rem 1rem; resize: vertical; tab-size: 4; white-space: pre; overflow-x: auto;
}
.spiel-eingabe { border-radius: 0; border-left: none; border-right: none; font: .82rem var(--mono); }
.spiel-leiste { display: flex; align-items: center; gap: .7rem; padding: .4rem .6rem; border-top: 1px solid var(--linie); background: var(--flaeche); }
.spiel-ausgabe, .ausgabe-box pre { background: #0f1115; color: #e6e7ea; white-space: pre-wrap; max-height: 360px; overflow-y: auto; }
.mit-fehler { color: #ffb3a7 !important; }

/* ---------- Quiz ---------- */
.quiz .frage { border: 1px solid var(--linie); border-radius: var(--radius); background: var(--flaeche); padding: 1rem 1.2rem; margin: 1.2rem 0; }
.quiz .frage.richtig { border-color: var(--ok); }
.quiz .frage.falsch { border-color: var(--warn); }
.frage-text { font-weight: 600; margin-bottom: .6rem; }
.frage-text .codeblock { font-weight: 400; }
.frage-nr { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--akzent-sanft); color: var(--akzent); font-size: .85rem; margin-right: .3rem; }
.option { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem .7rem; margin: .35rem 0; border: 1px solid var(--linie); border-radius: 8px; cursor: pointer; }
.option:hover { border-color: var(--akzent); }
.option input { width: auto; margin-top: .35em; }
.option.ist-richtig { border-color: var(--ok); background: var(--ok-sanft); }
.option.ist-falsch { border-color: var(--fehler); background: var(--warn-sanft); }
.erklaerung { margin-top: .7rem; padding: .7rem .9rem; border-radius: 8px; background: var(--flaeche-2); }
.erklaerung p { display: inline; }

/* ---------- Übung ---------- */
.uebung-raster { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 1.6rem; align-items: start; }
.editor-bereich { position: sticky; top: 72px; }
.editor-kopf { display: flex; justify-content: space-between; align-items: center; margin-bottom: .3rem; }
.CodeMirror, .editor-fallback {
  height: auto; min-height: 320px; max-height: 62vh; border: 1px solid var(--linie); border-radius: var(--radius);
  font: .9rem/1.55 var(--mono); background: var(--code-bg); color: var(--text);
}
.CodeMirror-scroll { min-height: 320px; max-height: 62vh; }
.editor-fallback { width: 100%; min-height: 360px; padding: .8rem 1rem; resize: vertical; tab-size: 4; white-space: pre; }
textarea#code:not(.editor-fallback) { min-height: 320px; font-family: var(--mono); }
.CodeMirror-gutters { background: var(--flaeche-2); border-right: 1px solid var(--linie); }
.CodeMirror-linenumber { color: var(--gedimmt); }
.CodeMirror-cursor { border-left-color: var(--text); }
[data-theme="dunkel"] .CodeMirror-selected { background: #2c3a55 !important; }
[data-theme="dunkel"] .cm-keyword { color: #ff7b72; }
[data-theme="dunkel"] .cm-def, [data-theme="dunkel"] .cm-variable-2 { color: #d2a8ff; }
[data-theme="dunkel"] .cm-string { color: #a5d6ff; }
[data-theme="dunkel"] .cm-number, [data-theme="dunkel"] .cm-builtin { color: #79c0ff; }
[data-theme="dunkel"] .cm-comment { color: #8b949e; }
[data-theme="dunkel"] .cm-variable, [data-theme="dunkel"] .cm-property { color: var(--text); }
[data-theme="dunkel"] .CodeMirror-matchingbracket { color: #7ee787 !important; }
[data-theme="dunkel"] .cm-operator { color: #ff7b72; }
.editor-knoepfe { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .7rem 0; }
.eingaben { margin: .5rem 0; font-size: .92rem; }
.eingaben summary { cursor: pointer; color: var(--gedimmt); }
.eingaben label { display: block; margin: .5rem 0; }
.eingaben textarea, .eingaben input { font-family: var(--mono); font-size: .85rem; margin-top: .2rem; }
.ausgabe-box { margin: .8rem 0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--linie); }
.ausgabe-kopf { font-size: .8rem; padding: .3rem .8rem; background: var(--flaeche-2); font-weight: 600; }
.pruef-liste { list-style: none; padding: 0; margin: 0; }
.pruef-liste li { padding: .4rem 0; border-bottom: 1px solid var(--linie); font-size: .93rem; }
.pruef-liste li:last-child { border-bottom: none; }
.pl-symbol { display: inline-block; width: 1.3rem; font-weight: 700; }
.pruef-liste li.ok { color: var(--ok); }
.pruef-liste li.fehlt .pl-symbol { color: var(--fehler); }
.pl-meldung { font-size: .85rem; color: var(--warn); margin-left: 1.3rem; white-space: pre-wrap; }
.checkliste { list-style: none; padding: 0; }
.checkliste label { display: flex; gap: .6rem; align-items: flex-start; padding: .3rem 0; cursor: pointer; }
.checkliste input { width: auto; margin-top: .4em; }

.schritt-nav { display: flex; justify-content: space-between; gap: .8rem; flex-wrap: wrap; margin-top: 2rem; }
.schritt-nav form { margin: 0; }

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 980px) {
  .uebung-raster { grid-template-columns: minmax(0, 1fr); }
  .editor-bereich { position: static; }
}
@media (max-width: 820px) {
  .layout { display: block; }
  .seitenleiste { display: none; position: static; height: auto; border-right: none; border-bottom: 1px solid var(--linie); }
  .seitenleiste.offen { display: block; }
  .sl-umschalter { display: inline-flex; }
  .held, .zwei-spalten { grid-template-columns: minmax(0, 1fr); }
  .inhalt { padding: 1rem 1rem 3rem; }
}
