/* ============================================================
 * AI Tutor — Stylesheet v4 „Weißes Blatt / Tafelbild“
 * Grundfläche weiß wie ein Blatt Papier, Linien wie mit Bleistift
 * gezogen (sketchy borders), Handschrift-Font für Überschriften.
 * Dark Mode = Tafel: dunkles Anthrazit, kreideweiße Linien.
 * Akzent: genau EIN Stift-Blau. Keine Emojis, nur Strichicons.
 * ============================================================ */

/* ---------- Lokale Handschrift-Font (offline, kein CDN) ---------- */
@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('assets/fonts/patrick-hand-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('assets/fonts/patrick-hand-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Papier + Graphit */
  --paper: #FFFFFF;
  --bg: #FDFDFC;
  --ink: #2A2A27;          /* Graphit: Text UND Linien */
  --muted: #6E6E68;
  --line-soft: #DCDCD7;    /* Hilfslinien (hauchzart) */
  --wash: #F4F4F1;         /* einzige getönte Fläche: hauchzartes Grau */

  /* EIN Akzent: Stift-Blau */
  --accent: #2B5BAA;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(43, 91, 170, 0.08);
  --ring: rgba(43, 91, 170, 0.25);

  /* Buntstift-Semantik (gedeckt) */
  --ok: #3C7A4E;
  --ok-soft: rgba(60, 122, 78, 0.10);
  --err: #B5443C;
  --err-soft: rgba(181, 68, 60, 0.10);
  --warn: #8A6A1F;
  --warn-soft: rgba(138, 106, 31, 0.10);

  /* Buntstift-„Schraffur“ (richtig/falsch markiert) */
  --ok-hatch: repeating-linear-gradient(-48deg,
      rgba(60, 122, 78, 0.10) 0 2px, transparent 2px 7px);
  --err-hatch: repeating-linear-gradient(-48deg,
      rgba(181, 68, 60, 0.10) 0 2px, transparent 2px 7px);
  --warn-hatch: repeating-linear-gradient(-48deg,
      rgba(138, 106, 31, 0.10) 0 2px, transparent 2px 7px);

  /* Sketchy Borders: unregelmäßige Radius-Sets („mit der Hand gezogen“) */
  --sk-a: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --sk-b: 15px 225px 15px 255px / 225px 15px 255px 15px;
  --sk-c: 125px 12px 165px 18px / 18px 195px 15px 185px;
  --sk-d: 18px 205px 22px 195px / 215px 16px 185px 18px;
  --sk-e: 95px 12px 105px 10px / 10px 95px 12px 105px;

  --hand: 'Patrick Hand', 'Comic Sans MS', 'Chalkboard SE', cursive;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Wellige Unterstreichung (Bleistiftstrich) */
  --wavy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='6' viewBox='0 0 80 6'%3E%3Cpath d='M1 3.6 C 8 1.4, 14 5.2, 21 3.4 S 34 1.6, 41 3.6 S 55 5.0, 62 3.0 S 75 2.0, 79 3.8' fill='none' stroke='%232A2A27' stroke-width='1.4' stroke-linecap='round' opacity='0.75'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: __dark-deaktiviert) {
  :root {
    /* Tafel */
    --paper: #20231F;
    --bg: #1C1F1B;
    --ink: #ECEDE8;        /* Kreide */
    --muted: #A6A89F;
    --line-soft: #3C403A;
    --wash: #282B26;

    --accent: #8FB5E8;     /* Kreide-Blau */
    --accent-ink: #161A15;
    --accent-soft: rgba(143, 181, 232, 0.12);
    --ring: rgba(143, 181, 232, 0.35);

    --ok: #8CC49B;
    --ok-soft: rgba(140, 196, 155, 0.12);
    --err: #E29A93;
    --err-soft: rgba(226, 154, 147, 0.12);
    --warn: #D9BC76;
    --warn-soft: rgba(217, 188, 118, 0.12);

    --ok-hatch: repeating-linear-gradient(-48deg,
        rgba(140, 196, 155, 0.13) 0 2px, transparent 2px 7px);
    --err-hatch: repeating-linear-gradient(-48deg,
        rgba(226, 154, 147, 0.13) 0 2px, transparent 2px 7px);
    --warn-hatch: repeating-linear-gradient(-48deg,
        rgba(217, 188, 118, 0.13) 0 2px, transparent 2px 7px);

    --wavy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='6' viewBox='0 0 80 6'%3E%3Cpath d='M1 3.6 C 8 1.4, 14 5.2, 21 3.4 S 34 1.6, 41 3.6 S 55 5.0, 62 3.0 S 75 2.0, 79 3.8' fill='none' stroke='%23ECEDE8' stroke-width='1.4' stroke-linecap='round' opacity='0.75'/%3E%3C/svg%3E");
  }
}

