/* Vokabeltrainer – mobile first, Hell/Dunkel über prefers-color-scheme. */

:root {
  color-scheme: light dark;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #efede7;
  --ink: #1f1f22;
  --ink-2: #4a4a52;
  --muted: #74747c;
  --line: #e0ddd5;
  --accent: #d9530b;
  --accent-ink: #ffffff;
  --accent-soft: #fde6d6;
  --ok: #217a36;
  --ok-soft: #dcf2e1;
  --bad: #b42323;
  --bad-soft: #fbe1e1;
  --warn: #9a5b00;
  --warn-soft: #fbedd0;
  /* Sequenzielle Stufen (Fach 0 → 5), ein Farbton hell → dunkel */
  --seq-0: #fbd9c0;
  --seq-1: #f6b78b;
  --seq-2: #ee935a;
  --seq-3: #dd6f2c;
  --seq-4: #b9531a;
  --seq-5: #8a3a0f;
  --heat-none: #e7e4dc;
  --heat-active: #f6c7a4;
  --heat-freeze: #8fb3d9;
  --heat-goal: #d9530b;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1f1f23;
    --surface-2: #2a2a2f;
    --ink: #ececf0;
    --ink-2: #c4c4cc;
    --muted: #9a9aa3;
    --line: #34343b;
    --accent: #ff8a3d;
    --accent-ink: #1a0d04;
    --accent-soft: #3d2414;
    --ok: #5ccb73;
    --ok-soft: #173a21;
    --bad: #ff7b7b;
    --bad-soft: #3e1a1a;
    --warn: #f2b84b;
    --warn-soft: #3a2c10;
    --seq-0: #4a2a16;
    --seq-1: #6e3a17;
    --seq-2: #9a4f1c;
    --seq-3: #c96826;
    --seq-4: #ee8a45;
    --seq-5: #ffb37d;
    --heat-none: #2a2a2f;
    --heat-active: #5a3a24;
    --heat-freeze: #3f6690;
    --heat-goal: #ff8a3d;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  min-height: 100dvh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Layout ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700; text-decoration: none; color: var(--ink);
  white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.brand-mark {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 800;
}
#hud { flex: 1; display: flex; justify-content: flex-end; align-items: center; gap: 10px; min-width: 0; }
.topnav { display: flex; gap: 4px; }
.in-session .topnav, .in-session #hud { display: none; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

#banner {
  background: var(--warn-soft); color: var(--warn);
  padding: 10px 16px; font-size: .9rem; text-align: center;
  border-bottom: 1px solid var(--line);
}

/* ---------- Buttons & Controls ---------- */

.btn {
  appearance: none; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.btn.bad { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink);
  width: 44px; height: 44px; border-radius: 10px; font-size: 1.25rem;
  display: inline-grid; place-items: center; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

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

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  text-align: center; padding: 10px 6px; border-radius: 9px; cursor: pointer;
  font-weight: 600; font-size: .92rem; color: var(--ink-2); min-height: 44px;
  display: grid; place-items: center;
}
.segmented input:checked + label { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 3px solid var(--accent); }

select, input[type="text"], input[type="number"] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 8px 10px;
  max-width: 100%;
}

.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field label { flex: 1; }
.switch { width: 22px; height: 22px; accent-color: var(--accent); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; flex: 1; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

.hint {
  background: var(--accent-soft); border-radius: 10px; padding: 10px 12px;
  font-size: .88rem; color: var(--ink-2); margin: 12px 0 0;
}

/* ---------- HUD ---------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .85rem; font-weight: 700; white-space: nowrap;
}
.level-chip { flex-direction: column; align-items: stretch; gap: 3px; min-width: 64px; }
.level-chip .bar { height: 4px; flex: none; }

/* ---------- Start ---------- */

.today { display: flex; align-items: center; gap: 16px; }
.ring { width: 84px; height: 84px; flex: none; }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--surface-2); }
.ring .value { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s; }
.ring text { font: 700 15px var(--font); fill: var(--ink); }
.today-stats { flex: 1; min-width: 0; }
.today-stats .big { font-size: 1.15rem; font-weight: 700; }

