/* Layout: App-Schale. iPhone = Kopfzeile + Tab-Leiste unten; iPad hoch = breiter, 2 Spalten;
   iPad quer / Mac = Seitenleiste links, Inhalt mittig. Farben: Tannengrün (Behörde/Ordnung) + Siegelgold. */
:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #e9e8e2;
  --text: #1b201f;
  --muted: #5f6865;
  --line: #d9d8d0;
  --brand: #0f3d3a;
  --brand-2: #14625c;
  --on-brand: #ffffff;
  --bar-bg: #0f3d3a;
  --bar-fg: #ffffff;
  --accent: #d99a1e;
  --ok: #15803d;
  --ok-bg: #e4f3e8;
  --bad: #c2410c;
  --bad-bg: #fbe9de;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 4px 14px rgba(20, 30, 28, .05);
  --scrim: rgba(10, 20, 18, .45);
  --radius: 16px;
  --tabbar-h: 64px;
  --rail-w: 92px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101413; --surface: #1a1f1e; --surface-2: #252b29; --text: #eaeeec; --muted: #9aa5a1; --line: #2f3735;
    --brand: #7fd1c6; --brand-2: #5fb8ad; --on-brand: #0b1514; --bar-bg: #0b2321; --bar-fg: #eaeeec;
    --accent: #f0bf4c; --ok: #4ade80; --ok-bg: #15301f; --bad: #fb923c; --bad-bg: #3a2418;
    --shadow: none; --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101413; --surface: #1a1f1e; --surface-2: #252b29; --text: #eaeeec; --muted: #9aa5a1; --line: #2f3735;
  --brand: #7fd1c6; --brand-2: #5fb8ad; --on-brand: #0b1514; --bar-bg: #0b2321; --bar-fg: #eaeeec;
  --accent: #f0bf4c; --ok: #4ade80; --ok-bg: #15301f; --bad: #fb923c; --bad-bg: #3a2418;
  --shadow: none; --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 20; background: var(--bar-bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* Kopfzeile */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bar-bg); color: var(--bar-fg); }
