:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --ink: #1d2433;
  --ink-2: #4a5468;
  --ink-3: #7c879c;
  --line: #dfe4ee;
  --primary: #4b6bfb;
  --primary-ink: #ffffff;
  --primary-soft: #e3e9ff;
  --ok: #1fa463;
  --ok-soft: #dcf5e8;
  --warn: #d98a00;
  --warn-soft: #fff1d6;
  --bad: #e5484d;
  --bad-soft: #fde4e4;
  --flame: #ff7a1a;
  --gold: #f5b400;
  /* Sequenzielle Skala (eine Farbe hell -> dunkel) für Kisten und Kalender */
  --seq-0: #e9edf5;
  --seq-1: #d5defe;
  --seq-2: #aebffd;
  --seq-3: #8aa1fc;
  --seq-4: #6684fb;
  --seq-5: #4b6bfb;
  --seq-6: #2a45c9;
  --shadow: 0 2px 0 rgba(29, 36, 51, .06), 0 6px 18px rgba(29, 36, 51, .06);
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151f;
    --surface: #1a2030;
    --surface-2: #232b3e;
    --ink: #eef1f8;
    --ink-2: #b9c1d3;
    --ink-3: #8691a8;
    --line: #2c354a;
    --primary: #7b93ff;
    --primary-ink: #0f1424;
    --primary-soft: #26305a;
    --ok: #3fcf84;
    --ok-soft: #173a2a;
    --warn: #f2b23c;
    --warn-soft: #3a2f16;
    --bad: #ff6b6f;
    --bad-soft: #3d1f22;
    --seq-0: #232b3e;
    --seq-1: #2b3866;
    --seq-2: #354a8f;
    --seq-3: #4560b8;
    --seq-4: #5d7ae0;
    --seq-5: #7b93ff;
    --seq-6: #a9b9ff;
    --shadow: 0 2px 0 rgba(0, 0, 0, .25), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Layout */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.page.narrow { max-width: 440px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card.tap { cursor: pointer; transition: transform .1s; }
.card.tap:active { transform: scale(.98); }

/* Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; min-height: 44px;
}
.topbar h1 { margin: 0; font-size: 1.35rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-weight: 700; box-shadow: var(--shadow); white-space: nowrap;
}
.chip.flame { color: var(--flame); }
.chip.gold { color: var(--gold); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  background: var(--surface-2); color: var(--ink-2);
}
.badge.test { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 12px 18px; min-height: 48px;
  background: var(--surface-2); color: var(--ink); font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  transition: transform .08s, box-shadow .08s, filter .15s;
  text-decoration: none;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 4px 0 color-mix(in srgb, var(--primary) 60%, #000); }
.btn.ok { background: var(--ok); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--ok) 60%, #000); }
.btn.bad { background: var(--bad); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--bad) 60%, #000); }
.btn.warn { background: var(--warn); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--warn) 60%, #000); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 1.2rem; border-radius: 18px; }
.btn.round { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: 1.3rem;
  width: 44px; height: 44px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--surface-2); }

/* Formulare */
label.field { display: block; }
label.field > span { display: block; font-weight: 700; margin-bottom: 6px; font-size: .95rem; }
input[type=text], input[type=password], input[type=date], input[type=number], input:not([type]), select, textarea {
  width: 100%; border: 2px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 12px 14px; outline: none; min-height: 48px; font-size: 1rem;
}
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: .9rem; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.hint { font-size: .85rem; color: var(--ink-3); margin-top: 4px; }
.error { color: var(--bad); font-weight: 700; min-height: 1.2em; }

/* Untere Navigation */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { display: flex; width: 100%; max-width: 720px; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 10px; text-decoration: none; color: var(--ink-3); font-size: .75rem; font-weight: 700;
}
.nav a .ico { font-size: 1.4rem; filter: grayscale(1); opacity: .7; }
.nav a.active { color: var(--primary); }
.nav a.active .ico { filter: none; opacity: 1; }

/* Profilauswahl */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.profile {
  background: var(--surface); border: 0; border-radius: 22px; padding: 18px 10px; cursor: pointer;
  box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: transform .1s;
}
.profile:active { transform: scale(.96); }
.profile .av { font-size: 3.4rem; line-height: 1; }
.profile .nm { font-weight: 800; font-size: 1.05rem; }
.profile .rl { font-size: .78rem; color: var(--ink-3); }

.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 280px; margin: 0 auto; }
.pinpad button { min-height: 62px; font-size: 1.5rem; }
.pindots { display: flex; justify-content: center; gap: 12px; margin: 14px 0 18px; min-height: 18px; }
.pindots i { width: 16px; height: 16px; border-radius: 50%; background: var(--line); }
.pindots i.on { background: var(--primary); }
.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-8px) } 75% { transform: translateX(8px) } }

