@font-face {
  font-family: "Caveat";
  src: url("fonts/caveat-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  --paper: #f3ece0;
  --paper-deep: #e9dfcd;
  --card: #fcfaf5;
  --slip: #fffdf8;
  --ink: #1e2a22;
  --ink-soft: #5d665c;
  --line: #dccfb8;
  --pine: #1f4d3a;
  --berry: #b8322a;
  --berry-dark: #8f2119;
  --mustard: #c8963e;
  --ok: #2f8a5b;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Noto Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --hand: "Caveat", "Bradley Hand", cursive;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  font: 16px/1.5 var(--sans);
  color: var(--ink);
  background: radial-gradient(circle at 1px 1px, rgba(30, 42, 34, .07) 1px, transparent 0) 0 0 / 22px 22px, var(--paper);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--pine); outline-offset: 3px; }

/* ---------- Kopf ---------- */

.masthead { position: relative; text-align: center; padding: 30px 16px 4px; }
.masthead::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 6px;
  background: repeating-linear-gradient(90deg, var(--berry) 0 18px, var(--card) 18px 24px, var(--pine) 24px 42px, var(--card) 42px 48px);
}
.holly { display: block; width: 92px; margin: 0 auto; }
.kicker { margin: 0; font-size: .75rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--berry); }
.masthead h1 {
  margin: 0;
  font: 700 clamp(2.8rem, 13vw, 4.2rem)/1 var(--serif);
  letter-spacing: -.02em;
}
.me-bar { margin: 12px 0 0; color: var(--ink-soft); font-size: .95rem; }
.me-bar strong { color: var(--ink); }
.link { background: none; border: 0; padding: 0 0 0 8px; color: var(--berry); text-decoration: underline; text-underline-offset: 3px; }

main { max-width: 680px; margin: 0 auto; padding: 18px 16px 120px; }
.admin main { max-width: 980px; }

.section-title { margin: 8px 0 2px; text-align: center; font: 700 1.9rem/1.2 var(--serif); }
.lead { margin: 0 0 24px; text-align: center; color: var(--ink-soft); }
.hint { margin: 0; text-align: center; color: var(--ink-soft); font-size: .95rem; }

/* ---------- Buttons & Eingaben ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 22px;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  background: transparent;
  font-weight: 600;
  line-height: 1.1;
  text-decoration: none;
  transition: translate .1s, box-shadow .1s, background-color .15s;
}
.btn.primary { background: var(--berry); border-color: var(--berry-dark); color: #fff8ef; box-shadow: 0 3px 0 var(--berry-dark); }
.btn.primary:active:not(:disabled) { translate: 0 2px; box-shadow: 0 1px 0 var(--berry-dark); }
.btn.secondary { background: var(--card); border-color: var(--line); }
.btn.secondary:hover { background: var(--paper); }
.btn.ghost { border-color: transparent; }
.btn.danger { color: var(--berry); border-color: rgba(184, 50, 42, .45); }
.btn.big { width: 100%; max-width: 340px; padding: 17px 28px; font-size: 1.15rem; }
.btn.small { padding: 7px 12px; border-radius: 9px; font-size: .85rem; }
.btn.icon { padding: 3px 9px; border-radius: 8px; font-size: .9rem; }
.btn:disabled { opacity: .45; box-shadow: none; }

.input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
}
.input:focus { outline: none; border-color: var(--pine); box-shadow: 0 0 0 3px rgba(31, 77, 58, .14); }

/* ---------- Zettel (Auswahl, Lobby, Dialog) ---------- */

.slip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 26px 16px; padding-top: 10px; }

.note {
  position: relative;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  min-height: 100px;
  padding: 22px 12px 16px;
  text-align: center;
  border: 0;
  border-radius: 3px;
  background: var(--slip);
  box-shadow: 0 1px 1px rgba(30, 42, 34, .08), 0 10px 16px -12px rgba(30, 42, 34, .55);
  rotate: var(--tilt, 0deg);
  transition: rotate .2s, translate .2s, opacity .3s;
}
/* Klebestreifen */
.note::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 56px;
  height: 18px;
  margin-left: -28px;
  background: rgba(200, 150, 62, .5);
  rotate: -3deg;
}
.note:nth-child(even)::before { background: rgba(184, 50, 42, .32); rotate: 4deg; }
.note-name { font: 600 2rem/1 var(--hand); color: var(--ink); overflow-wrap: anywhere; }
.note-meta { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }

