/* ============ Themes ============ */
body[data-theme="chess"] {
  --bg: #312e2b;
  --bg-image: none;
  --card: #262421;
  --option: #3c3a37;
  --option-hover: #45423e;
  --shadow: #1c1a18;
  --text: #ffffff;
  --muted: #b3b1ad;
  --accent: #81b64c;
  --accent-dark: #45753c;
  --accent-text: #ffffff;
  --good: #81b64c;
  --bad: #e2412d;
  --radius: 8px;
  --font: "Nunito Sans", "Segoe UI", system-ui, sans-serif;
  --logo: "♞";
}
body[data-theme="pony"] {
  --bg: #fde4f2;
  --bg-image: linear-gradient(160deg, #ffd3ea 0%, #e8d6ff 45%, #cfeeff 100%);
  --card: rgba(255, 255, 255, 0.82);
  --option: #ffffff;
  --option-hover: #fff3fa;
  --shadow: #f0b3d6;
  --text: #5b2a70;
  --muted: #a07bb0;
  --accent: #ec4f9e;
  --accent-dark: #b3317a;
  --accent-text: #ffffff;
  --good: #34c98b;
  --bad: #ff5f86;
  --radius: 22px;
  --font: "Fredoka", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  --logo: "🦄";
}
body[data-theme="custom"] {
  /* --bg, --card, --accent, --text, --good, --bad werden per JS gesetzt */
  --bg-image: none;
  --option: color-mix(in srgb, var(--card) 88%, var(--text));
  --option-hover: color-mix(in srgb, var(--card) 80%, var(--text));
  --shadow: color-mix(in srgb, var(--bg) 70%, #000);
  --muted: color-mix(in srgb, var(--text) 62%, var(--bg));
  --accent-dark: color-mix(in srgb, var(--accent) 65%, #000);
  --accent-text: #ffffff;
  --radius: 14px;
  --font: "Nunito Sans", "Segoe UI", system-ui, sans-serif;
  --logo: "🎨";
}

/* ============ Grundlayout ============ */
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .3s, color .3s;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  font-family: inherit; font-size: .7em; padding: .1em .45em; border-radius: 4px;
  background: rgba(0,0,0,.18); opacity: .8; margin: 0 .2em;
}
.screen { max-width: 780px; margin: 0 auto; padding: 16px 16px 48px; position: relative; z-index: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); font-weight: 700; margin: 0; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 3px 0 var(--shadow);
}
body[data-theme="pony"] .card { backdrop-filter: blur(6px); border: 2px solid #fff; }

.logo { font-weight: 800; font-size: 1.25rem; display: flex; align-items: center; gap: .4em; }
.logo-icon::before { content: var(--logo); font-size: 1.5em; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.topbar-right { display: flex; gap: 8px; }
.icon-btn {
  border: 0; background: var(--option); border-radius: var(--radius);
  width: 44px; height: 44px; font-size: 1.2rem; box-shadow: 0 3px 0 var(--shadow);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }

.btn {
  border: 0; border-radius: var(--radius); padding: 12px 22px; font-weight: 800;
  background: var(--option); box-shadow: 0 4px 0 var(--shadow); transition: transform .06s, filter .15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--shadow); }
.btn-primary { background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 0 var(--accent-dark); }
.btn-primary:active { box-shadow: 0 1px 0 var(--accent-dark); }
.btn-big { width: 100%; font-size: 1.2rem; padding: 16px; }

.section-title { font-weight: 800; margin-bottom: 10px; }
.section-title.big { font-size: 1.25rem; margin: 22px 0 12px; }

/* ============ Login ============ */
#screen-auth { min-height: 100vh; display: grid; place-items: center; }
#screen-auth[hidden] { display: none; }
.auth-card { width: 100%; max-width: 400px; text-align: center; padding: 28px; }
.auth-card .logo { justify-content: center; font-size: 1.6rem; }
.tabs { display: flex; gap: 6px; background: var(--option); border-radius: var(--radius); padding: 4px; margin: 18px 0; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: calc(var(--radius) - 2px); font-weight: 700; color: var(--muted); }
.tab.active { background: var(--accent); color: var(--accent-text); }
#auth-form { display: grid; gap: 14px; text-align: left; }
#auth-form label { display: grid; gap: 6px; font-weight: 700; font-size: .9rem; }
#auth-form input {
  padding: 12px 14px; border-radius: var(--radius); border: 2px solid transparent;
  background: var(--option); outline: none;
}
#auth-form input:focus { border-color: var(--accent); }

/* ============ Startseite ============ */
.profile { display: flex; gap: 16px; align-items: center; }
.level-badge {
  width: 72px; height: 72px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; align-content: center;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 0 var(--accent-dark);
}
body[data-theme="pony"] .level-badge { background: conic-gradient(#ff7eb6, #ffb86b, #ffe76b, #7ee8a6, #6bc8ff, #b78bff, #ff7eb6); color: #5b2a70; }
.level-badge small { font-size: .7rem; font-weight: 700; line-height: 1; }
.level-badge b { font-size: 1.8rem; line-height: 1; }
.profile-main { flex: 1; min-width: 0; }
.profile-name { font-weight: 800; font-size: 1.3rem; margin-bottom: 8px; overflow-wrap: anywhere; }

.xpbar { height: 14px; background: var(--option); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.xpbar.slim { height: 8px; margin: -6px 0 16px; }
.xpbar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
body[data-theme="pony"] .xpbar-fill { background: linear-gradient(90deg, #ff7eb6, #ffb86b, #ffe76b, #7ee8a6, #6bc8ff, #b78bff); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { display: grid; gap: 2px; text-align: center; padding: 14px 8px; }
.stat small { font-weight: 700; color: var(--muted); }
.stat b { font-size: 1.7rem; }

.history { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; }
.history i { aspect-ratio: 1; border-radius: 3px; background: var(--option); }
.history i.g { background: var(--good); }
.history i.b { background: var(--bad); }

.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.mode {
  border: 0; text-align: left; padding: 18px; border-radius: var(--radius);
  background: var(--card); box-shadow: 0 4px 0 var(--shadow);
  display: grid; gap: 4px; transition: transform .08s, filter .15s;
}
.mode:hover { filter: brightness(1.08); transform: translateY(-2px); }
.mode:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.mode b { font-size: 1.15rem; }
.mode span:last-child { color: var(--muted); font-size: .88rem; }
.mode-emoji { font-size: 1.8rem; }
.mode[data-mode="hardcore"] { background: linear-gradient(135deg, var(--card), color-mix(in srgb, var(--bad) 25%, var(--card))); }

/* ============ Aufgaben ============ */
.play-mode { font-weight: 800; font-size: 1.1rem; }
.play-meta { display: flex; gap: 8px; align-items: center; }
.pill { background: var(--option); padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: .9rem; }
.streak { font-weight: 800; }

.question-card { position: relative; text-align: center; padding: 34px 16px 26px; min-height: 180px; display: grid; align-content: center; }
.question { font-size: clamp(1.8rem, 6.5vw, 3rem); font-weight: 700; line-height: 1.5; overflow-x: auto; }
.question .system { display: inline-grid; gap: 4px; text-align: left; border-left: 3px solid var(--accent); padding-left: 16px; }
.ask { margin-top: 6px; color: var(--muted); font-size: 1.3rem; font-weight: 700; }
.topic-chip { position: absolute; top: 10px; left: 12px; font-size: .75rem; color: var(--muted); font-weight: 700; }

.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .8em; margin: 0 .12em; line-height: 1.15; }
.frac > span:last-child { border-top: .08em solid currentColor; }
.frac > span { padding: 0 .15em; }
/* Exponenten: größer und deutlich hochgestellt; negative Exponenten bekommen einen Kasten,
   damit das Minus klar zum Exponenten gehört (und nicht zur Rechnung davor/danach) */
sup { font-size: .62em; font-weight: 800; line-height: 0; position: relative; top: -.95em; vertical-align: baseline; margin-left: .05em; }
sup.neg {
  display: inline-block; padding: .12em .28em .08em; border-radius: .35em; top: -.9em; line-height: 1;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 0 0 0 .09em color-mix(in srgb, var(--accent) 70%, transparent);
}
.question, .option { padding-top: .15em; }
.sqrt { white-space: nowrap; }
.sqrt .rad { border-top: .07em solid currentColor; padding: 0 .1em; margin-left: .05em; }

.options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.option {
  border: 0; border-radius: var(--radius); background: var(--option); box-shadow: 0 5px 0 var(--shadow);
  padding: 20px 12px; font-size: clamp(1.15rem, 4.2vw, 1.6rem); font-weight: 700; min-height: 84px;
  position: relative; transition: transform .06s, background .15s, filter .15s;
}
.option:hover:not(:disabled) { background: var(--option-hover); }
.option:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--shadow); }
.option kbd { position: absolute; top: 6px; left: 8px; font-size: .75rem; }
.option:disabled, .btn-none:disabled { cursor: default; }
.option.correct, .btn-none.correct { background: var(--good); color: #fff; box-shadow: 0 5px 0 color-mix(in srgb, var(--good) 60%, #000); animation: pop .35s; }
.option.wrong, .btn-none.wrong { background: var(--bad); color: #fff; box-shadow: 0 5px 0 color-mix(in srgb, var(--bad) 60%, #000); animation: shake .4s; }
.option.dim { opacity: .45; }

.btn-none { width: 100%; margin-top: 14px; padding: 16px; font-size: 1.05rem; }

.feedback { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-weight: 800; font-size: 1.15rem; }
.feedback[hidden] { display: none; }
.feedback .good { color: var(--good); }
.feedback .bad { color: var(--bad); }

.xp-float { position: absolute; right: 16px; top: 12px; font-weight: 800; color: var(--good); opacity: 0; pointer-events: none; }
.xp-float.show { animation: floatUp 1.1s ease-out; }

/* ============ Einstellungen ============ */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.theme-card {
  border: 3px solid transparent; background: var(--card); border-radius: var(--radius); padding: 12px;
  box-shadow: 0 3px 0 var(--shadow); display: grid; gap: 8px; text-align: center;
}
.theme-card.active { border-color: var(--accent); }
.swatch { height: 70px; border-radius: 8px; display: grid; grid-template-columns: repeat(4, 1fr); overflow: hidden; }
.swatch-chess i:nth-child(odd) { background: #769656; } .swatch-chess i:nth-child(even) { background: #eeeed2; }
.swatch-pony i:nth-child(1) { background: #ff9ccd; } .swatch-pony i:nth-child(2) { background: #c9a6ff; }
.swatch-pony i:nth-child(3) { background: #9edcff; } .swatch-pony i:nth-child(4) { background: #fff08a; }
.swatch-custom i { background: var(--sw, #888); }
.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.color-grid label { display: grid; gap: 6px; font-weight: 700; font-size: .9rem; }
.color-grid input { width: 100%; height: 44px; border: 0; border-radius: 8px; background: none; padding: 0; cursor: pointer; }
.setting-row { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.switch { position: relative; width: 54px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--option); border-radius: 999px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 4px; top: 4px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(24px); }

/* ============ Overlays ============ */
.levelup { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0,0,0,.55); animation: fadeIn .2s; }
.levelup[hidden] { display: none; }
.levelup-inner { text-align: center; animation: zoom .6s cubic-bezier(.2,1.6,.4,1); color: #fff; }
.levelup-star { font-size: 5rem; animation: spin 1.2s ease-out; }
.levelup-title { font-size: 3rem; font-weight: 800; text-shadow: 0 4px 0 rgba(0,0,0,.3); }
body[data-theme="pony"] .levelup-title { background: linear-gradient(90deg, #ff7eb6, #ffb86b, #ffe76b, #7ee8a6, #6bc8ff, #b78bff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.levelup-level { font-size: 1.4rem; font-weight: 700; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--bad); color: #fff; padding: 12px 18px; border-radius: var(--radius); font-weight: 700; max-width: calc(100% - 32px); }

/* Pony-Glitzer im Hintergrund */
.bg-deco { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
body[data-theme="pony"] .bg-deco {
  background-image:
    radial-gradient(circle, #fff 1.5px, transparent 2px),
    radial-gradient(circle, rgba(255,255,255,.8) 1px, transparent 1.5px);
  background-size: 90px 90px, 55px 55px;
  background-position: 0 0, 25px 35px;
  animation: twinkle 4s ease-in-out infinite alternate;
}
body[data-theme="chess"] .bg-deco {
  background-image: repeating-conic-gradient(rgba(255,255,255,.018) 0 25%, transparent 0 50%);
  background-size: 80px 80px;
}

/* ============ Avatare & Ränge ============ */
.avatar {
  width: 72px; aspect-ratio: 1; max-width: 100%; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--option); container-type: inline-size; box-shadow: 0 0 0 3px var(--accent);
}
.avatar svg { display: block; width: 100%; height: 100%; }
.avatar-glyph { display: grid; place-items: center; width: 100%; height: 100%; font-size: 58cqw; line-height: 1; font-weight: 700; }
.avatar-xl { width: 120px; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.level-chip {
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 1px 9px; font-size: .9rem;
  box-shadow: 0 2px 0 var(--accent-dark);
}
.level-chip small { font-size: .65rem; font-weight: 700; }
#open-profile { cursor: pointer; transition: filter .15s; }
#open-profile:hover { filter: brightness(1.06); }
#open-profile:focus-visible { outline: 3px solid var(--accent); }
.profile-bio { margin: -4px 0 8px; overflow-wrap: anywhere; }
.profile-bio:empty { display: none; }
.rank-mini { display: grid; justify-items: center; text-align: center; gap: 1px; min-width: 88px; }
.rank-mini b { font-size: .95rem; }
.emblem { width: 56px; aspect-ratio: 1; }
.emblem svg { display: block; width: 100%; height: 100%; overflow: visible; }
.emblem-xs { display: inline-block; width: 20px; vertical-align: middle; margin-right: 4px; }
.emblem-xl { width: 110px; flex-shrink: 0; }
.emblem-xxl { width: 150px; margin: 0 auto; animation: spin 1s ease-out; }

.profile-hero { display: flex; gap: 22px; align-items: flex-start; }
.profile-hero-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.bio-label { font-weight: 700; font-size: .9rem; margin-top: 8px; }
#pr-bio {
  width: 100%; resize: vertical; padding: 10px 12px; border-radius: var(--radius); border: 2px solid transparent;
  background: var(--option); color: var(--text); font: inherit; outline: none;
}
#pr-bio:focus { border-color: var(--accent); }
.bio-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.rank-card { display: flex; gap: 22px; align-items: center; }
.rank-card-main { flex: 1; display: grid; gap: 4px; }
.rank-title { font-size: 1.6rem; font-weight: 800; }

.avatar-group { margin-bottom: 14px; }
.avatar-group-title { font-weight: 700; color: var(--muted); margin: 0 0 8px 2px; font-size: .9rem; }
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.avatar-option {
  border: 3px solid transparent; background: var(--card); border-radius: var(--radius); padding: 10px 6px 8px;
  display: grid; justify-items: center; gap: 6px; font-size: .78rem; font-weight: 700; box-shadow: 0 3px 0 var(--shadow);
  position: relative; transition: transform .08s;
}
.avatar-option .avatar { width: 64px; box-shadow: none; }
.avatar-option:hover:not(:disabled) { transform: translateY(-2px); }
.avatar-option.selected { border-color: var(--accent); }
.avatar-option:disabled { cursor: not-allowed; }
.avatar-option:disabled .avatar { filter: grayscale(1) brightness(.6); }
.avatar-option .lock { position: absolute; top: 30px; background: rgba(0,0,0,.7); color: #fff; padding: 2px 7px; border-radius: 999px; font-size: .72rem; }

.mode-stats { display: grid; gap: 10px; }
.mode-row { display: grid; grid-template-columns: 130px 1fr 110px; gap: 10px; align-items: center; font-weight: 700; }
.mode-row .xpbar { margin: 0; }
.mode-row span:last-child { text-align: right; color: var(--muted); font-size: .9rem; }
.stats2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.topic-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.topic-list li { display: flex; justify-content: space-between; gap: 8px; }
.topic-list li.empty { color: var(--muted); font-size: .9rem; }
.pw-form { display: grid; gap: 12px; }
.pw-form label { display: grid; gap: 6px; font-weight: 700; font-size: .9rem; }
.pw-form input { padding: 12px 14px; border-radius: var(--radius); border: 2px solid transparent; background: var(--option); outline: none; }
.pw-form input:focus { border-color: var(--accent); }
.pw-form .btn { justify-self: start; }
.toast.ok { background: var(--good); }

@media (max-width: 560px) {
  .profile { flex-wrap: wrap; }
  .rank-mini { grid-auto-flow: column; align-items: center; gap: 8px; min-width: 0; width: 100%; justify-content: start; }
  .rank-mini .emblem { width: 40px; }
  .profile-hero, .rank-card { flex-direction: column; align-items: center; text-align: center; }
  .profile-hero-main { width: 100%; text-align: left; }
  .stats2 { grid-template-columns: 1fr; }
  .mode-row { grid-template-columns: 100px 1fr 90px; }
}

/* ============ Kategorien & Tipps ============ */
.cat-tabs { margin: 0 0 12px; flex-wrap: wrap; }
.cat-tabs .tab { font-size: .95rem; min-width: 110px; }
.hint-btn {
  justify-self: center; margin-top: 14px; border: 0; border-radius: 999px; padding: 7px 16px; font-weight: 800;
  background: color-mix(in srgb, #f5c542 25%, var(--option)); color: var(--text); box-shadow: 0 3px 0 var(--shadow);
}
.hint-btn:disabled { opacity: .45; cursor: default; }
.hint-box {
  margin: -4px 0 14px; padding: 12px 16px; border-radius: var(--radius); font-size: 1.05rem; line-height: 1.6;
  background: color-mix(in srgb, #f5c542 18%, var(--card)); border-left: 4px solid #f5c542; animation: fadeIn .25s;
}
.hint-box b { color: var(--accent); }
.hint-box .hint-title { font-weight: 800; margin-right: 6px; }

/* ============ Hintergründe ============ */
body[data-bg] .bg-deco {
  background-size: cover !important; background-position: center !important;
  background-repeat: no-repeat !important; animation: none !important;
}
/* leichter Schleier in der Theme-Farbe, damit Schrift lesbar bleibt und alles zum Theme passt */
body[data-bg] .bg-deco::after { content: ""; position: absolute; inset: 0; background: var(--bg); opacity: .35; }
body[data-bg] .section-title.big, body[data-bg] .topbar .play-mode, body[data-bg] .logo {
  text-shadow: 0 1px 2px var(--bg), 0 0 10px var(--bg), 0 0 18px var(--bg);
}
/* kleine Hinweistexte außerhalb von Karten bekommen eine Hinterlegung statt Leuchten */
body[data-bg] .calc-note, body[data-bg] .bg-note, body[data-bg] .group-grid > .empty {
  display: inline-block; background: var(--card); color: var(--text); padding: 4px 12px; border-radius: 999px;
}
.bg-note { margin: -6px 0 10px 2px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head .section-title { margin: 0; }
.bg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.bg-tile {
  border: 3px solid transparent; background: var(--card); border-radius: var(--radius); padding: 8px;
  display: grid; gap: 6px; text-align: center; box-shadow: 0 3px 0 var(--shadow); font-size: .85rem;
}
.bg-tile.active { border-color: var(--accent); }
.bg-preview { display: block; aspect-ratio: 16 / 10; border-radius: 8px; background-size: cover; background-position: center; }
.bg-preview-theme { background-color: var(--bg); background-image: var(--bg-image); }

/* ============ Rangliste ============ */
.lb-tabs { margin: 0 0 14px; }
.lb-pos { font-size: 1.2rem; width: 34px; }
.lb-main { cursor: default; }
.lb-score { text-align: right; font-weight: 800; font-size: 1.15rem; display: grid; line-height: 1.15; }
.lb-score small { font-size: .72rem; color: var(--muted); font-weight: 700; }
.lb-note { margin: 12px 0 0; }

/* ============ Taschenrechner ============ */
.calc-tabs { margin: 0 0 6px; flex-wrap: wrap; }
.calc-tabs .tab { min-width: 150px; }
.calc-note { margin: 0 0 12px 4px; }
.card-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.card-tools .hint-btn { margin-top: 0; }
.card-tools [hidden] { display: none; }
.calc { margin: 14px 0 0; padding: 14px; }
.calc-display { background: var(--option); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 10px; }
#calc-input {
  width: 100%; border: 0; outline: none; background: transparent; color: var(--text);
  font: inherit; font-size: 1.4rem; font-weight: 700; text-align: right;
}
.calc-preview { text-align: right; color: var(--muted); font-weight: 700; min-height: 1.4em; }
.calc-preview.err { color: var(--bad); }
.calc-keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.calc-keys button {
  border: 0; border-radius: calc(var(--radius) * .8); background: var(--option); color: var(--text);
  box-shadow: 0 3px 0 var(--shadow); padding: 11px 0; font-size: 1.15rem; font-weight: 700;
}
.calc-keys button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.calc-keys .op { background: color-mix(in srgb, var(--accent) 25%, var(--option)); }
.calc-keys .fn { color: var(--muted); }
.calc-keys .zero { grid-column: span 2; }
.calc-keys .eq { grid-column: span 2; background: var(--accent); color: var(--accent-text); box-shadow: 0 3px 0 var(--accent-dark); }
.calc-keys sup { top: -.6em; font-size: .65em; }

/* ============ Freunde & Gruppen ============ */
.icon-btn { position: relative; }
.badge {
  position: absolute; top: -5px; right: -5px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: .72rem; font-weight: 800; display: grid; place-items: center;
}
.badge.inline { position: static; display: inline-grid; margin-left: 4px; vertical-align: middle; }
.badge[hidden], .badge.inline[hidden] { display: none; }
.text-input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius); border: 2px solid transparent;
  background: var(--option); color: var(--text); font: inherit; outline: none;
}
.text-input:focus { border-color: var(--accent); }
textarea.text-input { resize: vertical; }
.social-tabs { margin: 0 0 14px; }

.list { display: grid; gap: 8px; }
.list:not(:empty) { margin-top: 10px; }
.list .empty { color: var(--muted); font-size: .9rem; padding: 4px 2px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius); background: var(--option);
}
.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; background: none; border: 0; text-align: left; padding: 0; cursor: pointer; }
.row-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.row .avatar { width: 44px; box-shadow: none; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-pos { width: 26px; text-align: center; font-weight: 800; color: var(--muted); }
.row.me { outline: 2px solid var(--accent); }
.btn-sm { padding: 7px 12px; font-size: .85rem; box-shadow: 0 3px 0 var(--shadow); }
.btn-danger { background: var(--bad); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--bad) 55%, #000); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--muted); }
.role { font-size: .72rem; font-weight: 800; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-text); margin-left: 6px; }
.role.owner { background: #f5c542; color: #3b2a00; }
.tag-status { font-size: .8rem; color: var(--muted); font-weight: 700; }

.group-logo {
  width: 56px; aspect-ratio: 1; border-radius: 28%; overflow: hidden; flex-shrink: 0; display: grid; place-items: center;
  container-type: inline-size; background: var(--option);
}
.group-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.group-logo span { font-size: 58cqw; line-height: 1; }
.group-logo-xl { width: 110px; }
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 14px; }
.group-grid > .empty { grid-column: 1 / -1; }
.group-card {
  border: 0; background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 3px 0 var(--shadow);
  display: flex; gap: 12px; align-items: center; text-align: left; transition: transform .08s;
}
.group-card:hover { transform: translateY(-2px); }
.group-card-main { min-width: 0; display: grid; gap: 2px; }
.group-card-main b { font-size: 1.05rem; overflow-wrap: anywhere; }
.group-hero { display: flex; gap: 20px; align-items: flex-start; }
.group-hero-main { flex: 1; min-width: 0; display: grid; gap: 4px; overflow-wrap: anywhere; }
.group-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.invite-row { display: flex; gap: 8px; }
.small-title { font-size: .9rem; color: var(--muted); margin: 14px 0 0; }
.profile-bio-big { margin-top: 6px; overflow-wrap: anywhere; }

.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { width: 100%; max-width: 520px; display: grid; gap: 12px; margin: 0; }
.modal-card label { display: grid; gap: 6px; font-weight: 700; font-size: .9rem; }
.modal-card .section-title.big { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.logo-editor { display: flex; gap: 16px; align-items: flex-start; }
.logo-controls { flex: 1; min-width: 0; display: grid; gap: 10px; }
.logo-tabs { margin: 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.emoji-grid button { border: 2px solid transparent; background: var(--option); border-radius: 10px; font-size: 1.35rem; padding: 4px 0; }
.emoji-grid button.selected { border-color: var(--accent); }
.modal-card .inline-label { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.inline-label input[type=color] { width: 56px; height: 34px; border: 0; background: none; padding: 0; cursor: pointer; }
.file-btn { display: inline-block; cursor: pointer; }
.danger-title { color: var(--bad); }
.danger-card { border: 2px solid color-mix(in srgb, var(--bad) 50%, transparent); }

@media (max-width: 560px) {
  .row { flex-wrap: wrap; }
  .row-actions { width: 100%; justify-content: flex-start; }
  .group-hero, .logo-editor { flex-direction: column; align-items: center; text-align: center; }
  .logo-controls { width: 100%; }
  .group-actions { justify-content: center; }
}

@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(10px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes zoom { from { transform: scale(.3); opacity: 0; } }
@keyframes spin { from { transform: rotate(-180deg) scale(.2); } }
@keyframes twinkle { from { opacity: .45; } to { opacity: 1; } }

@media (max-width: 560px) {
  .modes, .themes { grid-template-columns: 1fr; }
  .stats { gap: 8px; }
  .stat b { font-size: 1.35rem; }
  .color-grid { grid-template-columns: repeat(2, 1fr); }
  .options { gap: 10px; }
  .history { grid-template-columns: repeat(10, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