/* Startseite */
.hello { display: flex; align-items: center; gap: 12px; }
.hello .av { font-size: 2.6rem; }
.goal { display: flex; align-items: center; gap: 18px; }
.ring { width: 110px; height: 110px; flex-shrink: 0; }
.ring circle { fill: none; stroke-width: 12; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset .8s; }
.ring text { font-weight: 800; fill: var(--ink); font-family: var(--font); }
.start-btn { flex-direction: column; gap: 2px; padding: 16px; }
.start-btn small { font-weight: 600; opacity: .85; font-size: .9rem; }

.boxes { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; }
.boxcol { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.boxcol .bar { width: 100%; max-width: 34px; border-radius: 4px 4px 0 0; min-height: 3px; }
.boxcol .n { font-weight: 800; font-size: .85rem; }
.boxcol .lb { font-size: .7rem; color: var(--ink-3); text-align: center; }
.boxes-wrap { height: 120px; display: flex; align-items: end; }

/* Lektionspfad */
.path { display: flex; flex-direction: column; gap: 10px; }
.node { display: flex; align-items: center; gap: 14px; }
.node .dot {
  width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.7rem;
  background: conic-gradient(var(--ok) calc(var(--p) * 1%), var(--surface-2) 0);
  position: relative;
}
.node .dot::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--surface); }
.node .dot span { position: relative; z-index: 1; }
.node .stars { color: var(--gold); letter-spacing: 1px; font-size: .9rem; }
.node:nth-child(4n+2) { padding-left: 28px; }
.node:nth-child(4n+3) { padding-left: 56px; }
.node:nth-child(4n+4) { padding-left: 28px; }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); border-radius: 999px; transition: width .5s; }

/* Vokabelliste */
.vlist { display: flex; flex-direction: column; }
.vrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.vrow:last-child { border-bottom: 0; }
.vrow .em { width: 34px; font-size: 1.5rem; text-align: center; flex-shrink: 0; }
.vrow .tx { flex: 1; min-width: 0; }
.vrow .en { font-weight: 800; }
.vrow .de { color: var(--ink-2); font-size: .95rem; }
.vrow .ex { color: var(--ink-3); font-size: .8rem; font-style: italic; }
.lvl { display: flex; gap: 3px; }
.lvl i { width: 7px; height: 16px; border-radius: 3px; background: var(--seq-0); }
.lvl i.on { background: var(--seq-5); }

