/* kapiert.ch
   Idee: Jedes Fach ist ein Schulheft. Der Code wird in Häuschen geschrieben wie im Dossier.
   Ein Fach öffnen zeigt das aufklappbare Inhaltsverzeichnis (Kapitel, Unterkapitel).
   Ein Kapitel zeigt die Inhalte im Aufbau der Dossier-Aufgaben: Art links, Titel rechts.
   Hintergrund: liniertes Heftpapier mit Randlinie. Texte stehen nie auf den Linien,
   sondern auf einem Zettel in einem hellen Ton der Fachfarbe. Häuschen nur im Code-Feld.
   Orange bleibt wie im Dossier für erweiterte Ansprüche reserviert. */

/* Schriften: liegen im Ordner /fonts auf kapiert.ch selbst (keine Verbindung zu Google).
   Lizenz: SIL Open Font License, siehe fonts/OFL-*.txt */
@font-face { font-family: "Fraunces"; src: url("fonts/fraunces-variable.woff") format("woff"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Young Serif"; src: url("fonts/young-serif-regular.woff") format("woff"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-regular.woff") format("woff"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-bold.woff") format("woff"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-italic.woff") format("woff"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --bg: #ffffff;
  --ink: #1d1f3f;
  --muted: #5d6079;
  --line: #d9dbe6;
  --grid: #c3c6d6;
  --zeile: rgba(70, 170, 225, 0.38);
  --rand: rgba(226, 60, 45, 0.75);
  --blue: #000099;
  --orange: #e97132;
  --mark: #ffe2bf;
  --err: #b42318;
  --ok: #2e7d3e;
  --no: #c0392b;
  /* Fachfarben: --c = Heftumschlag, --i = Schriftfarbe (dunkler, gut lesbar) */
  --c-deutsch: #c8242f;  --i-deutsch: #b51f29;
  --c-englisch: #ffd83b; --i-englisch: #1d1f3f;
  --c-rzg: #3d9ad1;      --i-rzg: #1c6898;
  --c-musik: #6d3fa6;    --i-musik: #6d3fa6;
  --btn-ink: #ffffff;
  /* Heftrücken */
  --s-deutsch: #a31c26; --s-englisch: #f2bf12; --s-rzg: #2b7fb3; --s-musik: #553087;
  --label-bg: #fbfbf8;
  --label-ink: #1d1f3f;
  --label-line: #b7bacb;
  --display: "Young Serif", "Calisto MT", Georgia, serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
/* Die Seite bleibt immer hell, auch wenn das Gerät auf Darkmode steht. */
:root, html, body { color-scheme: only light; }

* { box-sizing: border-box; }
/* Platz für die Scrollleiste immer freihalten, damit Hintergrund und Inhalt
   beim Wechsel zwischen kurzen und langen Seiten nicht seitlich springen. */
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
@supports not (scrollbar-gutter: stable) { html { overflow-y: scroll; } }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--rand), var(--rand)),
    linear-gradient(transparent 32px, var(--zeile) 32px);
  background-size: 2px 100%, 100% 33px;
  background-repeat: no-repeat, repeat;
  background-position: max(7px, calc(50% - 500px)) 0, 0 0;
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.125rem;
  line-height: 1.55;
}
main { flex: 1; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding-block: 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Kopf */
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 22px 8px; }
/* Logo: kapiert?! in Fraunces, Fragezeichen leicht gekippt */
.logo {
  font-family: "Fraunces", var(--display); font-weight: 900; font-size: 2.6rem; line-height: 1;
  font-variation-settings: "SOFT" 100, "WONK" 1;
  color: var(--blue); text-decoration: none; white-space: nowrap;
}
.logo .q, .logo .x { display: inline-block; color: var(--orange); }
.logo .q { transform: rotate(12deg); margin-left: .04em; }
.logo .x { margin-left: -.04em; }
.head-link { font-weight: 700; color: var(--muted); text-decoration: none; }
.head-link:hover { color: var(--blue); }

