/* Gemeinsames Layout für alle Übungsblöcke – optimiert für Bildschirm und Druck (A4) */
:root {
  color-scheme: light;
  --text: #1a1a1a;
  --muted: #555;
  --line: #333;
  --soft: #f3f4f6;
  --accent: #1f4e79;
  --immer: #b91c1c;
  --meistens: #c2410c;
  --oft: #a16207;
  --wahrsch: #15803d;
  --sonst: #6b7280;
  --tipp-bg: #eef6ee;
  --falle-bg: #fdf0ef;
  --merke-bg: #eef3fa;
}

* { box-sizing: border-box; }

html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

body {
  margin: 0 auto;
  padding: 24px 16px 64px;
  max-width: 820px;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: #fff;
}

h1, h2, h3, h4 { line-height: 1.25; color: #111; }
h1 { font-size: 28px; margin: 0 0 6px; }
h2 { font-size: 22px; margin: 40px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); }
h3 { font-size: 18px; margin: 30px 0 10px; color: var(--accent); }
h4 { font-size: 16px; margin: 20px 0 8px; }
p { margin: 8px 0; }
a { color: var(--accent); }
ul, ol { padding-left: 22px; }
li { margin: 3px 0; }

/* Kopfbereich */
.blockkopf { border-bottom: 3px solid var(--accent); padding-bottom: 10px; margin-bottom: 18px; }
.blockkopf .unter { color: var(--muted); font-size: 14px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600;
  color: #fff; vertical-align: middle; white-space: nowrap;
}
.k-immer { background: var(--immer); }
.k-meistens { background: var(--meistens); }
.k-oft { background: var(--oft); }
.k-wahrscheinlich { background: var(--wahrsch); }
.k-sonstige { background: var(--sonst); }

