:root {
  --bg: #f5f6fb; --surface: #fff; --line: #e3e6ef; --text: #1c2030; --muted: #687086;
  --accent: #5b5bd6; --accent-soft: #ececfd;
  --new: #3b82f6; --learn: #e5740b; --due: #12a594;
  --again: #e5484d; --hard: #d98a06; --good: #2f9e5c; --easy: #3b82f6;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 6px 20px rgba(20, 24, 50, .06);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11131b; --surface: #1a1d29; --line: #2a2e3f; --text: #e7e9f2; --muted: #969db3; --accent: #8b8bf5; --accent-soft: #26284a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, "Segoe UI", Roboto, sans-serif; display: flex; -webkit-tap-highlight-color: transparent; }
h2 { font-size: 1.35rem; margin: 0; } h3 { font-size: 1.05rem; margin: 0 0 .6rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .pad { padding: 1.5rem 0; }
kbd { font: 600 .7rem system-ui; border: 1px solid currentColor; border-radius: 5px; padding: 0 .35em; opacity: .55; margin-left: .5em; }

/* Navigation: Seitenleiste am Laptop, Leiste unten am Handy */
#nav { width: 210px; flex: none; padding: 1.2rem .8rem; display: flex; flex-direction: column; gap: .25rem; border-right: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; padding: 0 .5rem 1.2rem; }
.brand img { width: 30px; height: 30px; }
#nav button { display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: 10px; color: var(--muted); font-weight: 600; }
#nav button:hover { background: var(--bg); }
#nav button.on { background: var(--accent-soft); color: var(--accent); }
#nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#main { flex: 1; min-width: 0; overflow-y: auto; padding: 1.6rem clamp(1rem, 4vw, 2.5rem) 3rem; }
#main > * { max-width: 860px; margin-left: auto; margin-right: auto; }

.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; margin: 1.4rem auto .8rem; }
.row.end { justify-content: flex-end; margin-top: 1rem; }
.row.grow > * { flex: 1; min-width: 150px; }
.btn { padding: .5rem .9rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--again); border-color: color-mix(in srgb, var(--again) 40%, transparent); }
.btn.big { padding: .8rem 1.5rem; font-size: 1.05rem; border-radius: 12px; }
.btn.wide { width: 100%; max-width: 420px; }
.icon { width: 34px; height: 34px; border-radius: 8px; font-size: 1.2rem; color: var(--muted); }
.icon:hover { background: var(--bg); }