/* ---------- Basis ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--hand);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Strichicons (Inline-SVG) */
.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -4px;
  pointer-events: none;
}

/* ---------- Topbar: weiß, dünne Graphit-Linie unten ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  background: var(--paper);
  border-bottom: 1.5px solid var(--ink);
}

#topbar h1 {
  flex: 1;
  font-size: 1.3rem;
  margin: 0;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chip {
  font-family: var(--hand);
  font-size: 1rem;
  color: var(--muted);
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-e);
  padding: 3px 14px;
  background: var(--paper);
}
.profile-chip:empty { display: none; }

/* ---------- Layout ---------- */
#app {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + 96px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.loading-screen { text-align: center; padding: 72px 0; color: var(--muted); font-family: var(--hand); font-size: 1.2rem; }

/* ---------- Buttons: Bleistift-Umrandung ---------- */
button {
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 18px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-b);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  transition: background 140ms ease, transform 90ms ease, border-color 140ms ease;
}
.btn:hover { background: var(--wash); }
.btn:active { transform: scale(0.98) rotate(-0.3deg); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  border-color: var(--accent);
  border-width: 2px;
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.btn-block { width: 100%; margin-bottom: 10px; }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: var(--err-soft); border-color: var(--err); }
.btn-small { min-height: 44px; padding: 5px 14px; font-size: 1rem; }

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--hand);
  font-size: 1.05rem;
  text-decoration: underline;
  text-decoration-style: wavy;
  text-decoration-color: var(--line-soft);
  text-underline-offset: 4px;
}
.btn-link:hover { color: var(--ink); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  border-radius: var(--sk-e);
  color: var(--ink);
  transition: background 140ms ease;
}
.icon-btn:hover, .icon-btn:active { background: var(--wash); }

/* ---------- Karten: das Blatt mit Bleistift-Rahmen ---------- */
.card {
  position: relative;
  background: var(--paper);
  border: 1.7px solid var(--ink);
  border-radius: var(--sk-a);
  padding: 22px 22px 20px;
  margin-bottom: 18px;
}
/* „Nachzieh-Linie“: zweiter, minimal versetzter Bleistiftstrich */
.card::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px solid var(--ink);
  border-radius: var(--sk-d);
  opacity: 0.22;
  transform: rotate(0.25deg);
  pointer-events: none;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 1.45rem;
  display: inline-block;
  padding-bottom: 5px;
  background: var(--wavy) repeat-x left bottom;
  background-size: 80px 6px;
}
.card h3 {
  margin: 16px 0 6px;
  font-size: 1.1rem;
  color: var(--muted);
}

.muted { color: var(--muted); font-size: 0.9rem; }
.hidden { display: none !important; }

/* ---------- Formulare ---------- */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
  font: inherit;
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-c);
  background: var(--paper);
  color: var(--ink);
  transition: box-shadow 140ms ease, border-color 140ms ease;
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1.2 1.4l4.8 4.8 5-4.6' fill='none' stroke='%236E6E68' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

input[type="file"] {
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  width: 100%;
}
input[type="file"]::file-selector-button {
  font-family: var(--hand);
  font-size: 1rem;
  margin-right: 10px;
  min-height: 40px;
  padding: 5px 14px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-b);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin: 2px 0 4px;
}

.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

details > summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--hand);
  font-size: 1.1rem;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Profil-Screen ---------- */
.profile-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.profile-row { display: flex; gap: 8px; align-items: center; }
.profile-row .btn { flex: 1; justify-content: flex-start; }

