:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --text: #15191c;
  --text-2: #5b656d;
  --text-3: #8a949b;
  --line: #dde2e6;
  --accent: #0b6e79;
  --accent-2: #e3f1f2;
  --accent-text: #ffffff;
  --warn: #b5541c;
  --ok: #2f7d4a;
  --mark: #ffe58a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --tabbar-h: 58px;
  --c-altostar: #0b6e79;
  --c-realstar: #c0392b;
  --c-flexstar: #7a4bbf;
  --c-extrastar: #c98a12;
  --c-geraete: #3d6fb6;
  --c-allgemein: #6b7780;
  --c-topic: #8a949b;
  --c-panel: #2f7d4a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --surface: #181c20;
    --surface-2: #22282d;
    --text: #e9edf0;
    --text-2: #a7b1b8;
    --text-3: #77828a;
    --line: #2b3238;
    --accent: #3fb6c2;
    --accent-2: #173238;
    --accent-text: #08262a;
    --mark: #6b5a12;
    --shadow: none;
    --c-altostar: #3fb6c2;
    --c-realstar: #e6716a;
    --c-flexstar: #a98be0;
    --c-extrastar: #e0b04a;
    --c-geraete: #7aa6e6;
    --c-allgemein: #9aa6ae;
    --c-panel: #6cc28a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 28px; font-weight: 750; letter-spacing: -.02em; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar.small h1 { font-size: 19px; font-weight: 650; }
.icon-btn { border: 0; background: none; padding: 6px; margin-left: -8px; color: var(--accent); display: flex; }
.top-right { display: flex; gap: 6px; }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 4px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-3); font-size: 10.5px; padding: 2px 0; }
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

/* Suche */
.searchbox { position: sticky; top: 0; z-index: 4; background: var(--bg); padding: 2px 0 10px; }
.search-wrap { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 12px; padding: 0 10px; }
.search-wrap svg { flex: none; width: 18px; height: 18px; stroke: var(--text-3); fill: none; stroke-width: 2.2; stroke-linecap: round; }
.search-wrap input { flex: 1; border: 0; background: none; padding: 11px 0; outline: none; font-size: 17px; min-width: 0; }
.search-wrap .clear { border: 0; background: var(--text-3); color: var(--surface); width: 18px; height: 18px; border-radius: 50%; font-size: 12px; line-height: 18px; padding: 0; flex: none; }
.suggest { background: var(--surface); border-radius: 12px; margin-top: 6px; box-shadow: var(--shadow); overflow: hidden; }
.suggest button { display: flex; width: 100%; text-align: left; padding: 11px 14px; border: 0; background: none; border-bottom: 1px solid var(--line); gap: 10px; align-items: center; }
.suggest button:last-child { border-bottom: 0; }
.suggest small { color: var(--text-3); margin-left: auto; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap; color: var(--text-2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.soft { background: var(--accent-2); border-color: transparent; color: var(--accent); }
.chip small { opacity: .7; margin-left: 4px; }

.meta-line { color: var(--text-3); font-size: 13px; margin: 8px 2px; }
.meta-line b { color: var(--text-2); font-weight: 600; }

.result { background: var(--surface); border-radius: var(--radius); padding: 13px 14px 10px; margin: 10px 0; box-shadow: var(--shadow); }
.result h3 { margin: 0 0 4px; font-size: 16.5px; font-weight: 650; line-height: 1.3; }
.result .sub { font-size: 13px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.hit { display: block; width: 100%; text-align: left; border: 0; background: var(--surface-2); border-radius: 10px; padding: 9px 10px; margin-top: 8px; font-size: 14px; color: var(--text-2); line-height: 1.45; }
.hit .pg { display: inline-block; font-weight: 650; color: var(--accent); margin-right: 6px; font-size: 12.5px; }
.result-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.result-foot .spacer { flex: 1; }
.fb { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--text-2); }
.fb.on { background: var(--accent-2); color: var(--accent); border-color: transparent; }
.learned { font-size: 11.5px; color: var(--accent); font-weight: 600; }

.badge { font-size: 11.5px; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-weight: 600; letter-spacing: .01em; }
.badge.line-AltoStar { color: var(--c-altostar); }
.badge.line-RealStar { color: var(--c-realstar); }
.badge.line-FlexStar { color: var(--c-flexstar); }
.badge.line-ExtraStar { color: var(--c-extrastar); }
.badge.line-Geräte { color: var(--c-geraete); }
.badge.new { background: var(--accent); color: var(--accent-text); }
.badge.old { color: var(--warn); }

.empty { text-align: center; color: var(--text-3); padding: 40px 20px; }
.empty h2 { color: var(--text-2); font-size: 18px; margin: 10px 0 6px; }
.empty .big { font-size: 40px; }

/* Listen & Karten */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin: 12px 0; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; margin: 0 0 6px; }
.card p { margin: 6px 0; color: var(--text-2); font-size: 14.5px; }
.card .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 20px 4px 6px; font-weight: 600; }

