:root {
  --bg: #f7f3ec;
  --bg-deep: #efe7da;
  --card: #ffffff;
  --text: #22302b;
  --muted: #6b7a73;
  --line: #e4ddd1;
  --primary: #1f5c48;
  --primary-hover: #174a39;
  --primary-soft: #e3efe9;
  --accent: #b8322f;
  --accent-soft: #f8e4e2;
  --gold: #c9973f;
  --gold-soft: #f7ecd6;
  --ok: #2f8a5b;
  --shadow: 0 1px 2px rgba(34, 48, 43, .06), 0 6px 24px rgba(34, 48, 43, .07);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111a17;
    --bg-deep: #0c1311;
    --card: #19241f;
    --text: #e8eee9;
    --muted: #93a39b;
    --line: #2a3832;
    --primary: #3f9a77;
    --primary-hover: #4cae88;
    --primary-soft: #1d3329;
    --accent: #e0605a;
    --accent-soft: #3a2120;
    --gold: #ddb062;
    --gold-soft: #33291a;
    --ok: #5cc28c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-family: var(--font-display); font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
h2.inline { display: inline; margin: 0; }
p { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--primary); }
code { background: var(--bg-deep); padding: .1em .35em; border-radius: 6px; font-size: .9em; }

.container { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 600px; margin: 0 auto; padding: 24px 16px 64px; }
.center-page { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.right { text-align: right; }
.top-gap { margin-top: 1rem; }

/* ----------------------------------------------------------- Layout-Bausteine */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-dashed { border-style: dashed; box-shadow: none; background: transparent; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.grid-2.tight { gap: 12px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + section { margin-top: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.cards > .card { margin: 0; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.crumbs { font-size: .875rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--primary); }

/* ----------------------------------------------------------- Formulare */

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }

input, select, textarea {
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--primary); }
textarea { resize: vertical; min-height: 3em; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row input, .row select { width: auto; flex: 1 1 140px; }
.input-short { max-width: 120px; }

fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 16px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 700; padding: 0 6px; }

.segmented { display: inline-flex; background: var(--bg-deep); border-radius: 12px; padding: 4px; gap: 4px; align-self: flex-start; flex-wrap: wrap; }
.segmented label { font-weight: 500; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 6px 16px; border-radius: 9px; cursor: pointer; }
.segmented input:checked + span { background: var(--card); box-shadow: var(--shadow); color: var(--primary); font-weight: 700; }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-weight: 500; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; background: var(--card); color: var(--muted); text-decoration: line-through; }
.chip input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); text-decoration: none; font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--primary); }

/* ----------------------------------------------------------- Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg-deep); border-color: transparent; color: var(--text); }
.btn-danger { color: var(--accent); border-color: var(--accent-soft); }
.btn-danger:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-small { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn-big { padding: 13px 22px; font-size: 1.05rem; border-radius: 12px; }
.btn.copied { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }

/* ----------------------------------------------------------- Elemente */

