/* Wichtel-App: mobil zuerst, hell und dunkel nach Systemeinstellung. */
:root {
  --bg: #fbf7f2;
  --card: #ffffff;
  --text: #1f1b16;
  --muted: #6b635a;
  --line: #e7ded3;
  --primary: #b3261e;
  --primary-text: #ffffff;
  --accent: #1f6f43;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --danger: #b3261e;
  --new: #1f6f43;
  --changed: #9a5b00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
  --giver-bg: #c62828;
  --giver-text: #ffffff;
  --giver-muted: #ffe3e0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --card: #221d18;
    --text: #f2ebe3;
    --muted: #b3a89c;
    --line: #3a322a;
    --primary: #e5534b;
    --primary-text: #1b0705;
    --accent: #6fcf97;
    --warn-bg: #3a2f12;
    --warn-text: #f2d48a;
    --danger: #ff7b72;
    --new: #6fcf97;
    --changed: #f2b45a;
    --shadow: none;
    --giver-bg: #5c1512;
    --giver-text: #fff1ef;
    --giver-muted: #f2b8b2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: var(--primary); word-break: break-word; }
h1 { font-size: 1.5rem; margin: .25rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .5rem 0; }

.container { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.help { color: var(--muted); font-size: .875rem; margin: .25rem 0 0; display: block; }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: .6rem .8rem; border-radius: 10px; }
.banner { background: var(--warn-bg); color: var(--warn-text); padding: .75rem 1rem; border-radius: var(--radius); font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Kopfleiste und feste Kopfzeile der Runde */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  max-width: 720px; margin: 0 auto;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar-tools { display: flex; gap: 8px; align-items: center; }
.lang-select { padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: .9rem; }
.sticky { position: sticky; top: 0; z-index: 10; background: var(--bg); }
.round-header {
  max-width: 720px; margin: 0 auto; padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.rh-name { font-weight: 700; font-size: 1.05rem; }
.rh-facts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .9rem; color: var(--muted); }
.rh-days.soon { color: var(--primary); font-weight: 700; }
.round-header.closed .rh-days { color: var(--danger); font-weight: 700; }

/* Reiter */
.tabs { display: flex; max-width: 720px; margin: 0 auto; padding: 0 16px; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 10px 6px; background: none; border: 0; border-bottom: 3px solid transparent;
  color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; position: relative;
}
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.dot {
  display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 6px;
  border-radius: 10px; background: var(--primary); color: var(--primary-text);
  font-size: .75rem; line-height: 20px; vertical-align: middle;
}

/* Karten, Formulare, Knöpfe */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; box-shadow: var(--shadow); }
.page-title { margin-top: 1rem; }
.hello { font-size: 1.1rem; margin-top: 1rem; }
.form { display: grid; gap: 14px; }
.form.compact { gap: 10px; margin-top: 12px; }
.field { display: grid; gap: 4px; }
.field-label { font-weight: 600; font-size: .95rem; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
input[type="checkbox"] { width: 20px; height: 20px; flex: none; accent-color: var(--primary); }
.grid-2 { display: grid; gap: 10px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row > input, .row > textarea { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-text { color: var(--danger); }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: .875rem; }
.btn.block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; flex: none;
}
.icon-btn.small { width: 36px; height: 36px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.actions.left { justify-content: flex-start; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--line); color: var(--muted); vertical-align: middle; }
.badge.ok { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.status { font-weight: 600; }
.status.ok { color: var(--accent); }

/* Startseite */
.hero { text-align: center; padding: 24px 0 4px; }
.hero-icon { font-size: 56px; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.link-list li:last-child { border-bottom: 0; }
.secret-link { font-family: ui-monospace, monospace; font-size: .85rem; background: var(--bg); border: 1px dashed var(--line); padding: 10px; border-radius: 10px; word-break: break-all; user-select: all; }

/* Teilnehmerlisten (Admin) */
.people { list-style: none; padding: 0; margin: 0; }
.person { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person-name { font-weight: 600; }
.person-sub { color: var(--muted); font-size: .875rem; word-break: break-all; }
.person-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.check-list { list-style: none; padding: 0; margin: 8px 0; max-height: 45vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.check-list li { border-bottom: 1px solid var(--line); }
.check-list li:last-child { border-bottom: 0; }
.check { display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; }
.check.mirror { padding-left: 0; }
.field-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.pairs { padding-left: 1.4rem; }
.pairs li { padding: 4px 0; }
.arrow { color: var(--muted); }

/* Profil, Einträge */
.visible-note { margin-top: .5rem; color: var(--muted); font-size: .9rem; }
.profile-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar { border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; background: var(--bg); border: 1px solid var(--line); flex: none; }
.avatar.initial { font-weight: 700; color: var(--muted); }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatar-choice { font-size: 36px; padding: 8px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); cursor: pointer; }
.avatar-choice.selected { border-color: var(--primary); }
.big-name { font-size: 1.3rem; font-weight: 700; }
.entries { list-style: none; padding: 0; margin: 0 0 8px; }
.entry { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry-text { flex: 1 1 200px; white-space: pre-wrap; word-break: break-word; }
.entry-actions { display: flex; gap: 6px; }
.add-entry { margin-top: 8px; }
.entry.mark-deleted .entry-text { color: var(--muted); }
.entry.mark-new { border-left: 4px solid var(--new); padding-left: 10px; }
.entry.mark-changed { border-left: 4px solid var(--changed); padding-left: 10px; }
.previous { flex-basis: 100%; color: var(--muted); font-size: .875rem; }
.badge.mark.new { background: color-mix(in srgb, var(--new) 20%, transparent); color: var(--new); }
.badge.mark.changed { background: color-mix(in srgb, var(--changed) 22%, transparent); color: var(--changed); }
.badge.mark.deleted { background: var(--line); color: var(--muted); }

/* Chat */
.chat-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.mystery-bg { fill: #2d2a4a; }
.mystery-cloak { fill: #4b4677; }
.mystery-face { fill: #17152b; }
.mystery-q { fill: #f2d48a; font: 700 26px system-ui, sans-serif; }
.chat-list { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; padding: 8px 2px; }
.chat-date { align-self: center; font-size: .75rem; color: var(--muted); margin: 6px 0; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.bubble.mine { align-self: flex-end; background: var(--primary); color: var(--primary-text); border-bottom-right-radius: 4px; }
.bubble.mine a { color: inherit; }
.bubble.theirs { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.preview { max-width: 100%; margin: 8px 0; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
.chat-form textarea { flex: 1; }
.tips { padding-left: 1.2rem; margin: .5rem 0; }
.tips li { margin: 2px 0; }

/* Dialoge, Meldungen */
.dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 520px); background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-body { padding: 20px; max-height: 85vh; overflow-y: auto; }
.dialog.tall .dialog-body { max-height: 90vh; }
.intro-icon { font-size: 44px; text-align: center; }
.seg { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; margin: 8px 0; }
.seg-btn { flex: 1; padding: 8px; border: 0; border-radius: 9px; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.steps { padding-left: 1.3rem; }
.steps li { margin: 6px 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); transform: translate(-50%, 140%);
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 12px; background: #1f1b16; color: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3); transition: transform .25s ease; z-index: 100;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: #8c1d18; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* Fehler beim Mailversand (T-071) */
.error-text { color: var(--danger); font-size: .9rem; word-break: break-word; }
.failures { list-style: none; padding: 0; margin: 8px 0; }
.failures li { display: grid; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.failures li:last-child { border-bottom: 0; }
.failures .btn { justify-self: start; }

/* Reiter "Ich als Wichtel": rote Fläche, damit man sofort sieht, in welchem
   Chat man ist (T-072). Karten und Eingabefelder bleiben neutral und lesbar. */
body.giver-mode { background: var(--giver-bg); }
body.giver-mode .sticky { background: var(--giver-bg); }
body.giver-mode .topbar .brand,
body.giver-mode .round-header,
body.giver-mode .rh-name,
body.giver-mode .hello { color: var(--giver-text); }
body.giver-mode .rh-facts,
body.giver-mode .round-header .rh-days.soon { color: var(--giver-muted); }
body.giver-mode .round-header,
body.giver-mode .tabs { border-color: rgba(255, 255, 255, .25); }
body.giver-mode .tab { color: var(--giver-muted); }
body.giver-mode .tab.active { color: var(--giver-text); border-bottom-color: var(--giver-text); }
body.giver-mode .dot { background: var(--giver-text); color: var(--giver-bg); }
body.giver-mode main > .muted { color: var(--giver-muted); }

/* Umformulierung (T-073) */
.rewrite-preview { min-height: 3em; align-self: stretch; max-width: 100%; }

/* Meine Runden (T-076) */
.back-link { display: inline-block; margin-top: 1rem; text-decoration: none; font-weight: 600; }
.link-list li a { flex: 1; min-width: 0; text-decoration: none; color: var(--text); }

/* Schwebende Navigation (T-077) */
.topbar-extra { display: contents; }
.nav-box {
  position: fixed; z-index: 40; width: min(270px, 82vw);
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .22); overflow: hidden; touch-action: none;
}
.nav-box.dragging { opacity: .92; box-shadow: 0 12px 36px rgba(0, 0, 0, .3); }
.nav-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; cursor: grab;
  background: var(--bg); border-bottom: 1px solid var(--line); user-select: none;
}
.nav-box.dragging .nav-head { cursor: grabbing; }
.nav-grip { color: var(--muted); }
.nav-title { flex: 1; font-weight: 700; font-size: .9rem; }
.nav-close { width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--text); font-size: 1.2rem; cursor: pointer; }
.nav-items { display: grid; touch-action: auto; }
.nav-item {
  display: grid; gap: 2px; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line);
  background: none; color: var(--text); font: inherit; cursor: pointer;
}
.nav-item:last-child { border-bottom: 0; }
.nav-item:hover:not(:disabled) { background: var(--bg); }
.nav-item:disabled { cursor: default; opacity: .6; }
.nav-label { font-weight: 600; font-size: .92rem; }
.nav-sub { color: var(--muted); font-size: .8rem; }
.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 55%, transparent); } 100% { box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 3px solid var(--primary); } }
.rewrite-applied { margin: 4px 0 0; font-weight: 600; color: var(--accent, inherit); }

/* Sende-Dialog des Wichtels (T-080): Stil-Chips, Stärke, drei Versionen. */
.style-picker { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 12px 0; }
.style-picker summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; list-style-position: inside; }
.style-current { color: var(--accent); font-weight: 600; }
.chip-group { margin-top: 10px; }
.chip-group-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: .9rem; cursor: pointer;
  transition: transform .12s ease, background-color .12s ease;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }
.chip:active { transform: scale(.95); }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 6px; }
.seg {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; padding: 6px 4px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-size: .8rem; cursor: pointer;
}
.seg-icon { font-size: 1.2rem; line-height: 1; }
.seg.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.versions { display: grid; gap: 8px; margin-top: 6px; }
.version {
  display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.version:active { transform: scale(.99); }
.version.on { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.version-head { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.version-style { color: var(--accent); font-weight: 600; text-align: right; }
.version-text { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.versions-loading { display: flex; align-items: center; gap: 10px; padding: 16px 4px; color: var(--muted); }
.dice { font-size: 1.6rem; display: inline-block; animation: dice-roll 0.9s ease-in-out infinite; }
@keyframes dice-roll { 0% { transform: rotate(0); } 50% { transform: rotate(180deg) scale(1.15); } 100% { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .dice { animation: none; } .chip, .version { transition: none; } }
.btn.link { border: none; background: none; color: var(--muted); text-decoration: underline; min-height: 36px; padding: 4px 0; }

/* T-081: Schnellwahl, "nur diese neu", Stil-Abzeichen, Glücksrad, Walzen. */
.recent-row { margin: 12px 0 0; }
.chip.recent { font-size: .85rem; }
.version-head { align-items: center; }
.version-style { flex: 1; }
.reroll {
  flex: none; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: .95rem; line-height: 1; cursor: pointer;
}
.reroll:active { transform: rotate(90deg); }
.version.loading { opacity: .65; }
.style-badge { display: block; margin-top: 4px; font-size: .75rem; opacity: .85; }
.wheel { position: relative; display: inline-block; width: 8.4em; height: 8.4em; flex: none; font-size: .78rem; }
.wheel-disc {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--line);
  background: radial-gradient(circle, var(--card) 35%, var(--bg) 36%);
  animation: wheel-spin 1.6s linear infinite;
}
.wheel-icon { position: absolute; left: 50%; top: 50%; width: 1.4em; height: 1.4em; margin: -.7em 0 0 -.7em; text-align: center; line-height: 1.4em; }
.wheel-pointer { position: absolute; left: 50%; top: -.9em; transform: translateX(-50%); color: var(--primary); z-index: 1; font-size: .9rem; }
@keyframes wheel-spin { to { transform: rotate(360deg); } }
.reel { display: inline-block; height: 1.3em; line-height: 1.3em; overflow: hidden; vertical-align: bottom; }
.reel-strip { display: flex; flex-direction: column; animation: reel-roll .9s cubic-bezier(.2, .7, .3, 1) var(--delay, 0ms) both; }
.reel-strip > span { height: 1.3em; }
@keyframes reel-roll { from { transform: translateY(0); } to { transform: translateY(calc(var(--steps) * -1.3em)); } }
.reel-name { animation: reel-name .3s ease-out calc(var(--delay, 0ms) + 900ms) both; }
@keyframes reel-name { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .wheel-disc { animation: none; } .reel-strip, .reel-name { animation: none; } }

/* Stand unten rechts (T-082): klein und unauffällig. */
.version-footer {
  text-align: right; font-size: .66rem; color: var(--muted); opacity: .65;
  padding: 24px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  font-variant-numeric: tabular-nums; user-select: all;
}
body.giver-mode .version-footer { color: var(--giver-muted); }
