:root {
  --wein: #7A1F35;
  --wein-dunkel: #4E1222;
  --wein-hell: #A8475C;
  --rose: #F5E4E1;
  --beige: #F7F0E6;
  --beige-2: #EEE2D0;
  --beige-3: #DCC8AB;
  --karte: #FCF8F2;
  --gold: #B08A55;
  --gold-hell: #E3CFA8;
  --tinte: #3B1F25;
  --tinte-2: #6B5056;
  --salbei: #5F7150;
  --schrift: "Palatino", "Palatino Linotype", "Book Antiqua", "TeX Gyre Pagella", "URW Palladio L", Georgia, serif;
  --oben: env(safe-area-inset-top, 0px);
  --unten: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  background: var(--beige);
  color: var(--tinte);
  font-family: var(--schrift);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; }
strong { color: var(--wein); }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em; letter-spacing: 0.02em; }
.katex { font-size: 1.04em; }

/* ---------- Kopfzeile ---------- */
.kopf {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  padding: calc(var(--oben) + 6px) 12px 8px;
  min-height: calc(var(--oben) + 52px);
  background: linear-gradient(180deg, #84243D, var(--wein));
  color: var(--beige);
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  box-shadow: 0 1px 0 var(--gold), 0 3px 0 -1px rgba(176,138,85,.45);
}
.kopf-titel {
  margin: 0; text-align: center; font-weight: normal;
  font-variant: small-caps; letter-spacing: 0.06em; font-size: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kopf-knopf {
  width: 44px; height: 44px; border: 0; background: none; color: var(--beige);
  display: grid; place-items: center; border-radius: 22px; cursor: pointer;
}
.kopf-knopf:active { background: rgba(255,255,255,.12); }
.kopf-rechts { display: flex; justify-content: flex-end; }

.ansicht {
  padding: calc(var(--oben) + 70px) 16px calc(var(--unten) + 28px);
  max-width: 720px; margin: 0 auto; min-height: 100%;
}

/* ---------- Ornament ---------- */
.ornament { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 18px; color: var(--gold); }
.ornament::before, .ornament::after { content: ""; height: 1px; width: 72px; background: var(--gold); opacity: .7; }
.raute { width: 9px; height: 9px; background: var(--wein); transform: rotate(45deg); outline: 1px solid var(--gold); outline-offset: 2px; }

/* ---------- Startseite ---------- */
.gruss { text-align: center; margin: 10px 0 0; }
.gruss h2 { margin: 0; font-weight: normal; font-variant: small-caps; color: var(--wein); font-size: 30px; letter-spacing: .04em; }
.gruss p { margin: 4px 0 0; font-style: italic; color: var(--tinte-2); }

.kachel {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--karte); border: 1px solid var(--beige-3); border-radius: 18px;
  padding: 16px 18px; margin: 0 0 14px; position: relative; overflow: hidden;
  box-shadow: 0 1px 2px rgba(78,18,34,.06), 0 6px 18px -10px rgba(78,18,34,.25);
}
.kachel:active { transform: scale(.985); }
.kachel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--wein); }
.kachel-oben { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.kachel h3 { margin: 0; font-weight: normal; font-variant: small-caps; color: var(--wein); font-size: 21px; letter-spacing: .03em; }
.kachel .zahl { color: var(--gold); font-style: italic; white-space: nowrap; }
.kachel p { margin: 4px 0 10px; color: var(--tinte-2); font-size: 15px; }
.balken { height: 7px; border-radius: 4px; background: var(--beige-2); overflow: hidden; }
.balken > i { display: block; height: 100%; background: linear-gradient(90deg, var(--wein-hell), var(--wein)); border-radius: 4px; transition: width .4s; }
.balken-text { font-size: 13px; color: var(--tinte-2); margin-top: 5px; }
.kachel.merk::before { background: var(--gold); }

.fuss { text-align: center; color: var(--gold); font-style: italic; margin-top: 26px; font-size: 15px; }
.hinweis {
  background: var(--rose); border-left: 3px solid var(--wein-hell); border-radius: 10px;
  padding: 10px 12px; font-size: 14.5px; margin: 0 0 16px; position: relative;
}
.hinweis button { position: absolute; right: 6px; top: 4px; border: 0; background: none; font-size: 20px; color: var(--wein-hell); }

/* ---------- Deck ---------- */
.abschnitt-titel { font-variant: small-caps; color: var(--wein); font-size: 18px; letter-spacing: .04em; margin: 22px 0 8px; border-bottom: 1px solid var(--gold-hell); padding-bottom: 4px; }
.knopf {
  display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px; cursor: pointer;
  background: var(--wein); color: var(--beige); font-size: 18px; font-variant: small-caps; letter-spacing: .05em;
  box-shadow: 0 6px 16px -8px rgba(78,18,34,.6);
}
.knopf:active { background: var(--wein-dunkel); }
.knopf.zart { background: var(--karte); color: var(--wein); border: 1px solid var(--beige-3); box-shadow: none; }
.knopf + .knopf { margin-top: 10px; }
.schalter { display: flex; align-items: center; justify-content: space-between; padding: 11px 2px; border-bottom: 1px solid var(--beige-2); }
.schalter input { appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--beige-3); position: relative; transition: background .2s; flex: none; }
.schalter input::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .2s; }
.schalter input:checked { background: var(--wein); }
.schalter input:checked::after { left: 23px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--beige-3); background: var(--karte); border-radius: 20px; padding: 6px 12px;
  font-size: 14.5px; cursor: pointer; color: var(--tinte);
}
.chip small { color: var(--gold); margin-left: 4px; }
.chip.an { background: var(--wein); border-color: var(--wein); color: var(--beige); }
.chip.an small { color: var(--gold-hell); }
.zeile-knoepfe { display: flex; gap: 10px; margin: 10px 0 4px; }
.zeile-knoepfe button { flex: 1; border: 0; background: none; color: var(--wein); text-decoration: underline; text-underline-offset: 3px; font-size: 14.5px; cursor: pointer; }

