/* Buchdeckel, Fach-Uebersicht und Fach-Seite — fuer alle drei Buecher identisch.
   Die Farben kommen aus lib/theme.css (je Buch anders), deshalb steht hier kein :root.
   Diese Datei wird nie von Hand geaendert; nach jeder Aenderung ueber die drei
   Buecher verteilen und mit tools/check_links.py gegen die Seiten pruefen. */

/* ---------- Grundlagen ---------- */
* { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; background-color: var(--board); color: var(--chalk); font: 18px/1.55 var(--ui);
  /* Kreidekoernung auf dem body, damit sie ueber die ganze Dokumenthoehe liegt.
     Ein fixed::before streicht nur eine Bildschirmhoehe und hinterlaesst auf langen
     Inhaltsseiten eine sichtbare Kante. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' seed='5'/%3E%3CfeColorMatrix values='0 0 0 0 0.96 0 0 0 0 0.93 0 0 0 0 0.88 0 0 0 0.055 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23g)'/%3E%3C/svg%3E"); }
/* Nur die Vignette ist bildschirmbezogen, also fixiert. */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 40%, transparent 52%, rgba(0, 0, 0, .42)); }
a { color: inherit; }
a:focus-visible { outline: 3px solid var(--task); outline-offset: 3px; }
.kicker { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--task); }

/* ---------- Deckel ---------- */
#cover { position: relative; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 16px 64px; text-align: center; overflow: hidden; }
.open #cover, body:not(.open) #contents { display: none; }
#cover > * { animation: rise .8s var(--ease) backwards; }
#cover .mascot { animation: none; margin-bottom: 22px; view-transition-name: guide; }
#cover .kicker { animation-delay: .9s; }
#cover h1 { animation-delay: 1s; }
#cover .lede { animation-delay: 1.12s; }
#cover .acts { animation-delay: 1.24s; }
#cover .meta { animation-delay: 1.36s; }
h1 { margin: 12px 0 16px; max-width: 16em; font: 600 clamp(38px, 6.6vw, 76px)/1.06 var(--book); letter-spacing: -.015em; view-transition-name: book; }
h1 i { color: var(--task); font-style: italic; }
.lede { max-width: 34em; margin: 0 0 32px; color: var(--dim); font-size: clamp(17px, 2.2vw, 20px); text-wrap: balance; }
.lede b { color: var(--chalk); font-weight: 600; }
.acts { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 12px; padding: 14px 30px; border-radius: 999px;
  font-weight: 600; font-size: 19px; text-decoration: none;
  transition: transform .25s var(--ease), background-color .25s, border-color .25s; }
.btn[hidden] { display: none; }
.btn:hover { transform: translateY(-2px); }
.btn.go { background: var(--chalk); color: var(--board); }
.btn.quiet { border: 1.5px solid var(--edge); color: var(--chalk); }
.btn.quiet:hover { border-color: var(--dim); }
.btn svg { width: 15px; height: 15px; fill: currentColor; }
.meta { margin: 28px 0 0; color: var(--faint); font-size: 15px; letter-spacing: .04em; }
.chalk { position: absolute; inset: 0; z-index: -1; pointer-events: none; animation: none !important; }
.chalk span { position: absolute; font: italic 400 clamp(22px, 3vw, 38px) var(--book); color: var(--chalk); opacity: 0; white-space: nowrap;
  animation: chalk 1.6s ease-out forwards, drift 14s ease-in-out infinite alternate; animation-delay: calc(var(--d) * 1s), calc(var(--d) * 1s); }
@keyframes chalk { to { opacity: .07; } }
@keyframes drift { to { transform: translateY(-10px); } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

/* ---------- die Begleitfigur ---------- */
.mascot { display: block; overflow: visible; }
.mascot .mbody { transform-box: view-box; transform-origin: 60px 56px; animation: mbob 3.6s ease-in-out infinite; }
.mascot .pupil { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.mascot .joy, .mascot .flat { display: none; }
.mascot.happy .pupil { display: none; }
.mascot.happy .joy { display: inline; }
.mascot.happy .flat { display: inline; }
.mascot.oops .eyes { transform: translate(-3px, 4px); }
.mascot.oops .smile { display: none; }
.mascot.oops .flat { display: inline; }
.mascot.oops .mbody { animation: wobble .5s ease-in-out, mbob 3.6s ease-in-out .5s infinite; }
#cover:has(.go:hover, .go:focus-visible) .pupil { display: none; }
#cover:has(.go:hover, .go:focus-visible) .joy { display: inline; }
.draw .loop { stroke-dasharray: 1 1; animation: draw 1.3s cubic-bezier(.6, 0, .3, 1) backwards; }
.draw .loop:nth-of-type(2) { animation-delay: .2s; }
.draw .loop:nth-of-type(3) { animation-delay: .4s; }
.draw .face { transform-box: view-box; transform-origin: 60px 56px; animation: pop .45s var(--ease) 1.2s backwards; }
@keyframes draw { from { stroke-dashoffset: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.6); } }
@keyframes mbob { 50% { transform: translateY(-3px) rotate(-2deg); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(6deg); } }

/* ---------- Kopfzeile ---------- */
.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 14px; padding: 12px max(16px, calc(50% - 590px));
  background: rgba(30, 21, 16, .88); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--edge); }