.new-profile-row { display: flex; gap: 8px; margin-top: 8px; }
.new-profile-row input { flex: 1; width: auto; }

/* ---------- Meine Module ---------- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.module-card { position: relative; }
.module-card .module-open {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 14px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-b);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  min-height: 120px;
  transition: background 140ms ease, transform 90ms ease;
}
.module-card .module-open:hover { background: var(--wash); transform: rotate(-0.4deg); }
.module-card .module-name { font-family: var(--hand); font-size: 1.15rem; line-height: 1.2; }
.module-card .module-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 34px;
  min-height: 34px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Monogramm (RT, MT, …): Kreis wie mit dem Stift gezogen */
.course-monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 1.7px solid var(--ink);
  border-radius: 49% 51% 48% 52% / 52% 47% 53% 48%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.discover-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.discover-row:last-child { border-bottom: none; }
.discover-row .discover-name { flex: 1; min-width: 0; font-weight: 500; }

/* ---------- Modulseite: Lerneinheiten ---------- */
.unit-list { display: flex; flex-direction: column; gap: 10px; }
.unit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-c);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, transform 90ms ease;
}
.unit-row:hover { background: var(--wash); transform: rotate(-0.2deg); }
.unit-row .unit-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.unit-row .unit-title { font-family: var(--hand); font-size: 1.15rem; }
.unit-row .unit-meta { font-size: 0.82rem; }
.unit-row .unit-progress {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.unit-row .unit-progress-label { font-size: 0.82rem; white-space: nowrap; }
.unit-bar {
  display: block;
  width: 96px;
  height: 7px;
  border: 1px solid var(--ink);
  border-radius: 6px 4px 7px 5px / 5px 7px 4px 6px;
  background: var(--paper);
  overflow: hidden;
}
.unit-bar-fill { display: block; height: 100%; background: var(--accent); }
.unit-completed .unit-bar-fill { background: var(--ok); }
.unit-done-badge { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }

/* ---------- Unit-Reader ---------- */
.reader-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.reader-head .reader-title { margin: 0; }
.reader-progress { white-space: nowrap; flex-shrink: 0; }
.unit-page-content { overflow-x: auto; }

/* ---------- Übungsbereich: Chips ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-e);
  background: var(--paper);
  color: var(--ink);
  padding: 5px 14px;
  font-family: var(--hand);
  font-size: 1rem;
  min-height: 38px;
  cursor: pointer;
  transition: background 140ms ease;
}
.chip:hover { background: var(--wash); }
.chip.chip-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  border-width: 2px;
  color: var(--accent);
}

/* ---------- Statistik ---------- */
.boxbar {
  display: flex;
  height: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 5px 7px 4px 6px / 6px 4px 7px 5px;
  overflow: hidden;
  margin-top: 8px;
  background: var(--paper);
}
.boxbar span { display: block; height: 100%; }
.boxbar .b0 { background: var(--err); }
.boxbar .b1 { background: var(--warn); }
.boxbar .b2 { background: var(--accent); }
.boxbar .b3 { background: var(--ok); }
.boxbar .bn { background: var(--line-soft); }

.topic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line-soft);
  font-size: 0.92rem;
}
.topic-row:last-child { border-bottom: none; }
.topic-row .tname { flex: 1; min-width: 0; }

.sim-history-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line-soft);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.sim-history-row:last-child { border-bottom: none; }

/* ---------- Player: Kopf, Badges ---------- */
.player-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  font-family: var(--hand);
  font-size: 0.95rem;
  padding: 2px 12px;
  border: 1.5px solid var(--accent);
  border-radius: var(--sk-e);
  background: var(--paper);
  color: var(--accent);
}
.badge-topic {
  border-color: var(--line-soft);
  color: var(--muted);
}
.badge-warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }

.q-title {
  font-family: var(--hand);
  font-size: 1.35rem;
  margin: 4px 0 10px;
  display: inline-block;
  padding-bottom: 5px;
  background: var(--wavy) repeat-x left bottom;
  background-size: 80px 6px;
}
.q-text { margin-bottom: 14px; }
.q-text p { margin: 8px 0; }

