:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #eef1f7; --border: #dfe3ec;
  --text: #0f172a; --text-2: #475569; --muted: #94a3b8;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-soft: #dbeafe;
  --new: #2563eb; --learn: #d97706; --due: #16a34a; --young: #60a5fa; --mature: #1e3a8a;
  --again: #dc2626; --hard: #d97706; --good: #16a34a; --easy: #2563eb;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px -12px rgba(15,23,42,.18);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #121a2b; --surface-2: #1a2438; --border: #243049;
    --text: #e6ebf5; --text-2: #aab6cc; --muted: #6b7a94;
    --accent: #60a5fa; --accent-2: #93c5fd; --accent-soft: #1e3a8a;
    --young: #3b82f6; --mature: #93c5fd;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .92em; }
pre { background: var(--surface-2); padding: .75rem; border-radius: 8px; overflow-x: auto; }
pre code { background: none; padding: 0; }
table { border-collapse: collapse; margin: .5rem 0; font-size: .95em; }
td, th { border: 1px solid var(--border); padding: .3rem .55rem; text-align: left; }

.top { display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.top nav a { margin-left: 1rem; color: var(--text-2); font-weight: 500; }
.top nav a.active { color: var(--accent); }
main { max-width: 900px; margin: 0 auto; padding: 1.25rem 1rem 6rem; }
.loading { color: var(--muted); text-align: center; padding: 3rem; }

.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .55rem 1rem; border-radius: 10px; font-weight: 600; transition: transform .05s, background .15s; }
.btn:hover { background: var(--surface-2); } .btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.sm { padding: .35rem .7rem; font-size: .9rem; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.danger { color: var(--again); }
.btn:disabled { opacity: .5; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .text2 { color: var(--text-2); }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }

/* dashboard */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .7rem .9rem; }
.stat .v { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--text-2); font-size: .8rem; }
.deck { display: flex; flex-direction: column; gap: .6rem; cursor: pointer; }
.deck:hover { border-color: var(--accent); }
.deck .icon { font-size: 1.7rem; }
.deck h3 { margin: 0; }
.counts { display: flex; gap: .9rem; font-size: .85rem; font-weight: 600; }
.counts .n { color: var(--new); } .counts .l { color: var(--learn); } .counts .d { color: var(--due); }
.bar { display: flex; height: 8px; border-radius: 6px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.bar span { display: block; height: 100%; }
.bar .mature { background: var(--mature); } .bar .young { background: var(--young); } .bar .learning { background: var(--learn); }
.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }

/* deck page */
.intro { font-size: .98rem; }
.intro h1, .intro h2, .intro h3 { margin-top: 1rem; }
.topic { display: grid; grid-template-columns: 1fr auto; gap: .5rem 1rem; align-items: center; padding: .8rem 0; border-top: 1px solid var(--border); }
.topic:first-child { border-top: 0; }
.topic .bar { margin-top: .4rem; }
.topic .summary { grid-column: 1 / -1; font-size: .9rem; color: var(--text-2); display: none; }
.topic.open .summary { display: block; }

/* study */
.study-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.progress { display: flex; gap: .8rem; font-weight: 700; font-size: .9rem; }
.progress .n { color: var(--new); } .progress .l { color: var(--learn); } .progress .d { color: var(--due); }
.flash { min-height: 260px; display: flex; flex-direction: column; }
.flash .meta { display: flex; gap: .5rem; align-items: center; font-size: .78rem; color: var(--muted); margin-bottom: .8rem; flex-wrap: wrap; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.badge.rechnung, .badge.formel { background: var(--accent-soft); color: var(--accent); }
.front { font-size: 1.3rem; font-weight: 600; line-height: 1.35; }
.back { border-top: 1px dashed var(--border); margin-top: 1rem; padding-top: 1rem; font-size: 1.02rem; }
.back .example { margin-top: .8rem; background: var(--surface-2); border-radius: 10px; padding: .7rem .9rem; font-size: .95rem; }
.back .example::before { content: "Beispiel"; display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .3rem; font-weight: 700; }
.actions { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom)); z-index: 9; }
.actions .inner { max-width: 900px; margin: 0 auto; display: flex; gap: .5rem; }
.actions .btn { flex: 1; justify-content: center; flex-direction: column; gap: 0; padding: .5rem .3rem; line-height: 1.2; }
.actions .btn small { font-weight: 500; color: var(--text-2); font-size: .75rem; }
.actions .btn.again { border-color: var(--again); color: var(--again); }
.actions .btn.hard { border-color: var(--hard); color: var(--hard); }
.actions .btn.good { border-color: var(--good); color: var(--good); }
.actions .btn.easy { border-color: var(--easy); color: var(--easy); }
.actions .btn.show { background: var(--accent); color: #fff; border-color: var(--accent); }
.kbd { display: inline-block; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 .35rem; font-size: .72rem; color: var(--muted); }
.done { text-align: center; padding: 2rem 1rem; }
.done .big { font-size: 3rem; }
.saved { font-size: .75rem; color: var(--muted); }
.saved.ok::before { content: "✓ "; color: var(--good); }

/* browse */
.search { width: 100%; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; }
select { padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
.item { padding: .7rem 0; border-top: 1px solid var(--border); cursor: pointer; }
.item .q { font-weight: 600; }
.item .a { display: none; margin-top: .5rem; color: var(--text-2); font-size: .95rem; }
.item.open .a { display: block; }
.state { font-size: .75rem; color: var(--muted); }
.state.due { color: var(--due); } .state.learn { color: var(--learn); } .state.new { color: var(--new); }

/* stats */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; margin-top: .5rem; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.chart .col b { display: block; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.chart .col:hover b { opacity: 1; }
.chart .col .tip { display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); font-size: .72rem; padding: .15rem .4rem; border-radius: 5px; white-space: nowrap; z-index: 2; }
.chart .col:hover .tip { display: block; }
.axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: .25rem; }
.deckbar { display: grid; grid-template-columns: 150px 1fr 60px; gap: .75rem; align-items: center; padding: .4rem 0; font-size: .9rem; }
.deckbar .bar { height: 12px; }
.deckbar .bar .new { background: var(--surface-2); }
input[type=number] { width: 80px; padding: .4rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }

.login { max-width: 360px; margin: 4rem auto; text-align: center; }
.login input { width: 100%; padding: .7rem; margin: .75rem 0; border: 1px solid var(--border); border-radius: 10px; font: inherit; background: var(--surface); color: var(--text); }
.err { color: var(--again); font-size: .9rem; }

.toast { position: fixed; bottom: 6rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .5rem .9rem; border-radius: 999px; font-size: .9rem; z-index: 20; box-shadow: var(--shadow); }
.toast[hidden] { display: none; }

@media (max-width: 600px) {
  main { padding: 1rem .85rem 7rem; }
  .front { font-size: 1.15rem; }
  .deckbar { grid-template-columns: 1fr; gap: .2rem; }
  .top nav a { margin-left: .75rem; }
}