.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin: 8px 0; }
.li { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 52px; }
.li:last-child { border-bottom: 0; }
.li .ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-2); color: var(--accent); font-size: 16px; flex: none; font-weight: 700; }
.li .txt { flex: 1; min-width: 0; }
.li .t { font-weight: 560; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.li .s { font-size: 13px; color: var(--text-3); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .r { color: var(--text-3); font-size: 13px; flex: none; display: flex; align-items: center; gap: 6px; }
.li .chev { width: 8px; height: 8px; border-right: 2px solid var(--text-3); border-top: 2px solid var(--text-3); transform: rotate(45deg); opacity: .6; }
.st { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; flex: none; }
.st.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.st.cloud { background: var(--surface-2); color: var(--text-3); }
.st.wait { background: var(--accent-2); color: var(--accent); }
.st.err { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.tile { border: 0; text-align: left; background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; }
.tile .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.tile .l { font-weight: 600; font-size: 15px; }
.tile .s { font-size: 12.5px; color: var(--text-3); }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 2px; margin: 4px 0 8px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 14px; color: var(--text-2); font-weight: 560; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

details.grp { background: var(--surface); border-radius: var(--radius); margin: 8px 0; box-shadow: var(--shadow); overflow: hidden; }
details.grp > summary { list-style: none; padding: 12px 14px; display: flex; gap: 10px; align-items: center; font-weight: 600; }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary .cnt { margin-left: auto; color: var(--text-3); font-weight: 500; font-size: 14px; }
details.grp > summary::after { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(-45deg); transition: transform .15s; margin-left: 4px; }
details.grp[open] > summary::after { transform: rotate(45deg); }
details.grp .list { box-shadow: none; border-radius: 0; margin: 0; border-top: 1px solid var(--line); }

/* Buttons & Formulare */
.btn { border: 0; background: var(--accent); color: var(--accent-text); padding: 11px 16px; border-radius: 12px; font-weight: 650; font-size: 15.5px; }
.btn.secondary { background: var(--accent-2); color: var(--accent); }
.btn.ghost { background: none; color: var(--accent); padding-left: 4px; padding-right: 4px; }
.btn.danger { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; font-weight: 560; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.toggle:last-child { border-bottom: 0; }
.toggle input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; transition: background .15s; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }
.toggle .tl { font-size: 15px; }
.toggle .tl small { display: block; color: var(--text-3); font-size: 12.5px; }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 19px; }
.stats span { font-size: 11.5px; color: var(--text-3); }
.log { font: 12px/1.4 ui-monospace, Menlo, monospace; color: var(--text-3); max-height: 140px; overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 8px; white-space: pre-wrap; margin-top: 8px; }

.dlbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 15; background: var(--surface); border-radius: 12px; padding: 8px 12px; box-shadow: 0 4px 20px rgba(0,0,0,.15); }
.dlbar-text { font-size: 13px; color: var(--text-2); margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s; }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92%; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 6px 16px calc(env(safe-area-inset-bottom) + 20px); animation: up .25s cubic-bezier(.2,.8,.2,1); -webkit-overflow-scrolling: touch; }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 21px; margin: 4px 0 6px; line-height: 1.25; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14.5px; margin: 10px 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.btn-row .btn { flex: 1 1 auto; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* PDF-Betrachter */
.pv { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.pv-bar { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 6px) 10px 6px; background: var(--surface); border-bottom: 1px solid var(--line); }
.pv-title { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.pv-tools { display: flex; gap: 4px; }
.pv-btn { border: 0; background: none; color: var(--accent); font-weight: 650; padding: 6px 8px; font-size: 16px; display: flex; align-items: center; }
.pv-btn.sm { font-size: 22px; min-width: 34px; justify-content: center; }
.pv-hint { background: var(--accent-2); color: var(--text-2); font-size: 13px; padding: 8px 12px; line-height: 1.4; }
.pv-pages { position: relative; flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px; background: var(--surface-2); }
.pv-page { margin: 0 auto 10px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); position: relative; }
.pv-page canvas { display: block; }
.pv-num { position: absolute; top: 40%; left: 0; right: 0; text-align: center; color: #bbb; font-size: 28px; }
.pv-foot { text-align: center; font-size: 13px; padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px); color: var(--text-2); background: var(--surface); border-top: 1px solid var(--line); }
.tv-body { flex: 1; overflow: auto; margin: 0; padding: 16px; white-space: pre-wrap; font: 15px/1.5 -apple-system, sans-serif; }

/* Wissensnetz */
.graph-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin: 10px 0; touch-action: pan-y; }
.graph-wrap svg { display: block; width: 100%; height: auto; }
.graph-wrap text { font-size: 10px; fill: var(--text-2); pointer-events: none; }
.graph-wrap line { stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--text-2); margin: 6px 2px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.link-row { display: flex; align-items: center; gap: 10px; }
.wbar { height: 6px; border-radius: 3px; background: var(--accent); opacity: .75; flex: none; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 70px); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14.5px; max-width: 88%; box-shadow: 0 6px 24px rgba(0,0,0,.25); animation: fade .2s; text-align: center; }

