/* Vokabelkasten – Gestaltung: Karteikarten, Königsblau, Textmarker */
:root {
  --paper: #F1F5FB;
  --card: #FFFFFF;
  --ink: #17213A;
  --ink-soft: #5B667D;
  --line: #DCE4F1;
  --royal: #2343C4;
  --royal-press: #1A339A;
  --royal-soft: #E5EAFB;
  --rule: #D3DEF0;
  --margin-red: #E2474F;
  --ok: #188F50;
  --ok-bg: #E2F5EA;
  --close: #D97800;
  --close-bg: #FFF0DB;
  --bad: #D2353A;
  --bad-bg: #FCE5E6;
  --marker: #FFE45C;
  --marker-ink: #17213A;
  --shadow: 0 1px 2px rgba(23, 33, 58, .06), 0 8px 24px rgba(23, 33, 58, .07);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-card: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", -apple-system, system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0D1322;
    --card: #172038;
    --ink: #E7ECF8;
    --ink-soft: #9AA6C0;
    --line: #26314F;
    --royal: #8EA5FF;
    --royal-press: #B4C3FF;
    --royal-soft: #1F2B52;
    --rule: #26335A;
    --margin-red: #FF6B72;
    --ok: #43D390;
    --ok-bg: #123329;
    --close: #FFAA45;
    --close-bg: #3A2A12;
    --bad: #FF6E70;
    --bad-bg: #3C1A20;
    --marker: #6E5C00;
    --marker-ink: #FFF6C7;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--royal); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
}
.bar-inner { max-width: 736px; width: 100%; margin: 0 auto; display: flex; align-items: center; gap: 4px; min-height: 56px; }
.bar h1 { font-size: 17px; font-weight: 600; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .brand { font-family: var(--font-card); font-size: 20px; font-weight: 700; text-align: left; padding-left: 8px; }
.bar .spacer { width: 44px; flex: none; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--royal);
  cursor: pointer;
}
.icon-btn:active { background: var(--royal-soft); }

.section-title { font-size: 15px; font-weight: 600; color: var(--ink-soft); margin: 28px 4px 10px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.center { text-align: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 20px;
  border-radius: 14px; border: 0;
  background: var(--royal); color: #fff;
  font-weight: 600; font-size: 17px; text-decoration: none;
  cursor: pointer; user-select: none;
  transition: transform .08s ease, background .15s ease;
}
@media (prefers-color-scheme: dark) { .btn { color: #0D1322; } }
.btn:active { transform: scale(.98); background: var(--royal-press); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--card); color: var(--royal); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.secondary:active { background: var(--royal-soft); }
.btn.ghost { background: transparent; color: var(--royal); min-height: 44px; padding: 0 12px; }
.btn.danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1.5px currentColor; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; white-space: nowrap; }
.btn-stack { display: grid; gap: 10px; }
:focus-visible { outline: 3px solid var(--royal); outline: 3px solid color-mix(in srgb, var(--royal) 55%, transparent); outline-offset: 2px; }

/* ---------- forms ---------- */
label.field { display: block; margin: 14px 0; }
label.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--ink-soft); margin: 0 4px 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 50px;
  padding: 12px 14px;
  font-size: 17px; /* >=16px: kein Zoom auf dem iPhone */
  border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: none; border-color: var(--royal); box-shadow: 0 0 0 3px var(--royal-soft); }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%); background-position: calc(100% - 20px) 22px, calc(100% - 14px) 22px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }
.error-box { background: var(--bad-bg); color: var(--bad); padding: 12px 14px; border-radius: 12px; margin: 12px 0; font-size: 15px; }
.note-box { background: var(--royal-soft); padding: 12px 14px; border-radius: 12px; margin: 12px 0; font-size: 15px; }

/* ---------- auth ---------- */
.auth { max-width: 420px; margin: 0 auto; padding-top: calc(48px + env(safe-area-inset-top)); }
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth h1 { font-family: var(--font-card); font-size: 34px; text-align: center; }
.auth p.lead { text-align: center; color: var(--ink-soft); margin: 8px 0 24px; }
.tabs { display: flex; background: var(--royal-soft); border-radius: 12px; padding: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- home ---------- */
.hello { font-family: var(--font-card); font-size: 30px; font-weight: 700; margin: 10px 4px 18px; }
.home-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 560px) { .home-actions { grid-template-columns: 1.4fr 1fr; } }
.home-actions .btn { min-height: 60px; justify-content: flex-start; padding: 0 20px; }
.marker { background: linear-gradient(transparent 12%, var(--marker) 12%, var(--marker) 88%, transparent 88%); color: var(--marker-ink); padding: 0 .2em; border-radius: 2px; }