.badge { display: inline-block; font-family: var(--font); font-size: .75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; letter-spacing: .02em; vertical-align: middle; }
.badge-draft { background: var(--gold-soft); color: var(--gold); }
.badge-drawn { background: var(--primary-soft); color: var(--primary); }
.badge-archived { background: var(--bg-deep); color: var(--muted); }
.tag { font-size: .75rem; background: var(--bg-deep); color: var(--muted); padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.arrow { color: var(--muted); margin: 0 4px; }
.ok { color: var(--ok); font-weight: 700; }

.avatar {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .85rem; margin-right: 6px;
}

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list-main { display: flex; flex-direction: column; text-decoration: none; color: var(--text); flex: 1; }
.list-main:hover strong { color: var(--primary); }

details > summary { cursor: pointer; }
.inline-edit { flex: 1; }
.inline-edit summary { list-style: none; display: flex; align-items: center; }
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit[open] form { margin-top: 8px; }

.group-card { text-decoration: none; color: var(--text); transition: transform .15s, border-color .15s; }
.group-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.group-card h2 { font-family: var(--font-display); font-size: 1.35rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; }
.stat-num { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-num small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.stat-label { font-size: .82rem; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th.right { text-align: right; }

.message-preview { white-space: pre-wrap; font-family: var(--font); background: var(--bg-deep); padding: 14px; border-radius: 12px; margin-top: 10px; }
.spoiler summary { font-weight: 600; }
.cycles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.cycles li { display: flex; flex-wrap: wrap; align-items: center; row-gap: 8px; line-height: 1; }
.cycle-name { background: var(--primary-soft); color: var(--primary); font-weight: 600; padding: 6px 12px; border-radius: 999px; }
.cycles .arrow { margin: 0 6px; }
.danger-zone { border-color: var(--accent-soft); box-shadow: none; }

/* ----------------------------------------------------------- Meldungen */

.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.flash { padding: 12px 16px; border-radius: 12px; border: 1px solid; font-weight: 500; animation: slide-in .25s ease-out; }
.flash-success { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.flash-error { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.flash-warning { background: var(--gold-soft); border-color: var(--gold); color: var(--text); }
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } }

/* ----------------------------------------------------------- Admin-Kopfzeile */

.topbar { background: var(--primary); color: #fff; }
.topbar-inner { max-width: 1040px; margin: 0 auto; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; }
.topnav { display: flex; align-items: center; gap: 18px; }
.topnav a, .topnav .linklike { color: rgba(255, 255, 255, .85); text-decoration: none; font-weight: 500; font-size: .95rem; }
.topnav a:hover, .topnav .linklike:hover { color: #fff; }
@media (prefers-color-scheme: dark) { .topbar { background: #16302a; } }

/* ----------------------------------------------------------- Festliche Seiten */

body.festive { background: linear-gradient(180deg, #1f5c48 0, #1f5c48 280px, var(--bg) 280px); }
@media (prefers-color-scheme: dark) {
  body.festive { background: linear-gradient(180deg, #16302a 0, #16302a 280px, var(--bg) 280px); }
}
body.festive > main { position: relative; z-index: 1; }

/* Schneefall – Flocken werden von app.js zufällig erzeugt */
.snow { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.flake {
  position: absolute; top: -12px; left: var(--x);
  width: var(--size); height: var(--size); border-radius: 50%;
  background: radial-gradient(circle, #fff 0 45%, rgba(255, 255, 255, .6) 70%, transparent 100%);
  box-shadow: 0 0 3px rgba(31, 92, 72, .18);
  opacity: var(--o);
  filter: blur(var(--blur));
  animation:
    fall var(--dur) linear var(--delay) infinite,
    sway var(--sway-dur) ease-in-out var(--delay) infinite alternate;
}
@keyframes fall { to { transform: translate3d(var(--drift), 105vh, 0); } }
@keyframes sway { from { margin-left: calc(var(--sway) * -1); } to { margin-left: var(--sway); } }
@media (prefers-color-scheme: dark) { .flake { box-shadow: none; opacity: calc(var(--o) * .7); } }
@media (prefers-reduced-motion: reduce) { .flake { top: var(--y); } }

.hero-card { text-align: center; padding: 36px 24px; }
.hero-icon { font-size: 3rem; line-height: 1; margin-bottom: 12px; }

.player-hero { color: #fff; text-align: center; padding: 24px 8px 28px; }
.player-hero h1 { font-size: clamp(2rem, 7vw, 2.8rem); margin-bottom: 8px; }
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; opacity: .85; margin-bottom: 6px; }
.greeting { font-size: 1.15rem; opacity: .95; }

.prose { font-size: 1.02rem; }
.wish-form h2 { font-family: var(--font-display); font-size: 1.4rem; }
.wish-form textarea { font-size: 1.05rem; }
.waiting { text-align: center; padding: 32px 24px; }
.own-wish h3 { margin: 0; }
.own-wish p { margin-top: 10px; }
.player-footer { text-align: center; margin-top: 24px; }

/* Aufdecken */
.reveal { margin-bottom: 20px; position: relative; }
.reveal.resizing { overflow: hidden; transition: height .5s cubic-bezier(.2, .7, .2, 1); }
.reveal-cover.opening { position: absolute; inset: 0; z-index: 2; }
.reveal-cover {
  width: 100%; min-height: 220px; border: 0; border-radius: var(--radius); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #fff; font: inherit; font-weight: 700; font-size: 1.1rem;
  background:
    linear-gradient(90deg, transparent calc(50% - 14px), var(--gold) calc(50% - 14px), var(--gold) calc(50% + 14px), transparent calc(50% + 14px)),
    linear-gradient(180deg, transparent calc(50% - 14px), var(--gold) calc(50% - 14px), var(--gold) calc(50% + 14px), transparent calc(50% + 14px)),
    linear-gradient(135deg, #c8403b, #9e2724);
  box-shadow: var(--shadow);
  transition: transform .2s;
}
.reveal-cover:hover { transform: scale(1.01) rotate(-.4deg); }
.reveal-cover:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.reveal-gift { font-size: 3.4rem; line-height: 1; animation: wiggle 2.4s ease-in-out infinite; }
.reveal-hint { background: rgba(0, 0, 0, .28); padding: 6px 16px; border-radius: 999px; }
.reveal-cover.opening { animation: pop .4s ease-in forwards; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-10deg); } 90% { transform: rotate(9deg); } 95% { transform: rotate(-5deg); } }
@keyframes pop { to { transform: scale(1.04); opacity: 0; } }

.reveal-content {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 22px; text-align: center; animation: fade-up .5s ease-out;
}
.reveal-content .eyebrow { color: var(--muted); opacity: 1; }
.giftee-name { font-family: var(--font-display); font-size: clamp(2.4rem, 10vw, 3.4rem); font-weight: 700; color: var(--accent); margin: 0 0 18px; line-height: 1.1; }
.giftee-name::before, .giftee-name::after { content: "🎁"; font-size: .55em; vertical-align: middle; margin: 0 .3em; }
.giftee-wish { text-align: left; background: var(--gold-soft); border-radius: 12px; padding: 16px 18px; }
.giftee-wish h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); margin-bottom: 8px; }
.giftee-wish .fresh { animation: fade-up .5s ease-out; }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }

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

@media (max-width: 560px) {
  .card { padding: 16px; }
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 2px 4px; }
  .table td.right { grid-column: 1 / -1; }
  .table td.right .row { justify-content: flex-start; }
}
