/* Design A · Fokus — hell, reduziert, ein Akzent */
:root {
  --bg: #F4F2EE;
  --surface: #FFFFFF;
  --ink: #1A1A1A;
  --muted: #6B665E;
  --soft: #4A463F;
  --line: #D9D5CD;
  --line-2: #E2DED6;
  --accent: #2F5BEA;
  --accent-ink: #FFFFFF;
  --new: #2F5BEA;
  --learn: #B4530B;
  --due: #1E7A4C;
  --danger: #B42318;
  --star: #B7791F;
  --shadow: 0 1px 2px rgba(26, 26, 26, .06), 0 12px 32px rgba(26, 26, 26, .06);
  --radius: 28px;
  color-scheme: light;
}
/* Dunkel: automatisch nach Systemeinstellung (data-theme fehlt) oder fest gewählt (data-theme="dark") */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1F1E1C;
    --ink: #F2F0EB;
    --muted: #A39E95;
    --soft: #C9C4BB;
    --line: #3A3834;
    --line-2: #2E2C29;
    --accent: #6D8DF5;
    --accent-ink: #0E1430;
    --new: #8EA8F7;
    --learn: #F0A866;
    --due: #6FCF97;
    --danger: #F97066;
    --star: #F2C94C;
  --star: #F2C94C;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1F1E1C;
  --ink: #F2F0EB;
  --muted: #A39E95;
  --soft: #C9C4BB;
  --line: #3A3834;
  --line-2: #2E2C29;
  --accent: #6D8DF5;
  --accent-ink: #0E1430;
  --new: #8EA8F7;
  --learn: #F0A866;
  --due: #6FCF97;
  --danger: #F97066;
  --star: #F2C94C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.loading { padding: 40px; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
