:root {
  /* Fantasy-Theming: Burg bei Nacht – Leder, Eichenholz, Gold und Karmesin */
  --bg: #16110c;
  --bg-2: #1d1610;
  --surface: #261d14;
  --surface-2: #30251a;
  --line: #5c4629;
  --text: #f1e4c6;
  --muted: #b3a07c;
  --accent: #9e2a2f;
  --accent-2: #d9a441;
  --xp: #e9b949;
  --xp-2: #c98a1e;
  --good: #6f9e4f;
  --mid: #d08a2c;
  --bad: #b8323a;
  --new: #7fa7c9;
  --learn: #d08a2c;
  --due: #8fbf5f;
  --ember: #e8742a;
  --card-bg: #f1e2bd;
  --card-text: #2b1d0e;
  --ink-red: #8b2e2e;
  --radius: 14px;
  --shadow: 0 10px 28px rgba(0, 0, 0, .5);
  --frame: inset 0 0 0 3px var(--surface), inset 0 0 0 4px rgba(217, 164, 65, .22);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Heller Modus: Pergament und Tinte */
    --bg: #e9dab5;
    --bg-2: #e0cda2;
    --surface: #f6ecd2;
    --surface-2: #ecdcb4;
    --line: #c3a46b;
    --text: #33230f;
    --muted: #7a6240;
    --due: #4f7f33;
    --good: #5a8a3c;
    --shadow: 0 8px 22px rgba(90, 60, 20, .22);
    --frame: inset 0 0 0 3px var(--surface), inset 0 0 0 4px rgba(139, 90, 43, .25);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-2); }

#app { max-width: 640px; margin: 0 auto; }
#view { padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(var(--nav-h) + var(--safe-b) + 24px); }
body.study-mode #nav { display: none; }
body.study-mode #view { padding-bottom: calc(var(--safe-b) + 16px); }

/* ---------- Navigation ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
#nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#nav a.active { color: var(--accent-2); }
#nav a.active svg { filter: drop-shadow(0 0 8px var(--accent)); }

/* ---------- Generic ---------- */
h1 { font-size: 24px; margin: 0; line-height: 1.2; }
h2 { font-size: 18px; margin: 0 0 10px; }
section { margin-top: 26px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sec-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px;
  padding: 10px 16px; font-weight: 700; min-height: 44px;
  transition: transform .12s, filter .12s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5b3df5); border: 0; color: #fff;
  box-shadow: 0 6px 0 #3a26a8, 0 12px 24px rgba(124, 92, 255, .35);
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #3a26a8; }
.btn-danger { color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn.big { width: 100%; font-size: 18px; min-height: 58px; border-radius: 18px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 12px; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); display: grid; place-items: center; font-size: 18px; flex: none;
}

input[type=text], input[type=search], textarea, select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.5; }
label.lbl { display: block; font-weight: 700; font-size: 14px; margin: 18px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Hero / Profile ---------- */
.brand { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand b { font-size: 20px; letter-spacing: -.01em; }
.brand b span { color: var(--accent-2); }
.hero { padding: 18px; }
.hero-top { display: flex; align-items: center; gap: 14px; }
.lvl-badge {
  width: 58px; height: 58px; flex: none; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--xp), var(--xp-2)); color: #3b2300; font-weight: 900; font-size: 24px;
  box-shadow: 0 4px 0 #c46d00, 0 0 24px rgba(255, 180, 40, .35); transform: rotate(-4deg);
}
.lvl-badge small { display: block; font-size: 9px; font-weight: 800; letter-spacing: .08em; margin-bottom: -6px; text-align: center; }
.hero-info { flex: 1; min-width: 0; }
.hero-title { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xpbar { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; border: 1px solid var(--line); }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--xp-2), var(--xp)); border-radius: 99px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.xp-txt { font-size: 12px; color: var(--muted); font-weight: 600; }

.streak { display: flex; flex-direction: column; align-items: center; min-width: 54px; }
.streak .flame { font-size: 30px; line-height: 1; filter: grayscale(1) opacity(.5); transition: filter .3s; }
.streak b { font-size: 18px; line-height: 1.1; }
.streak small { font-size: 11px; color: var(--muted); height: 14px; }
.streak.lit .flame { filter: drop-shadow(0 0 10px rgba(255, 120, 0, .8)); animation: flicker 1.6s infinite; }
.streak.risk .flame { filter: grayscale(.2); animation: pulse 1.4s infinite; }
@keyframes flicker { 50% { transform: scale(1.08) rotate(-3deg); } }
@keyframes pulse { 50% { transform: scale(1.15); opacity: .7; } }

