/* LearningApp – Mischung aus "Fokus" (große Typo, Wischen) und "Tipp-Trainer" (Eingabe, Fortschritt).
   Farben nur über Tokens. Dunkel = Tinte/Bernstein, Hell = Papierweiß/Tinte. */
@font-face { font-family: "Bricolage"; src: url("../fonts/bricolage.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "InterVar"; src: url("../fonts/inter.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eaf0f2;
  --ink: #0f2430;
  --muted: #587080;
  --line: #d9e3e7;
  --accent: #f0a12c;          /* Flächen */
  --accent-ink: #8a5300;      /* Text in Akzentfarbe */
  --on-accent: #1d1300;
  --good: #23864f;
  --good-bg: #e5f5ec;
  --bad: #c9473a;
  --bad-bg: #fbe9e6;
  --warn: #8a5a00;
  --warn-bg: #fff2d6;
  --shadow: 0 1px 2px rgba(15, 36, 48, .06), 0 8px 24px -12px rgba(15, 36, 48, .18);
  --f-display: "Bricolage", "Segoe UI", system-ui, sans-serif;
  --f-body: "InterVar", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d212c; --surface: #143040; --surface-2: #1a3a4b; --ink: #eaf2f5; --muted: #8fb0bd; --line: #24475a;
    --accent: #ffb547; --accent-ink: #ffc670; --on-accent: #1d1300;
    --good: #5fd08f; --good-bg: #133a2d; --bad: #ff7a6b; --bad-bg: #3d2226; --warn: #ffcf70; --warn-bg: #3a3020;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -12px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d212c; --surface: #143040; --surface-2: #1a3a4b; --ink: #eaf2f5; --muted: #8fb0bd; --line: #24475a;
  --accent: #ffb547; --accent-ink: #ffc670; --on-accent: #1d1300;
  --good: #5fd08f; --good-bg: #133a2d; --bad: #ff7a6b; --bad-bg: #3d2226; --warn: #ffcf70; --warn-bg: #3a3020;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -12px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.1; margin: 0; text-wrap: balance; }

#app { min-height: 100%; }
.page {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 32px) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 20px;
}

/* --- Kopfzeile --- */
.bar { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.bar h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--muted); flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 650; font-size: 16px;
  background: var(--surface-2); color: var(--ink); min-height: 48px; text-decoration: none;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.good { background: var(--good); color: var(--surface); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn:active:not(:disabled) { transform: scale(.98); }

/* --- Stapel-Karten auf der Startseite --- */
.deck {
  background: var(--surface); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; border: 0; text-align: left; width: 100%;
}
.deck-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.deck-name { font-family: var(--f-display); font-weight: 700; font-size: 20px; }
.deck-sub { color: var(--muted); font-size: 14px; }
.due { text-align: right; flex: none; }
.due b { display: block; font-family: var(--f-display); font-size: 32px; font-weight: 800; line-height: 1; color: var(--accent-ink); }
.due span { font-size: 12px; color: var(--muted); }
.due.zero b { color: var(--muted); }

.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.boxes > div { display: flex; flex-direction: column; gap: 4px; }
.boxes i { display: block; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.boxes i b { display: block; height: 100%; background: var(--accent); }
.boxes span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--muted); padding: 32px 12px; display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* --- Statistik --- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.stat b { display: block; font-family: var(--f-display); font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.panel { background: var(--surface); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.field { display: flex; flex-direction: column; gap: 6px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.links { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.links a, .links button {
  display: flex; align-items: center; gap: 12px; padding: 15px 18px; text-decoration: none; color: var(--ink);
  border: 0; background: none; text-align: left; border-bottom: 1px solid var(--line); font-weight: 550;
}
.links > :last-child { border-bottom: 0; }
.links .chev { margin-left: auto; color: var(--muted); }
.links svg { width: 20px; height: 20px; color: var(--muted); }

/* --- Formulare --- */
.input, textarea, select {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 16px;
}
.input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 200px; resize: vertical; font-family: var(--f-mono); font-size: 14px; line-height: 1.6; }
.hint { font-size: 13px; color: var(--muted); }

/* --- Wortliste --- */
.list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; width: 100%; }
.row:last-child { border-bottom: 0; }
.row .txt { flex: 1; min-width: 0; }
.row .front { font-weight: 650; overflow-wrap: anywhere; }
.row .back { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.pill.new { background: var(--good-bg); color: var(--good); }
.pill.update { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--bad-bg); color: var(--bad); }

/* --- Bottom-Sheet / Dialog --- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 15, 20, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; max-height: 92%; overflow-y: auto;
  padding: 20px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 20px) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 16px; animation: up .2s ease-out;
}
.sheet h2 { font-size: 22px; }
.sheet .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 60;
  box-shadow: var(--shadow); animation: up .2s; max-width: calc(100% - 32px);
}

/* ================= Lernen ================= */
.learn {
  height: 100%; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px));
}
body.learning { overflow: hidden; }
body.learning #app { height: 100%; }
.learn-top { display: flex; align-items: center; gap: 10px; }
.progress { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s ease; }
.count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }

.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; position: relative; min-height: 0; }
/* Tipp-Modus: Karte oben, damit sie über der Bildschirmtastatur sichtbar bleibt */
.learn.type .stage { justify-content: flex-start; padding-top: min(10vh, 72px); }
.qcard {
  position: relative; padding: 8px 4px; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  transition: transform .25s ease, opacity .25s ease;
}
.qcard.dragging { transition: none; }
.qdir { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 650; display: flex; align-items: center; gap: 8px; }
.qword {
  font-family: var(--f-display); font-weight: 800; letter-spacing: -.025em; line-height: 1.02;
  font-size: clamp(36px, 11vw, 56px); margin-top: 10px; overflow-wrap: anywhere;
}
.qword.long { font-size: clamp(26px, 7vw, 36px); line-height: 1.15; letter-spacing: -.01em; }
.qword.xlong { font-size: clamp(20px, 5.4vw, 26px); line-height: 1.25; letter-spacing: 0; font-weight: 700; }
.qnote { color: var(--muted); font-size: 14px; margin-top: 8px; }
.answers { margin-top: 22px; display: flex; flex-direction: column; gap: 6px; }
.answers .a1 { font-family: var(--f-display); font-size: 26px; font-weight: 600; color: var(--accent-ink); overflow-wrap: anywhere; line-height: 1.2; }
.answers .an { font-size: 18px; color: var(--ink); opacity: .8; overflow-wrap: anywhere; }
.tap-hint { margin-top: 26px; color: var(--muted); font-size: 14px; }
.speak { width: 32px; height: 32px; border-radius: 8px; border: 0; background: var(--surface-2); color: var(--muted); display: inline-grid; place-items: center; }
.speak svg { width: 16px; height: 16px; }

