/* ===== Farben ============================================================ */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #1c1f2e;
  --muted: #646a82;
  --border: #dde0ee;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-text: #ffffff;
  --primary-soft: #e8e7fd;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --near: #d97706;
  --near-soft: #fef3c7;
  --info-soft: #e0f2fe;
  --seg-new: #c9cddd;
  --seg-1: #ef4444;
  --seg-2: #f97316;
  --seg-3: #eab308;
  --seg-4: #84cc16;
  --seg-5: #16a34a;
  --bar-time: #6366f1;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 4px 16px rgba(20, 24, 50, .06);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131c;
    --surface: #1b1e2b;
    --surface-2: #252938;
    --text: #e8eaf3;
    --muted: #9ba1bb;
    --border: #2f3446;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-text: #11131c;
    --primary-soft: #2a2d4a;
    --ok: #4ade80;
    --ok-soft: #14321f;
    --bad: #f87171;
    --bad-soft: #3b1a1a;
    --near: #fbbf24;
    --near-soft: #3a2c0c;
    --info-soft: #11314a;
    --seg-new: #464b60;
    --bar-time: #818cf8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #11131c;
  --surface: #1b1e2b;
  --surface-2: #252938;
  --text: #e8eaf3;
  --muted: #9ba1bb;
  --border: #2f3446;
  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-text: #11131c;
  --primary-soft: #2a2d4a;
  --ok: #4ade80;
  --ok-soft: #14321f;
  --bad: #f87171;
  --bad-soft: #3b1a1a;
  --near: #fbbf24;
  --near-soft: #3a2c0c;
  --info-soft: #11314a;
  --seg-new: #464b60;
  --bar-time: #818cf8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ===== Grundlagen ======================================================= */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
pre.code { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow-x: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.warn { color: var(--near); }
.inline { display: inline; }
[hidden] { display: none !important; }

.container { max-width: 980px; margin: 0 auto; padding: 16px; }

/* ===== Kopfzeile & Navigation ========================================== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.who { color: var(--muted); font-size: .9rem; margin: 0 4px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  background: none; border: 0; cursor: pointer; font-size: 1.25rem; line-height: 1;
  padding: 8px; border-radius: 10px; color: var(--text); text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }

.mainnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.mainnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; font-size: .72rem; color: var(--muted); text-decoration: none;
}
.mainnav a.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.3rem; line-height: 1; }

@media (min-width: 760px) {
  body { padding-bottom: 24px; }
  .mainnav {
    position: static; justify-content: center; gap: 4px;
    border-top: 0; border-bottom: 1px solid var(--border); padding: 6px;
  }
  .mainnav a { flex: 0 0 auto; flex-direction: row; gap: 6px; font-size: .95rem; padding: 8px 14px; border-radius: 10px; }
  .mainnav a.active { background: var(--primary-soft); }
  .nav-icon { font-size: 1.05rem; }
}

/* ===== Karten, Listen, Raster =========================================== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.card.narrow { max-width: 420px; margin: 24px auto; }
.card-link { display: block; color: inherit; text-decoration: none; transition: transform .1s, border-color .1s; }
.card-link:hover { border-color: var(--primary); }
.card-link:active { transform: scale(.99); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin-bottom: 16px; }
.grid .card { margin: 0; }
.two-col { display: grid; gap: 0 16px; }
@media (min-width: 760px) { .two-col { grid-template-columns: 1fr 1fr; } }
.list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.list .card { margin: 0; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: .6rem; }
.steps li { margin-bottom: .4rem; }
.danger-zone { border-color: var(--bad-soft); }

/* ===== Buttons ========================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-outline { background: none; border-color: var(--bad); color: var(--bad); }
.btn-link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding-left: 0; }
.btn-block { width: 100%; }
.btn-big { font-size: 1.2rem; padding: 14px 28px; min-height: 56px; }
.btn-small { min-height: 34px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.actions.center { justify-content: center; }

/* ===== Formulare ======================================================== */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--primary); flex: 0 0 auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
input:disabled { opacity: .7; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 600; padding: 0 6px; }
details summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-bottom: 8px; }
details[open] { display: flex; flex-direction: column; gap: 12px; }
.segmented { flex-direction: row; gap: 18px; }
.segmented label { flex-direction: row; align-items: center; gap: 8px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== Meldungen ======================================================== */
.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; }
.flash ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.flash-ok { background: var(--ok-soft); }
.flash-error { background: var(--bad-soft); }
.flash-info { background: var(--info-soft); }

/* ===== Tabellen ========================================================= */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
.vocab-table td { min-width: 110px; }

/* ===== Login ============================================================ */
.login-card { text-align: center; }
.login-card .form { text-align: left; }
.login-logo { margin: 4px 0 8px; }