.q-image {
  max-width: 100%;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-c);
  background: #FFFFFF;
  cursor: zoom-in;
  display: block;
  margin: 12px auto;
  padding: 4px;
}

.mermaid-box {
  background: var(--paper);
  border: 1.5px solid var(--line-soft);
  border-radius: var(--sk-c);
  padding: 12px;
  margin: 12px 0;
  overflow-x: auto;
}
.mermaid-box pre {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
}

/* ---------- MC/Multi-Optionen ---------- */
.option-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  margin-bottom: 9px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-c);
  background: var(--paper);
  text-align: left;
  font-size: 1rem;
  font-family: var(--sans);
  color: var(--ink);
  transition: background 140ms ease, transform 90ms ease;
}
.option-card:nth-child(even) { border-radius: var(--sk-d); }
.option-card:hover { background: var(--wash); }

.option-card.selected {
  border-color: var(--accent);
  border-width: 2px;
  background: var(--accent-soft);
}
.option-card.opt-correct { border-color: var(--ok); background: var(--ok-hatch); }
.option-card.opt-wrong { border-color: var(--err); background: var(--err-hatch); }
.option-card:disabled { cursor: default; }

.option-card .opt-mark {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 48% 52% 47% 53% / 53% 46% 54% 47%;
  border: 1.6px solid var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  background: var(--paper);
  transition: background 140ms ease, border-color 140ms ease;
}
.option-card.multi .opt-mark { border-radius: 5px 7px 4px 6px / 6px 4px 7px 5px; }
.option-card.selected .opt-mark {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.option-card.opt-correct .opt-mark { border-color: var(--ok); }
.option-card.opt-wrong .opt-mark { border-color: var(--err); }
.option-card.selected.opt-correct .opt-mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.option-card.selected.opt-wrong .opt-mark { background: var(--err); border-color: var(--err); color: #fff; }

.numeric-row { display: flex; align-items: center; gap: 10px; }
.numeric-row input { flex: 1; width: auto; font-size: 1.05rem; }
.unit-label { font-family: var(--hand); font-size: 1.1rem; color: var(--muted); min-width: 36px; }

.field-row { margin-bottom: 14px; }
.field-row .f-label { font-size: 0.9rem; font-weight: 500; margin-bottom: 4px; }
.field-row.f-correct input, .field-row.f-correct select { border-color: var(--ok); background: var(--ok-hatch); }
.field-row.f-wrong input, .field-row.f-wrong select { border-color: var(--err); background: var(--err-hatch); }
.f-feedback { font-size: 0.85rem; margin-top: 4px; }
.f-feedback.ok { color: var(--ok); }
.f-feedback.no { color: var(--err); }

.tf-hint { font-size: 0.82rem; color: var(--muted); margin-top: 8px; }

/* ---------- Drag-and-Drop ---------- */
.dnd-text { line-height: 2.3; }

.dnd-slot {
  display: inline-block;
  vertical-align: middle;
  min-width: 96px;
  min-height: 44px;
  margin: 2px 4px;
  padding: 2px;
  border: 1.6px dashed var(--ink);
  border-radius: var(--sk-e);
  background: var(--wash);
  text-align: center;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}
.dnd-slot.dnd-over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
}
.dnd-slot.dnd-filled { border-style: solid; padding: 0; background: transparent; touch-action: none; }
.dnd-slot.dnd-correct { border-color: var(--ok); background: var(--ok-hatch); }
.dnd-slot.dnd-wrong { border-color: var(--err); background: var(--err-hatch); }

.dnd-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  margin-top: 10px;
  border: 1.5px solid var(--line-soft);
  border-radius: var(--sk-c);
  background: var(--paper);
}

.dnd-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-e);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: border-color 140ms ease, background 140ms ease;
}
.dnd-chip:hover { background: var(--wash); }
.dnd-chip.dnd-selected { border-color: var(--accent); border-width: 2px; background: var(--accent-soft); }
.dnd-chip.dnd-used { display: none; }
.dnd-chip.dnd-dragging { opacity: 0.35; }
.dnd-chip.dnd-in-slot { border-color: transparent; min-width: 90px; width: 100%; background: transparent; }