.sheet-list { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; min-height: 64px;
  color: inherit; text-decoration: none;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
a.row:active { background: var(--royal-soft); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 14px; color: var(--ink-soft); margin-top: 2px; }
.chev { color: var(--ink-soft); opacity: .6; }
.progress { height: 6px; border-radius: 3px; background: var(--royal-soft); overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.pct { font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink-soft); min-width: 38px; text-align: right; }
.flag { font-size: 22px; line-height: 1; }
@media (min-width: 820px) {
  .lang-group .sheet-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .lang-group .row:nth-child(2) { border-top: 0; }
  .lang-group .row:nth-child(even) { border-left: 1px solid var(--line); }
}

.empty { text-align: center; padding: 36px 20px; }
.empty .stack-art { margin: 0 auto 16px; }
.empty h2 { font-family: var(--font-card); font-size: 22px; margin-bottom: 6px; }
.empty p { color: var(--ink-soft); margin: 0 auto 18px; max-width: 32ch; }

.install-hint { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow); font-size: 15px; }
.install-hint .icon-btn { width: 32px; height: 32px; margin: -6px -6px 0 auto; color: var(--ink-soft); }

/* ---------- index card ---------- */
.kcard {
  position: relative;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px 20px 26px;
  margin: 8px 0 22px;
  background-image:
    linear-gradient(var(--margin-red), var(--margin-red)),
    repeating-linear-gradient(to bottom, transparent 0, transparent 33px, var(--rule) 33px, var(--rule) 34px);
  background-size: 100% 2px, 100% calc(100% - 64px);
  background-position: 0 52px, 0 64px;
  background-repeat: no-repeat;
}
.kcard.stack::before, .kcard.stack::after {
  content: ""; position: absolute; left: 10px; right: 10px; height: 100%; top: 0;
  border-radius: 14px; background: var(--card); box-shadow: var(--shadow); z-index: -1;
  transform: translateY(7px) rotate(-1.2deg); opacity: .75;
}
.kcard.stack::after { left: 22px; right: 22px; transform: translateY(13px) rotate(1deg); opacity: .5; }
.kcard-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 28px; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.kcard-word {
  font-family: var(--font-card); font-weight: 700;
  font-size: clamp(28px, 8vw, 40px); line-height: 1.15;
  margin: 34px 0 6px; word-break: break-word; hyphens: auto;
}
.kcard-note { color: var(--ink-soft); font-size: 15px; min-height: 22px; }
.kcard.fb-correct { background-image: linear-gradient(var(--ok), var(--ok)), repeating-linear-gradient(to bottom, transparent 0, transparent 33px, var(--rule) 33px, var(--rule) 34px); box-shadow: var(--shadow), inset 0 0 0 3px var(--ok); }
.kcard.fb-close { background-image: linear-gradient(var(--close), var(--close)), repeating-linear-gradient(to bottom, transparent 0, transparent 33px, var(--rule) 33px, var(--rule) 34px); box-shadow: var(--shadow), inset 0 0 0 3px var(--close); }
.kcard.fb-wrong { background-image: linear-gradient(var(--bad), var(--bad)), repeating-linear-gradient(to bottom, transparent 0, transparent 33px, var(--rule) 33px, var(--rule) 34px); box-shadow: var(--shadow), inset 0 0 0 3px var(--bad); }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; margin: 4px 4px 10px; font-size: 15px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.quiz-top .progress { flex: 1; margin: 0; height: 8px; border-radius: 4px; }
.quiz-top .progress > i { background: var(--royal); }
.answer-input { font-size: 22px; min-height: 58px; font-family: var(--font-card); }
.keys { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.keys button { min-width: 42px; height: 42px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); font-size: 19px; cursor: pointer; }
.keys button:active { background: var(--royal-soft); }
.quiz-actions { display: flex; gap: 10px; margin-top: 14px; }
.quiz-actions .btn.primary-check { flex: 1; }
.feedback { border-radius: 14px; padding: 14px 16px; margin-top: 14px; }
.feedback h3 { font-size: 20px; font-family: var(--font-card); display: flex; align-items: center; gap: 8px; }
.feedback .reasons { font-size: 15px; margin-top: 2px; }
.feedback .solution { margin-top: 10px; font-size: 18px; }
.feedback .solution b { font-family: var(--font-card); }
.feedback .yours { margin-top: 4px; font-size: 15px; color: var(--ink-soft); }
.feedback .yours s { text-decoration-thickness: 2px; }
.fb-correct-box { background: var(--ok-bg); color: var(--ok); }
.fb-close-box { background: var(--close-bg); color: var(--close); }
.fb-wrong-box { background: var(--bad-bg); color: var(--bad); }
.feedback .solution, .feedback .solution b { color: var(--ink); }

