:root {
  --bg: #f4f5f9; --card: #ffffff; --text: #181a22; --muted: #6b7080; --line: #e3e5ee;
  --accent: #4f46e5; --accent-2: #6d5ff0; --accent-text: #fff;
  --again: #e5484d; --hard: #f08c00; --good: #2f9e63; --easy: #2b7de9;
  --shadow: 0 1px 2px rgba(20,22,40,.06), 0 6px 20px rgba(20,22,40,.06);
  --r: 18px;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1117; --card: #1a1d27; --text: #eceef5; --muted: #9096a8; --line: #2a2e3b;
    --accent: #7c74ff; --accent-2: #8f88ff; --accent-text: #0f1117; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
#app { min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 780px; margin: 0 auto;
  padding: calc(var(--sat) + 18px) calc(var(--sar) + 16px) calc(90px + var(--sab)) calc(var(--sal) + 16px); }
h1 { font-size: 30px; line-height: 1.15; margin: 4px 0 14px; letter-spacing: -.5px; }
h2 { font-size: 20px; margin: 22px 0 10px; letter-spacing: -.2px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

/* Navigation: unten auf iPhone, links auf iPad */
nav#nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + var(--sab)); background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px); border-top: 1px solid var(--line); }
nav#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; min-height: 48px; }
nav#nav a svg { width: 26px; height: 26px; }
nav#nav a.on { color: var(--accent); }
@media (min-width: 900px) {
  nav#nav { top: 0; right: auto; bottom: 0; width: 96px; flex-direction: column; justify-content: flex-start; gap: 6px;
    padding: calc(var(--sat) + 20px) 8px 16px calc(var(--sal) + 8px); border-top: 0; border-right: 1px solid var(--line); }
  #app.has-nav main { margin-left: max(96px, calc((100% - 780px) / 2 + 48px)); margin-right: auto; padding-bottom: 40px; }
}
#app.studying nav#nav { display: none; }
#app.studying main { padding-bottom: calc(24px + var(--sab)); margin-left: auto; margin-right: auto; }

/* Bausteine */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
a.card, .tap { display: block; color: inherit; text-decoration: none; cursor: pointer; }
a.card:active, .tap:active { transform: scale(.985); }
.grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.two .card + .card { margin-top: 0; } }
.btn { appearance: none; border: 0; border-radius: 14px; background: var(--card); color: var(--accent); font: inherit; font-weight: 650;
  min-height: 48px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  box-shadow: var(--shadow); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-text); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.danger { color: var(--again); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 22px; height: 22px; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--accent); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.badge.new { background: color-mix(in srgb, var(--easy) 16%, transparent); color: var(--easy); }
.badge.due { background: color-mix(in srgb, var(--again) 14%, transparent); color: var(--again); }
.badge.ok { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.badge.warn { background: color-mix(in srgb, var(--hard) 18%, transparent); color: var(--hard); }

input, textarea, select { width: 100%; font: inherit; font-size: 17px; /* >=16px verhindert iOS-Zoom */ color: var(--text); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px; appearance: none; -webkit-appearance: none; }
textarea { resize: vertical; min-height: 96px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.hero { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-text); border-radius: 22px; padding: 20px; box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 30%, transparent); }
.hero .big { font-size: 44px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.hero .btn { background: rgba(255,255,255,.95); color: #4f46e5; margin-top: 14px; box-shadow: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.deck-title { font-weight: 700; font-size: 18px; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; opacity: .5; }

/* Karten-Liste */
.clist .item { padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.clist .item:first-child { border-top: 0; }
.clist .q { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clist .a { color: var(--muted); font-size: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Scan */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 12px; overflow: hidden; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; line-height: 1; }
.thumb .pdf { display: grid; place-items: center; height: 100%; font-weight: 800; color: var(--muted); }
.prop { display: grid; grid-template-columns: 32px 1fr; gap: 10px; }
.prop input[type=checkbox] { width: 26px; height: 26px; min-height: 0; padding: 0; margin-top: 6px; accent-color: var(--accent); }
.prop textarea { min-height: 64px; margin-bottom: 8px; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Lernmodus */
.study-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.bar { flex: 1; height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.flash { min-height: min(52dvh, 460px); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 28px 22px;
  font-size: 22px; line-height: 1.4; cursor: pointer; user-select: none; -webkit-user-select: none; position: relative; }
@media (min-width: 700px) { .flash { font-size: 26px; min-height: 420px; } }
.flash .txt { white-space: pre-wrap; overflow-wrap: anywhere; width: 100%; }
.flash .lab { position: absolute; top: 12px; left: 16px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.flash hr { width: 60%; border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.flash .ans { color: var(--accent); font-weight: 650; }
.flash.flip { animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.97); opacity: .6; } to { transform: none; opacity: 1; } }
.cz-blank { display: inline-block; min-width: 56px; border-bottom: 3px solid var(--accent); color: transparent; user-select: none; }
.cz-ans { color: var(--accent); font-weight: 750; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.rate button { appearance: none; border: 0; border-radius: 14px; padding: 10px 2px 9px; font: inherit; font-weight: 700; color: #fff; min-height: 62px; cursor: pointer; }
.rate button small { display: block; font-weight: 500; font-size: 12px; opacity: .9; margin-top: 2px; }
.rate .r1 { background: var(--again); } .rate .r2 { background: var(--hard); } .rate .r3 { background: var(--good); } .rate .r4 { background: var(--easy); }
.rate button:active { transform: scale(.96); }
.showbtn { margin-top: 14px; }

/* Statistik */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat .n { font-size: 32px; font-weight: 800; letter-spacing: -.5px; }
.week { display: flex; align-items: flex-end; gap: 8px; height: 110px; margin-top: 10px; }
.week > div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; font-size: 12px; color: var(--muted); }
.week i { width: 100%; max-width: 34px; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg, var(--accent-2), var(--accent)); min-height: 3px; }

/* Sheet */
dialog#sheet { border: 0; padding: 0; background: var(--card); color: var(--text); width: min(560px, 100%); max-height: 88dvh; border-radius: 22px 22px 0 0;
  margin: auto auto 0; box-shadow: 0 -10px 40px rgba(0,0,0,.25); overflow: auto; }
dialog#sheet::backdrop { background: rgba(0,0,0,.4); }
@media (min-width: 700px) { dialog#sheet { margin: auto; border-radius: 22px; } }
.sheet-in { padding: 18px 18px calc(18px + var(--sab)); }
.sheet-in h2 { margin-top: 0; }
.sheet-in .actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-in .actions .btn { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(86px + var(--sab)); transform: translate(-50%, 20px); background: #222; color: #fff; padding: 11px 18px; border-radius: 99px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--again); }
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 12px; }
.error { color: var(--again); font-size: 15px; margin-top: 10px; }
.install { border: 1.5px dashed var(--line); background: transparent; box-shadow: none; }
