:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #2e3856;
  --muted: #6b7393;
  --line: #e1e4ef;
  --primary: #4255ff;
  --primary-text: #ffffff;
  --know: #18ae79;
  --again: #ff8c3a;
  --danger: #e0435b;
  --shadow: 0 6px 24px rgba(46, 56, 86, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a092d;
    --surface: #2e3856;
    --text: #f6f7fb;
    --muted: #a8b1d1;
    --line: #424c70;
    --primary: #6b7bff;
    --shadow: 0 6px 24px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 1.4rem; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--bg); }
main { max-width: 640px; margin: 0 auto; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.view { display: flex; flex-direction: column; gap: 14px; }

input, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { width: 100%; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 140px; }
.row.small { font-size: .92rem; color: var(--muted); }
.row.actions { justify-content: space-between; flex-wrap: nowrap; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 10px;
  padding: 10px 16px; border: 2px solid var(--line); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; }
.btn.big { padding: 14px; font-size: 1.1rem; width: 100%; }
.know-btn { border-color: var(--know); color: var(--know); flex: 1; }
.again-btn { border-color: var(--again); color: var(--again); flex: 1; }

.deck-list, .card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.deck-list li {
  background: var(--surface); border-radius: 14px; padding: 16px; box-shadow: var(--shadow);
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.deck-list li:hover { outline: 2px solid var(--primary); }
.deck-list .name { font-weight: 700; overflow-wrap: anywhere; }
.deck-list .meta { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.card-list li {
  background: var(--surface); border-radius: 12px; padding: 10px 12px;
  display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center;
}
.card-list .t { font-weight: 600; overflow-wrap: anywhere; }
.card-list .d { color: var(--muted); overflow-wrap: anywhere; }
.card-list .known { color: var(--know); }
.card-list button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.05rem; padding: 4px; }
.empty { color: var(--muted); text-align: center; }
.hint { color: var(--muted); font-size: .9rem; margin: 0; }
.center { text-align: center; }
.check { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.box { background: var(--surface); border-radius: 14px; padding: 12px 14px; }
.box summary { font-weight: 700; cursor: pointer; }
.box[open] > * + * { margin-top: 10px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; }
.steps { margin: 0; padding-left: 20px; }

/* Lernmodus */
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--know); transition: width .3s; }
.counts { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.pill { padding: 4px 12px; border-radius: 99px; border: 2px solid; font-weight: 600; }
.pill.know { color: var(--know); }
.pill.again { color: var(--again); }
.stage { position: relative; height: min(52dvh, 420px); perspective: 1200px; touch-action: none; }
.card {
  position: absolute; inset: 0; cursor: grab; user-select: none; -webkit-user-select: none;
  transition: transform .3s ease;
}
.card.dragging { transition: none; cursor: grabbing; }
.card .inner {
  position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .45s;
}
.card.flipped .inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 600; overflow-wrap: anywhere;
  border: 3px solid transparent;
}
.face.back { transform: rotateY(180deg); }
.face .label { position: absolute; top: 14px; left: 0; right: 0; font-size: .8rem; font-weight: 500; color: var(--muted); }
.card .stamp {
  position: absolute; top: 24px; z-index: 2; padding: 4px 12px; border: 3px solid; border-radius: 8px;
  font-weight: 800; font-size: 1.1rem; opacity: 0; transform: rotate(-12deg); pointer-events: none;
}
.card .stamp.know { left: 24px; color: var(--know); }
.card .stamp.again { right: 24px; color: var(--again); transform: rotate(12deg); }
.card.behind { transform: scale(.95) translateY(10px); pointer-events: none; }
.card.behind .face { box-shadow: none; filter: brightness(.97); }

.done { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; padding-top: 30px; }
.done .big-emoji { font-size: 4rem; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 20;
  max-width: calc(100% - 32px);
}