.score { font-family: var(--font-card); font-size: 44px; font-weight: 700; line-height: 1; margin-top: 34px; }
.score-sub { font-size: 18px; margin-top: 8px; }
.tally { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 22px; }
.tally div { border-radius: 12px; padding: 10px; text-align: center; font-size: 14px; font-weight: 600; }
.tally b { display: block; font-size: 26px; font-family: var(--font-card); }

/* ---------- vocab lists ---------- */
.vlist .row { min-height: 56px; align-items: flex-start; }
.vpair { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr; gap: 2px; }
@media (min-width: 560px) { .vpair { grid-template-columns: 1fr 1fr; gap: 16px; } }
.vpair .f { font-weight: 600; }
.vpair .g { color: var(--ink-soft); }
.counts { display: flex; gap: 6px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; flex: none; padding-top: 2px; }
.counts span { padding: 2px 7px; border-radius: 7px; }
.c-ok { background: var(--ok-bg); color: var(--ok); }
.c-close { background: var(--close-bg); color: var(--close); }
.c-bad { background: var(--bad-bg); color: var(--bad); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; margin-top: 8px; }
.dot.l0 { background: var(--bad); } .dot.l1 { background: var(--close); } .dot.l2 { background: var(--ok); }

/* ---------- set detail ---------- */
.set-head { margin: 8px 4px 16px; }
.set-head h2 { font-family: var(--font-card); font-size: 28px; display: flex; gap: 10px; align-items: center; }
.set-head p { margin: 6px 0 0; color: var(--ink-soft); }
.danger-zone { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 28px; }

/* ---------- editor ---------- */
.erow { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; margin-bottom: 8px; display: grid; grid-template-columns: 1fr 44px; gap: 6px; }
.erow .pair { display: grid; grid-template-columns: 1fr; gap: 6px; }
/* Hinweisfeld nur zeigen, wenn es etwas enthält oder die Zeile bearbeitet wird */
.erow .note-in:placeholder-shown { display: none; }
.erow:focus-within .note-in { display: block; }
@media (min-width: 560px) { .erow .pair { grid-template-columns: 1fr 1fr; } .erow .pair .note-in { grid-column: 1 / -1; } }
.erow .input { min-height: 44px; padding: 9px 12px; }
.erow .note-in { font-size: 16px; min-height: 40px; padding: 8px 12px; color: var(--ink-soft); }
.erow .icon-btn { color: var(--bad); align-self: start; }
.save-bar { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 30%); }

/* ---------- scan ---------- */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin: 14px 0; }
.thumb { position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--card); box-shadow: var(--shadow); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.thumb button svg.i { width: 16px; height: 16px; }
.pick { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 160px; border-radius: 16px; border: 2px dashed var(--rule); background: var(--card); color: var(--royal); font-weight: 600; cursor: pointer; text-align: center; padding: 20px; }
.pick svg.i { width: 36px; height: 36px; }
.pick input { display: none; }
.tips { margin: 6px 4px 0; padding-left: 20px; color: var(--ink-soft); font-size: 15px; }

/* ---------- chips & segmented ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 14px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 15px; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--royal); border-color: var(--royal); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #0D1322; } }
.seg { display: grid; gap: 6px; }
.seg button { text-align: left; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 10px; color: var(--ink); }
.seg button::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--rule); flex: none; }
.seg button.on { border-color: var(--royal); background: var(--royal-soft); }
.seg button.on::before { border: 6px solid var(--royal); }
.check { display: flex; align-items: center; gap: 10px; margin: 6px 0 4px; font-size: 16px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--royal); }

/* ---------- bottom sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 16, 32, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--paper); border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .22s cubic-bezier(.2,.8,.2,1); }
@media (min-width: 620px) { .backdrop { align-items: center; } .sheet { border-radius: 22px; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--rule); margin: 0 auto 12px; }
.sheet h2 { font-family: var(--font-card); font-size: 22px; margin-bottom: 4px; }
.sheet h4 { margin: 18px 0 8px; font-size: 14px; color: var(--ink-soft); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* ---------- loading / toast ---------- */
.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 48px 20px; color: var(--ink-soft); text-align: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--royal-soft); border-top-color: var(--royal); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.overlay { position: fixed; inset: 0; z-index: 60; background: var(--paper); background: color-mix(in srgb, var(--paper) 92%, transparent); display: flex; align-items: center; justify-content: center; }
.overlay .loading { max-width: 300px; }
.overlay .loading strong { color: var(--ink); font-size: 19px; font-family: var(--font-card); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px; z-index: 70; font-weight: 600; font-size: 15px; animation: up .2s ease; max-width: calc(100% - 32px); }
.skeleton { height: 64px; border-radius: 16px; background: var(--card); opacity: .6; margin-bottom: 10px; }

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