.dnd-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 300;
  transform: translate(-50%, -110%);
  pointer-events: none;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dnd-locked .dnd-slot, .dnd-locked .dnd-chip { cursor: default; }
.dnd-locked .dnd-pool { opacity: 0.6; }

.dnd-solution {
  display: inline-block;
  vertical-align: middle;
  margin: 2px 4px;
  padding: 4px 10px;
  border: 1.5px solid var(--ok);
  border-radius: var(--sk-e);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ok);
  background: var(--ok-soft);
}

.dnd-hint { margin-top: 10px; }

/* ---------- Feedback / Lösung ---------- */
.result-banner {
  border: 1.7px solid;
  border-radius: var(--sk-b);
  padding: 12px 16px;
  font-family: var(--hand);
  font-size: 1.2rem;
  margin: 16px 0;
}
.result-correct { background: var(--ok-hatch); color: var(--ok); border-color: var(--ok); }
.result-wrong { background: var(--err-hatch); color: var(--err); border-color: var(--err); }
.result-partial { background: var(--warn-hatch); color: var(--warn); border-color: var(--warn); }

.solution-box {
  border: 1.5px solid var(--ink);
  border-left: 3px solid var(--accent);
  background: var(--paper);
  border-radius: var(--sk-c);
  padding: 14px 16px;
  margin: 14px 0;
}
.solution-box ol { padding-left: 22px; }

.warning-box {
  border: 1.5px solid var(--warn);
  border-radius: var(--sk-c);
  background: var(--warn-hatch);
  padding: 14px 16px;
  margin: 14px 0;
  color: var(--ink);
}

.sketch-hint {
  background: var(--accent-soft);
  border: 1.5px dashed var(--accent);
  border-radius: var(--sk-c);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.player-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.player-actions .btn { flex: 1; min-width: 140px; }

/* ---------- Hilfe-Stufen ---------- */
.help-area { margin-top: 12px; }
.help-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.help-btn { color: var(--muted); }
.hint-box {
  margin-top: 10px;
  padding: 10px 14px;
  border: 1.6px dashed var(--warn);
  border-radius: var(--sk-c);
  background: var(--warn-hatch);
}
.solution-note { margin: 8px 0 4px; }

/* ---------- Klausur ---------- */
.exam-timer {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  z-index: 40;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-family: var(--hand);
  font-size: 1.2rem;
  background: var(--paper);
  border: 1.6px solid var(--ink);
  border-radius: var(--sk-e);
  padding: 5px 20px;
  width: fit-content;
  margin: 0 auto 14px;
}
.exam-timer.low { color: var(--err); border-color: var(--err); }

details.exam-q { margin-bottom: 10px; }
details.exam-q summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-c);
  background: var(--paper);
  cursor: pointer;
  list-style: none;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  transition: background 140ms ease;
}
details.exam-q summary:hover { background: var(--wash); }
details.exam-q summary::-webkit-details-marker { display: none; }
details.exam-q .exam-q-body {
  padding: 14px;
  border: 1.5px solid var(--line-soft);
  border-top: none;
  border-radius: 0 0 14px 10px;
  background: var(--paper);
}
.exam-mark { font-weight: 700; font-size: 1.05rem; }
.exam-mark.m-ok { color: var(--ok); }
.exam-mark.m-part { color: var(--warn); }
.exam-mark.m-bad { color: var(--err); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(20, 20, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  border-radius: 8px;
  background: #fff;
}

/* ============================================================
 * TEIL 2 — Aufgabe als großes Blatt + Werkzeugleiste
 * ============================================================ */
.worksheet {
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}

/* Arbeitsbereich: der freie Platz auf dem Blatt */
.ws-workspace {
  flex: 1;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1.5px dashed var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 180px;
}
.ws-workspace:empty::after {
  content: "Freier Arbeitsbereich — Werkzeuge über die Leiste am Blattrand.";
  color: var(--muted);
  font-family: var(--hand);
  font-size: 1.05rem;
  opacity: 0.7;
}

/* Werkzeugleiste: schwebend am Blattrand (unten rechts) */
.ws-toolbar {
  position: fixed;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 60;
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: var(--paper);
  border: 1.7px solid var(--ink);
  border-radius: var(--sk-b);
}
.ws-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 52px;
  min-height: 52px;
  padding: 4px 6px;
  border: none;
  border-radius: var(--sk-e);
  background: transparent;
  color: var(--ink);
  font-family: var(--hand);
  font-size: 0.78rem;
  line-height: 1.1;
  transition: background 140ms ease;
}
.ws-tool-btn:hover { background: var(--wash); }
.ws-tool-btn.active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.ws-tool-btn .icon { width: 22px; height: 22px; }