.goal { display: flex; align-items: center; gap: 14px; margin: 18px 0 16px; padding: 12px; border-radius: 16px; background: var(--surface-2); }
.ring { width: 64px; height: 64px; flex: none; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--line); }
.ring .ring-fg { stroke: var(--good); transition: stroke-dashoffset .8s cubic-bezier(.2, .8, .2, 1); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.goal-txt b { display: block; }
.goal-txt span { font-weight: 700; }
.goal-txt small { display: block; color: var(--muted); font-size: 13px; }
.goal.done .goal-txt small { color: var(--good); font-weight: 700; }

/* ---------- Quests ---------- */
.quests { display: grid; gap: 8px; }
.quest { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.quest .q-ico { font-size: 22px; width: 32px; text-align: center; }
.quest .q-body { flex: 1; min-width: 0; }
.quest .q-title { font-weight: 700; font-size: 15px; }
.quest .q-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.quest .q-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.quest .q-xp { font-size: 12px; font-weight: 800; color: var(--xp); white-space: nowrap; }
.quest.done { opacity: .75; }
.quest.done .q-bar i { background: var(--good); }
.quest.done .q-xp { color: var(--good); }

/* ---------- Decks ---------- */
.decks { display: grid; gap: 10px; }
.deck { display: flex; align-items: stretch; gap: 8px; padding: 8px 8px 8px 0; position: relative; overflow: hidden; }
.deck::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c, var(--accent)); }
.deck-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; text-align: left; padding: 6px 4px 6px 16px; }
.deck-emoji { font-size: 30px; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: color-mix(in srgb, var(--c, var(--accent)) 22%, transparent); flex: none; }
.deck-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.deck-body b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-body small { color: var(--muted); font-size: 12px; }
.deck .icon-btn { align-self: center; }
.counts { display: flex; gap: 10px; font-weight: 800; font-size: 14px; font-style: normal; }
.counts em { font-style: normal; }
.c-new { color: var(--new); }
.c-learn { color: var(--learn); }
.c-due { color: var(--due); }
.counts .zero { opacity: .35; }
.mastery { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.mastery i { display: block; height: 100%; background: linear-gradient(90deg, var(--c, var(--accent)), var(--good)); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .big-emoji { font-size: 44px; display: block; margin-bottom: 8px; }

/* ---------- Deck detail ---------- */
.deck-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 14px; }
.deck-stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 4px; }
.deck-stats b { display: block; font-size: 20px; }
.deck-stats span { font-size: 11px; color: var(--muted); font-weight: 600; }
.card-list { display: grid; gap: 8px; margin-top: 12px; }
.card-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; text-align: left; width: 100%; }
.card-row .txt { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.tag.new { color: var(--new); background: color-mix(in srgb, var(--new) 15%, transparent); }
.tag.learn { color: var(--learn); background: color-mix(in srgb, var(--learn) 15%, transparent); }
.tag.mature { color: var(--good); background: color-mix(in srgb, var(--good) 15%, transparent); }

/* ---------- Editor ---------- */
.tabs { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 6px rgba(0, 0, 0, .15); }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.toolbar button { min-width: 38px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 14px; }
.editor-actions { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); margin-top: 18px; display: flex; gap: 10px; }
.editor-actions .btn { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Flashcard (Markdown) ---------- */
.flash {
  background: var(--card-bg); color: var(--card-text); border-radius: 24px; padding: 24px 22px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35), 0 0 0 1px rgba(255, 255, 255, .05);
  min-height: 42vh; display: flex; flex-direction: column;
  animation: cardIn .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(.97) rotate(-1deg); } }