/* ===== Kennzahlen ======================================================= */
.kid-head { display: flex; justify-content: space-between; align-items: center; }
.kid-head h2 { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; text-align: center; }
.kpis strong { display: block; font-size: .95rem; white-space: nowrap; }
.kpis span { font-size: .72rem; color: var(--muted); }
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 760px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; flex-direction: column; align-items: flex-start;
}
.kpi-icon { font-size: 1.4rem; }
.kpi strong { font-size: 1.6rem; line-height: 1.2; }
.kpi span { font-weight: 600; }
.kpi small { color: var(--muted); }
.streak { font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.streak.on { background: #ffedd5; color: #c2410c; }
:root[data-theme="dark"] .streak.on { background: #3b2410; color: #fdba74; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .streak.on { background: #3b2410; color: #fdba74; } }
.streak.big { font-size: 1.2rem; padding: 6px 14px; }
.hello { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero { text-align: center; padding: 26px 18px; }
.hero h2 { font-size: 1.4rem; }

/* ===== Karteikasten-Balken ============================================== */
.boxbar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin: 10px 0 4px; }
.boxbar .seg { height: 100%; }
.seg-new { background: var(--seg-new); }
.seg-1 { background: var(--seg-1); }
.seg-2 { background: var(--seg-2); }
.seg-3 { background: var(--seg-3); }
.seg-4 { background: var(--seg-4); }
.seg-5 { background: var(--seg-5); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.bar-ok { background: var(--ok); }
.legend i.bar-bad { background: var(--bad); }
.legend i.bar-time { background: var(--bar-time); }
.progress-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.progress-row:last-of-type { border-bottom: 0; }
.progress-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pill { display: inline-block; min-width: 26px; text-align: center; padding: 1px 8px; border-radius: 999px; font-size: .8rem; font-weight: 700; color: #fff; }
.pill.seg-new { color: var(--text); }

.meter-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; font-size: .9rem; }
.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok); }

/* ===== Diagramme ======================================================== */
.chart { width: 100%; height: auto; display: block; }
.chart .gridline {stroke: var(--border); stroke-width: 1; }
.chart { max-height: 320px; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar-ok { fill: var(--ok); }
.chart .bar-bad { fill: var(--bad); }
.chart .bar-time { fill: var(--bar-time); }
.chart .hit { fill: transparent; }
.chart g:hover .hit { fill: var(--surface-2); opacity: .5; }

/* ===== Abzeichen ======================================================== */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.badge {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  padding: 12px 8px; border-radius: 14px; background: var(--surface-2);
}
.badge.locked { opacity: .55; }
.badge.earned { background: var(--primary-soft); }
.badge-icon { font-size: 2rem; line-height: 1.2; }
.badge strong { font-size: .9rem; }
.badge small { font-size: .74rem; color: var(--muted); }
.new-badges { margin: 16px auto; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.pop { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.5); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }

/* ===== Übungsauswahl ==================================================== */
.mode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(125px, 1fr)); gap: 8px; }
.mode-card {
  position: relative; display: flex !important; flex-direction: column; gap: 2px !important;
  padding: 12px; border: 2px solid var(--border); border-radius: 14px; cursor: pointer; font-weight: 500 !important;
}
.mode-card input { position: absolute; opacity: 0; pointer-events: none; }
.mode-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.mode-card:has(input:focus-visible) { outline: 2px solid var(--primary); }
.mode-icon { font-size: 1.3rem; }
.mode-card small { color: var(--muted); font-size: .78rem; }

/* ===== Üben ============================================================= */
.page-practice .mainnav { display: none; }
.page-practice { padding-bottom: 24px; }
.practice { max-width: 560px; margin: 0 auto; }
.practice-top { display: flex; align-items: center; gap: 10px; }
.progress { flex: 1; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 999px; transition: width .3s; }
.loading { text-align: center; padding: 48px 0; color: var(--muted); font-size: 1.1rem; }
.question { text-align: center; padding: 22px 18px; }
.question.is-repeat { border-color: var(--near); }
.q-text { color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.prompt-wrap { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 20px; min-height: 3rem; }
.prompt { font-size: 2rem; font-weight: 800; line-height: 1.2; word-break: break-word; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 14px;
  font: inherit; font-size: 1.2rem; font-weight: 600; text-align: left; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: 14px; cursor: pointer;
  transition: transform .08s, border-color .1s, background .1s;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option:active:not(:disabled) { transform: scale(.98); }
.option:disabled { cursor: default; }
.opt-key {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; color: var(--muted);
}
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
.option.dim { opacity: .45; }
.answer-input { font-size: 1.3rem !important; text-align: center; padding: 14px !important; border-width: 2px !important; }
.answer-input.correct { border-color: var(--ok) !important; background: var(--ok-soft); }
.answer-input.wrong { border-color: var(--bad) !important; background: var(--bad-soft); animation: shake .35s; }
.typed { display: flex; flex-direction: column; gap: 10px; }
.special-chars { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.special-chars:empty { display: none; }
.char {
  min-width: 42px; height: 42px; font: inherit; font-size: 1.15rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.feedback { margin-top: 16px; padding: 14px; border-radius: 14px; text-align: center; }
.feedback p { margin: 4px 0; }
.st-correct .feedback { background: var(--ok-soft); }
.st-near .feedback { background: var(--near-soft); }
.st-wrong .feedback { background: var(--bad-soft); }
.fb-title { font-size: 1.3rem; font-weight: 800; }
.fb-answer { font-size: 1.15rem; }
.fb-note { font-size: .95rem; }
.feedback .btn { margin-top: 8px; }
.next { margin-top: 14px; }
.summary { padding: 28px 18px; }
.summary-emoji { font-size: 4rem; line-height: 1.1; margin: 0; }
.summary-score { font-size: 1.5rem; font-weight: 800; margin: 6px 0; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
