:root {
  --bg: #f4f5f9; --surface: #fff; --text: #1d2230; --muted: #667085; --line: #dfe3ec;
  --accent: #3b5bdb; --accent-text: #fff; --ok: #2f9e44; --bad: #e03131; --soft: #edf0ff;
  --radius: 10px; --shadow: 0 1px 3px rgba(20,30,60,.08), 0 4px 14px rgba(20,30,60,.06);
  --ratio: 1.695; /* Kartenformat 100 x 59 mm */
  --head: 49px;   /* Höhe der Kopfzeile */
  --s: 1;         /* Maßstab der Druckvorschau */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --surface: #1d2029; --text: #e8eaf2; --muted: #98a0b3; --line: #2e3340;
    --accent: #7b93ff; --accent-text: #10131c; --soft: #262c45; --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

header#top { flex: none; height: var(--head); display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
header .brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
header nav { display: flex; gap: 2px; flex: 1; }
header nav a { padding: 5px 11px; border-radius: 8px; text-decoration: none; color: var(--text); }
header nav a.active, header nav a:hover { background: var(--soft); }
header .who { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { flex: 1; min-height: 0; overflow: auto; width: 100%; max-width: 1100px; margin: 0 auto; padding: 14px 16px; }
main.fill { display: flex; flex-direction: column; overflow: hidden; max-width: 1000px; }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 6px 13px; border-radius: 8px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); }
button.small, .btn.small { padding: 3px 9px; font-size: .85rem; }
button.big-btn { padding: 11px 24px; font-size: 1.05rem; font-weight: 600; }
button:disabled { opacity: .45; cursor: default; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; max-width: 100%; }
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible, .editable:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.error { color: var(--bad); margin: 6px 0; min-height: 1.4em; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--accent); white-space: nowrap; }

.auth { max-width: 380px; margin: 4vh auto 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tabs button { flex: 1; justify-content: center; }
.tabs button.active { background: var(--soft); border-color: var(--accent); }

.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-top: 14px; }
.deck { display: flex; flex-direction: column; gap: 6px; padding: 12px; }
.deck h3 { margin: 0; overflow-wrap: anywhere; font-size: 1.05rem; }
.deck .actions { display: flex; gap: 5px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

/* Karten-Kacheln: festes Format 100 x 59 mm, Schrift passt sich automatisch an */
.tile { position: relative; display: flex; flex-direction: column; justify-content: center; overflow: hidden; background: #fff; color: #111; border: 1px solid #c9cfdd; border-radius: 6px; padding: 4%; text-align: center; aspect-ratio: var(--ratio); }
.tile .fit-inner { width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.18; font-size: 10px; }
.tile.empty .fit-inner { color: #9aa1b2; }
.tile .side { position: absolute; top: 6px; left: 10px; font-size: .72rem; color: #7b8296; text-transform: uppercase; letter-spacing: .05em; pointer-events: none; }
.editable { outline: none; cursor: text; min-height: 1em; }
.editable:empty::before { content: attr(data-ph); color: #9aa1b2; }

/* Stapel-Ansicht */
.deck-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.deck-bar .title-in { font-size: 1.15rem; font-weight: 600; min-width: 200px; flex: 1; max-width: 420px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.card-grid .tile { cursor: pointer; }
.card-grid .tile:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--soft); }
.card-grid .tile .num { position: absolute; top: 3px; left: 7px; font-size: .7rem; color: #8a92a6; }
.empty-state { text-align: center; padding: 8vh 0; }

/* Karten-Assistent, Lernen, Ansehen: alles in einer Bildschirmhöhe */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.stage .head { width: min(94vw, 900px); display: flex; align-items: center; gap: 10px; }
.stage .head .spacer { flex: 1; }
.big { width: min(94vw, 900px, calc((100dvh - var(--head) - 215px) * var(--ratio))); box-shadow: var(--shadow); border-radius: 12px; font-size: 16px; }
.big.click { cursor: pointer; user-select: none; }
.progress { width: min(94vw, 900px, calc((100dvh - var(--head) - 215px) * var(--ratio))); height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }
.answer-btns button { padding: 9px 20px; font-weight: 600; }
.answer-btns .ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.answer-btns .no { background: var(--bad); color: #fff; border-color: var(--bad); }
.overview { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; width: 100%; align-self: flex-start; overflow: auto; max-height: 100%; }
.overview .tile { cursor: pointer; }
.hint { font-size: .8rem; color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(560px, 92vw); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog textarea { height: 40vh; resize: none; }

/* Admin */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow: auto; max-height: calc(100dvh - var(--head) - 200px); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(80px); background: #222; color: #fff; padding: 9px 16px; border-radius: 8px; transition: transform .25s; z-index: 50; max-width: 90vw; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }

/* Druck: 10 Karten à 100 x 59 mm (2 x 5) auf A4 hochkant */
.print-wrap { flex: 1; min-height: 0; display: flex; justify-content: center; align-items: flex-start; }
.sheet-wrap { display: none; width: calc(210mm * var(--s)); height: calc(297mm * var(--s)); }
.sheet-wrap.cur { display: block; }
.sheet { width: 210mm; height: 297mm; padding: 1mm 5mm; background: #fff; color: #000; box-shadow: 0 2px 12px rgba(0,0,0,.25); transform: scale(var(--s)); transform-origin: 0 0; overflow: hidden; break-after: page; page-break-after: always; }
.sheet .grid { display: grid; grid-template-columns: repeat(2, 100mm); grid-template-rows: repeat(5, 59mm); }
.sheet .cell { width: 100mm; height: 59mm; border: .2mm dashed #888; padding: 3mm; display: flex; flex-direction: column; justify-content: center; overflow: hidden; text-align: center; }
.sheet .cell .fit-inner { width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.18; font-size: 10px; }
.sheet .cell.blank { border-color: transparent; }

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { height: auto; overflow: visible; display: block; background: #fff; }
  .no-print, header#top, #toast { display: none !important; }
  main, main.fill { display: block; overflow: visible; max-width: none; padding: 0; margin: 0; }
  .print-wrap { display: block; }
  .sheet-wrap, .sheet-wrap.cur { display: block; width: auto; height: auto; }
  .sheet { transform: none; box-shadow: none; height: 296.5mm; }
  .sheet-wrap:last-child .sheet { break-after: auto; page-break-after: auto; }
}

@media (max-width: 640px) {
  header .who, header .pw { display: none; }
  header { gap: 6px; padding: 0 10px; }
  header nav a { padding: 5px 7px; white-space: nowrap; font-size: .9rem; }
  main { padding: 10px; }
}