/* Startseite: Code */
.start { padding-block: 24px 48px; display: grid; gap: 40px; }
.code h1 { font-family: var(--display); font-weight: 400; font-size: clamp(1.6rem, 4vw, 2rem); line-height: 1.1; margin: 0 0 12px; color: var(--ink); }
.code-row { display: flex; gap: 14px; align-items: stretch; flex-wrap: wrap; }
/* Das Feld hat keine vorgegebenen Kästchen: jedes getippte Zeichen bekommt sein eigenes. */
.code-field {
  position: relative; display: flex; align-items: stretch; height: 46px;
  min-width: 190px; /* Platz für 4 Zeichen und den Cursor, ab 5 Zeichen wird es breiter */
  border: 2px solid var(--blue);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 13px 13px;
}
.cells { display: flex; align-items: stretch; }
.cell {
  width: 42px; display: grid; place-items: center;
  font-family: var(--display); font-size: 1.7rem; color: var(--blue);
  border-right: 1px solid var(--grid);
}
.cursor { width: 3px; margin: 9px 0 9px 8px; background: var(--orange); animation: blink 1.1s steps(2, start) infinite; }
.placeholder { align-self: center; padding-left: 14px; color: var(--muted); font-family: "Fraunces", var(--display); font-weight: 400; font-variation-settings: "SOFT" 100, "WONK" 0; font-size: 1.05rem; }
@keyframes blink { to { visibility: hidden; } }
.code-field input {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; padding: 0;
  background: transparent; color: transparent; caret-color: transparent;
  font-size: 16px; text-transform: uppercase; cursor: text;
}
.code-field input:focus { outline: none; }
.code-field:focus-within { outline: 3px solid var(--orange); outline-offset: 4px; }
.code-btn {
  font-family: var(--display); font-weight: 400; font-size: 1.1rem; padding: 0 22px; min-height: 46px;
  border: 0; border-radius: 6px; background: var(--blue); color: var(--bg); cursor: pointer;
}
.code-hint { margin: 10px 0 0; color: var(--muted); font-family: "Fraunces", var(--display); font-weight: 400; font-variation-settings: "SOFT" 100, "WONK" 0; font-size: 1rem; }
.code-hint.error { color: var(--err); }

/* Startseite: Hefte */
.faecher h2 { font-family: var(--display); font-weight: 400; font-size: 1.6rem; margin: 0 0 20px; }
.hefte { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px; max-width: 900px; }
.heft {
  position: relative; display: block; aspect-ratio: 5 / 6.4; max-width: 100%;
  background: var(--c); border-radius: 3px 9px 9px 3px; text-decoration: none; color: var(--label-ink);
  box-shadow: 0 14px 20px -16px rgba(10, 12, 50, .55);
  transition: transform .15s ease;
}
.heft::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 11%;
  background: var(--s, rgba(0, 0, 0, .2)); border-radius: 3px 0 0 3px;
}
.heft:hover { transform: translateY(-4px); }
.etikett {
  position: absolute; left: 22%; right: 9%; top: 20%;
  background: var(--label-bg); border-radius: 5px; padding: 12px 12px 16px;
}
.etikett span {
  display: block; font-family: var(--display); line-height: 1.15;
  font-size: clamp(1.05rem, 1.2vw + .75rem, 1.5rem);
  padding-bottom: 5px; border-bottom: 1px solid var(--label-line); overflow-wrap: anywhere;
}
.etikett i { display: block; height: 1px; margin-top: 18px; background: var(--label-line); }

/* Fach- und Kapitelseiten */
.page { padding-block: 24px 64px; }
.zurueck {
  display: inline-grid; place-items: center; width: 40px; height: 40px; margin: 0 0 14px;
  border-radius: 50%; background: var(--blue); color: var(--bg);
  box-shadow: 0 6px 12px -8px rgba(10, 12, 60, .6); transition: transform .15s ease;
}
.zurueck:hover { transform: translateX(-2px); }

/* Zettel: Fläche ohne Linien, damit Text nicht auf den Heftlinien steht */
.zettel {
  max-width: 52rem; padding: 26px 32px 30px; border-radius: 3px;
  background: color-mix(in srgb, var(--c, var(--blue)) 10%, var(--bg));
  box-shadow: 0 1px 2px rgba(20, 22, 60, .08), 0 14px 26px -20px rgba(20, 22, 60, .5);
}
.zettel.neutral { background: color-mix(in srgb, var(--blue) 5%, var(--bg)); }
.zettel > :last-child { margin-bottom: 0; }
.code.zettel { width: fit-content; max-width: 100%; padding: 20px 24px 20px; }
.kontext { margin: 0 0 4px; color: var(--muted); font-weight: 700; }
.page-title {
  font-family: var(--display); font-weight: 400; font-size: clamp(2.2rem, 6vw, 3rem); line-height: 1.08;
  color: var(--blue); margin: 0 0 28px; padding-bottom: 10px; border-bottom: 2px solid currentColor; text-wrap: balance;
}
.page-title.colored { color: var(--i); border-bottom: 4px solid var(--c); }
.empty { color: var(--muted); font-style: italic; margin: 0; }