/* Breite Bildschirme: vertikale Leiste rechts neben dem Blatt */
@media (min-width: 1180px) {
  .ws-toolbar {
    flex-direction: column;
    right: calc(50% - 430px - 78px);
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
  }
}

/* Notizfeld */
.ws-note { position: relative; }
.ws-note textarea {
  min-height: 96px;
  resize: none;
  overflow: hidden;
  line-height: 1.6;
  border-style: dashed;
  border-color: var(--ink);
}
.ws-block-label {
  display: block;
  font-family: var(--hand);
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 4px;
}

/* Handschrift-Block (Inline-Canvas) */
.ws-sketch {
  border: 1.6px solid var(--ink);
  border-radius: var(--sk-c);
  overflow: hidden;
  background: var(--paper);
}
.ws-sketch-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-bottom: 1.5px dashed var(--line-soft);
  flex-wrap: wrap;
}
.ws-sketch-bar .tool-btn { min-width: 44px; min-height: 44px; }
.ws-sketch-bar .ws-sketch-spacer { flex: 1; }
.ws-sketch-canvas {
  display: block;
  width: 100%;
  height: 380px;
  touch-action: none;
  background: var(--paper);
}
.ws-sketch .scratch-grade-panel {
  position: static;
  border: none;
  border-top: 1.5px dashed var(--line-soft);
  border-radius: 0;
  max-height: 320px;
}

/* Blanko-Tabelle */
.ws-table-wrap { position: relative; overflow-x: auto; padding-top: 6px; }
.ws-table {
  border-collapse: collapse;
  width: 100%;
}
.ws-table td, .ws-table th {
  border: 1.5px solid var(--ink);
  min-width: 64px;
  padding: 8px 10px;
  font-size: 0.95rem;
  outline: none;
}
.ws-table th { background: var(--wash); font-family: var(--hand); font-size: 1.05rem; text-align: left; }
.ws-table td:focus, .ws-table th:focus { box-shadow: inset 0 0 0 2px var(--ring); }
.ws-table-remove {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 34px;
  min-height: 34px;
  font-size: 0.8rem;
  color: var(--muted);
  z-index: 1;
}

/* Tabellen-Dialog */
.ws-dialog {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1.6px dashed var(--ink);
  border-radius: var(--sk-c);
}
.ws-dialog .ws-dialog-field { flex: 0 0 auto; }
.ws-dialog .ws-dialog-field input[type="number"] { width: 84px; }
.ws-dialog label.ws-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
  font-size: 0.9rem;
}
.ws-dialog input[type="checkbox"] { width: 18px; height: 18px; min-height: 18px; accent-color: var(--accent); }

/* Taschenrechner-Panel (schwebend am Blattrand) */
.calc-panel {
  position: fixed;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  z-index: 70;
  width: min(330px, calc(100vw - 28px));
  background: var(--paper);
  border: 1.7px solid var(--ink);
  border-radius: var(--sk-b);
  padding: 10px;
}
.calc-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-family: var(--hand);
  font-size: 1.05rem;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
.calc-panel-head .icon-btn { min-width: 36px; min-height: 36px; }