.stamp {
  position: absolute; top: 4px; padding: 4px 10px; border: 3px solid; border-radius: 6px; font-weight: 800; font-size: 18px;
  letter-spacing: .08em; opacity: 0; pointer-events: none; font-family: var(--f-body);
}
.stamp.ok { left: 0; color: var(--good); transform: rotate(-12deg); }
.stamp.no { right: 0; color: var(--bad); transform: rotate(12deg); }

.grade { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grade .btn { min-height: 56px; font-size: 16px; }
.grade .no { background: var(--bad-bg); color: var(--bad); }
.grade .ok { background: var(--good); color: var(--surface); }
.swipe-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Tipp-Modus */
.type-form { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
.type-input {
  width: 100%; font-size: 20px; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface);
}
.type-input:focus { outline: none; border-color: var(--accent); }
.type-input.correct { border-color: var(--good); background: var(--good-bg); }
.type-input.typo { border-color: var(--warn); background: var(--warn-bg); }
.type-input.wrong { border-color: var(--bad); background: var(--bad-bg); }
.type-meta { font-size: 13px; color: var(--muted); }
.type-actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; }

.feedback { border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 8px; animation: up .18s ease-out; }
.feedback.correct { background: var(--good-bg); }
.feedback.typo { background: var(--warn-bg); }
.feedback.wrong { background: var(--bad-bg); }
.feedback .verdict { font-family: var(--f-display); font-weight: 800; font-size: 20px; }
.feedback.correct .verdict { color: var(--good); }
.feedback.typo .verdict { color: var(--warn); }
.feedback.wrong .verdict { color: var(--bad); }
.feedback p { margin: 0; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { background: var(--surface); border-radius: 99px; padding: 5px 11px; font-size: 14px; }
.chips span.hit { outline: 2px solid currentColor; font-weight: 650; }
.fb-actions { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 4px; }
.fb-actions.two { grid-template-columns: auto 1fr; }

/* Zusammenfassung */
.summary-big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-big .stat b { font-size: 36px; }
.summary-big .ok b { color: var(--good); }
.summary-big .no b { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 700px) {
  .page { padding-top: 40px; }
}

/* --- Ergänzungen: Konten, Lernstand je Richtung --- */
.boxes { grid-template-columns: repeat(6, 1fr); }
.boxes i b.new { background: var(--muted); opacity: .45; }
.boxes span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pills { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex: none; }
.mono { font-family: var(--f-mono); letter-spacing: .02em; }
.links button:disabled { opacity: .5; cursor: default; }
.auth-page { min-height: 100%; justify-content: center; max-width: 420px; }
.auth-head { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
.auth-head img { border-radius: 14px; }
.auth-head h1 { font-size: 36px; font-weight: 800; letter-spacing: -.02em; }
.invite-code {
  font-size: 30px; font-weight: 700; text-align: center; padding: 18px; border-radius: 14px;
  background: var(--surface); border: 2px dashed var(--accent); color: var(--ink);
}
.qdir .pill { letter-spacing: 0; text-transform: none; }
@media (max-width: 520px) {
  .boxes { grid-template-columns: repeat(3, 1fr); row-gap: 10px; column-gap: 8px; }
}

/* --- Offline-Statusleiste --- */
#netbar {
  position: sticky; top: 0; z-index: 40;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
  font-size: 13px; font-weight: 600; text-align: center;
  background: var(--surface-2); color: var(--muted);
}
#netbar.offline { background: var(--warn-bg); color: var(--warn); }
body.learning { display: flex; flex-direction: column; }
body.learning #app { flex: 1; min-height: 0; }

/* --- Auswahl-Modus --- */
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  min-height: 54px; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); font-size: 17px; font-weight: 550; overflow-wrap: anywhere;
}
.choice:active:not(:disabled) { transform: scale(.99); }
.choice-key {
  flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.choice.correct { border-color: var(--good); background: var(--good-bg); }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice:disabled { cursor: default; color: var(--ink); }
.choice:disabled:not(.correct):not(.wrong) { opacity: .55; }
.pill.hard { background: var(--bad-bg); color: var(--bad); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--muted); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* --- Statistik ---
   Eine Farbe (Bernstein) in Stufen für Mengen; Stufe 0 = Fläche. Dunkel eigene Stufen. */
:root { --heat-0: var(--surface-2); --heat-1: #fbe3b8; --heat-2: #f6c06a; --heat-3: #e08e12; --heat-4: #9a5b00; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --heat-1: #4b3a1c; --heat-2: #7f5c20; --heat-3: #c48a2c; --heat-4: #ffc670; } }
:root[data-theme="dark"] { --heat-1: #4b3a1c; --heat-2: #7f5c20; --heat-3: #c48a2c; --heat-4: #ffc670; }

.stats-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 480px) { .stats-4 { grid-template-columns: repeat(2, 1fr); } }
.chart { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.chart-title { font-size: 18px; font-weight: 700; }
.chart-scroll { overflow-x: auto; margin-inline: -4px; padding-inline: 4px; }
.cal { display: block; max-width: none; }
.cal text, .bars text { fill: var(--muted); font: 10px var(--f-body); }
.cal rect { stroke: var(--surface); stroke-width: 0; }
.cal rect.active { stroke: var(--ink); stroke-width: 1.5px; }
.cal .heat-0, .heat-legend .heat-0 { fill: var(--heat-0); background: var(--heat-0); }
.cal .heat-1, .heat-legend .heat-1 { fill: var(--heat-1); background: var(--heat-1); }
.cal .heat-2, .heat-legend .heat-2 { fill: var(--heat-2); background: var(--heat-2); }
.cal .heat-3, .heat-legend .heat-3 { fill: var(--heat-3); background: var(--heat-3); }
.cal .heat-4, .heat-legend .heat-4 { fill: var(--heat-4); background: var(--heat-4); }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: 11px; color: var(--muted); }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.bars { width: 100%; height: auto; display: block; }
.bars .grid { stroke: var(--line); stroke-width: 1; }
.bars .bar { fill: var(--heat-3); }
.bars .hit { fill: transparent; cursor: pointer; }
.bars .hit.active { fill: var(--ink); opacity: .06; }
.tip {
  position: absolute; transform: translate(-50%, -100%); pointer-events: none; z-index: 5;
  background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 600; padding: 6px 9px;
  border-radius: 8px; white-space: nowrap; box-shadow: var(--shadow);
}
.stackbar { display: flex; gap: 2px; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface); }
.stackbar i { display: block; min-width: 4px; }
.s3 { background: var(--heat-4); } .s2 { background: var(--heat-2); } .s0 { background: var(--heat-0); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--ink); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.table-wrap { overflow-x: auto; margin-top: 8px; max-height: 260px; overflow-y: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.table-wrap th, .table-wrap td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table-wrap th { color: var(--muted); font-weight: 600; font-size: 12px; }
.shared { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 var(--f-mono);
  background: var(--surface); border-radius: var(--r); padding: 14px 16px; max-height: 40vh; overflow-y: auto; }
.label-icon { display: inline-flex; align-items: center; gap: 8px; }
.label-icon svg { width: 16px; height: 16px; flex: none; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- Wörterbuch-Vorschläge --- */
.sugg { display: flex; flex-direction: column; gap: 8px; margin-top: -4px; }
.sugg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sugg-chip {
  display: inline-flex; align-items: baseline; gap: 6px; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 99px; padding: 6px 12px; font-size: 14px; font-weight: 550; min-height: 34px;
}
.sugg-chip small { font-size: 11px; font-weight: 500; color: var(--muted); }
.sugg-chip.on { border-color: var(--accent); background: var(--warn-bg); }
.sugg-chip.on::before { content: "✓"; color: var(--accent-ink); font-weight: 700; }