/* ---------- Lernen ---------- */
.lernen { display: flex; flex-direction: column; min-height: calc(100vh - var(--oben) - 100px); min-height: calc(100dvh - var(--oben) - 100px); }
.fortschritt { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--tinte-2); margin-bottom: 12px; }
.fortschritt .balken { flex: 1; }
.buehne { perspective: 1400px; flex: 1; display: flex; min-height: 320px; }
.karte {
  position: relative; flex: 1; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3,.7,.3,1);
  cursor: pointer; touch-action: pan-y;
}
.karte.umgedreht { transform: rotateY(180deg); }
.seite {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 22px; padding: 0; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 2px 4px rgba(78,18,34,.08), 0 18px 36px -18px rgba(78,18,34,.45);
}
.seite-kopf { display: flex; justify-content: space-between; padding: 11px 18px; font-variant: small-caps; letter-spacing: .05em; font-size: 15px; }
.seite-inhalt { flex: 1; overflow-y: auto; padding: 18px 22px 24px; display: flex; flex-direction: column; justify-content: center; }
.vorne { background: var(--karte); border: 1.5px solid var(--wein); }
.vorne .seite-kopf { background: var(--wein); color: var(--beige); }
.vorne .seite-inhalt { text-align: center; font-size: 22px; line-height: 1.45; }
.hinten { background: #FFFDF9; border: 1.5px solid var(--gold); transform: rotateY(180deg); }
.hinten .seite-kopf { background: var(--gold-hell); color: var(--wein); }
.hinten .seite-inhalt { font-size: 18.5px; line-height: 1.55; justify-content: flex-start; }
.hinten .seite-inhalt > div { margin: auto 0; }
.tippen { text-align: center; color: var(--gold); font-style: italic; font-size: 14px; padding: 0 0 12px; }
.seite-inhalt ul, .seite-inhalt ol, .merk-text ul, .merk-text ol { margin: 6px 0; padding-left: 1.3em; text-align: left; }

.antworten { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.antworten button {
  border: 0; border-radius: 14px; padding: 15px 8px; font-size: 18px; font-variant: small-caps; letter-spacing: .05em; cursor: pointer;
}
.nochmal { background: var(--karte); color: var(--wein); border: 1.5px solid var(--wein-hell) !important; }
.gewusst { background: var(--wein); color: var(--beige); box-shadow: 0 6px 16px -8px rgba(78,18,34,.6); }
.antworten button:disabled { opacity: .35; }
.karte.weg-rechts { transition: transform .32s ease-in, opacity .32s; transform: rotateY(180deg) translateX(-120%) rotate(-12deg); opacity: 0; }
.karte.weg-links { transition: transform .32s ease-in, opacity .32s; transform: rotateY(180deg) translateX(120%) rotate(12deg); opacity: 0; }

.fertig { text-align: center; padding-top: 30px; }
.fertig h2 { font-weight: normal; font-variant: small-caps; color: var(--wein); font-size: 30px; margin: 0; }
.fertig .gross { font-size: 54px; color: var(--wein); margin: 10px 0 0; }
.fertig p { color: var(--tinte-2); }

/* ---------- Liste ---------- */
.liste-eintrag { background: var(--karte); border: 1px solid var(--beige-2); border-radius: 14px; margin-bottom: 10px; overflow: hidden; }
.liste-eintrag summary { list-style: none; padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; }
.liste-eintrag summary::-webkit-details-marker { display: none; }
.liste-eintrag summary .nr { color: var(--gold); font-size: 13px; min-width: 2.2em; padding-top: 3px; }
.liste-eintrag .liste-antwort { padding: 0 14px 14px 48px; border-top: 1px dashed var(--beige-3); padding-top: 10px; font-size: 16px; }
.punkt { width: 9px; height: 9px; border-radius: 5px; flex: none; margin-top: 9px; background: var(--beige-3); }
.punkt.g { background: var(--salbei); }
.punkt.n { background: var(--wein-hell); }

/* ---------- Merksätze ---------- */
.reiter { display: grid; grid-template-columns: 1fr 1fr; background: var(--beige-2); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.reiter button { border: 0; background: none; padding: 8px; border-radius: 10px; font-variant: small-caps; letter-spacing: .04em; cursor: pointer; color: var(--tinte-2); }
.reiter button.an { background: var(--karte); color: var(--wein); box-shadow: 0 1px 3px rgba(78,18,34,.15); }
.suche { width: 100%; border: 1px solid var(--beige-3); background: var(--karte); border-radius: 12px; padding: 10px 14px; font: inherit; font-size: 16px; color: var(--tinte); margin: 4px 0 6px; }
.suche:focus { outline: 2px solid var(--gold-hell); }
.merk-box {
  background: var(--wein); color: var(--beige); border-radius: 16px; padding: 14px 16px 15px; margin: 12px 0;
  box-shadow: 0 8px 20px -12px rgba(78,18,34,.7); position: relative;
}
.merk-box .merk-titel { display: inline-block; background: var(--gold); color: #fff; font-variant: small-caps; letter-spacing: .05em; font-size: 14px; padding: 1px 10px; border-radius: 6px; margin-bottom: 6px; }
.merk-box .merk-text { font-style: italic; font-size: 17px; line-height: 1.5; }
.merk-box strong { color: #fff; }
.merk-kurz { display: flex; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--beige-2); }
.merk-kurz .nr { color: var(--gold); min-width: 1.8em; text-align: right; font-style: italic; }
.leer { text-align: center; color: var(--tinte-2); font-style: italic; padding: 30px 0; }

@media (min-width: 700px) {
  .vorne .seite-inhalt { font-size: 25px; }
  .hinten .seite-inhalt { font-size: 20px; }
}
.kopf-knopf[hidden] { visibility: hidden; display: grid; }