button.note:hover:not(:disabled) { rotate: 0deg; translate: 0 -3px; }
button.note:active:not(:disabled) { translate: 0 0; }
.note.taken { opacity: .4; }

.note.here .note-meta { color: var(--ok); }
.note.here .note-meta::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 138, 91, .18);
  vertical-align: 1px;
}
.note.away { opacity: .6; }
.note.missing { background: transparent; box-shadow: none; outline: 1.5px dashed var(--line); outline-offset: -1px; }
.note.missing::before { display: none; }
.note.missing .note-name { color: var(--ink-soft); }

.start-area { display: grid; justify-items: center; gap: 10px; margin-top: 34px; }

/* ---------- Dialog ---------- */

.modal { width: min(92vw, 380px); padding: 0; border: 0; background: transparent; }
.modal::backdrop { background: rgba(30, 42, 34, .5); }
.modal form {
  padding: 26px 22px 20px;
  border-radius: 18px;
  background: var(--card);
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .45);
}
.modal[open] form { animation: pop .3s cubic-bezier(.2, .9, .3, 1.15); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.modal-note { width: 190px; margin: 18px auto 4px; --tilt: -2deg; }
.modal-text { margin: 14px 0 20px; font: 600 1.3rem/1.3 var(--serif); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Bühne mit Beutel ---------- */

.stage { position: relative; height: clamp(440px, 62vh, 600px); }
#slip-layer { position: absolute; inset: 0; pointer-events: none; }

.bag {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 200px;
  height: 218px;
  margin: -109px 0 0 -100px;
  padding: 0;
  border: 0;
  background: none;
  transform-origin: 50% 60%;
}
.bag svg { display: block; width: 100%; height: 100%; transition: transform .12s; }
.bag.ready { cursor: pointer; animation: nudge 3.4s ease-in-out infinite; }
.bag.ready:active svg { transform: scale(.95); }
@keyframes nudge {
  0%, 68%, 100% { transform: rotate(0); }
  74% { transform: rotate(-4deg); }
  80% { transform: rotate(3.5deg); }
  86% { transform: rotate(-1.5deg); }
}

/* Faltbarer Zettel: untere Hälfte, obere Hälfte (klappt nach vorn) und Rückseite der oberen Hälfte */
.slip {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 250px;
  height: 168px;
  margin: -84px 0 0 -125px;
  perspective: 900px;
}
.slip-face { position: absolute; left: 0; right: 0; height: 50%; overflow: hidden; background: var(--slip); }
.slip-top {
  top: 0;
  border-radius: 4px 4px 0 0;
  transform-origin: 50% 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 -6px 14px -10px rgba(30, 42, 34, .35);
}
.slip-bottom { bottom: 0; border-radius: 0 0 4px 4px; box-shadow: 0 14px 22px -14px rgba(30, 42, 34, .6); }
.slip-bottom::before { content: ""; position: absolute; inset: 0 0 auto; height: 1px; background: rgba(30, 42, 34, .06); z-index: 1; }
.slip-content {
  position: absolute;
  left: 0;
  right: 0;
  height: 200%;
  display: grid;
  place-content: center;
  text-align: center;
}
.slip-top .slip-content { top: 0; }
.slip-bottom .slip-content { top: -100%; }
.slip-content small { font-size: .7rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-soft); }
.slip-content strong { font: 600 2.8rem/1.05 var(--hand); color: var(--ink); padding: 0 12px; overflow-wrap: anywhere; }
.slip-back {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 50%;
  border-radius: 0 0 4px 4px;
  background: repeating-linear-gradient(transparent 0 15px, rgba(30, 42, 34, .05) 15px 16px), #f1e8d8;
  transform-origin: 50% 0;
  transform: rotateX(180deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.slip.folded .slip-top { transform: rotateX(-180deg); }
.slip.folded .slip-back { transform: rotateX(0deg); }

.stage-caption { min-height: 1.6em; margin: 4px 0 10px; text-align: center; font: 600 1.35rem/1.3 var(--serif); }
.stage-actions { display: grid; justify-items: center; gap: 10px; }

/* ---------- Wünsche ---------- */

.wish-form { display: flex; gap: 8px; margin: 0 0 18px; }
.wish-form .btn { flex: none; }

.wishes { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.wishes li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-wrap: anywhere;
}
.wishes li.empty { justify-content: center; color: var(--ink-soft); background: none; border-style: dashed; }
.wish-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; }
.wish-link:hover strong { color: var(--berry); }
.wish-link img { flex: none; width: 64px; height: 64px; padding: 4px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.wish-text { flex: 1; min-width: 0; display: grid; }
.wish-text small { color: var(--ink-soft); }
.wishes .del { flex: none; padding: 4px 9px; border: 0; border-radius: 8px; background: none; color: var(--ink-soft); }
.wishes .del:hover { color: var(--berry); background: var(--paper); }

/* ---------- Navigation, Hinweise ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabbar button { position: relative; flex: 1; padding: 15px 6px 17px; border: 0; background: none; font-size: .92rem; font-weight: 600; color: var(--ink-soft); }
.tabbar button.active { color: var(--berry); }
.tabbar button.active::after { content: ""; position: absolute; top: -1px; left: 26%; right: 26%; height: 3px; border-radius: 0 0 3px 3px; background: var(--berry); }
.tabbar button:disabled { opacity: .35; }

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 50;
  max-width: 90vw;
  padding: 10px 16px;
  translate: -50% 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: .95rem;
}

.sim-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  padding: 9px 16px;
  background: #fbefd2;
  border-bottom: 1px solid var(--mustard);
  color: #6b4c12;
  font-size: .9rem;
  font-weight: 600;
}

/* ---------- Backend ---------- */

.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; } /* minmax: breite Matrix scrollt statt die Seite zu verbreitern */
.card {
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 28px -24px rgba(30, 42, 34, .5);
}
.card h2 { margin: 0 0 4px; font: 700 1.5rem/1.2 var(--serif); }
.card h3 { margin: 0 0 6px; font: 700 1.15rem/1.2 var(--serif); }
.card.narrow { max-width: 380px; margin: 0 auto; display: grid; gap: 12px; }
.muted { margin-top: 0; color: var(--ink-soft); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.actions, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form .btn { flex: none; }
.warning { padding: 10px 14px; border-radius: 12px; background: #f9e1dc; border: 1px solid #e7b1a8; color: var(--berry-dark); }

.persons {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) minmax(140px, 1fr) auto auto auto;
  gap: 10px;
}
.person {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid; /* alle Zeilen teilen dieselben Spalten */
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.order { display: grid; gap: 4px; }
.last-year { display: grid; font-size: .75rem; color: var(--ink-soft); }
.host { display: flex; align-items: center; gap: 6px; font-size: .85rem; white-space: nowrap; cursor: pointer; }
.host input { accent-color: var(--berry); width: 18px; height: 18px; }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--paper-deep); color: var(--ink-soft); font-size: .75rem; white-space: nowrap; }
.chip.ok { background: #dcefe3; color: #1d6a43; }

.matrix-wrap { overflow-x: auto; margin-top: 12px; }
.matrix { min-width: 100%; border-collapse: collapse; }
.matrix th, .matrix td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.matrix thead th { font-size: .85rem; color: var(--ink-soft); }
.matrix tbody th { text-align: left; }
.matrix .corner { text-align: left; font-weight: 400; font-size: .75rem; }
.matrix .self { color: var(--line); }
.matrix .last { font-size: .75rem; color: var(--mustard); font-weight: 600; }
.matrix input { width: 20px; height: 20px; accent-color: var(--berry); cursor: pointer; }

.wish-admin { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 12px; }
.wish-person { padding: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.wish-person .inline-form .btn { padding: 8px 16px; font-size: 1.2rem; line-height: 1; }

@media (max-width: 720px) {
  .persons { grid-template-columns: auto minmax(0, 1fr); }
  .person > :nth-child(n + 3) { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .bag.ready, .modal[open] form { animation: none; }
}