.flash .divider { height: 0; border-top: 2px dashed #d9d3f3; margin: 18px -4px; }
.flash .back { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }
.md { overflow-wrap: anywhere; font-size: 18px; line-height: 1.55; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.25; margin: .6em 0 .4em; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.12em; }
.md p { margin: .5em 0; }
.md ul, .md ol { padding-left: 1.4em; margin: .5em 0; }
.md li.task { list-style: none; margin-left: -1.2em; }
.md img { max-width: 100%; max-height: 50vh; border-radius: 12px; display: block; margin: 10px auto; cursor: zoom-in; }
.md code { background: rgba(124, 92, 255, .12); padding: .1em .4em; border-radius: 6px; font-size: .9em; font-family: ui-monospace, Menlo, monospace; }
.md pre { background: #1d1838; color: #eeeaff; padding: 12px 14px; border-radius: 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; color: inherit; }
.md blockquote { margin: .6em 0; padding: .4em 1em; border-left: 4px solid var(--accent); background: rgba(124, 92, 255, .08); border-radius: 0 10px 10px 0; }
.md mark { background: #ffe066; color: inherit; padding: 0 .15em; border-radius: 4px; }
.md hr { border: 0; border-top: 1px solid #ddd6f5; margin: 1em 0; }
.md .table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; width: 100%; font-size: .9em; margin: .5em 0; }
.md th, .md td { border: 1px solid #ddd6f5; padding: 6px 10px; text-align: left; }
.md th { white-space: nowrap; background: rgba(124, 92, 255, .1); }
.md a { color: #5b3df5; }

/* ---------- Study ---------- */
.study-top { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.study-prog { flex: 1; height: 14px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.study-prog i { display: block; height: 100%; background: linear-gradient(90deg, var(--good), #6ff0b5); border-radius: 99px; transition: width .4s; }
.combo {
  font-weight: 900; font-size: 15px; padding: 6px 10px; border-radius: 12px; min-width: 64px; text-align: center;
  background: var(--surface-2); color: var(--muted); transition: all .2s;
}
.combo.hot { background: linear-gradient(135deg, var(--xp-2), #ff5d3a); color: #fff; box-shadow: 0 0 18px rgba(255, 120, 40, .5); }
.combo.bump { animation: bump .3s; }
@keyframes bump { 40% { transform: scale(1.25); } }
.study-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 14px; }
.sess-xp { color: var(--xp); font-weight: 800; }
.study-actions { margin-top: 16px; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rate button {
  border: 0; border-radius: 16px; padding: 12px 6px; color: #fff; font-weight: 800; font-size: 16px; min-height: 64px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .1s;
}
.rate button small { font-size: 12px; font-weight: 700; opacity: .85; }
.rate button:active { transform: translateY(4px); }
.rate .r1 { background: var(--bad); box-shadow: 0 5px 0 #b8324a; }
.rate .r2 { background: var(--mid); box-shadow: 0 5px 0 #b87500; color: #3a2500; }
.rate .r3 { background: var(--good); box-shadow: 0 5px 0 #179460; color: #053a24; }
.kbd-hint { text-align: center; font-size: 12px; color: var(--muted); margin-top: 12px; }
.xp-pop {
  position: fixed; z-index: 60; pointer-events: none; font-weight: 900; font-size: 22px; color: var(--xp);
  text-shadow: 0 2px 0 #7a4a00, 0 0 12px rgba(255, 190, 40, .6); animation: pop 1s ease-out forwards;
}
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 0) scale(.6); } 20% { opacity: 1; transform: translate(-50%, -20px) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -90px) scale(1); } }

/* ---------- Summary ---------- */
.summary { text-align: center; padding-top: 10px; }
.summary .trophy { font-size: 72px; animation: bounceIn .7s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes bounceIn { from { transform: scale(0) rotate(-30deg); } }
.summary h1 { margin: 6px 0 4px; }
.sum-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 20px 0; }
.sum-grid div { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 8px; }
.sum-grid b { display: block; font-size: 26px; }
.sum-grid b.xp { color: var(--xp); }
.sum-grid span { font-size: 12px; color: var(--muted); font-weight: 700; }
.dist { display: flex; height: 12px; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.dist i:nth-child(1) { background: var(--bad); } .dist i:nth-child(2) { background: var(--mid); } .dist i:nth-child(3) { background: var(--good); }

/* ---------- Stats ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.tile b { display: block; font-size: 26px; line-height: 1.1; }
.tile span { font-size: 12px; color: var(--muted); font-weight: 700; }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 14px; height: 14px; border-radius: 4px; background: var(--surface-2); }
.heat i[data-l="1"] { background: color-mix(in srgb, var(--good) 30%, var(--surface-2)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--good) 55%, var(--surface-2)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--good) 80%, var(--surface-2)); }
.heat i[data-l="4"] { background: var(--good); }
.heat i.today { outline: 2px solid var(--accent-2); }
.stack { display: flex; height: 22px; border-radius: 10px; overflow: hidden; margin: 8px 0; background: var(--surface-2); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--dot); margin-right: 6px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars i { width: 100%; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bars span { font-size: 10px; color: var(--muted); }
.bars b { font-size: 10px; }

/* ---------- Badges ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 10px; text-align: center; }
.badge .b-ico { font-size: 36px; display: block; }
.badge b { display: block; font-size: 14px; margin-top: 4px; }
.badge small { color: var(--muted); font-size: 12px; line-height: 1.3; display: block; margin-top: 2px; }
.badge.locked .b-ico { filter: grayscale(1) opacity(.35); }
.badge.locked b { color: var(--muted); }
.badge.got { border-color: color-mix(in srgb, var(--xp) 50%, var(--line)); background: linear-gradient(180deg, color-mix(in srgb, var(--xp) 10%, var(--surface)), var(--surface)); }
.ladder { display: grid; gap: 6px; }
.ladder div { display: flex; justify-content: space-between; padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.ladder div.cur { border-color: var(--xp); background: color-mix(in srgb, var(--xp) 12%, var(--surface)); font-weight: 800; }
.ladder div.past { opacity: .6; }

/* ---------- Settings ---------- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row select { width: auto; min-width: 90px; }
.set-row div small { display: block; color: var(--muted); font-size: 13px; }
.switch { width: 52px; height: 30px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: all .2s; }
.switch.on { background: var(--good); }
.switch.on::after { left: 25px; background: #fff; }
.rules p { margin: 8px 0; font-size: 14px; }

/* ---------- Toast / Modal / FX ---------- */
#toasts { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 12px); left: 50%; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: toastIn .35s cubic-bezier(.2, 1.4, .4, 1), toastOut .3s ease-in 3.2s forwards;
}
.toast .t-ico { font-size: 26px; }
.toast b { display: block; font-size: 15px; }
.toast small { color: var(--muted); font-size: 13px; }
.toast.gold { border-color: var(--xp); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-20px) scale(.9); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

#modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgba(8, 6, 20, .7); backdrop-filter: blur(6px); animation: fadeIn .2s; }
#modal[hidden] { display: none; }
.modal-box { width: min(440px, 100%); max-height: 90dvh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); animation: cardIn .3s cubic-bezier(.2, .8, .2, 1); }
.modal-box h2 { margin-bottom: 14px; }
.modal-img { max-width: 100%; max-height: 85dvh; border-radius: 12px; background: #fff; }
.emoji-pick, .color-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; border: 2px solid transparent; background: var(--surface-2); }
.color-pick button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.emoji-pick button.sel, .color-pick button.sel { border-color: var(--text); }
.levelup { text-align: center; }
.levelup .lvl-badge { width: 110px; height: 110px; font-size: 48px; margin: 6px auto 14px; border-radius: 30px; animation: bounceIn .8s cubic-bezier(.2, 1.6, .4, 1); }
.levelup .new-title { font-size: 20px; font-weight: 800; color: var(--xp); }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 90; }
#offline-pill { position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); left: 50%; transform: translateX(-50%); z-index: 30; background: var(--surface-2); border: 1px solid var(--line); padding: 6px 14px; border-radius: 99px; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Anmeldung ---------- */
body.auth-mode #nav { display: none; }
body.auth-mode #view { padding-bottom: 32px; }
.auth { max-width: 420px; margin: 0 auto; padding-top: 4vh; }
.auth-logo { text-align: center; margin-bottom: 20px; }
.auth-logo img { border-radius: 22px; box-shadow: 0 12px 30px rgba(124, 92, 255, .4); }
.auth-logo h1 { font-size: 32px; margin-top: 12px; }
.auth-logo h1 span { color: var(--accent-2); }
.auth .tabs { margin-bottom: 4px; }
.auth form .btn { margin-top: 18px; }
.auth-err { color: var(--bad); font-size: 14px; font-weight: 600; min-height: 20px; margin-top: 10px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.center { text-align: center; }
input[type=password] { width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; outline: none; }

/* ---------- Topbar: Coins, Avatar, Sync ---------- */
.brand-r { display: flex; align-items: center; gap: 8px; }
.coin-pill {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 8px; border-radius: 99px; text-decoration: none; color: var(--text);
  background: color-mix(in srgb, var(--xp) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--xp) 45%, var(--line)); font-size: 15px;
}
.coin-pill b { color: var(--xp); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; text-decoration: none; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #e05cff); color: #fff; flex: none;
}
.avatar.big { width: 52px; height: 52px; font-size: 22px; }
.sync-dot { width: 12px; height: 12px; border-radius: 50%; border: 0; padding: 0; background: var(--good); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.sync-dot[data-s=syncing] { background: var(--new); box-shadow: 0 0 0 3px color-mix(in srgb, var(--new) 25%, transparent); animation: pulse 1s infinite; }
.sync-dot[data-s=offline] { background: var(--muted); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 25%, transparent); }
.sync-dot[data-s=error], .sync-dot[data-s=auth] { background: var(--mid); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mid) 30%, transparent); }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 14px; border-radius: 16px; font-size: 14px;
  background: color-mix(in srgb, var(--mid) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--mid) 45%, var(--line)); }
.banner span { flex: 1; }

/* ---------- Konto ---------- */
.account .acc-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.account .acc-row b { display: block; font-size: 18px; }
.sync-box { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--surface-2); margin-bottom: 12px; }
.sync-box div { flex: 1; min-width: 0; }
.sync-box b { display: block; font-size: 14px; }
.sync-box small { font-size: 12px; }

/* ---------- Shop ---------- */
.btn-gold { background: linear-gradient(135deg, var(--xp), var(--xp-2)); color: #3b2300; border: 0; box-shadow: 0 4px 0 #c46d00; }
.btn-gold:active { transform: translateY(3px); box-shadow: 0 1px 0 #c46d00; }
.btn-danger.btn:not(.btn-ghost) { background: var(--bad); color: #fff; border: 0; }
.wallet { display: flex; align-items: center; gap: 12px; background: linear-gradient(135deg, color-mix(in srgb, var(--xp) 18%, var(--surface)), var(--surface)); }
.wallet div { flex: 1; }
.wallet small { display: block; color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.wallet b { display: block; font-size: 32px; color: var(--xp); line-height: 1.2; }
.rewards { display: grid; gap: 10px; }
.reward, .next-reward { display: flex; align-items: center; gap: 12px; padding: 14px; }
.next-reward { text-decoration: none; color: inherit; }
.reward.ready { border-color: color-mix(in srgb, var(--xp) 60%, var(--line)); }
.r-emoji { font-size: 34px; width: 48px; text-align: center; flex: none; }
.r-body { flex: 1; min-width: 0; }
.r-body b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-body small { font-size: 12px; color: var(--muted); }
.r-bar, .b-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.r-bar i, .b-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--xp-2), var(--xp)); }
.r-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.r-btns { display: flex; gap: 6px; align-items: center; }
.price { font-weight: 800; color: var(--xp); white-space: nowrap; font-size: 14px; }
.icon-btn.sm { width: 36px; height: 36px; border-radius: 12px; font-size: 15px; }
.templates { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.tpl { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: 16px; background: var(--surface); border: 1px dashed var(--line); font-weight: 700; font-size: 14px; }
.tpl span { font-size: 28px; }
.tpl small { color: var(--xp); font-weight: 800; }
.earn-grid { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; font-size: 14px; }
.earn-grid b { color: var(--xp); text-align: right; }
.history { display: grid; gap: 6px; }
.hist-row { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.hist-row b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-row .price { color: var(--bad); }
.sum-grid b.coin { color: var(--xp); }

/* ---------- Erfolgsstufen ---------- */
.badge { position: relative; display: flex; flex-direction: column; align-items: center; }
.badge .b-bar { width: 80%; }
.tier-chip { margin-top: 8px; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--tc, var(--muted)); }
.badge.t1 { --tc: #d9915a; } .badge.t2 { --tc: #b9c3d8; } .badge.t3 { --tc: #ffc53d; } .badge.t4 { --tc: #7fe3ff; }
.badge.got { border-color: color-mix(in srgb, var(--tc) 60%, var(--line)); background: linear-gradient(180deg, color-mix(in srgb, var(--tc) 14%, var(--surface)), var(--surface)); }
.badge.got.t4 { box-shadow: 0 0 18px color-mix(in srgb, var(--tc) 35%, transparent); }
.tier-sum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.tier-sum div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 4px; }
.tier-sum b { display: block; font-size: 22px; }
.tier-sum span { font-size: 12px; font-weight: 700; }
.tier-sum .t1 span { color: #d9915a; } .tier-sum .t2 span { color: #b9c3d8; } .tier-sum .t3 span { color: #ffc53d; } .tier-sum .t4 span { color: #7fe3ff; }
#nav a span { white-space: nowrap; }
.quest .q-reward { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }


/* ==============================================================
   Fantasy / Mittelalter
   ===================================================================== */
body {
  font-family: var(--serif);
  background-color: var(--bg);
  background-image:
    radial-gradient(120% 55% at 50% -12%, rgba(232, 116, 42, .22), transparent 60%),
    radial-gradient(140% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, .55)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .012) 0 2px, transparent 2px 9px);
}
@media (prefers-color-scheme: light) {
  body {
    background-image:
      radial-gradient(120% 55% at 50% -12%, rgba(217, 164, 65, .35), transparent 60%),
      radial-gradient(140% 100% at 50% 50%, transparent 55%, rgba(120, 80, 30, .25)),
      repeating-linear-gradient(0deg, rgba(120, 80, 30, .03) 0 1px, transparent 1px 5px);
  }
}
h1, h2, .brand b, .hero-title, .new-title, .auth-logo h1, .summary h1, .modal-box h2 {
  font-family: var(--serif);
  font-variant: small-caps;
  letter-spacing: .04em;
}
section > h2::before, .sec-head h2::before { content: "⚜ "; color: var(--accent-2); font-size: .85em; }
.brand b span, .auth-logo h1 span { color: var(--accent-2); }
.brand .fleur { color: var(--accent-2); margin-right: 2px; }

/* Rahmen: Leder mit Goldprägung */
.panel, .modal-box, .toast, .tile, .deck-stats div, .sum-grid div, .tier-sum div, .badge, .card-row, .hist-row, .tpl, .ladder div {
  box-shadow: var(--frame), var(--shadow);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(0, 0, 0, .08));
}
.btn { font-family: var(--serif); border-color: var(--line); background-image: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(0, 0, 0, .12)); letter-spacing: .02em; }
.btn-primary {
  background: linear-gradient(180deg, #b3343a, #7a1d22); color: #f8e8c0;
  border: 1px solid var(--accent-2);
  box-shadow: 0 5px 0 #3e0d10, 0 10px 24px rgba(158, 42, 47, .35), inset 0 1px 0 rgba(255, 220, 160, .35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}
.btn-primary:active { box-shadow: 0 1px 0 #3e0d10; }
.btn-primary:disabled { filter: grayscale(.6); }
.btn-gold { border: 1px solid #7a5310; }
input[type=text], input[type=search], input[type=password], textarea, select { font-family: var(--serif); }
textarea { font-family: ui-monospace, Menlo, monospace; }

/* Stufen-Abzeichen als Wappenschild */
.lvl-badge {
  transform: none; border-radius: 0; width: 56px; height: 64px;
  clip-path: polygon(0 0, 100% 0, 100% 62%, 50% 100%, 0 62%);
  background: linear-gradient(160deg, #f6d77e, #c98a1e 55%, #8a5a12);
  color: #3a2305; box-shadow: none; padding-bottom: 10px;
  filter: drop-shadow(0 3px 0 #5b3a0b) drop-shadow(0 0 14px rgba(233, 185, 73, .35));
  text-shadow: 0 1px 0 rgba(255, 240, 200, .6);
  font-family: var(--serif);
}
.lvl-badge small { font-size: 8px; letter-spacing: .12em; }
.levelup .lvl-badge { width: 110px; height: 128px; border-radius: 0; font-size: 50px; padding-bottom: 20px; }
.xpbar { border-color: var(--line); background: #1a130d; }
@media (prefers-color-scheme: light) { .xpbar { background: #dcc89c; } }
.xpbar i { background: linear-gradient(90deg, #a8701a, var(--xp), #f7dc8f); box-shadow: 0 0 8px rgba(233, 185, 73, .5); }

/* Wachfeuer */
.ring .ring-fg { stroke: var(--ember); filter: drop-shadow(0 0 4px rgba(232, 116, 42, .6)); }
.goal { background: rgba(0, 0, 0, .18); border: 1px solid var(--line); }
@media (prefers-color-scheme: light) { .goal { background: rgba(139, 90, 43, .08); } }
.goal.done .goal-txt small { color: var(--ember); }

/* Bücher statt Stapel: Buchrücken mit Goldbändern */
.deck::before {
  width: 12px;
  background:
    linear-gradient(var(--accent-2), var(--accent-2)) 0 18% / 100% 2px no-repeat,
    linear-gradient(var(--accent-2), var(--accent-2)) 0 82% / 100% 2px no-repeat,
    linear-gradient(90deg, rgba(0, 0, 0, .35), transparent 40%, rgba(255, 255, 255, .12) 60%, rgba(0, 0, 0, .3)),
    var(--c, var(--accent));
}
.deck-main { padding-left: 22px; }
.deck-emoji { border-radius: 10px; border: 1px solid color-mix(in srgb, var(--c) 60%, var(--line)); background: color-mix(in srgb, var(--c) 30%, transparent); }
.mastery i { background: linear-gradient(90deg, #a8701a, var(--xp)); }
.quest .q-bar i { background: linear-gradient(90deg, var(--accent), #d0504f); }
.quest.done .q-bar i { background: var(--good); }

/* Karteikarte als Pergament mit Initiale */
.flash {
  background:
    radial-gradient(120% 90% at 50% 40%, #f7ebcc 40%, #e6cf9c 100%),
    var(--card-bg);
  border: 1px solid #b89458; border-radius: 6px;
  box-shadow: inset 0 0 38px rgba(120, 80, 30, .35), inset 0 0 0 6px rgba(247, 235, 204, .6), inset 0 0 0 7px rgba(139, 90, 43, .35), 0 18px 40px rgba(0, 0, 0, .55);
  font-family: var(--serif);
}
.flash .front > :first-child::first-letter { font-size: 1.7em; font-weight: 700; color: var(--ink-red); line-height: 1; }
.flash .divider {
  border: 0; height: 22px; margin: 16px 0; text-align: center; line-height: 22px;
  background:
    linear-gradient(#b08a4e, #b08a4e) left center / calc(50% - 20px) 1px no-repeat,
    linear-gradient(#b08a4e, #b08a4e) right center / calc(50% - 20px) 1px no-repeat;
}
.flash .divider::before { content: "⚜"; color: #8a5a2b; font-size: 18px; }
.md mark { background: #f0c96a; }
.md code { background: rgba(139, 90, 43, .15); }
.md pre { background: #2b1d0e; color: #f1e4c6; }
.md blockquote { border-left-color: var(--ink-red); background: rgba(139, 46, 46, .07); font-style: italic; }
.md th, .md td, .md hr { border-color: #c7a86a; }
.md th { background: rgba(139, 90, 43, .15); }
.md a { color: var(--ink-red); }

/* Lernen */
.study-prog { background: #1a130d; border-color: var(--line); }
.study-prog i { background: linear-gradient(90deg, #a8701a, var(--xp)); }
.combo.hot { background: linear-gradient(180deg, #e8742a, #9e2a2f); border: 1px solid var(--accent-2); }
.rate button { font-family: var(--serif); border: 1px solid rgba(255, 230, 170, .45); letter-spacing: .02em; }
.rate .r1 { background: linear-gradient(180deg, #c23b42, #8e2329); box-shadow: 0 5px 0 #4e1115; }
.rate .r2 { background: linear-gradient(180deg, #e0a040, #b36d1a); box-shadow: 0 5px 0 #6b3f08; color: #2e1a02; }
.rate .r3 { background: linear-gradient(180deg, #7fae5c, #4f7f35); box-shadow: 0 5px 0 #2b4a1a; color: #0f2406; }
.xp-pop { font-family: var(--serif); color: var(--xp); text-shadow: 0 2px 0 #5b3a0b, 0 0 12px rgba(233, 185, 73, .6); }

/* Navigation: Eichenholz mit Goldkante */
#nav {
  background: linear-gradient(180deg, color-mix(in srgb, #2a1f14 94%, transparent), color-mix(in srgb, #1a130c 96%, transparent));
  border-top: 2px solid #6b5230; box-shadow: 0 -1px 0 rgba(217, 164, 65, .25);
}
@media (prefers-color-scheme: light) {
  #nav { background: linear-gradient(180deg, #f3e6c6, #e6d3a7); border-top-color: #b8955a; }
}
#nav a { font-family: var(--serif); letter-spacing: .02em; }
#nav a.active { color: var(--accent-2); }
#nav a.active svg { filter: drop-shadow(0 0 8px rgba(217, 164, 65, .7)); }

/* Truhe, Wappen, Trophäen */
.coin-pill { background: linear-gradient(180deg, #3a2c16, #2a1f10); border-color: #8a6a2c; }
@media (prefers-color-scheme: light) { .coin-pill { background: #f7e7b8; } }
.avatar { background: linear-gradient(160deg, #b3343a, #6e1a1f); border: 2px solid var(--accent-2); font-family: var(--serif); }
.wallet { background: linear-gradient(135deg, rgba(233, 185, 73, .18), transparent), var(--surface); }
.wallet b { text-shadow: 0 0 14px rgba(233, 185, 73, .4); }
.badge.t4 { --tc: #a8d8e8; }
.tier-sum .t4 span { color: #a8d8e8; }
.badge .b-ico { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .4)); }
.badge.locked .b-ico { filter: grayscale(1) sepia(.4) opacity(.35); }
.ladder div.cur { border-color: var(--accent-2); }
.heat i[data-l="1"] { background: color-mix(in srgb, var(--ember) 30%, var(--surface-2)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--ember) 55%, var(--surface-2)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--ember) 80%, var(--surface-2)); }
.heat i[data-l="4"] { background: var(--xp); }
.bars i { background: linear-gradient(180deg, var(--xp), #a8701a); }
.streak.lit .flame { filter: drop-shadow(0 0 12px rgba(232, 116, 42, .9)); }
.toast { border-color: var(--line); }
.toast.gold { border-color: var(--accent-2); }
.switch.on { background: var(--good); }
.auth-logo img { border-radius: 18px; box-shadow: 0 12px 30px rgba(232, 116, 42, .35); }
.study-meta .muted { flex: 1; min-width: 0; margin: 0 10px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-xp { white-space: nowrap; }
@media (prefers-color-scheme: light) {
  /* Altgold statt Hellgold, damit Text auf Pergament lesbar bleibt */
  :root { --accent-2: #8a5a12; }
  .coin-pill b, .quest .q-xp, .price, .wallet b, .sess-xp, .sum-grid b.xp, .sum-grid b.coin, .tpl small, .earn-grid b, .levelup .new-title { color: #7a4e0e; }
  .tier-sum .t3 span, .badge.t3 { --tc: #9a6b14; color: inherit; }
  .tier-sum .t3 span { color: #9a6b14; }
  .tier-sum .t4 span, .badge.t4 { --tc: #3f7f95; }
  .tier-sum .t4 span { color: #3f7f95; }
  .tier-sum .t2 span, .badge.t2 { --tc: #6b7280; }
  .tier-sum .t2 span { color: #6b7280; }
}
/* ---------- Variable Belohnung: Funde, Krits, Tagestruhe ---------- */
.loot-drop {
  position: fixed; left: 50%; top: 38%; z-index: 65; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-radius: 18px; pointer-events: none;
  width: max-content; max-width: min(360px, calc(100vw - 48px));
  background: var(--surface); border: 2px solid var(--xp); box-shadow: 0 0 0 6px color-mix(in srgb, var(--xp) 18%, transparent), var(--shadow);
  animation: lootIn .45s cubic-bezier(.2, 1.6, .4, 1), lootOut .4s ease-in 2.2s forwards;
}
.loot-drop .loot-ico { font-size: 40px; animation: lootSpin .6s ease-out; }
.loot-drop b { display: block; font-size: 18px; color: var(--xp); }
.loot-drop small { color: var(--muted); font-size: 13px; }
.loot-drop.loot-boost { border-color: var(--new); }
.loot-drop.loot-boost b { color: var(--new); }
.loot-drop.loot-freeze { border-color: #7fe3ff; }
@keyframes lootIn { from { opacity: 0; transform: translate(-50%, -30%) scale(.5); } }
@keyframes lootOut { to { opacity: 0; transform: translate(-50%, -80%) scale(.9); } }
@keyframes lootSpin { from { transform: rotate(-200deg) scale(.3); } }
.xp-pop.crit { font-size: 28px; color: #ff7a3d; text-shadow: 0 2px 0 #7a2a00, 0 0 18px rgba(255, 120, 40, .8); }
.boost-pill { font-style: normal; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: color-mix(in srgb, var(--new) 22%, transparent); color: var(--new); margin-right: 4px; }

.chest { text-align: center; }
.chest-head { font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.chest-box {
  font-size: 96px; line-height: 1; background: none; border: 0; margin: 18px auto 4px; display: block;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, .4)); animation: chestIdle 1.6s ease-in-out infinite;
}
.chest-box.opening { animation: chestShake .75s ease-in-out; }
@keyframes chestIdle { 50% { transform: translateY(-6px) rotate(-3deg); } }
@keyframes chestShake {
  15% { transform: rotate(-12deg) scale(1.05); } 30% { transform: rotate(12deg) scale(1.1); } 45% { transform: rotate(-10deg) scale(1.15); }
  60% { transform: rotate(10deg) scale(1.2); } 80% { transform: scale(1.4); opacity: .6; } 100% { transform: scale(1.8); opacity: 0; }
}
.chest-loot { animation: bounceIn .6s cubic-bezier(.2, 1.6, .4, 1); }
.chest-ico { font-size: 72px; margin: 8px 0; }
.chest-loot ul { list-style: none; padding: 0; margin: 10px 0 18px; display: grid; gap: 8px; font-weight: 700; font-size: 17px; }
.chest-loot li small { color: var(--muted); font-weight: 600; font-size: 12px; }
.chest[data-rarity=common] h2 { color: var(--muted); }
.chest[data-rarity=rare] h2 { color: var(--new); }
.chest[data-rarity=epic] h2 { color: #c77dff; }
.chest[data-rarity=legendary] h2 { color: var(--xp); text-shadow: 0 0 16px rgba(255, 197, 61, .6); }
.chest[data-rarity=legendary] .chest-ico { animation: pulse 1.2s infinite; }
.chest-box[hidden], .chest-loot[hidden] { display: none; }

/* Fantasy: Funde und Truhen */
.loot-drop { font-family: var(--serif); background-image: linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(0, 0, 0, .12)); box-shadow: var(--frame), 0 0 0 6px rgba(217, 164, 65, .18), var(--shadow); }
.loot-drop.loot-boost { border-color: #b3343a; }
.loot-drop.loot-boost b { color: #e0656b; }
.loot-drop.loot-freeze { border-color: #6fb8c9; }
.xp-pop.crit { color: #f0b429; text-shadow: 0 2px 0 #5b3a0b, 0 0 18px rgba(232, 116, 42, .9); }
.boost-pill { background: rgba(179, 52, 58, .25); color: #e0656b; }
.chest-loot ul { font-family: var(--serif); }
.chest[data-rarity=rare] h2 { color: #9fb3c8; }
.chest[data-rarity=epic] h2 { color: #b98ae0; }
@media (prefers-color-scheme: light) {
  .loot-drop.loot-boost b, .boost-pill { color: #8e2329; }
  .chest[data-rarity=rare] h2 { color: #4a6580; }
  .chest[data-rarity=epic] h2 { color: #6b3f99; }
  .chest[data-rarity=legendary] h2 { color: #8a5a12; }
}

/* ---------- Lückentext ---------- */
.cloze {
  display: inline-block; padding: 0 .45em; margin: 0 .05em; border-radius: 8px; font-weight: 800;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent);
}
.cloze.reveal { border-style: solid; color: #0f6b43; background: rgba(47, 208, 138, .18); border-color: rgba(47, 208, 138, .6); animation: fadeIn .3s ease; }
.cloze-tag { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-2); font-family: ui-monospace, Menlo, monospace; }
.type-tabs { margin-bottom: 10px; }
.cloze-btn { color: var(--accent-2); }
.cloze-count { font-size: 13px; }
.cloze-count .warn { color: var(--bad); font-weight: 700; }
.preview-label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 6px; }
.flash.preview { min-height: 0; animation: none; }
/* Grid-Spalten dürfen schrumpfen, sonst sprengen lange (nicht umbrechende) Kartentexte die Liste */
.card-list, .decks, .quests, .rewards, .history { grid-template-columns: minmax(0, 1fr); }

/* Fantasy: Lücken als Tintenklecks auf Pergament */
.flash .cloze { font-family: var(--serif); color: var(--ink-red); background: rgba(139, 46, 46, .08); border-color: rgba(139, 46, 46, .5); border-radius: 4px; }
.flash .cloze.reveal { color: #3f5f22; background: rgba(111, 158, 79, .16); border-color: rgba(79, 127, 53, .6); }

/* ---------- Bibliothek ---------- */
.library { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.lib-set { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-style: dashed; }
.lib-set .deck-emoji { background: color-mix(in srgb, var(--c) 22%, transparent); }
.lib-body { flex: 1; min-width: 0; }
.lib-body b { display: block; }
.lib-body small { color: var(--muted); font-size: 12px; line-height: 1.35; display: block; }

/* ---------- Regale ---------- */
.sec-actions { display: flex; gap: 6px; }
.shelf { margin-bottom: 14px; }
.shelf-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 10px 4px; margin-bottom: 8px;
  border-bottom: 6px solid transparent;
  border-image: linear-gradient(180deg, #7a5530, #4a311a) 1;
  box-shadow: 0 6px 8px -6px rgba(0, 0, 0, .6);
}
@media (prefers-color-scheme: light) { .shelf-head { border-image: linear-gradient(180deg, #b8895a, #8a5f36) 1; } }
.shelf-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; text-align: left; }
.shelf-toggle .chev { color: var(--muted); transition: transform .2s; font-size: 14px; width: 14px; }
.shelf.collapsed .chev { transform: rotate(-90deg); }
.shelf-emoji { font-size: 26px; }
.shelf-title { min-width: 0; display: flex; flex-direction: column; }
.shelf-title b { font-family: var(--serif); font-variant: small-caps; letter-spacing: .03em; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf-title small { color: var(--muted); font-size: 12px; }
.shelf-books { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); padding-left: 10px; border-left: 2px solid color-mix(in srgb, var(--line) 70%, transparent); }
.shelf.collapsed .shelf-books { display: none; }
.shelf.loose .shelf-head { border-image: none; border-bottom: 1px dashed var(--line); box-shadow: none; }
.shelf-empty { padding: 4px 2px; }
.shelf-add { background: none; border: 1px dashed var(--line); border-radius: 12px; padding: 8px; color: var(--muted); font-family: var(--serif); }
.shelf-picks { display: grid; gap: 6px; max-height: 40dvh; overflow: auto; padding: 2px; }
.shelf-pick { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; }
.shelf-pick input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.shelf-pick .sp-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf-pick small { font-size: 11px; white-space: nowrap; }
