:root {
  --night: #1a3c40;
  --deep: #14313a;
  --surface: #1f4a50;
  --line: #2e6b70;
  --mint: #02c39a;
  --mint-ink: #0c2f2c;
  --mist: #8fc3c8;
  --snow: #e6f6f2;
  --paper: #fbfdfc;
  --leaf: #f2f5f3;
  --ink: #15302f;
  --ink-soft: #4d6664;
  --coral: #ef7b6c;
  --amber: #f0b54a;
  --radius: 14px;
  --bar-h: 76px;
  --font: 'Atkinson Hyperlegible Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--snow);
  background: var(--night);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.muted { color: var(--mist); font-size: 15px; }
.error { color: var(--coral); font-size: 15px; margin-top: 8px; }
.loading { padding: 40px 0; text-align: center; }

/* ---------- App-Rahmen ---------- */
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  max-width: 520px; margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px 4px;
  background: var(--night);
}
.appbar h1 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: var(--surface); }
.app {
  max-width: 520px; margin: 0 auto;
  padding: 4px 16px max(32px, env(safe-area-inset-bottom));
}
.h2 { font-size: 15px; font-weight: 700; color: var(--mist); margin-bottom: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 12px 18px;
  border-radius: 12px; border: 1.5px solid transparent;
  font-weight: 700; font-size: 17px; text-decoration: none; cursor: pointer;
  transition: transform .08s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn--primary { background: var(--mint); color: var(--mint-ink); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--snow); }
.btn--wide { width: 100%; }
.actions { display: grid; gap: 10px; margin: 8px 0 32px; }
.actions__row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Übersicht ---------- */
.hero { padding: 20px 0 22px; }
.hero__num { font-size: 76px; font-weight: 800; line-height: 1; letter-spacing: -0.04em; color: var(--mint); }
.hero__num small { font-size: 32px; color: var(--mist); letter-spacing: 0; }
.hero__label { font-size: 19px; margin-top: 8px; max-width: 26ch; }
.hero__intro { font-size: 22px; line-height: 1.35; font-weight: 600; max-width: 28ch; }

.systems ul { list-style: none; display: grid; gap: 14px; margin-bottom: 36px; }
.sysrow { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: baseline; }
.sysrow__name { font-weight: 700; }
.sysrow__nums { color: var(--mist); font-size: 14px; font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; position: relative; height: 8px; border-radius: 4px; background: var(--surface); overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; }
.bar__seen { background: color-mix(in srgb, var(--sys) 40%, var(--surface)); }
.bar__done { background: var(--sys); }

.codebox { border-top: 1px solid var(--line); padding-top: 22px; }
.codebox p { margin-bottom: 12px; max-width: 60ch; }
.code {
  font-size: 22px; font-weight: 800; letter-spacing: 0.01em; color: var(--snow);
  background: var(--surface); border-radius: 10px; padding: 12px 14px; word-break: break-all;
}
.sync { color: var(--mist); font-size: 14px; min-height: 1.2em; }

.codeform { display: grid; gap: 12px; padding-top: 16px; }
.codeform label, legend { font-weight: 700; }
.codeform input, .search {
  width: 100%; min-height: 52px; padding: 12px 14px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--deep);
  font-size: 18px; color: var(--snow);
}
.codeform input:focus, .search:focus { outline: none; border-color: var(--mint); }

/* ---------- Setup ---------- */
.setup { display: grid; gap: 26px; padding: 8px 0 calc(var(--bar-h) + 24px); }
fieldset { border: 0; display: grid; gap: 10px; }
legend { margin-bottom: 4px; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  --sys: var(--mist);
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 8px 14px; border-radius: 22px;
  border: 1.5px solid var(--line); background: transparent; cursor: pointer; font-size: 15px; font-weight: 600;
  white-space: nowrap;
}
.chip::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--sys); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked), .chip[aria-pressed="true"] { border-color: var(--sys); background: color-mix(in srgb, var(--sys) 22%, transparent); }
.chip:has(input:focus-visible) { outline: 3px solid var(--mint); outline-offset: 2px; }
.toggles { display: grid; gap: 2px; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--mint); flex: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: grid; place-items: center; min-height: 48px; font-weight: 700; }
.seg input:checked + span { background: var(--mint); color: var(--mint-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--snow); outline-offset: -4px; }
.setup__bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--night) 28%);
}
.setup__bar .btn { display: flex; max-width: 488px; margin: 0 auto; }