/* Übersicht */
.hero { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 1.4rem 1.6rem; border-radius: 20px; color: #fff;
  background: linear-gradient(120deg, #5b5bd6, #7c5cdb 55%, #12a594 130%); box-shadow: var(--shadow); }
.hero-label { font-weight: 600; opacity: .85; }
.hero-num { font-size: 3rem; font-weight: 800; line-height: 1.1; } .hero-num small { font-size: 1.1rem; font-weight: 600; opacity: .85; }
.hero-sub { opacity: .9; font-size: .92rem; }
.hero .btn { background: #fff; color: #4a4ac4; border: 0; }

.decks { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.deck { display: grid; grid-template-columns: 26px 1fr 52px 52px 52px 38px; align-items: center; padding: .2rem .5rem .2rem calc(.5rem + var(--depth, 0) * 20px); border-top: 1px solid var(--line); }
.deck:first-child { border-top: 0; }
.deck.head { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: .45rem; padding-bottom: .45rem; }
.deck:not(.head):hover { background: color-mix(in srgb, var(--c) 6%, transparent); }
.caret { color: var(--muted); font-size: 1.2rem; transition: transform .15s; height: 30px; } .caret.open { transform: rotate(90deg); }
.dname { display: flex; align-items: center; gap: .6rem; text-align: left; padding: .5rem .2rem; min-width: 0; }
.dname i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.dname b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dname small { color: var(--muted); font-size: .75rem; }
.cnt { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.cnt.new { color: var(--new); } .cnt.learn { color: var(--learn); } .cnt.due { color: var(--due); } .cnt.zero { color: var(--line); }

/* Lernen */
body[data-view=study] #main { display: flex; flex-direction: column; padding-bottom: 1rem; }
body[data-view=study] #main > * { width: 100%; }
.sbar { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.sbar .cnt { min-width: 1.6rem; } .stitle { font-weight: 700; }
.card { flex: 1; background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--c); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 1.2rem clamp(1rem, 4vw, 2.2rem) 2rem; overflow-y: auto; min-height: 220px; }
.card-deck { font-size: .78rem; color: var(--muted); margin-bottom: 1.2rem; }
.content { font-size: 1.25rem; line-height: 1.55; text-align: center; overflow-wrap: anywhere; }
.content img { max-width: 100%; max-height: 55vh; border-radius: 8px; }
.content ul, .content ol { display: inline-block; text-align: left; }
.content table { margin: .5rem auto; border-collapse: collapse; } .content td, .content th { border: 1px solid var(--line); padding: .3rem .6rem; }
.cloze { color: var(--accent); font-weight: 700; }
hr.ans { border: 0; border-top: 2px dashed var(--line); margin: 1.4rem 0; }
.answer { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; padding-top: 1rem; justify-items: center; }
.answer > .wide { grid-column: 1 / -1; }
.rate { width: 100%; padding: .55rem .3rem .65rem; border-radius: 12px; color: #fff; font-weight: 700; display: flex; flex-direction: column; align-items: center; position: relative; }
.rate small { font-weight: 600; opacity: .9; font-size: .78rem; } .rate kbd { position: absolute; right: 8px; top: 8px; }
.rate.again { background: var(--again); } .rate.hard { background: var(--hard); } .rate.good { background: var(--good); } .rate.easy { background: var(--easy); }
.rate:hover { filter: brightness(1.08); }
.done { text-align: center; margin-top: 12vh !important; } .done p { margin: .4rem 0 1.4rem; }
.done-mark { width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 1rem; display: grid; place-items: center; font-size: 2.4rem; color: #fff; background: var(--due); }

/* Kartenliste */
.filters { margin-bottom: .6rem; } .filters input { flex: 2; min-width: 180px; } .filters select { flex: 1; min-width: 140px; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; width: 100%; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; font-family: inherit; }
.nrow { display: grid; grid-template-columns: 1fr 1fr auto; gap: .8rem; width: 100%; text-align: left; align-items: center; padding: .6rem .8rem; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 10px; margin-bottom: .35rem; }
.nrow:hover { border-color: var(--accent); border-left-color: var(--c); }
.nf, .nb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .nb { color: var(--muted); }
.nm { display: flex; gap: .3rem; }
.tag { font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 99px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.tag.new { color: var(--new); } .tag.learn { color: var(--learn); } .tag.due { color: var(--due); }

/* Statistik & Einstellungen */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; margin-top: 1rem; }
.tile, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem; }
.tile b { font-size: 1.8rem; display: block; line-height: 1.2; } .tile span { font-weight: 600; display: block; } .tile small { color: var(--muted); }
.panel { margin-top: .8rem; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-bottom: 1.3rem; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; min-width: 0; }
.bar i { width: 100%; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .9; } .bar:hover i { opacity: 1; }
.bar em { font-style: normal; font-size: .62rem; color: var(--muted); }
.bar span { position: absolute; bottom: -1.3rem; font-size: .65rem; color: var(--muted); white-space: nowrap; }
.mix { display: flex; height: 16px; border-radius: 8px; overflow: hidden; gap: 2px; background: var(--bg); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; font-size: .88rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; }
.field, .editor label, .sheet form > label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .8rem; }
.field input, .editor input, .editor select, .editor textarea, .sheet form > label input, .sheet form > label select { margin-top: .3rem; font-weight: 400; font-size: 1rem; }
.field { max-width: 380px; } .field small { font-weight: 400; }
.check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .9rem; font-size: .92rem; font-weight: 400 !important; }

/* Dialoge */
#modal { position: fixed; inset: 0; background: rgba(15, 18, 35, .5); display: grid; place-items: center; padding: 1rem; z-index: 10; overflow-y: auto; }
#modal[hidden], #toast[hidden] { display: none; }
.sheet { background: var(--surface); border-radius: 18px; padding: 1.3rem 1.4rem; width: min(560px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.menu { display: grid; } .menu button { text-align: left; padding: .75rem .6rem; border-radius: 10px; font-weight: 600; } .menu button:hover { background: var(--bg); } .menu .red { color: var(--again); }
.tools { float: right; display: flex; gap: .2rem; } .tools button { font-size: .78rem; padding: .1rem .5rem; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); }
.tools button:hover { color: var(--accent); border-color: var(--accent); }
.pv { margin-bottom: 1rem; } .pv summary { cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--muted); } .pv .content { font-size: 1.05rem; padding: .6rem 0; } .pv hr.ans { margin: .4rem 0; }
#toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); background: #1c2030; color: #fff; padding: .6rem 1rem; border-radius: 12px; z-index: 20; max-width: 90vw; box-shadow: var(--shadow); font-size: .92rem; }

/* Anmeldung, Nutzerverwaltung, Sync-Hinweis */
body[data-view=login] #nav { display: none; }
.login { max-width: 340px !important; margin-top: 10vh !important; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 2rem 1.6rem; box-shadow: var(--shadow); text-align: center; }
.login img { width: 64px; height: 64px; } .login h1 { margin: .4rem 0 1.4rem; font-size: 1.6rem; }
.login label { display: block; text-align: left; font-weight: 600; font-size: .88rem; margin-bottom: .9rem; } .login input { margin-top: .3rem; font-weight: 400; font-size: 1rem; }
.login .btn { width: 100%; }
.err { color: var(--again); font-size: .9rem; min-height: 1.3rem; margin: 0 0 .6rem; }
.row.flat { margin: 0 0 .4rem; } .row.flat h3 { margin: 0; }
.urow { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.urow b { margin-right: .4rem; } .urow .tag { margin-right: .3rem; } .urow small { display: block; }
#syncpill { position: fixed; top: .7rem; right: .9rem; z-index: 5; background: var(--learn); color: #fff; font-size: .78rem; font-weight: 700; padding: .3rem .8rem; border-radius: 99px; box-shadow: var(--shadow); }
#syncpill[hidden] { display: none; }

@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  #nav { width: 100%; flex-direction: row; justify-content: space-around; padding: .3rem .3rem calc(.3rem + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); }
  .brand { display: none; }
  #nav button { flex-direction: column; gap: .1rem; font-size: .7rem; padding: .35rem .8rem; }
  body[data-view=study] #nav { display: none; }
  #main { padding-top: 1rem; }
  .tiles { grid-template-columns: 1fr 1fr; } .tile b { font-size: 1.5rem; }
  .hero { padding: 1.1rem 1.2rem; } .hero .btn { width: 100%; }
  .deck { grid-template-columns: 24px 1fr 38px 38px 38px 34px; padding-left: calc(.3rem + var(--depth, 0) * 14px); }
  .deck.head { font-size: .56rem; letter-spacing: 0; }
  .filters input, .filters select { flex: 1 1 100%; }
  .nrow { grid-template-columns: 1fr; gap: .15rem; }
  .content { font-size: 1.12rem; }
  .rate kbd, .btn kbd { display: none; }
  .sheet { padding: 1.1rem; }
}