/* Training */
.train { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 10px) 16px calc(env(safe-area-inset-bottom) + 12px); }
.train-top { display: flex; align-items: center; gap: 10px; }
.train-top .progress { flex: 1; height: 14px; }
.train-body { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 18px 0; }
.instr { font-weight: 800; color: var(--ink-2); font-size: 1.05rem; margin-bottom: 10px; }
.prompt { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.prompt .em { font-size: 3rem; }
.prompt .word { font-size: 1.9rem; font-weight: 800; word-break: break-word; }
.options { display: grid; gap: 12px; }
.option {
  border: 2px solid var(--line); border-bottom-width: 4px; background: var(--surface); border-radius: 16px;
  padding: 16px; min-height: 60px; font-size: 1.15rem; font-weight: 700; cursor: pointer; text-align: left;
}
.option:active { transform: translateY(2px); }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; }
.speak-big {
  width: 120px; height: 120px; border-radius: 50%; border: 0; cursor: pointer; font-size: 3.2rem;
  background: var(--primary); color: var(--primary-ink); box-shadow: 0 6px 0 color-mix(in srgb, var(--primary) 60%, #000);
  margin: 0 auto 12px; display: flex; align-items: center; justify-content: center;
}
.speak-big:active { transform: translateY(3px); box-shadow: 0 3px 0 color-mix(in srgb, var(--primary) 60%, #000); }
.answer-input { font-size: 1.4rem !important; min-height: 60px !important; text-align: center; font-weight: 700; }
.intro { text-align: center; }
.intro .em { font-size: 5rem; line-height: 1.1; }
.intro .en { font-size: 2.3rem; font-weight: 800; }
.intro .de { font-size: 1.4rem; color: var(--ink-2); margin-top: 6px; }
.intro .ex { font-style: italic; color: var(--ink-3); margin-top: 16px; }
.new-tag { display: inline-block; background: var(--gold); color: #3a2a00; border-radius: 999px; padding: 4px 14px; font-weight: 800; margin-bottom: 14px; }

.slots {
  min-height: 80px; border-bottom: 3px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center; justify-content: center; padding: 8px 0 12px; margin-bottom: 18px;
}
.tiles { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tile {
  min-width: 46px; min-height: 52px; padding: 6px 12px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); border-bottom-width: 4px; background: var(--surface);
  font-size: 1.35rem; font-weight: 800;
}
.tile.used { visibility: hidden; }

.feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: up .2s ease-out;
}
.feedback .inner { max-width: 640px; margin: 0 auto; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.almost { background: var(--warn-soft); color: var(--warn); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback h2 { margin: 0 0 4px; }
.feedback .sol { color: var(--ink); font-size: 1.1rem; margin-bottom: 12px; }
@keyframes up { from { transform: translateY(100%) } to { transform: translateY(0) } }

.summary { text-align: center; }
.summary .trophy { font-size: 5rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpis.three { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpis.three .kpi { padding: 10px; }
.kpis.three .v { font-size: 1.3rem; }
.kpi { background: var(--surface); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.kpi .v { font-size: 1.6rem; font-weight: 800; }
.kpi .l { font-size: .8rem; color: var(--ink-3); font-weight: 700; }

/* Statistik */
.heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heat .cell { aspect-ratio: 1; border-radius: 6px; background: var(--seq-0); position: relative; }
.heat .cell.today { outline: 2px solid var(--ink-3); outline-offset: 1px; }
.heat .wd { font-size: .7rem; color: var(--ink-3); text-align: center; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .78rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.stack-bar { display: flex; height: 22px; gap: 2px; border-radius: 4px; overflow: hidden; }
.stack-bar > div { min-width: 2px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 48px; gap: 8px; align-items: center; margin: 6px 0; font-size: .9rem; }
.hbar .track { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .track > div { height: 100%; background: var(--seq-5); border-radius: 0 4px 4px 0; }
.week { display: flex; gap: 4px; align-items: end; height: 44px; }
.week > div { flex: 1; background: var(--seq-5); border-radius: 4px 4px 0 0; min-height: 3px; }
.week > div.zero { background: var(--seq-0); }
table.simple { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.simple td, table.simple th { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
table.simple th { font-size: .78rem; color: var(--ink-3); }

/* Modal + Toast */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10, 14, 25, .5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s;
}
.modal {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  border-radius: 24px 24px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .2s ease-out;
}
@media (min-width: 700px) {
  .modal-bg { align-items: center; }
  .modal { border-radius: 24px; }
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60;
  font-weight: 700; box-shadow: var(--shadow); animation: fade .2s; max-width: 90vw; text-align: center;
}
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.avatars button { font-size: 1.7rem; height: 52px; border-radius: 12px; border: 2px solid transparent; background: var(--surface); cursor: pointer; }
.avatars button.sel { border-color: var(--primary); background: var(--primary-soft); }
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 10px 6px; font-weight: 700; cursor: pointer; font-size: .9rem; }
.seg button.sel { background: var(--surface); box-shadow: var(--shadow); color: var(--primary); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti span { position: absolute; top: -40px; font-size: 1.6rem; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

.loading { display: flex; align-items: center; justify-content: center; min-height: 60dvh; font-size: 2.5rem; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .4; transform: scale(.95) } to { opacity: 1; transform: scale(1.05) } }
.logo { font-size: 4rem; text-align: center; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-3); }
.empty .big { font-size: 3rem; }

/* Foto-Import: erkannte Zeilen prüfen */
.ocr-rows { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.ocr-row { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 6px; align-items: center;
  padding: 6px; border-radius: 12px; background: var(--surface-2); }
.ocr-row input { min-height: 42px !important; padding: 8px 10px !important; font-size: .95rem !important; }
.ocr-row input.ex { grid-column: 1 / 3; font-style: italic; }
.ocr-row.incomplete { background: var(--warn-soft); }

.heat2 { display: grid; gap: 4px; align-items: center; }
.heat2 .wdl { font-size: .8rem; color: var(--ink-2); font-weight: 700; }
.heat2 .cell { height: 24px; border-radius: 6px; background: var(--seq-0); }
.heat2 .cell.today { outline: 2px solid var(--ink-3); outline-offset: 1px; }

/* Sprechübung */
.mic-btn {
  --lvl: 0;
  width: 132px; height: 132px; border-radius: 50%; border: 0; cursor: pointer; font-size: 3.4rem;
  background: var(--primary); color: var(--primary-ink); margin: 6px auto 14px; display: flex;
  align-items: center; justify-content: center;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--primary) 60%, #000);
  transition: transform .1s;
}
.mic-btn:active { transform: translateY(3px); }
.mic-btn.rec {
  background: var(--bad);
  box-shadow: 0 0 0 calc(10px + var(--lvl) * 26px) color-mix(in srgb, var(--bad) 25%, transparent), 0 6px 0 color-mix(in srgb, var(--bad) 60%, #000);
}
.mic-btn.busy { opacity: .6; animation: pulse 1s infinite alternate; }
.mic-state { font-weight: 700; color: var(--ink-2); min-height: 2.6em; }
.feedback .heard { color: var(--ink-2); font-size: .95rem; margin-bottom: 4px; }