/* Aufklappbares Inhaltsverzeichnis */
.toc { max-width: 40rem; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul ul { margin: 0 0 10px 5px; padding-left: 20px; border-left: 2px solid color-mix(in srgb, var(--c) 50%, transparent); }
.toc a, .toc summary { display: flex; align-items: baseline; gap: 12px; padding: 9px 0; color: var(--ink); text-decoration: none; }
.toc summary { cursor: pointer; list-style: none; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary::before, .toc a::before { content: ""; flex: 0 0 9px; height: 9px; }
.toc summary::before {
  border-right: 2.5px solid var(--i); border-bottom: 2.5px solid var(--i);
  transform: translateY(-3px) rotate(-45deg); transition: transform .15s;
}
.toc details[open] > summary::before { transform: translateY(-6px) rotate(45deg); }
.toc .t { font-family: var(--display); font-size: 1.4rem; line-height: 1.25; }
.toc ul ul .t { font-size: 1.2rem; }
.toc .dots { flex: 1; min-width: 1.5rem; border-bottom: 2px dotted var(--grid); transform: translateY(-6px); }
.toc .n { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.toc .n.leer { font-style: italic; }
.toc a:hover .t, .toc summary:hover .t { color: var(--i); text-decoration: underline; text-underline-offset: 4px; }

.hinweis { margin-top: 20px; }

.inhalte { list-style: none; margin: 0; padding: 0; max-width: 46rem; border-top: 1.5px solid var(--grid); }
.inhalt {
  display: grid; grid-template-columns: 6.5rem minmax(0, 1fr) auto; gap: 6px 18px; align-items: baseline;
  padding: 16px 0; border-bottom: 1.5px solid var(--grid);
}
.inhalt .typ { font-weight: 700; color: var(--i); }
.inhalt .typ small { display: block; font-size: .85rem; font-weight: 700; }
.inhalt.zusatz .typ { color: var(--orange); }
.inhalt h2 { margin: 0; font-size: 1.15rem; font-weight: 700; line-height: 1.35; }
.inhalt .bsp { font-weight: 400; font-style: italic; color: var(--muted); font-size: 1rem; }
.inhalt .soon { color: var(--muted); font-style: italic; font-size: 1rem; }
.player { grid-column: 2 / -1; aspect-ratio: 16 / 9; max-width: 100%; margin-top: 8px; }
.player iframe { width: 100%; height: 100%; border: 0; display: block; border-radius: 6px; }
.player-note { grid-column: 2 / -1; margin: 0; color: var(--muted); font-size: .95rem; }

.btn {
  display: inline-block; font-family: var(--body); font-weight: 700; font-size: 1rem; line-height: 1.2;
  padding: 9px 18px; border: 0; border-radius: 6px; background: var(--i, var(--blue)); color: var(--btn-ink);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }

.text { max-width: 38rem; }
.text h2 { font-family: var(--display); font-weight: 400; font-size: 1.3rem; margin: 28px 0 6px; color: var(--blue); }
.text p { margin: 0 0 12px; }
.todo { background: var(--mark); padding: 0 4px; border-radius: 3px; }

/* Fusszeile wie im Dossier */
.site-foot .wrap {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding-block: 12px 24px; font-size: .95rem; color: var(--muted);
}
.site-foot .line { border-top: 1px solid var(--grid); }
.site-foot nav { display: flex; gap: 20px; }
.site-foot a { color: var(--muted); }

@media (max-width: 760px) {
  .hefte { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
}
@media (max-width: 480px) {
  .zettel { padding: 20px 18px 22px; }
  .start { padding-block: 28px 48px; gap: 44px; }
  .code-field { flex: 1 1 100%; }
  .cell { width: 39px; font-size: 1.8rem; }
  .code-btn { flex: 1 1 100%; }
  .inhalt { grid-template-columns: minmax(0, 1fr) auto; }
  .inhalt .typ { grid-column: 1 / -1; }
  .player, .player-note { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } .cursor { animation: none; } }

/* Impressum und Datenschutz: Fenster über der Seite */
.info {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: min(44rem, calc(100% - 32px)); max-height: calc(100dvh - 48px);
}
.info::backdrop { background: rgba(20, 22, 60, .45); }
.info-blatt {
  position: relative; max-width: none; max-height: calc(100dvh - 48px); overflow-y: auto;
  background: var(--bg); padding-top: 30px;
}
.info-zu {
  position: sticky; top: 0; float: right; margin: -14px -14px 0 12px; z-index: 1; display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--blue); color: var(--bg); box-shadow: 0 6px 12px -8px rgba(10, 12, 60, .6);
}
.info-zu:hover { transform: scale(1.06); }
body:has(.info[open]) { overflow: hidden; }

/* Falscher Code: Feld wackelt kurz */
@keyframes wackeln {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); } 40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(3px); }
}
.code-field.wackeln { animation: wackeln .4s ease; }
@media (prefers-reduced-motion: reduce) { .code-field.wackeln { animation: none; } }