.group-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 6px; }
.group-head h3 { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: .8rem; }

.lesson {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px;
}
.lesson.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.lesson.failed { opacity: .55; }
.lesson > label { flex: 1; display: flex; gap: 12px; cursor: pointer; min-width: 0; }
.lesson input[type="checkbox"] { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.lesson-main { flex: 1; min-width: 0; }
.lesson-title { font-weight: 700; }
.lesson-desc { font-size: .85rem; color: var(--muted); }
.lesson-meta { font-size: .82rem; color: var(--ink-2); margin: 4px 0 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  display: inline-block; font-size: .75rem; font-weight: 700;
  padding: 1px 8px; border-radius: 99px; background: var(--accent); color: var(--accent-ink);
}
.pill.soft { background: var(--surface-2); color: var(--ink-2); }
.rank { font-size: 1rem; }

.start-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.start-bar-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
.start-bar .summary { flex: 1; font-size: .85rem; color: var(--ink-2); min-width: 0; }
.notice { color: var(--warn); font-size: .85rem; }

/* ---------- Abfrage ---------- */

.session-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.session-top .count { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
.combo {
  text-align: center; font-weight: 800; color: var(--accent);
  margin: -4px 0 8px; font-size: .95rem; height: 1.4em;
}
.qcard {
  background: var(--surface); border: 2px solid var(--line); border-radius: 18px;
  padding: 18px 16px 22px; text-align: center; box-shadow: var(--shadow);
  position: relative; transition: border-color .2s, background-color .2s;
}
.qmeta { display: flex; justify-content: space-between; gap: 8px; font-size: .78rem; color: var(--muted); margin-bottom: 10px; }
.qword { font-size: clamp(1.5rem, 7vw, 2.1rem); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.qalts { color: var(--ink-2); margin-top: 6px; }
.qnote { font-size: .88rem; color: var(--muted); margin-top: 10px; }
.qcard.correct, .qcard.typo { border-color: var(--ok); background: var(--ok-soft); }
.qcard.partial { border-color: var(--warn); background: var(--warn-soft); }
.qcard.wrong { border-color: var(--bad); background: var(--bad-soft); }
.qcard.pulse { animation: pulse .5s ease-out; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}
.xp-float {
  position: absolute; right: 16px; top: 10px; font-weight: 800; color: var(--ok);
  animation: float 1.1s ease-out forwards; pointer-events: none;
}
@keyframes float { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-36px); } }

.answer-form { display: flex; gap: 8px; margin-top: 14px; }
.answer-form input {
  flex: 1; min-width: 0; font-size: 1.15rem; min-height: 52px; padding: 10px 14px; border-radius: 12px;
  border: 2px solid var(--line);
}
.answer-form input:focus { border-color: var(--accent); outline: none; }
.answer-form input[readonly] { background: var(--surface-2); }

.feedback { margin-top: 14px; }
.feedback .verdict { font-weight: 800; font-size: 1.05rem; margin-bottom: 4px; }
.feedback .verdict.ok { color: var(--ok); }
.feedback .verdict.bad { color: var(--bad); }
.feedback .verdict.warn { color: var(--warn); }
.solution { font-size: 1.2rem; font-weight: 700; }
.solution mark { background: var(--warn-soft); color: var(--warn); border-radius: 3px; padding: 0 1px; text-decoration: underline; }
.your-answer { color: var(--muted); text-decoration: line-through; }

/* Karteikarte */
.flipcard { perspective: 1200px; cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.flip-inner {
  display: grid; transition: transform .45s cubic-bezier(.2, .7, .3, 1);
  transform-style: preserve-3d; position: relative;
}
.flipcard.flipped .flip-inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border: 2px solid var(--line); border-radius: 20px;
  position: relative; min-height: 240px; padding: 40px 16px 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: center; text-align: center;
}
.face .qmeta { position: absolute; top: 14px; left: 16px; right: 16px; }
.face.back { transform: rotateY(180deg); border-color: var(--accent); }
.face .tap-hint { font-size: .8rem; color: var(--muted); margin-top: 16px; }
.flipcard.drag-right .face.back { border-color: var(--ok); background: var(--ok-soft); }
.flipcard.drag-left .face.back { border-color: var(--bad); background: var(--bad-soft); }
.rate { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.rate .btn { min-height: 56px; }
.keys-hint { text-align: center; font-size: .78rem; color: var(--muted); margin-top: 14px; }

/* Multiple Choice */
.options { display: grid; gap: 8px; margin-top: 14px; }
.option { justify-content: flex-start; text-align: left; font-weight: 600; min-height: 54px; }
.option .key {
  display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 7px; font-size: .8rem;
  background: var(--surface-2); color: var(--muted);
}
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.chosen-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.dim { opacity: .55; }
.option[aria-disabled="true"] { cursor: default; }
@media (min-width: 560px) { .options { grid-template-columns: 1fr 1fr; } }

/* ---------- Sitzungsende ---------- */

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.tile .num { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .lbl { font-size: .75rem; color: var(--muted); }
.events { list-style: none; padding: 0; margin: 0; }
.events li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.events li:last-child { border-bottom: 0; }
.events .ico { font-size: 1.4rem; width: 32px; text-align: center; }
.wordlist { list-style: none; padding: 0; margin: 0; }
.wordlist li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.wordlist li:last-child { border-bottom: 0; }
.wordlist .sol { font-weight: 700; text-align: right; }
.actions { display: grid; gap: 8px; margin-top: 14px; }

/* ---------- Vokabelliste ---------- */

.vtable { width: 100%; border-collapse: collapse; table-layout: fixed; }
.vtable th { text-align: left; font-size: .8rem; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--line); }
.vtable td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.vtable td small { display: block; color: var(--muted); }
.vtable tr { cursor: default; }
.cover-de .vtable tr, .cover-nl .vtable tr { cursor: pointer; }
.cover-de td.de:not(.shown) > *, .cover-nl td.nl:not(.shown) > * { visibility: hidden; }
.cover-de td.de:not(.shown), .cover-nl td.nl:not(.shown) {
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, transparent 6px 12px);
  border-radius: 6px;
}

/* ---------- Statistik ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--ink-2); margin: 6px 0 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.dist { margin-bottom: 12px; }
.dist-label { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.stacked { display: flex; height: 16px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface); }
.stacked > span { display: block; height: 100%; min-width: 2px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font: 11px var(--font); fill: var(--muted); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, auto); grid-auto-columns: 1fr; gap: 3px; max-width: 360px; }
.heatmap span { aspect-ratio: 1; border-radius: 3px; background: var(--heat-none); }
.heatmap span.active { background: var(--heat-active); }
.heatmap span.freeze { background: var(--heat-freeze); }
.heatmap span.goal { background: var(--heat-goal); }
.heatmap span.future { background: transparent; }
.heatmap span.today { outline: 2px solid var(--ink); outline-offset: -1px; }
details summary { cursor: pointer; font-size: .85rem; color: var(--muted); margin-top: 8px; }
.datatable { width: 100%; border-collapse: collapse; font-size: .82rem; margin-top: 6px; }
.datatable th, .datatable td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.datatable th:first-child, .datatable td:first-child { text-align: left; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.badge { border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.badge .ico { font-size: 1.8rem; }
.badge .t { font-weight: 700; font-size: .9rem; }
.badge .d { font-size: .75rem; color: var(--muted); }
.badge.locked { opacity: .45; filter: grayscale(1); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

@media (min-width: 560px) {
  .actions { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

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