.calc-widget .calc-history {
  min-height: 20px;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calc-widget .calc-history.calc-error { color: var(--err); }
.calc-widget .calc-display {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 1.15rem;
  text-align: right;
  margin-bottom: 8px;
}
.calc-widget .calc-keys {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
.calc-k {
  min-height: 44px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-e);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 1.05rem;
  padding: 2px;
  transition: background 120ms ease, transform 80ms ease;
}
.calc-k:nth-child(odd) { border-radius: 10px 5px 9px 6px / 6px 9px 5px 10px; }
.calc-k:hover { background: var(--wash); }
.calc-k:active { transform: scale(0.95); }
.calc-k-fn { font-size: 0.92rem; color: var(--muted); }
.calc-k-op { color: var(--accent); }
.calc-k-eq { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.calc-k-eq:hover { background: var(--accent); filter: brightness(1.08); }
.calc-k-active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* ---------- Scratchpad-Overlay (Vollbild-Modus) ---------- */
.scratch-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.scratch-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px 8px;
  background: var(--paper);
  border-bottom: 1.5px solid var(--ink);
}
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.05rem;
  border: 1.5px solid transparent;
  border-radius: var(--sk-e);
  background: transparent;
  color: var(--ink);
  transition: background 140ms ease, border-color 140ms ease;
}
.tool-btn:hover { background: var(--wash); }
.tool-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.scratch-spacer { flex: 1; }
#scratch-color {
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-e);
  padding: 4px;
  background: var(--paper);
}
#scratch-canvas { flex: 1; touch-action: none; background: var(--paper); }

/* ---------- Account / Sync ---------- */
.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1.5px solid var(--ink);
  border-radius: var(--sk-e);
  background: var(--paper);
  padding: 2px 2px 2px 12px;
  max-width: 60vw;
}

.account-chip .account-mail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.account-chip .account-logout {
  min-width: 38px;
  min-height: 38px;
  font-size: 1rem;
}

.sync-dot {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: var(--line-soft);
}
.sync-dot.s-ok { background: var(--ok); }
.sync-dot.s-busy { background: var(--warn); animation: rtt-sync-pulse 0.9s infinite alternate; }
.sync-dot.s-err { background: var(--err); }
.sync-dot.s-off { background: var(--line-soft); }

@keyframes rtt-sync-pulse {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

/* ---------- Auth-Screen ---------- */
.auth-card {
  max-width: 420px;
  margin: clamp(16px, 7vh, 64px) auto 0;
  padding: 28px 24px;
}

.auth-logo {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
}

.auth-title {
  display: block !important;
  text-align: center;
  font-size: 1.7rem !important;
  margin-bottom: 4px !important;
  background-position: center bottom !important;
}

.auth-sub { text-align: center; margin-top: 0; }

.auth-card input { margin-bottom: 12px; }

.auth-msg {
  border-radius: var(--sk-c);
  border: 1.5px solid;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 4px 0 12px;
}
.auth-msg.auth-error { background: var(--err-soft); color: var(--err); border-color: var(--err); }
.auth-msg.auth-info { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

.auth-divider {
  text-align: center;
  color: var(--muted);
  margin: 14px 0 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--hand);
  font-size: 0.95em;
}
.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  border-top: 1.5px dashed var(--line-soft);
}

.btn-oauth { font-family: var(--sans); font-size: 0.95rem; font-weight: 500; }
.btn-oauth svg { flex: 0 0 18px; width: 18px; height: 18px; }

.auth-guest { width: 100%; margin-top: 4px; }

/* ---------- Selbsttest ---------- */
.selftest-list { list-style: none; padding: 0; }
.selftest-list li {
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
}
.selftest-list li.pass { background: var(--ok-soft); color: var(--ok); }
.selftest-list li.fail { background: var(--err-soft); color: var(--err); }

/* ---------- KI-Bewertung (grader.js) ---------- */
.btn-grade {
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--accent);
  border-radius: var(--sk-e);
  background: var(--paper);
  color: var(--accent);
  font-family: var(--hand);
  font-size: 1rem;
  white-space: nowrap;
  transition: background 140ms ease;
}
.btn-grade:hover { background: var(--accent-soft); }
.btn-grade:disabled { opacity: 0.45; cursor: default; }