.shell { min-height: 100%; display: flex; }
.sidebar { display: none; }
.main {
  flex: 1; min-width: 0;
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 20px;
  max-width: 760px; margin: 0 auto; width: 100%;
}
@media (min-width: 900px) {
  .shell.with-sidebar .sidebar {
    display: flex; flex-direction: column; gap: 28px;
    width: 280px; flex-shrink: 0; padding: 32px 20px;
    border-right: 1px solid var(--line-2);
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .main { padding: 32px 48px 40px; max-width: 960px; }
  .shell.with-sidebar .main { max-width: none; }
  .shell.with-sidebar .back { display: none; }
}

.brand { font-size: 20px; font-weight: 800; letter-spacing: -.02em; text-decoration: none; padding: 0 12px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; }
.muted { color: var(--muted); }

.side-list { display: flex; flex-direction: column; gap: 4px; }
.side-list .eyebrow { padding: 0 12px 8px; }
.side-link {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px; border-radius: 12px; text-decoration: none; font-size: 15px; font-weight: 500;
}
.side-link:hover { background: var(--line-2); }
.side-link[aria-current="page"] { background: var(--surface); font-weight: 700; }
.side-name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.side-name svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--muted); }
.folder-ico { width: 40px; height: 40px; border-radius: 12px; background: var(--line-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.deck-row .folder-ico svg { width: 20px; height: 20px; color: var(--soft); }
.crumbs a { color: inherit; text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.side-link .n { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-link .n.hot { color: var(--accent); font-weight: 700; }

/* Topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.topbar .title { display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; }
.topbar .title strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 22px;
  border: 1px solid var(--line); background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--line-2); }
.icon-btn svg { width: 20px; height: 20px; }
.spacer { width: 44px; flex-shrink: 0; }

/* Buttons */
.btn {
  height: 52px; padding: 0 24px; border-radius: 26px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.dashed { background: transparent; border-style: dashed; color: var(--soft); }
.btn.danger { color: var(--danger); background: transparent; }
.btn.small { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 20px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn .kbd { opacity: .6; font-weight: 500; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row > .btn { flex: 1 1 auto; }

/* Home */
.hero { display: flex; flex-direction: column; gap: 6px; padding: 8px 0 4px; }
.hero h1 { font-size: 34px; }
.deck-list { display: flex; flex-direction: column; gap: 10px; }
.deck-row {
  display: flex; align-items: center; gap: 14px; padding: 18px 20px;
  background: var(--surface); border-radius: 20px; text-decoration: none; box-shadow: var(--shadow);
}
.deck-row .name { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.deck-row .meta { font-size: 13px; color: var(--muted); }
.deck-row svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.counts { display: flex; gap: 10px; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.c-new { color: var(--new); } .c-learn { color: var(--learn); } .c-due { color: var(--due); }
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-radius: 16px; border: 1px solid var(--line); font-size: 14px;
}
.empty { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; gap: 14px; }

/* Deck */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.search {
  height: 48px; width: 100%; border-radius: 24px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 20px;
}
.card-list { display: flex; flex-direction: column; gap: 6px; }
.card-item {
  width: 100%; text-align: left; border: none; background: var(--surface); border-radius: 16px;
  padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start;
}
.card-item:hover { outline: 1px solid var(--line); }
.card-item .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-item .f { font-weight: 600; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-item .b { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 10px; border: 1px solid var(--line); white-space: nowrap; color: var(--muted); }
.chip.new { color: var(--new); } .chip.learn { color: var(--learn); } .chip.due { color: var(--due); }

/* Study */
.study { min-height: calc(100vh - 64px); min-height: calc(100dvh - 64px); display: flex; flex-direction: column; gap: 20px; }
.progress { height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }
.flashcard {
  flex: 1; min-height: 340px; width: 100%; border: none; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); padding: 32px 28px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 24px; text-align: left;
}
.flashcard .side { color: var(--accent); }
.flashcard .q { font-size: 30px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; white-space: pre-wrap; overflow-wrap: anywhere; }
.flashcard .q.long { font-size: 22px; }
.flashcard .q.xlong { font-size: 18px; font-weight: 600; letter-spacing: 0; }
.flashcard .a { display: flex; flex-direction: column; gap: 16px; }
.flashcard .a .q { font-size: 18px; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.flashcard .a .ans { font-size: 20px; line-height: 1.5; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.flashcard .hint { font-size: 13px; color: var(--muted); }
.ratings { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.rate {
  height: 64px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0 4px;
}
.rate b { font-size: 14px; }
.rate span { font-size: 12px; color: var(--muted); }
.rate.good { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rate.good span { color: inherit; opacity: .85; }
.study-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 40px; }

/* Schalter „Antwort tippen“ */
.toggle .switch {
  width: 30px; height: 18px; border-radius: 9px; background: var(--line); position: relative; flex-shrink: 0;
  transition: background .2s;
}
.toggle .switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 7px;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .2s;
}
.toggle[aria-pressed="true"] .switch { background: var(--accent); }
.toggle[aria-pressed="true"] .switch::after { transform: translateX(12px); }

/* Favoriten */
.card-row { display: flex; align-items: stretch; gap: 6px; }
.card-row .card-item { flex: 1; min-width: 0; }
.star-btn {
  width: 48px; flex-shrink: 0; border: none; border-radius: 16px; background: var(--surface);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.star-btn:hover { color: var(--star); }
.star-btn[aria-pressed="true"], .star-ico, .star-toggle[aria-pressed="true"] svg { color: var(--star); }
.star-ico { display: inline-flex; }
.star-ico svg { width: 16px; height: 16px; }
.folder-ico.star-ico svg { width: 20px; height: 20px; }
.card-filter { align-self: flex-start; }
.card-filter .seg-btn { display: inline-flex; align-items: center; gap: 6px; }
.card-filter .seg-btn[disabled] { opacity: .5; cursor: default; }
.fav-group { display: flex; flex-direction: column; gap: 8px; }
.fav-head { text-decoration: none; }
.fav-head:hover { color: var(--ink); }

/* Bilder auf Karten */
.q-wrap { display: flex; flex-direction: column; gap: 18px; }
.card-img {
  display: block; max-width: 100%; max-height: 38vh; width: auto; height: auto;
  border-radius: 16px; object-fit: contain; align-self: flex-start; background: var(--line-2);
}
.q-mini { display: flex; align-items: center; gap: 12px; }
.q-mini img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; flex-shrink: 0; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; flex-shrink: 0; }
.side-edit { display: flex; flex-direction: column; gap: 8px; }
.img-slot .img-add { align-self: flex-start; }
.img-slot .img-add svg { color: var(--muted); }
.img-preview { display: flex; align-items: center; gap: 12px; }
.img-preview img { width: 88px; height: 88px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
dialog p.img-hint { font-size: 13px; }
@media (pointer: coarse) { dialog p.img-hint { display: none; } }

/* Lernoptionen */
.options { display: flex; flex-direction: column; background: var(--surface); border-radius: 18px; padding: 4px 16px; }
dialog .options { background: var(--bg); }
.opt-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 56px; padding: 8px 0; border: none; background: transparent; width: 100%; text-align: left;
}
.opt-row + .opt-row { border-top: 1px solid var(--line-2); }
.opt-label { font-size: 15px; font-weight: 600; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--line-2); padding: 3px; border-radius: 14px; }
.seg-btn {
  height: 36px; padding: 0 12px; border: none; border-radius: 11px; background: transparent;
  font-size: 13px; font-weight: 700; color: var(--soft);
}
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
dialog .seg-btn[aria-pressed="true"] { background: var(--surface); }
.btn svg { flex-shrink: 0; }

/* Antwort tippen */
.type-form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.type-form textarea {
  width: 100%; min-height: 56px; resize: none; border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); padding: 15px 18px; font-size: 18px; font-weight: 600; line-height: 1.4;
}
.type-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.chars { display: flex; flex-wrap: wrap; gap: 6px; }
.char {
  min-width: 40px; height: 40px; padding: 0 8px; border-radius: 12px; border: 1px solid var(--line);
  background: transparent; font-size: 16px; font-weight: 700;
}
.char:hover { background: var(--line-2); }
.yours { display: flex; flex-direction: column; gap: 6px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.verdict { font-size: 13px; font-weight: 800; letter-spacing: .02em; }
.verdict.ok { color: var(--due); }
.verdict.almost { color: var(--learn); }
.verdict.bad { color: var(--danger); }
.typed { font-size: 18px; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.typed del { color: var(--danger); text-decoration: line-through; text-decoration-thickness: 2px; }
.typed ins { color: var(--due); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.rate.suggest { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (min-width: 900px) {
  .type-form { max-width: 720px; }
  .flashcard:not(button) { cursor: default; }
}
@media (max-width: 899px) {
  /* Beim Tippen Platz für die Bildschirmtastatur lassen */
  .stage:has(.type-form) .flashcard { min-height: 180px; padding: 24px; }
  .chars { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -20px; padding: 0 20px; }
  .chars::-webkit-scrollbar { display: none; }
  .char { flex-shrink: 0; }
}
.kbd-hint { display: none; }
@media (min-width: 900px) {
  .study .stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
  .flashcard { max-width: 720px; min-height: 400px; flex: 0 0 auto; padding: 48px 56px; border-radius: 32px; }
  .flashcard .q { font-size: 40px; }
  .flashcard .q.long { font-size: 28px; }
  .flashcard .q.xlong { font-size: 21px; }
  .flashcard .a .ans { font-size: 24px; }
  .ratings, .study .reveal { width: 100%; max-width: 720px; }
  .ratings { gap: 12px; }
  .kbd-hint { display: inline; }
}
@media (max-width: 899px) {
  .study .stage { flex: 1; display: flex; flex-direction: column; gap: 20px; }
}
.done { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 40px 0; }
.done h1 { font-size: 32px; }

/* Dialog */
dialog {
  border: none; border-radius: 24px; padding: 0; width: min(560px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(20, 20, 19, .45); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
dialog h2 { margin: 0; font-size: 20px; font-weight: 800; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
dialog input[type="text"], dialog input[type="number"], dialog textarea, dialog select {
  width: 100%; border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
  padding: 12px 14px; font-size: 16px; font-weight: 500;
}
dialog textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
dialog textarea.big { min-height: 200px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
dialog .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
dialog .actions .left { margin-right: auto; }
dialog p { margin: 0; font-size: 14px; color: var(--muted); }
dialog hr { border: none; border-top: 1px solid var(--line-2); margin: 4px 0; width: 100%; }
@media (max-width: 600px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 24px 24px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}

#confirm-dlg { width: min(440px, calc(100vw - 24px)); }
.confirm-msg { margin: 0; font-size: 16px !important; line-height: 1.5; color: var(--ink) !important; white-space: pre-line; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 22px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Favoriten üben */
.ratings.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ratings.two .rate span { text-align: center; }
.fav-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Sync */
.sync-line { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: var(--muted); }
.sync-line .dot { width: 8px; height: 8px; border-radius: 4px; background: var(--line); flex-shrink: 0; }
.sync-line[data-state="ok"] .dot { background: var(--due); }
.sync-line[data-state="syncing"] .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-line[data-state="offline"] .dot { background: var(--learn); }
.sync-line[data-state="error"] .dot, .sync-line[data-state="signed-out"] .dot { background: var(--danger); }
.sidebar .sync-line { padding: 0 12px; }
.sync-box { display: flex; flex-direction: column; gap: 12px; }
dialog input[type="email"], dialog input[type="password"] {
  width: 100%; border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
  padding: 12px 14px; font-size: 16px; font-weight: 500;
}
@keyframes pulse { 50% { opacity: .35; } }