.topbar-inner {
  display: flex; align-items: center; gap: 8px; min-height: 52px;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar h1 { flex: 1; min-width: 0; font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { background: none; border: 0; padding: 6px; margin-left: -8px; display: grid; place-items: center; cursor: pointer; color: inherit; border-radius: 10px; }
.sync { font-size: 12px; opacity: .8; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.sync.ok::before { background: #4ade80; }
.sync.warn::before { background: var(--accent); }

main {
  max-width: 1040px; margin: 0 auto; outline: none;
  padding-top: 16px;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Tab-Leiste unten (iPhone, iPad hoch) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: 11px; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--brand-2); font-weight: 600; }
body.focus .tabbar { display: none; }
body.focus main { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px); }

/* iPad quer & Mac: Seitenleiste */
@media (min-width: 1000px) {
  .tabbar {
    top: 0; right: auto; width: var(--rail-w); height: 100%;
    grid-template-columns: 1fr; grid-auto-rows: 76px; align-content: start;
    padding-top: calc(env(safe-area-inset-top, 0px) + 72px);
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tabbar a { height: auto; font-size: 12px; }
  body.focus .tabbar { display: grid; }
  body { padding-left: var(--rail-w); }
  main { padding-top: 24px; padding-bottom: 48px; }
  body.focus main { padding-bottom: 48px; }
}

/* Bausteine */
h2 { font-size: 20px; margin: 28px 0 12px; letter-spacing: -.01em; text-wrap: balance; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.grid > *, .stack > * { min-width: 0; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent;
  background: var(--brand); color: var(--on-brand); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.cta-row { display: grid; gap: 10px; margin-top: 14px; }
@media (min-width: 700px) { .cta-row { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }

/* Gesamtfortschritt */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.hero-wrap { display: grid; gap: 14px; }
@media (min-width: 700px) { .hero-wrap { grid-template-columns: 1.3fr 1fr; align-items: center; } .hero-wrap .kpis { margin-top: 0; } }
.ring { width: 112px; height: 112px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .val { stroke: var(--brand-2); transition: stroke-dashoffset .6s ease; }
.ring .label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .label b { font-size: 26px; line-height: 1; display: block; font-variant-numeric: tabular-nums; }
.ring .label span { font-size: 11px; color: var(--muted); }
.hero-title { font-weight: 650; font-size: 18px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.kpi b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); line-height: 1.25; display: block; }

/* Balken: Sicher / Gelernt / Fehler / Neu */
.bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin-top: 6px; }
.bar i { display: block; height: 100%; }
.bar .s { background: var(--ok); }
.bar .g { background: var(--brand-2); opacity: .55; }
.bar .f { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.legend .sw-s { background: var(--ok); } .legend .sw-g { background: var(--brand-2); opacity: .55; }
.legend .sw-f { background: var(--bad); } .legend .sw-n { background: var(--surface-2); outline: 1px solid var(--line); }

/* Fachliste */
.fach { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; text-decoration: none; }
.fach.plain { grid-template-columns: 1fr auto; }
.fach .tag { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.fach .name { font-weight: 600; }
.fach .pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.fach.empty { opacity: .6; }

/* Modus-Auswahl */
.modes { display: grid; gap: 10px; }
@media (min-width: 700px) { .modes { grid-template-columns: 1fr 1fr; } }
.mode { display: flex; align-items: center; gap: 14px; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.mode .ico { flex: 0 0 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand-2); }
.mode .ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.mode .ico.tagged { color: #fff; font-size: 12px; font-weight: 700; }
.mode b { display: block; }
.mode span { font-size: 14px; color: var(--muted); }
.mode.disabled { opacity: .45; pointer-events: none; }

/* Frage */
.qwrap { max-width: 720px; margin: 0 auto; }
.qhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.qtext { font-size: 19px; font-weight: 600; line-height: 1.4; margin: 6px 0 16px; text-wrap: pretty; }
@media (min-width: 700px) { .qtext { font-size: 22px; } }
.hint { font-size: 13px; color: var(--muted); margin: -8px 0 12px; }
.options { display: grid; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; cursor: pointer; }
.opt .mark { flex: 0 0 24px; height: 24px; border: 2px solid var(--line); border-radius: 50%; display: grid; place-items: center; margin-top: 1px; font-size: 14px; font-weight: 700; }
.opt .key { display: none; margin-left: auto; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
@media (hover: hover) and (pointer: fine) { .opt .key { display: inline-block; } .opt:hover:not(:disabled) { border-color: var(--brand-2); } }
.opt.multi .mark { border-radius: 6px; }
.opt.sel { border-color: var(--brand-2); background: color-mix(in srgb, var(--brand-2) 9%, var(--surface)); }
.opt.sel .mark { background: var(--brand-2); border-color: var(--brand-2); color: var(--on-brand); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .mark { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .mark { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.opt.missed { border-style: dashed; border-color: var(--ok); }
.opt:disabled { cursor: default; color: inherit; }
.numinput { display: flex; gap: 10px; align-items: center; }
.numinput input { flex: 1; min-width: 0; min-height: 52px; font-size: 20px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); }
.numinput input:focus { outline: none; border-color: var(--brand-2); }
.numinput input.ok { border-color: var(--ok); } .numinput input.bad { border-color: var(--bad); }

.feedback { margin-top: 16px; border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); background: var(--surface); }
.feedback.ok { border-color: var(--ok); }
.feedback.bad { border-color: var(--bad); }
.feedback h3 { margin: 0 0 6px; font-size: 17px; }
.feedback.ok h3 { color: var(--ok); }
.feedback.bad h3 { color: var(--bad); }
.feedback p { margin: 0 0 10px; }
.fund { display: flex; flex-wrap: wrap; gap: 6px; }
.fund span { font-size: 13px; background: var(--surface-2); padding: 3px 9px; border-radius: 8px; }
.fund-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }

.actions { position: sticky; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); margin-top: 16px; display: flex; gap: 10px; }
.actions .btn { flex: 1; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); }
@media (min-width: 1000px) { .actions { position: static; } .actions .btn { box-shadow: none; } }

.progress-line { height: 4px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress-line i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* Prüfung */
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.timer.low { color: var(--bad); }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.qnav button { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 13px; font-variant-numeric: tabular-nums; }
.qnav button.done { background: var(--surface-2); }
.qnav button.cur { border-color: var(--brand-2); border-width: 2px; font-weight: 700; }

.result { text-align: center; padding: 24px 16px; }
.result .big { font-size: 48px; font-weight: 800; line-height: 1; margin: 10px 0; font-variant-numeric: tabular-nums; }
.result.pass .big { color: var(--ok); }
.result.fail .big { color: var(--bad); }
.result .ico-lg { width: 48px; height: 48px; margin: 0 auto; color: var(--brand-2); }
.result .ico-lg svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.review details { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.review details + details { margin-top: 8px; }
.review summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; list-style: none; }
.review summary::-webkit-details-marker { display: none; }
.review .dot { flex: 0 0 10px; height: 10px; border-radius: 50%; }
.review .dot.r { background: var(--ok); } .review .dot.w { background: var(--bad); }

.empty-state { text-align: center; padding: 32px 16px; }
.list > * { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > *:last-child { border-bottom: 0; }
.list > *:first-child { padding-top: 0; }
.pill-ok { background: var(--ok-bg); color: var(--ok); } .pill-bad { background: var(--bad-bg); color: var(--bad); }

/* Dialog + Hinweis */
.modal { position: fixed; inset: 0; z-index: 40; background: var(--scrim); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--surface); color: var(--text); border-radius: 18px; padding: 20px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-box p { margin: 0 0 18px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
  animation: fade 2.6s forwards;
}
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* Sachverhalt, Karteikarte, Lösungsweg, Selbstbewertung */
.sachverhalt { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin: 4px 0 14px; font-size: 15px; line-height: 1.55; }
.sachverhalt .fund-title { margin-bottom: 4px; }
.karte {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  min-height: 260px; padding: 28px 22px; display: grid; align-content: center; gap: 18px; text-align: center; cursor: pointer;
}
.karte.offen { cursor: default; text-align: left; align-content: start; }
.karte-vorn { font-size: 22px; font-weight: 650; line-height: 1.35; text-wrap: balance; }
.karte.offen .karte-vorn { font-size: 17px; color: var(--muted); padding-bottom: 14px; border-bottom: 1px dashed var(--line); }
.karte-hinten p { margin: 0 0 14px; font-size: 17px; line-height: 1.55; }
.karte-tipp { font-size: 13px; color: var(--muted); }
@media (min-width: 700px) { .karte { min-height: 320px; padding: 36px; } .karte-vorn { font-size: 26px; } }
.weg { margin: 0 0 12px; padding-left: 22px; display: grid; gap: 6px; }
.weg li { padding-left: 2px; }
.notiz { width: 100%; min-height: 110px; resize: vertical; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); font-size: 15px; line-height: 1.5; margin-top: 4px; }
.notiz:focus { outline: none; border-color: var(--brand-2); }
.btn.rate { padding: 0 10px; font-size: 15px; }
.btn.rate.bad { background: var(--bad); color: #fff; }
.btn.rate.mid { background: var(--accent); color: #1b201f; }
.btn.rate.good { background: var(--ok); color: var(--surface); }
.modes.arten { grid-template-columns: 1fr; }
@media (min-width: 700px) { .modes.arten { grid-template-columns: repeat(3, 1fr); } .modes.arten .mode { flex-direction: column; align-items: flex-start; } }

/* Lerncode */
.lerncode { font: 700 24px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; text-align: center; padding: 14px; border-radius: 12px; background: var(--surface-2); user-select: all; }
.code-zeile { display: flex; gap: 8px; }
.code-zeile input { flex: 1; min-width: 0; min-height: 48px; padding: 0 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font: 600 17px ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .06em; text-transform: uppercase; }
.code-zeile input:focus { outline: none; border-color: var(--brand-2); }