.scratch-grade-panel {
  position: absolute;
  left: max(12px, env(safe-area-inset-left, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  max-height: 48%;
  overflow-y: auto;
  background: var(--paper);
  border: 1.7px solid var(--ink);
  border-radius: var(--sk-c);
  padding: 14px 16px;
  z-index: 5;
}
.scratch-grade-panel.hidden { display: none; }

.grade-spinner { color: var(--muted); animation: rtt-sync-pulse 1s infinite alternate; }
.grade-error { background: var(--err-soft); color: var(--err); border: 1.5px solid var(--err); border-radius: var(--sk-c); padding: 10px 12px; }

.grade-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.grade-badge { font-family: var(--hand); border: 1.5px solid; border-radius: var(--sk-e); padding: 3px 12px; font-size: 1rem; }
.grade-badge.grade-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.grade-badge.grade-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.grade-badge.grade-unclear { background: var(--wash); color: var(--muted); border-color: var(--line-soft); }
.grade-badge.grade-bad { background: var(--err-soft); color: var(--err); border-color: var(--err); }
.grade-readability { color: var(--muted); font-size: 0.85rem; flex: 1; }
.grade-close { border: none; background: transparent; font-size: 1rem; color: var(--muted); min-width: 32px; min-height: 32px; border-radius: 6px; }
.grade-close:hover { background: var(--wash); }

.grade-steps { list-style: none; padding: 0; margin: 0 0 8px; }
.grade-step { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line-soft); font-size: 0.9rem; }
.grade-step:last-child { border-bottom: none; }
.grade-step-mark { flex-shrink: 0; font-weight: 600; }
.grade-step-korrekt .grade-step-mark, .grade-step-alternativ_korrekt .grade-step-mark { color: var(--ok); }
.grade-step-fehlerhaft .grade-step-mark { color: var(--err); }
.grade-step-unleserlich .grade-step-mark { color: var(--warn); }
.grade-step-comment { color: var(--muted); }

.grade-meta { font-size: 0.88rem; margin: 6px 0; }
.grade-feedback {
  background: var(--accent-soft);
  border-radius: var(--sk-c);
  padding: 10px 12px;
  font-size: 0.92rem;
  white-space: pre-wrap;
  margin: 8px 0;
}
.grade-hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

/* ---------- Lerninhalt-Modal ---------- */
.help-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.help-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 18, 0.45);
}
.help-modal-dialog {
  position: relative;
  width: 100%;
  max-width: 760px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1.8px solid var(--ink);
  border-radius: var(--sk-a);
  overflow: hidden;
}
.help-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1.5px solid var(--ink);
}
.help-modal-head h2 { margin: 0; font-size: 1.3rem; }
.help-modal-body {
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.help-page-title { margin: 18px 0 8px; }
.help-page-title:first-child { margin-top: 0; }

/* ---- Importierte Vault-Inhalte: Tabellen + Callouts ---- */
.q-text table, .solution-box table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  font-size: 0.95rem;
}
.q-text th, .q-text td, .solution-box th, .solution-box td {
  border: 1.5px solid var(--ink);
  padding: 6px 10px;
  text-align: left;
}
.q-text th, .solution-box th { background: var(--wash); font-family: var(--hand); font-size: 1.02rem; font-weight: 400; }
.callout {
  border: 1.5px solid var(--accent);
  border-left-width: 3px;
  background: var(--accent-soft);
  border-radius: var(--sk-c);
  padding: 8px 12px;
  margin: 10px 0;
}
.q-text pre, .solution-box pre {
  background: var(--wash);
  border: 1.5px solid var(--line-soft);
  border-radius: var(--sk-c);
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 0.85rem;
}

/* ---------- Klein-Layout ---------- */
@media (max-width: 480px) {
  .card { padding: 16px; }
  .player-actions .btn { min-width: 100%; }
  .auth-card { margin-top: 16px; }
  .ws-tool-btn { min-width: 48px; min-height: 48px; font-size: 0.72rem; }
  .ws-sketch-canvas { height: 300px; }
}

/* Mermaid auf Papier: nie abschneiden, immer hell */
.mermaid-box { overflow-x: auto; background: #fff; }
.mermaid svg { max-width: 100%; height: auto; background: #fff; }
.mermaid svg text, .mermaid svg tspan { fill: #2A2A27; }