.home { display: flex; align-items: center; gap: 14px; text-decoration: none; border-radius: 10px; }
.home .mascot { flex: none; view-transition-name: guide; }
.home strong { font: 600 21px/1.15 var(--book); max-width: 20em; view-transition-name: book; }
.home strong i { color: var(--task); }
.prog { margin-left: auto; color: var(--dim); font-size: 15px; white-space: nowrap; }
.prog b { color: var(--good); font-weight: 600; }
.back { padding: 7px 15px; border: 1.5px solid var(--edge); border-radius: 999px;
  font-size: 15px; text-decoration: none; color: var(--dim); white-space: nowrap; transition: border-color .25s, color .25s; }
.back:hover { border-color: var(--dim); color: var(--chalk); }
.back + .back { margin-left: 0; }

/* ---------- Kopf eines Faches ---------- */
main { padding-bottom: 80px; }
.fach-head { position: relative; max-width: 1212px; margin: 0 auto; padding: 34px 16px 4px; }
.fach-head h1 { position: relative; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  margin: 0; min-height: 132px; padding-top: 104px; font: 600 clamp(30px, 4.4vw, 46px)/1.12 var(--book); }
.fach-head h1 span { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
.fach-head p { position: relative; max-width: 46em; margin: 6px 0 0; color: var(--dim); font-size: clamp(17px, 2.1vw, 19px); }
.fach-head::before { content: ""; position: absolute; inset: 8px 16px auto; height: 180px; border-radius: 22px; pointer-events: none;
  background: radial-gradient(ellipse 46% 90% at 74% 55%, color-mix(in srgb, var(--c) 11%, transparent), transparent 70%); }

/* ---------- die Kreideskizze des Faches ---------- */
.unit-art { position: absolute; top: 26px; right: 28px; width: min(580px, 56%); height: auto; overflow: visible; pointer-events: none;
  color: var(--c); fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: .78; }
.unit-art text { fill: currentColor; stroke: none; font-family: var(--book); font-style: italic; }
.unit-art .a { color: var(--chalk); opacity: .55; }
.unit-art .d { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.unit-art .t { opacity: 0; }
.seen .unit-art .d { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards; animation-delay: calc(var(--k) * 55ms + 120ms); }
.seen .unit-art .t { animation: art-fade .6s ease-out forwards; animation-delay: calc(var(--k) * 55ms + 300ms); }
@keyframes art-draw { to { stroke-dashoffset: 0; } }
@keyframes art-fade { to { opacity: 1; } }
.seen .unit-art .pulse { animation: art-fade .6s ease-out forwards, pulse 3.6s ease-in-out infinite; animation-delay: 300ms, 2s; }
@keyframes pulse { 0%, 100% { r: 7; } 50% { r: 11; } }

/* ---------- Kapitelraster ---------- */
.grid { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 12px;
  max-width: 1212px; margin: 0 auto; padding: 26px 16px 0; }
.ch { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr auto; column-gap: 16px; row-gap: 8px; min-height: 112px;
  padding: 16px 18px 14px 16px; border-radius: 16px; background: var(--panel); border: 1.5px solid var(--edge); border-left: 6px solid var(--c);
  text-decoration: none; transition: transform .3s var(--ease), border-color .3s, box-shadow .3s; }
.ch:hover { transform: translateY(-3px); border-color: var(--c); box-shadow: 0 14px 34px rgba(0, 0, 0, .3); }
.ch b { grid-row: span 2; min-width: 1.15em; font: 600 42px/1 var(--book); color: var(--c); font-variant-numeric: lining-nums tabular-nums; }
.ch span { font-size: 18px; line-height: 1.3; }
.ch small { color: var(--dim); font-size: 14px; }
.ch.done small::before { content: "✓ Gelesen · "; color: var(--good); font-weight: 600; }
.ch.last small::after { content: " · Zuletzt geöffnet"; color: var(--quiz); }
.ch.here { animation: here 1.8s ease-out .3s; }
@keyframes here { 0% { box-shadow: 0 0 0 0 var(--c); } 25% { box-shadow: 0 0 0 5px var(--c); } 100% { box-shadow: 0 0 0 14px transparent; } }
/* Ein Fach ohne Kapitel: ehrlich benennen statt eine leere Flaeche zu zeigen. */
.pending { position: relative; max-width: 1212px; margin: 26px auto 0; padding: 18px 20px; border-radius: 16px; background: var(--panel);
  border: 1.5px dashed var(--edge); border-left: 6px solid color-mix(in srgb, var(--c) 55%, transparent); color: var(--dim); font-size: 16px; }
.pending b { display: block; color: var(--chalk); font-weight: 600; margin-bottom: 4px; }
.pending span { color: var(--dim); }

/* ---------- Uebersicht: eine Kachel je Fach ---------- */
.fach-grid { position: relative; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px;
  max-width: 1212px; margin: 0 auto; padding: 30px 16px 0; }
.fach-card { position: relative; display: flex; flex-direction: column; min-height: 300px; overflow: hidden;
  padding: 24px 24px 22px; border-radius: 20px; background: var(--panel); border: 1.5px solid var(--edge); border-left: 6px solid var(--c);
  text-decoration: none; transition: transform .3s var(--ease), border-color .3s, box-shadow .3s; }
.fach-card:hover { transform: translateY(-4px); border-color: var(--c); box-shadow: 0 18px 44px rgba(0, 0, 0, .38); }
.fach-card h2 { position: relative; z-index: 1; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 0 0 10px;
  font: 600 clamp(25px, 3vw, 32px)/1.14 var(--book); }
.fach-card h2 span { font: 600 13px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
.fach-card p { position: relative; z-index: 1; margin: 0; color: var(--dim); font-size: 17px; }
.fach-card .count { position: relative; z-index: 1; margin-top: auto; padding-top: 18px; color: var(--faint); font-size: 15px; }
.fach-card .count b { color: var(--chalk); font-weight: 600; }
.fach-card .go { position: absolute; right: 22px; bottom: 20px; z-index: 1; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 999px; border: 1.5px solid var(--edge); color: var(--dim); transition: border-color .25s, color .25s; }
.fach-card:hover .go { border-color: var(--c); color: var(--c); }
.fach-card .go svg { width: 14px; height: 14px; fill: currentColor; }
.fach-card .unit-art { top: -6px; right: -14px; width: min(300px, 72%); opacity: .5; }
.fach-card.seen .unit-art .d { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards; animation-delay: calc(var(--k) * 45ms + 120ms); }
.fach-card.seen .unit-art .t { animation: art-fade .6s ease-out forwards; animation-delay: calc(var(--k) * 45ms + 260ms); }
.fach-card.seen .unit-art .pulse { animation: art-fade .6s ease-out forwards, pulse 3.6s ease-in-out infinite; animation-delay: 260ms, 2s; }

/* ---------- Impressum ---------- */
.cover-credit { margin: 14px 0 0; color: var(--faint); font-size: 14px; letter-spacing: .04em; }
.cover-credit b { color: var(--dim); font-weight: 600; }
.credit { max-width: 1212px; margin: 46px auto 0; padding: 20px 16px 0; border-top: 1px solid var(--edge);
  color: var(--faint); font-size: 15px; letter-spacing: .04em; }
.credit b { color: var(--dim); font-weight: 600; }
.stagger .top, .stagger .fach-head, .stagger .fach-card, .stagger .grid > *, .stagger .pending { animation: rise .6s var(--ease) backwards; animation-delay: calc(min(var(--i), 14) * 32ms + 80ms); }

@view-transition { navigation: auto; }
::view-transition-group(*) { animation-duration: .5s; animation-timing-function: var(--ease); }
::view-transition-old(lesson), ::view-transition-new(lesson) { height: 100%; object-fit: cover; }
::view-transition-old(lesson) { animation-duration: .18s; }

@media (max-width: 820px) {
  /* Der Buchtitel ist lang; auf Tablet-Breite bricht er sonst in drei Zeilen um
     und reisst die Kopfzeile auf. */
  .home strong { font-size: 16px; max-width: 13em; }
  /* Frueher `#contents .top`. Das war zu eng gefasst: die Fach-Seite hat
     `<main><header class="top">` und **kein** `#contents`, die Regel griff dort
     nie. Ihre Kopfzeile ist ein Flex-Container ohne Umbruch, und die Kinder
     schrumpfen nicht (`min-width: auto`) — `.prog { white-space: nowrap }` plus
     die beiden `←`-Links brachten sie bei 390 px Viewport auf 534 px Content.
     `.home` darf schrumpfen, sonst bleibt der lange Buchtitel der-blockierend. */
  .top { flex-wrap: wrap; gap: 8px 12px; }
  .top .home { min-width: 0; }
  .top .home strong { min-width: 0; }
  .back { margin-left: auto; }
}
@media (max-width: 560px) {
  .home strong { font-size: 15px; max-width: 9em; }
  .fach-head .unit-art, .fach-card .unit-art { width: calc(100% - 32px); right: 0; opacity: .3; }
  .fach-head h1 { min-height: 0; padding-top: 96px; }
  .chalk span:not(:nth-child(3), :nth-child(4)) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .unit-art .d { stroke-dashoffset: 0; }
  .unit-art .t { opacity: 1; }
  .chalk span { opacity: .07; }
}