/* ---------- Packung (Vorderseite) ---------- */
.pack {
  position: relative; overflow: hidden;
  background: var(--paper); color: var(--ink);
  border-radius: 8px;
  padding: 44px 18px 18px 26px;
  box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 10px 24px -14px rgba(0,0,0,.6);
}
.pack::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 8px; background: var(--sys); }
.pack__band {
  position: absolute; top: 0; right: 0;
  background: var(--sys); color: var(--sys-fg, #fff);
  font-size: 13px; font-weight: 700; padding: 5px 12px 6px 16px;
  border-bottom-left-radius: 12px;
}
.pack__brand { font-size: clamp(30px, 9vw, 40px); font-weight: 800; letter-spacing: -0.025em; line-height: 1.05; overflow-wrap: anywhere; }
.pack__alt { margin-top: 6px; font-size: 15px; color: var(--ink-soft); }
.pack__ws { margin-top: 14px; font-size: 19px; font-weight: 600; }
.pack__ws span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); }

/* ---------- Fotos ---------- */
.photo {
  display: block; width: 100%; aspect-ratio: 4 / 3;
  background: #fff; border: 0; border-radius: 10px; overflow: hidden; cursor: zoom-in; padding: 6px;
}
.photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.photo--large { aspect-ratio: 1; }
.search-link, .photo--missing {
  display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 12px 14px; border-radius: 10px; background: var(--leaf); color: var(--ink);
  text-decoration: none; font-size: 15px;
}
.search-link svg { flex: none; color: var(--ink-soft); }
#zoom { margin: auto; border: 0; padding: 0; background: #fff; border-radius: 12px; max-width: 94vw; max-height: 88dvh; }
#zoom::backdrop { background: rgba(5, 20, 22, .85); }
#zoom img { display: block; max-width: 94vw; max-height: 88dvh; object-fit: contain; }

/* ---------- Beipackzettel (Rückseite) ---------- */
.leaflet { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; overflow-wrap: anywhere; background: var(--leaf); color: var(--ink); border-radius: 10px; overflow: hidden; }
.leaflet .pack { border-radius: 0; box-shadow: none; }
.leaflet__photos { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 12px 14px 4px; }
.leaflet__sec { padding: 14px 18px; border-top: 1px dashed #c9d3cf; }
.leaflet__photos + .leaflet__sec { border-top: 0; }
.leaflet__sec h3 { font-size: 14px; font-weight: 800; color: var(--ink-soft); margin-bottom: 4px; }
.leaflet__sec ul { list-style: none; display: grid; gap: 3px; }
.leaflet__sec li { padding-left: 16px; position: relative; }
.leaflet__sec li::before { content: ''; position: absolute; left: 2px; top: .62em; width: 6px; height: 6px; border-radius: 50%; background: var(--sys, var(--ink-soft)); }
.leaflet .muted { color: var(--ink-soft); }
.pre { white-space: pre-line; }
.leaflet__sec.is-focus { background: #dff6ee; box-shadow: inset 4px 0 0 var(--mint); }
.leaflet__sec.is-focus h3 { color: #067a62; }

/* ---------- Session ---------- */
body[data-view="session"] .appbar { display: none; }
body[data-view="session"] .app { padding: 0; }
.session { display: flex; flex-direction: column; min-height: 100dvh; }
.session__top {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 14px 6px 4px; background: var(--night);
}
.meter { flex: 1; height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--sys); transition: width .3s; }
.session__count { font-size: 14px; color: var(--mist); font-variant-numeric: tabular-nums; min-width: 4.5ch; text-align: right; }
.session__body { flex: 1; padding: 8px 16px calc(var(--bar-h) + 28px + env(safe-area-inset-bottom)); }
.session__bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--night) 26%);
}
.session__bar > * { max-width: 488px; margin: 0 auto; }
.session__bar:empty { display: none; }

