/* study-coach: mobil zuerst, große Tap-Flächen, heller und dunkler Modus */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eaefed;
  --text: #17201d;
  --muted: #5d6b66;
  --border: #d3dcd8;
  --accent: #1f5f4f;
  --accent-text: #ffffff;
  --accent-soft: #d9ebe5;
  --ok: #1d7a46;
  --ok-soft: #dcf2e4;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --warn: #8a5a00;
  --warn-soft: #fbefd5;
  --radius: 14px;
  --tap: 52px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --surface: #17221e;
    --surface-2: #213029;
    --text: #e6eeeb;
    --muted: #9cb0a8;
    --border: #2e403a;
    --accent: #5fbf9f;
    --accent-text: #08130f;
    --accent-soft: #1f3a31;
    --ok: #6fd69a;
    --ok-soft: #173326;
    --bad: #ff8a80;
    --bad-soft: #3a1c1a;
    --warn: #f3c262;
    --warn-soft: #3a2f16;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
main.wide { max-width: 1400px; }
h1 { font-size: 1.5rem; margin: 8px 0 4px; }
h2 { font-size: 1.15rem; margin: 20px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .88rem; }

/* Buttons */
button, .btn {
  font: inherit;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
button:disabled { opacity: .45; cursor: default; }
button:disabled.chosen, button:disabled.mark-ok, button:disabled.mark-bad, button:disabled.mark-missing { opacity: 1; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 650; }
button.block { display: block; width: 100%; }
button.big { min-height: 64px; font-size: 1.15rem; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.chosen { background: var(--accent-soft); border-color: var(--accent); font-weight: 650; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="password"], input[type="search"], input[inputmode] {
  font: inherit;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; }
.stack { display: grid; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.topbar .title { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar button, .topbar .chip { white-space: nowrap; flex: none; }
.topbar .title:focus { outline: none; }
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .82rem;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

/* Startseite */
.hero { display: flex; gap: 12px; align-items: stretch; margin: 12px 0; }
.stat { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; }
.stages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stage {
  text-align: left; padding: 12px; min-height: 96px; display: flex; flex-direction: column; gap: 4px;
}
.stage.locked { opacity: .55; }
.stage.selected { border: 2px solid var(--accent); }
.stage .name { font-weight: 650; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: auto; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.switch { display: flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; }
.switch input { width: 26px; height: 26px; accent-color: var(--accent); }

/* Aufgabe */
.case { font-size: 1.08rem; white-space: pre-wrap; }
.account-tag { font-weight: 650; }
.choices { display: grid; gap: 10px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.dirline { border-top: 1px solid var(--border); padding: 12px 0 4px; }
.dirline:first-child { border-top: 0; padding-top: 0; }
.side-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.codes button { text-align: left; padding: 8px 12px; }
.codes button b { display: block; }
.codes button span { font-size: .8rem; color: var(--muted); }

/* Buchungssatz */
.side { margin: 12px 0; }
.bline { display: grid; grid-template-columns: minmax(0, 1fr) 104px 44px; gap: 8px; align-items: center; margin: 8px 0; }
.bline .acc { overflow-wrap: anywhere; hyphens: auto; padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); min-height: var(--tap); display: flex; align-items: center; }
.bline button { min-height: 44px; padding: 0; }

/* Kontenauswahl */
.picker { margin: 8px 0; }
.picker .results { display: grid; gap: 6px; margin-top: 6px; max-height: 320px; overflow-y: auto; }
.picker .results button { text-align: left; min-height: 48px; padding: 8px 12px; }

/* Ergebnis */
.result { border-width: 2px; }
.result.ok { border-color: var(--ok); }
.result.bad { border-color: var(--bad); }
.result.pending { border-color: var(--warn); }
.verdict { font-size: 1.25rem; font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.verdict.pending { color: var(--warn); }
.parts { list-style: none; padding: 0; margin: 8px 0; }
.parts li { padding: 8px 0; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.parts li:first-child { border-top: 0; }
.parts .mark { width: 22px; flex: none; font-weight: 700; }
.parts .mark.ok { color: var(--ok); }
.parts .mark.bad { color: var(--bad); }
.solution { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.solution table { width: 100%; border-collapse: collapse; }
.solution table { table-layout: auto; }
.solution td { padding: 3px 4px; vertical-align: top; overflow-wrap: anywhere; hyphens: auto; }
.solution td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.explanation { white-space: pre-wrap; }
pre.json { white-space: pre-wrap; word-break: break-word; font-size: .85rem; margin: 0; }

/* Skizze: Hochformat = Kopf, Fläche, Abgeben untereinander; Querformat = Spalte links, Fläche rechts */
.sketch-layout {
  display: grid; gap: 10px;
  grid-template-areas: "side" "pad" "submit";
}
.sketch-side { grid-area: side; }
.sketch-pad { grid-area: pad; display: flex; justify-content: center; }
.sketch-submit { grid-area: submit; }
.sketch-case { margin: 4px 0 8px; font-size: .98rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbar button { min-width: 48px; min-height: 48px; padding: 6px 10px; }
.toolbar .icon { font-size: 1.25rem; }
.swatch { width: 48px; padding: 0; }
.swatch i { display: inline-block; width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; }
canvas.pad {
  display: block; height: auto;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  touch-action: none; cursor: crosshair;
}
canvas.pad.tall { aspect-ratio: 3 / 4; width: min(100%, calc((100dvh - 270px) * 3 / 4)); }
canvas.pad.wide { aspect-ratio: 4 / 3; width: min(100%, calc((100dvh - 270px) * 4 / 3)); }
@media (min-width: 900px), (orientation: landscape) and (max-height: 600px) {
  .sketch-layout {
    grid-template-columns: minmax(220px, 1fr) auto;
    grid-template-areas: "side pad" "submit pad";
    align-items: start;
  }
  .sketch-side { position: sticky; top: 8px; }
  canvas.pad.wide { width: min(100%, calc((100dvh - 24px) * 4 / 3)); }
  canvas.pad.tall { width: min(100%, calc((100dvh - 24px) * 3 / 4)); }
}
@media (orientation: landscape) and (max-height: 600px) {
  main.sketch-page { padding-top: 8px; padding-bottom: 8px; }
  .sketch-case { font-size: .9rem; }
  .sketch-pad { max-width: calc(100vw - 260px); }
}
button.armed { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

.sketch-thumb { width: 100%; border-radius: 10px; border: 1px solid var(--border); background: #fff; }
.error { color: var(--bad); }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* Bewertung direkt an der Antwort */
.mark-ok { border: 2px solid var(--ok) !important; }
.mark-bad { border: 2px solid var(--bad) !important; background: var(--bad-soft) !important; }
.mark-missing { border: 2px dashed var(--ok) !important; opacity: 1 !important; }
.bline.mark-ok .acc, .bline.mark-bad .acc { border: 0 !important; }
.bline.mark-ok, .bline.mark-bad { border-radius: var(--radius); padding: 4px; }
.bline.mark-ok { border-width: 0 0 0 4px !important; border-style: solid !important; }
.bline.mark-bad { border-width: 0 0 0 4px !important; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); font-weight: 600; }
.parts .note { font-size: .92rem; }

/* zuletzt verwendete Konten */
.recent { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip-btn { min-height: 40px; padding: 6px 12px; border-radius: 999px; font-size: .9rem; }

.toast { position: fixed; left: 16px; right: 16px; bottom: 24px; z-index: 9; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (orientation: landscape) and (max-height: 600px) {
  .sketch-side .topbar .title { display: none; }
}