.muted { color: var(--text-3); font-size: 13.5px; }
.center { text-align: center; }
a { color: var(--accent); }
.hr { height: 1px; background: var(--line); margin: 12px 0; }
.more-btn { display: block; margin: 10px auto; }

/* Antworten aus Kit-Daten */
.card.answer { border: 1.5px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.ans-k { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.card.answer h2 { font-size: 18px; margin: 2px 0 4px; }
.card.answer details.grp { box-shadow: none; border: 1px solid var(--line); }
.gval { font-weight: 560; font-size: 14px; line-height: 1.35; }
details.grp > summary .gval { flex: 1; }
.learned-note { background: var(--accent-2); color: var(--text); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.learned-note .btn { padding: 2px 6px; font-size: 14px; }
.fst { font-size: 13px; font-weight: 700; }
.fst.ok { color: var(--ok); }
.fst.ed { color: var(--accent); }
.tbl { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px -14px; padding: 0 14px; }
.tbl table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.tbl th, .tbl td { text-align: left; vertical-align: top; padding: 7px 8px; border-bottom: 1px solid var(--line); min-width: 120px; }
.tbl thead th { color: var(--text-2); font-size: 12.5px; }
.tbl tbody th { color: var(--text-2); font-weight: 600; min-width: 100px; }
.tbl tr.same td { background: color-mix(in srgb, var(--ok) 9%, transparent); }
.tbl a { color: var(--text); text-decoration: none; }
.li .s b { color: var(--text-2); font-weight: 600; }
.li .s { white-space: normal; }

/* Sprachsteuerung */
.search-wrap .mic { border: 0; background: none; padding: 4px 2px 4px 6px; display: flex; color: var(--accent); flex: none; }
.search-wrap .mic svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.search-wrap .mic.on { color: var(--warn); }
.voice-bar { display: flex; align-items: center; gap: 10px; background: var(--accent-2); border-radius: 12px; padding: 8px 12px; margin-top: 6px; font-size: 15px; }
.voice-bar #voiceText { flex: 1; }
.voice-bar .btn { padding: 4px 6px; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--warn); flex: none; animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { transform: scale(.7); opacity: .6; } 50% { transform: scale(1.15); opacity: 1; } }
.ready-bar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 45; background: var(--surface); border-radius: 14px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.2); display: flex; align-items: center; gap: 10px; font-weight: 600; animation: up .25s; }
.ready-bar #readyText { flex: 1; }
.ready-bar .btn.ghost { padding: 6px; }
.voice-bar .btn.stop { background: var(--warn); color: #fff; padding: 8px 16px; font-size: 15px; border-radius: 10px; min-width: 76px; }

/* Mehrfachauswahl & Struktur */
.li.sel .chk { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px; font-weight: 700; color: var(--accent-text); flex: none; }
.li.sel.on .chk { background: var(--accent); border-color: var(--accent); }
.li.sel.on { background: var(--accent-2); }
.li .btn.ghost { padding: 4px 6px; font-size: 14px; flex: none; }
#selBar .btn { padding: 8px 12px; }
#cmdInput { flex: 1; border: 0; background: none; padding: 11px 0; outline: none; font-size: 16px; min-width: 0; }