.flash { cursor: pointer; padding-top: 14px; }
.q__prompt { font-size: 24px; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; max-width: 22ch; }
.q__prompt--small { font-size: 17px; font-weight: 700; color: var(--mist); margin: 6px 0 12px; }
.q__type { font-size: 14px; color: var(--mist); margin: 6px 0 22px; }
.q__content { display: grid; gap: 12px; }
.q__term {
  font-size: clamp(30px, 9vw, 42px); font-weight: 800; line-height: 1.08; letter-spacing: -0.025em;
  color: var(--snow); overflow-wrap: anywhere;
  border-left: 6px solid var(--sys); padding: 6px 0 6px 16px;
}
.q__term--brand { background: var(--paper); color: var(--ink); border-radius: 8px; padding: 22px 18px 22px 20px; }
.q__list { list-style: none; display: grid; gap: 6px; font-size: 19px; border-left: 6px solid var(--sys); padding: 4px 0 4px 16px; }
.q__hint { color: var(--mist); font-size: 15px; padding-left: 22px; }
.q__photo { width: 100%; border-radius: 10px; background: #fff; }

.answer { touch-action: pan-y; transition: transform .2s, opacity .2s; border-radius: 12px; }
.answer[data-swipe="known"] { box-shadow: 0 0 0 3px var(--mint); }
.answer[data-swipe="wrong"] { box-shadow: 0 0 0 3px var(--coral); }

.grades { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grade {
  min-height: 56px; padding: 8px 4px; border-radius: 12px; border: 0; cursor: pointer;
  font-weight: 800; font-size: 15px; line-height: 1.15; color: var(--mint-ink);
}
.grade:active { transform: scale(.97); }
.grade--wrong { background: var(--coral); }
.grade--unsure { background: var(--amber); }
.grade--known { background: var(--mint); }

.options { display: grid; gap: 10px; margin-top: 22px; }
.option {
  text-align: left; min-height: 56px; padding: 14px 16px; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line); font-size: 17px; font-weight: 600;
}
.option:active:not(:disabled) { transform: scale(.99); }
.option.is-correct { background: color-mix(in srgb, var(--mint) 40%, var(--night)); border-color: var(--mint); }
.option.is-wrong { background: color-mix(in srgb, var(--coral) 45%, var(--night)); border-color: var(--coral); }
.options.is-done .option:not(.is-correct):not(.is-wrong) { opacity: .5; }
.verdict { font-size: 22px; font-weight: 800; margin: 22px 0 12px; }
.verdict--ok { color: var(--mint); }
.verdict--no { color: var(--coral); }

/* ---------- Nachschlagen ---------- */
.lookup__head { position: sticky; top: calc(max(8px, env(safe-area-inset-top)) + 52px); z-index: 4; background: var(--night); padding: 4px 0 10px; display: grid; gap: 10px; }
.chips--scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chips--scroll::-webkit-scrollbar { display: none; }
.results { list-style: none; display: grid; gap: 8px; }
.results--compact { margin-bottom: 24px; }
.row {
  display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 8px 12px 8px 8px;
  border-radius: 12px; background: var(--surface); text-decoration: none;
  border-left: 5px solid var(--sys);
}
.row img, .row__noimg { width: 56px; height: 56px; flex: none; border-radius: 8px; background: #fff; object-fit: contain; padding: 3px; }
.row__noimg { background: var(--deep); }
.row__text { display: grid; min-width: 0; }
.row__text b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__text span { font-size: 14px; color: var(--mist); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--mist); padding: 24px 0; }
.detail { padding: 8px 0 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
