:root {
  --bg: #f4efe6;
  --surface: #fbf8f3;
  --surface-2: #efe8dc;
  --line: #e2d9ca;
  --ink: #1d1b18;
  --ink-2: #5b554c;
  --ink-3: #8a8378;
  --accent: #b8321f;        /* Zinnoberrot */
  --accent-ink: #ffffff;
  --accent-soft: #f6e1da;
  --ok: #1f7a3a;
  --ok-soft: #dcefe1;
  --bad: #b3261e;
  --bad-soft: #f8dcd8;
  --s-master: #008300;
  --s-learn: #2a78d6;
  --s-hard: #eb6834;
  --s-new: #d9d1c3;
  --chart: #2a78d6;
  --r1: #b3261e; --r2: #b86e00; --r3: #1f7a3a; --r4: #2a5fb0;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 16px;
  --han: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", "Songti SC", sans-serif;
  --tab-h: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1c1a18;
    --surface-2: #26231f;
    --line: #34302a;
    --ink: #f0ece4;
    --ink-2: #bfb8ab;
    --ink-3: #8c8579;
    --accent: #e0563c;
    --accent-soft: #3a211b;
    --ok: #5fc27a;
    --ok-soft: #1d3324;
    --bad: #f07b6e;
    --bad-soft: #3d1f1b;
    --s-master: #0ca30c;
    --s-learn: #3987e5;
    --s-hard: #d95926;
    --s-new: #3a362f;
    --chart: #3987e5;
    --r1: #f07b6e; --r2: #e3a23c; --r3: #5fc27a; --r4: #7aa7ec;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, var(--han), sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
.han { font-family: var(--han); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

#app { min-height: 100%; }
.page {
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 640px; margin: 0 auto;
}
.page.full { padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
.head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: 40px; }
.head h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { border: 0; background: none; padding: 6px 8px 6px 0; color: var(--accent); font-size: 17px; cursor: pointer; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Karten / Kacheln */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.tight { padding: 12px 14px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .l { font-size: 13px; color: var(--ink-2); }
.tile .d { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* Knöpfe */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 16px;
  text-decoration: none; user-select: none; -webkit-user-select: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 18px; border-radius: 16px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn:disabled { opacity: .45; }
.btn:active { transform: scale(.98); }
.icon-btn { border: 0; background: var(--surface-2); width: 40px; height: 40px; border-radius: 12px; font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); }

/* Formular */
label.f { display: block; }
label.f > span { display: block; font-size: 13px; color: var(--ink-2); margin: 0 0 4px 2px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; min-height: 38px; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 12px; font-size: 14px; cursor: pointer; user-select: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface-2); font-size: 20px; cursor: pointer; }
.stepper output { min-width: 48px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 30px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.setting { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .t { flex: 1; }
.setting .t small { display: block; color: var(--ink-3); font-size: 12px; }

/* Listen */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; }
.li:last-child { border-bottom: 0; }
.li .main { flex: 1; min-width: 0; }
.li .hz { font-family: var(--han); font-size: 20px; line-height: 1.25; }
.li .sub { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .chev { color: var(--ink-3); }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); }
.badge { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.st-neu { background: var(--s-new); } .st-lernend { background: var(--s-learn); } .st-schwer { background: var(--s-hard); } .st-beherrscht { background: var(--s-master); }

/* Statusbalken */
.sbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--s-new); gap: 2px; }
.sbar > i { display: block; height: 100%; }
.sbar > i:first-child { border-radius: 6px 0 0 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Tab-Leiste */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 600; }
.tabs a .i { font-size: 21px; line-height: 1; font-family: var(--han); }
.tabs a.on { color: var(--accent); }

/* Start */
.hero { display: flex; gap: 16px; align-items: center; }
.ring { width: 96px; height: 96px; flex: none; }
.ring circle { fill: none; stroke-width: 10; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s; }
.ring text { font-weight: 750; fill: var(--ink); font-size: 22px; }
.banner { background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; }

/* Lern-Session */
.learn { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 8px) 14px calc(env(safe-area-inset-bottom) + 12px); max-width: 640px; margin: 0 auto; }
.learn .top { display: flex; align-items: center; gap: 10px; }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.counter { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; padding: 10px 0; }
.flash {
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 20px 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; gap: 10px;
  min-height: 46vh; max-height: 100%; overflow-y: auto; position: relative;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.flash .fhead { align-self: stretch; display: flex; justify-content: space-between; align-items: center; margin: -6px -2px 0; min-height: 22px; }
.flash .kind { font-size: 12px; font-weight: 700; color: var(--ink-3); letter-spacing: .03em; }
.flash .fhead + * { margin-top: auto; }
.flash > :last-child:not(.peek), .flash > :nth-last-child(2):has(+ .peek) { margin-bottom: auto; }
.flash .img { width: 112px; height: 112px; border-radius: 14px; object-fit: cover; }
.big-han { font-family: var(--han); font-size: 64px; line-height: 1.15; font-weight: 500; word-break: break-all; }
.big-han.l2 { font-size: 46px; } .big-han.l3 { font-size: 34px; } .big-han.l4 { font-size: 27px; line-height: 1.4; }
.py { font-size: 22px; color: var(--accent); font-weight: 500; }
.py.sm { font-size: 17px; }
.de { font-size: 22px; font-weight: 600; }
.de.sm { font-size: 17px; font-weight: 500; }
.note { font-size: 14px; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; text-align: left; white-space: pre-wrap; }
.peek { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-size: 24px; color: var(--accent); pointer-events: none; }
.speak { border: 0; background: var(--accent-soft); color: var(--accent); width: 46px; height: 46px; border-radius: 50%; font-size: 20px; cursor: pointer; }
.speak.huge { width: 96px; height: 96px; font-size: 40px; }
.links { width: 100%; text-align: left; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.links .lk { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; padding: 5px 0; font-size: 14px; border-bottom: 1px dashed var(--line); }
.links .lk:last-child { border-bottom: 0; }
.links .lk .gg { flex-basis: 100%; }
.links .lk .hz { font-family: var(--han); font-size: 17px; }
.links .lk .pp { color: var(--accent); font-size: 13px; }
.links .lk .gg { color: var(--ink-2); }
.actions { display: grid; gap: 8px; }
.actions.r4 { grid-template-columns: repeat(4, 1fr); }
.actions.r3 { grid-template-columns: repeat(3, 1fr); }
.actions.r2 { grid-template-columns: repeat(2, 1fr); }
.rate { min-height: 64px; border: 0; border-radius: 14px; cursor: pointer; font-weight: 700; font-size: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: var(--surface); box-shadow: var(--shadow); user-select: none; -webkit-user-select: none; }
.rate small { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.rate.g1 { color: var(--r1); } .rate.g2 { color: var(--r2); } .rate.g3 { color: var(--r3); } .rate.g4 { color: var(--r4); }
.flip { min-height: 64px; font-size: 18px; -webkit-touch-callout: none; touch-action: manipulation; }
.hint { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.opts { display: grid; gap: 8px; width: 100%; }
.opts.grid2 { grid-template-columns: 1fr 1fr; }
.opt { min-height: 56px; border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 10px; cursor: pointer; font-size: 17px; text-align: center; }
.opt.han { font-size: 26px; }
.opt.ok { border-color: var(--ok); background: var(--ok-soft); }
.opt.no { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.verdict { font-weight: 700; font-size: 16px; }
.verdict.ok { color: var(--ok); } .verdict.no { color: var(--bad); }
.answer-line { min-height: 64px; width: 100%; border: 2px dashed var(--line); border-radius: 14px; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; justify-content: center; }
.answer-line.ok { border-color: var(--ok); border-style: solid; background: var(--ok-soft); }
.answer-line.no { border-color: var(--bad); border-style: solid; background: var(--bad-soft); }
.pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; }
.chunk { font-family: var(--han); font-size: 22px; padding: 8px 12px; border-radius: 12px; border: 0; background: var(--surface-2); cursor: pointer; min-width: 46px; }
.chunk.used { visibility: hidden; }
.cloze-gap { display: inline-block; min-width: 2.2em; border-bottom: 3px solid var(--accent); margin: 0 2px; color: var(--accent); }

/* Zusammenfassung */
.sumgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.trend-up { color: var(--ok); font-weight: 700; } .trend-down { color: var(--bad); font-weight: 700; }

/* Diagramme */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 10px; }
.chart .bar { fill: var(--chart); }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.chart .sel { fill: var(--ink); opacity: .06; }
.tip { font-size: 13px; color: var(--ink-2); min-height: 20px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tip b { color: var(--ink); }
.datatable { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 8px; }
.datatable td, .datatable th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.datatable td:first-child, .datatable th:first-child { text-align: left; }
details > summary { cursor: pointer; color: var(--ink-3); font-size: 13px; margin-top: 6px; }

/* Bottom-Sheet & Toast */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: var(--shadow); }
.err { color: var(--bad); font-size: 14px; }
.empty { text-align: center; color: var(--ink-3); padding: 28px 12px; }
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; }
.logo { font-family: var(--han); font-size: 54px; color: var(--accent); text-align: center; line-height: 1; }
.prev-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.prev-table td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prev-table .hz { font-family: var(--han); font-size: 16px; }

/* Aufgaben-Mix */
.mixrow { padding: 10px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.mixrow.off b { color: var(--ink-3); }
.seg.mini button { min-height: 32px; font-size: 13px; }
.net { font-size: 12px; font-weight: 700; color: var(--ink-3); white-space: nowrap; }
.net.off { color: var(--bad); } .net.wait { color: var(--r2); }
.learn .top .icon-btn:disabled { opacity: .35; }

/* Schreibübung */
.wbox { position: relative; overflow: hidden; border: 2px solid var(--line); border-radius: 16px; background: var(--surface); touch-action: none; flex: none; }
.wbox.ok { border-color: var(--ok); } .wbox.no { border-color: var(--bad); }
.wgrid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.wgrid line { stroke: var(--line); stroke-width: .4; stroke-dasharray: 2 2; }
.wtarget { position: absolute; inset: 0; }
.wdots { display: flex; gap: 6px; min-height: 8px; }
.wdots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.wdots i.cur { background: var(--r2); } .wdots i.on { background: var(--ok); }
