:root {
  --bg: #0f1218;
  --panel: #171c26;
  --panel2: #1e2431;
  --line: #2a3242;
  --text: #e8ebf2;
  --muted: #9aa4b8;
  --accent: #5b9cff;
  --accent-ink: #08111f;
  --good: #4cc38a;
  --warn: #f2b44b;
  --bad: #ef6b6b;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; letter-spacing: .2px; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
body.in-session main { padding-bottom: 48px; }
h1 { font-size: 1.5rem; margin: .4rem 0 .2rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .5rem; }
.card > h2:first-child { margin-top: 0; }
h3 { font-size: 1rem; margin: 1rem 0 .3rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--bad); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0;
}
.card.q { border-left: 4px solid var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: inherit; cursor: pointer; min-height: 44px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.link { background: none; border: none; color: var(--muted); padding: 6px 8px; min-height: 0; }
.btn.link:hover { color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }

label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=password], input[type=text], textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font: inherit;
}
textarea { min-height: 170px; resize: vertical; }
input:focus, textarea:focus, .tabbar a:focus-visible, .chip-btn:focus-visible, .seg button:focus-visible, .btn:focus-visible, summary:focus-visible, .opt:focus-within {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.opts { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.opt {
  position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  background: var(--panel2); cursor: pointer;
}
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .t { font-weight: 650; display: block; }
.opt .d { color: var(--muted); font-size: .875rem; display: block; }
.opt.sel { border-color: var(--accent); background: #1a2740; }

.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.chip.en { color: var(--warn); border-color: #5a4a22; }
.chip.fu { color: var(--accent); border-color: #274575; }

progress { width: 100%; height: 8px; border-radius: 8px; accent-color: var(--accent); }
.speaker { margin-top: 12px; font-size: .9rem; font-weight: 650; color: var(--accent); }
.q-text { font-size: 1.15rem; line-height: 1.5; margin: 8px 0 0; }

.pips { display: inline-flex; gap: 4px; vertical-align: middle; }
.pip { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.pip.on { background: var(--accent); }
.score-big { font-size: 2.2rem; font-weight: 700; line-height: 1; }

ul.list { margin: .3rem 0; padding-left: 1.2rem; }
ul.list li { margin: .25rem 0; }
ul.good li::marker { color: var(--good); }
ul.todo li::marker { color: var(--warn); }

.model {
  background: var(--bg); border: 1px dashed var(--line); border-radius: 10px;
  padding: 12px; margin-top: 8px; white-space: pre-wrap;
}
details { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); margin: 8px 0; }
summary { cursor: pointer; padding: 12px 14px; list-style-position: inside; }
details > .inner { padding: 0 14px 14px; }
.answer-box { background: var(--bg); border-left: 3px solid var(--line); padding: 8px 12px; margin: 6px 0; white-space: pre-wrap; }
.corr { display: grid; gap: 4px; margin: 4px 0; }
.corr .o { color: var(--bad); text-decoration: line-through; }
.corr .b { color: var(--good); }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 40px; gap: 10px; align-items: center; font-size: .9rem; }
.bar-row progress { height: 10px; }
.counter { font-size: .8rem; color: var(--muted); text-align: right; }
.hist-item {
  display: flex; justify-content: space-between; gap: 10px; align-items: center; width: 100%;
  text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer; margin: 6px 0;
}
.hist-item:hover { border-color: var(--accent); }
.spinner {
  width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; display: inline-block; animation: spin 0.9s linear infinite; vertical-align: -3px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-card .btn { width: 100%; margin-top: 16px; }

@media (max-width: 520px) {
  .bar-row { grid-template-columns: 110px 1fr 36px; }
  .score-big { font-size: 1.8rem; }
}

/* ---------------------------------------------------------------- Navigation */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 8px;
  min-height: 56px; color: var(--muted); text-decoration: none; font-size: .75rem; line-height: 1.2;
}
.tabbar .ic { font-size: 1.35rem; line-height: 1; filter: grayscale(.6); opacity: .8; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 650; }
.tabbar a[aria-current="page"] .ic { filter: none; opacity: 1; }
body.in-session .tabbar { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--panel2); color: var(--text); border: 1px solid var(--accent); border-radius: 999px;
  padding: 10px 18px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------------------------------------------------------------- Startseite */
.hero { border-color: #274575; background: linear-gradient(160deg, #1a2740, var(--panel) 70%); }
.hero .big { font-size: 2.8rem; font-weight: 750; line-height: 1; color: var(--accent); }
.hero .when { display: flex; gap: 14px; align-items: center; }
.hero p { margin: .8rem 0 0; }
.cta { margin-top: 18px; }
.card .bars + p { margin-top: 14px; }
.card .bars ~ .btn { margin-top: 12px; }
.card > .row { margin-top: 12px; }
.card.soft { background: var(--panel2); }
.sub { color: var(--muted); margin: -.1rem 0 .8rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.ghost { background: none; }
.btn.good { border-color: #2c6b4d; color: var(--good); }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip-btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font: inherit; font-size: .9rem; cursor: pointer; min-height: 40px;
}
.chip-btn:hover { border-color: var(--accent); }
.chip-btn:disabled { opacity: .5; cursor: default; }
details.more { border: none; background: none; margin: 12px 0 0; }
details.more > summary { padding: 8px 0; color: var(--accent); }
details.more > .inner { padding: 0; }
details.tip { border-color: #5a4a22; background: #221d10; }
details.tip > summary { color: var(--warn); }
.checkline { display: flex; gap: 10px; align-items: center; font-weight: 400; margin: 10px 0 0; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

/* ---------------------------------------------------------------- Fragen */
textarea.short { min-height: 96px; }
.right { text-align: right; }
.autoread { font-size: .85rem; color: var(--muted); font-weight: 400; margin: 8px 0 0; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.autoread input { width: 18px; height: 18px; accent-color: var(--accent); }
.delta { font-weight: 650; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); }
.delta.up { color: var(--good); border-color: #2c6b4d; }
.delta.down { color: var(--warn); border-color: #5a4a22; }
.compare { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.attempt { border-left: 3px solid var(--good); padding: 4px 0 4px 12px; margin: 10px 0; }

/* ---------------------------------------------------------------- Fortschritt */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .8rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--accent); opacity: .5; }
.chart .bar.last { opacity: 1; }
.chart text { fill: var(--muted); font-size: 9px; font-family: inherit; }
.chart text.val { fill: var(--text); font-weight: 600; font-size: 10px; }
.bar-row.weak span:first-child { color: var(--warn); font-weight: 650; }

/* ---------------------------------------------------------------- Spickzettel */
.cheat-q { font-weight: 650; margin-bottom: 6px; }
.cheat-text { white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: 12px; margin: 8px 0; }
.chip.warn { color: var(--warn); border-color: #5a4a22; }
.chip.ok { color: var(--good); border-color: #2c6b4d; }
.empty { text-align: center; padding: 28px 16px; }
.empty .ic { font-size: 2.2rem; }

/* ---------------------------------------------------------------- Schütz */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin: 8px 0 12px; }
.seg button { appearance: none; border: none; background: none; color: var(--muted); font: inherit; padding: 10px 6px; border-radius: 9px; cursor: pointer; min-height: 44px; }
.seg button[aria-pressed="true"] { background: var(--panel2); color: var(--text); font-weight: 650; box-shadow: inset 0 0 0 1px var(--accent); }
.facts { display: grid; gap: 0; }
.facts .f { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.facts .f:first-child { border-top: none; }
.facts .k { color: var(--muted); font-size: .9rem; }
.div-card { border-left: 4px solid var(--line); }
.div-card.hl { border-left-color: var(--accent); }
.flash { text-align: center; min-height: 190px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.flash .front { font-size: 1.2rem; font-weight: 650; }
.flash .back { color: var(--good); font-size: 1.05rem; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 2px 0; }
.checklist label { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; margin: 6px 0; cursor: pointer; }
.checklist input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin-top: 2px; }
a { color: var(--accent); }

@media (max-width: 520px) {
  .facts .f { grid-template-columns: 1fr; gap: 2px; }
  .hero .big { font-size: 2.4rem; }
}

/* ---------------------------------------------------------------- Drucken (Spickzettel) */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .tabbar, .toast, .no-print, .btn { display: none !important; }
  main { padding: 0; max-width: none; }
  .card, details { border: 1px solid #999; background: #fff; color: #000; break-inside: avoid; }
  .cheat-text { background: #fff; border: 1px solid #ccc; color: #000; }
  .muted { color: #444; }
  a { color: #000; }
}