/* Inhaltsverzeichnis */
nav.toc { background: var(--soft); border: 1px solid #ddd; border-radius: 6px; padding: 10px 16px; font-size: 14px; }
nav.toc ol { margin: 4px 0; }

/* Teile (Erklärungssatz, Belegsatz, Aufgaben) beginnen im Druck auf neuer Seite */
section.teil { break-before: page; }
section.teil:first-of-type { break-before: auto; }

/* Kästen */
.merke, .tipp, .falle, .info {
  border-left: 4px solid; border-radius: 4px; padding: 8px 12px; margin: 12px 0; break-inside: avoid;
}
.merke { background: var(--merke-bg); border-color: var(--accent); }
.tipp { background: var(--tipp-bg); border-color: var(--wahrsch); }
.falle { background: var(--falle-bg); border-color: var(--immer); }
.info { background: var(--soft); border-color: #999; }
.merke > :first-child, .tipp > :first-child, .falle > :first-child, .info > :first-child { margin-top: 0; }
.kastentitel { font-weight: 700; display: block; margin-bottom: 2px; }

/* Tabellen */
table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; break-inside: avoid; }
th, td { border: 1px solid #999; padding: 4px 8px; text-align: left; vertical-align: top; }
th { background: #e8ecf1; }
table.daten td, table.daten th { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
caption { caption-side: top; text-align: left; font-weight: 600; padding: 4px 0; }

/* Code */
code { font-family: Consolas, "Courier New", monospace; font-size: 0.92em; background: var(--soft); padding: 0 3px; border-radius: 3px; }
pre {
  font-family: Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.45;
  background: var(--soft); border: 1px solid #ccc; border-radius: 4px; padding: 10px 12px;
  white-space: pre-wrap; word-wrap: break-word; break-inside: avoid;
}
pre code { background: none; padding: 0; }
pre.pseudo { border-left: 4px solid var(--accent); }
pre.java { border-left: 4px solid var(--meistens); }
pre.sql { border-left: 4px solid var(--wahrsch); }
.codelabel { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 -4px; }

/* Abbildungen / Diagramme */
figure { margin: 14px 0; break-inside: avoid; }
figure svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
figcaption { font-size: 13px; color: var(--muted); text-align: center; margin-top: 4px; }

/* Belegsatz / Anlagen */
.anlage { border: 1px solid #888; border-radius: 4px; padding: 10px 14px; margin: 16px 0; }
.anlage > h4:first-child { margin-top: 0; }

/* Aufgaben */
.aufgabe { border: 1px solid #888; border-radius: 6px; padding: 10px 14px 12px; margin: 16px 0; }
.aufgabe .kopf { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 1px solid #ccc; padding-bottom: 4px; margin-bottom: 6px; }
.aufgabe .kopf .nr { font-weight: 700; }
.aufgabe .kopf .punkte { font-weight: 700; white-space: nowrap; }
.stufe { color: var(--meistens); letter-spacing: 1px; font-size: 13px; }
.quelle { font-size: 12px; color: var(--muted); font-style: italic; }
.teilaufgabe { margin: 8px 0 4px; }
.teilaufgabe .tp { float: right; font-weight: 600; font-size: 13px; }

/* Antwortfelder für den Ausdruck */
.antwort {
  border: 1px solid #bbb; border-radius: 3px; margin: 6px 0 10px; min-height: 2.2em;
  background-image: linear-gradient(to bottom, transparent 27px, #b8b8b8 27px);
  background-size: 100% 28px;
  background-position: 0 2px;
}
.antwort.z3 { height: 90px; } .antwort.z5 { height: 145px; } .antwort.z8 { height: 230px; }
.antwort.z12 { height: 340px; } .antwort.z18 { height: 510px; }
.zeichenflaeche { border: 1px solid #888; border-radius: 3px; margin: 6px 0 10px; height: 420px; }
.zeichenflaeche.gross { height: 640px; }
.zeichenflaeche.voll { height: 900px; }

/* Lösungen */
.loesung { border-left: 4px solid var(--wahrsch); padding: 6px 0 6px 14px; margin: 18px 0; }
.loesung .kopf { font-weight: 700; }
.bewertung { font-size: 13px; color: var(--muted); }

.klein { font-size: 13px; color: var(--muted); }
.nowrap { white-space: nowrap; }
hr { border: none; border-top: 1px solid #ccc; margin: 24px 0; }

@page { size: A4; margin: 16mm 14mm 16mm 14mm; }
@media print {
  body { max-width: none; padding: 0; font-size: 11pt; }
  .no-print { display: none !important; }
  a { color: inherit; text-decoration: none; }
  h2, h3, h4 { break-after: avoid; }
  .aufgabe { break-inside: avoid; }
}

/* =====================================================================
   Ergänzung: Darkmode (nur Bildschirm) und digitale Antwortfelder
   Wird von uebungen.js gesteuert (Knopf oben rechts, sonst Systemeinstellung).
   Der Druck bleibt immer hell.
   ===================================================================== */
@media screen {
  html[data-theme="dark"] {
    color-scheme: dark;
    --text: #e3e6eb;
    --muted: #a3aab6;
    --line: #c9ced6;
    --soft: #232831;
    --accent: #8bb8ea;
    --tipp-bg: #172a1e;
    --falle-bg: #2f1c1c;
    --merke-bg: #1a2534;
  }
  html[data-theme="dark"] body { background: #14171c; color: var(--text); }
  html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h4 { color: #f2f4f7; }
  html[data-theme="dark"] th { background: #262c36; color: #eef1f5; }
  html[data-theme="dark"] th, html[data-theme="dark"] td { border-color: #4b5261; }
  html[data-theme="dark"] pre { border-color: #3b424e; }
  html[data-theme="dark"] nav.toc { border-color: #3b424e; }
  html[data-theme="dark"] .info { border-color: #6b7280; }
  html[data-theme="dark"] .aufgabe, html[data-theme="dark"] .anlage { border-color: #5a6271; }
  html[data-theme="dark"] .aufgabe .kopf { border-bottom-color: #3b424e; }
  html[data-theme="dark"] hr { border-top-color: #3b424e; }
  html[data-theme="dark"] .stufe { color: #f0a06a; }
  html[data-theme="dark"] .antwort {
    border-color: #4b5261;
    background-image: linear-gradient(to bottom, transparent 27px, #3a404b 27px);
  }
  html[data-theme="dark"] .zeichenflaeche { border-color: #5a6271; }
  /* Diagramme: Farben umkehren (Linien hell auf dunkel); Mockups bleiben als helle Karte */
  html[data-theme="dark"] svg:not(.ap2-hell) { filter: invert(0.88) hue-rotate(180deg); }
  html[data-theme="dark"] svg.ap2-hell { background: #fff; border-radius: 6px; }
  /* Feste helle Hintergründe aus einzelnen Blöcken */
  html[data-theme="dark"] pre.ausgabe, html[data-theme="dark"] pre.konsole,
  html[data-theme="dark"] .mail, html[data-theme="dark"] blockquote.en,
  html[data-theme="dark"] .muster, html[data-theme="dark"] table.leer td.lbl { background: var(--soft); }
  html[data-theme="dark"] table.syntax tr.gruppe td, html[data-theme="dark"] table.sheet th { background: #262c36; color: #eef1f5; }
  html[data-theme="dark"] table.sheet td.ziel { background: #4a505a; outline-color: #d9dde3; }
  html[data-theme="dark"] .formular, html[data-theme="dark"] .ausgabebox { border-color: #9aa3b1; }
  html[data-theme="dark"] .zn { color: #8c95a3; }
  html[data-theme="dark"] td.krit { color: #f28b8b; }
  html[data-theme="dark"] .luecke { border-bottom-color: #c9ced6; }
  html[data-theme="dark"] [style*="background:#"], html[data-theme="dark"] [style*="background: #"] { color: #111; }
}

/* Leiste oben rechts */
.ap2-leiste {
  position: fixed; top: 10px; right: 10px; z-index: 50;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end;
  max-width: calc(100vw - 20px); font-size: 13px;
}
.ap2-leiste button {
  font: inherit; padding: 4px 11px; border: 1px solid #9aa3b1; border-radius: 14px;
  background: var(--soft); color: var(--text); cursor: pointer;
}
.ap2-leiste button:hover { border-color: var(--accent); }
.ap2-status { color: var(--muted); font-size: 12px; background: var(--soft); padding: 3px 9px; border-radius: 10px; border: 1px solid transparent; }

/* Textfelder in den Antwortbereichen */
.antwort.ap2-aktiv { position: relative; height: auto; }
.antwort.ap2-aktiv:focus-within { border-color: var(--accent); }
textarea.ap2-eingabe {
  display: block; width: 100%; box-sizing: border-box; margin: 0;
  border: none; outline: none; resize: none; overflow: hidden; background: transparent;
  color: var(--text); font: inherit; font-size: 15px; line-height: 28px;
  padding: 0 40px 0 8px;
}
textarea.ap2-eingabe.ap2-code { font-family: Consolas, "Courier New", monospace; font-size: 14px; }
.ap2-mono {
  position: absolute; top: 3px; right: 3px; padding: 0 6px; line-height: 18px;
  font: 11px Consolas, "Courier New", monospace; color: var(--muted);
  background: var(--soft); border: 1px solid #b8bec8; border-radius: 3px; cursor: pointer; opacity: .75;
}
.ap2-mono:hover { opacity: 1; }

/* Beschreibbare Tabellenzellen und Lücken */
.ap2-zelle { white-space: pre-wrap; cursor: text; }
.ap2-zelle:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
@media screen {
  td.ap2-zelle:hover { background: rgba(127, 160, 210, .10); }
  .luecke.ap2-zelle:empty::after { content: "\00a0"; }
}

/* Bildzonen (Zeichenflächen) */
.ap2-bildzone { position: relative; outline: none; }
.ap2-bildzone.ap2-mit-bild { height: auto !important; min-height: 0; }
.ap2-bildzone:focus { box-shadow: 0 0 0 2px var(--accent); }
.ap2-bildzone.ap2-ziehen { box-shadow: 0 0 0 3px var(--accent); }
.ap2-extra { border: 1px dashed #9aa3b1; border-radius: 4px; margin: 8px 0; }
.ap2-hinweis { color: var(--muted); font-size: 13px; padding: 8px 10px; }
.ap2-wahl { font: inherit; font-size: 12px; padding: 1px 8px; border: 1px solid #9aa3b1; border-radius: 10px; background: var(--soft); color: var(--text); cursor: pointer; }
.ap2-bilder { padding: 0 8px 8px; }
.ap2-bild { position: relative; margin: 6px 0; }
.ap2-bild img { display: block; max-width: 100%; margin: 0 auto; border: 1px solid #c4c9d1; border-radius: 3px; background: #fff; }
.ap2-bild-entf {
  position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 2px 8px;
  border: 1px solid #9aa3b1; border-radius: 10px; background: var(--soft); color: var(--text); cursor: pointer;
}

@media print {
  .ap2-leiste, .ap2-mono, .ap2-hinweis, .ap2-bild-entf { display: none !important; }
  .ap2-extra.ap2-leer { display: none !important; }
  .ap2-extra { border: none; }
  textarea.ap2-eingabe { color: #000; font-size: 11pt; }
  .ap2-bild img { max-height: 24cm; object-fit: contain; }
}
@media screen {
  body.ap2-mit-leiste { padding-top: 58px; }
  .ap2-status { border-color: #9aa3b1; }
}
@media screen {
  html[data-theme="dark"] .blattname { background: var(--soft); color: var(--text); border-color: #6b7280; }
}
