/* Grundlook: dunkles Winterblau, warmes Rot und Gold, fürs iPhone optimiert */
:root {
  --bg: #0f1e33;
  --card: #1a2d4a;
  --red: #c8102e;
  --gold: #f2c14e;
  --text: #f4f6fa;
  --muted: #a9b6cc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 50% 0%, #1d3557 0%, var(--bg) 70%);
  color: var(--text);
  min-height: 100dvh;
  /* Platz für Notch und Home-Leiste am iPhone */
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  overflow-x: hidden;
}
main {
  position: relative; z-index: 1;
  max-width: 480px; margin: 0 auto; padding: 32px 0;
  text-align: center;
}
h1 { font-size: 2rem; margin: 16px 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; }
.card {
  background: var(--card); border-radius: 18px; padding: 20px;
  margin: 16px 0; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.countdown { display: flex; justify-content: center; gap: 12px; }
.countdown div { min-width: 64px; }
.countdown b { display: block; font-size: 1.8rem; color: var(--gold); }
.countdown span { font-size: .8rem; color: var(--muted); }
.emoji { font-size: 4rem; }
.hint { color: var(--muted); font-size: .9rem; }

/* Schneeflocken */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.flake {
  position: absolute; top: -10px; color: #fff; opacity: .8;
  animation: fall linear infinite;
}
@keyframes fall { to { transform: translateY(105vh) rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .flake { display: none; } }

/* ---------- Admin: Formulare, Listen, Knöpfe ---------- */
.admin { text-align: left; }
.admin h1, .admin > .emoji { text-align: center; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
form { display: grid; gap: 10px; margin-bottom: 8px; }
label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: end; }
.row > * { flex: 1; min-width: 0; }
.row > .arrow { flex: 0; align-self: center; color: var(--gold); }
/* 16px Schrift verhindert, dass das iPhone beim Antippen hineinzoomt */
input, select, button {
  font: inherit; font-size: 16px; border-radius: 12px; border: 1px solid #2d456b;
  padding: 12px; background: #0f1e33; color: var(--text); width: 100%; min-height: 46px;
}
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; }
button { background: var(--red); border: 0; font-weight: 600; cursor: pointer; }
button:active { transform: scale(.97); }
button.secondary { background: #2d456b; }
button.wide { margin: 8px 0 24px; }
button.icon { width: 44px; min-height: 44px; padding: 0; background: #24395c; font-size: 1.1rem; }
.badge { background: var(--gold); color: var(--bg); border-radius: 99px; padding: 1px 9px; font-size: .85rem; }
.list { list-style: none; padding: 0; margin: 12px 0 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid #2d456b; }
.list .info { flex: 1; min-width: 0; display: grid; }
.list .info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list small { color: var(--muted); }
.list .actions { display: flex; gap: 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #2a9d8f; color: #fff;
  width: max-content; max-width: 90vw; text-align: center;
  padding: 12px 18px; border-radius: 12px; z-index: 10; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.toast.error { background: var(--red); }
[hidden] { display: none !important; }

/* ---------- Ziehung ---------- */
.check { margin: 0 0 12px; }
.check.ok { color: #7bd389; }
.check.bad { color: #ff8a8a; }
button:disabled { opacity: .45; cursor: not-allowed; }
.locked { opacity: .45; pointer-events: none; }
.progress { height: 10px; background: #0f1e33; border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress div { height: 100%; width: 0; background: var(--gold); transition: width .6s; }

/* Fenster für den Notfall-Code */
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(5, 10, 20, .85);
  display: grid; place-items: center; padding: 16px;
}
.modal-box {
  background: var(--card); border-radius: 18px; padding: 24px; max-width: 420px; width: 100%;
  text-align: center; display: grid; gap: 12px;
}
.modal-box h2, .modal-box p { margin: 0; }
.code {
  /* Schrift passt sich der Bildschirmbreite an, damit der Code auf eine Zeile passt */
  font-family: ui-monospace, Menlo, monospace; font-size: clamp(.9rem, 4.4vw, 1.25rem);
  background: #0f1e33; border: 2px dashed var(--gold); border-radius: 12px; padding: 14px 6px;
  color: var(--gold); white-space: nowrap; user-select: all;
}
.checkline { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; text-align: left; }
.checkline input { width: 24px; min-height: 24px; height: 24px; }

/* Beim Drucken nur den Code-Zettel zeigen, schwarz auf weiß */
@media print {
  body { background: #fff; color: #000; padding: 0; }
  main, .snow, .toast, #code-print, #code-close, .checkline { display: none !important; }
  .modal { position: static; background: none; }
  .modal-box { background: none; box-shadow: none; color: #000; }
  .code { color: #000; border-color: #000; background: none; font-size: 1.6rem; }
}

/* ---------- Teilnehmer-Seite ---------- */
.card.left { text-align: left; }
textarea {
  font: inherit; font-size: 16px; width: 100%; border-radius: 12px; border: 1px solid #2d456b;
  padding: 12px; background: #0f1e33; color: var(--text); resize: vertical;
}
button.small { width: auto; min-height: 40px; padding: 8px 16px; font-size: 14px; justify-self: center; }
.tap-hint { color: var(--gold); font-weight: 600; margin: 24px 0 8px; }

/* Das Geschenk: Schachtel + Deckel mit Schleife, Bänder per Farbverlauf */
.gift {
  position: relative; width: 190px; height: 190px; margin: 10px auto 24px; display: block;
  background: none; border: 0; padding: 0; min-height: 0; cursor: pointer;
  animation: float 2.4s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}
.gift-box, .gift-lid {
  position: absolute; left: 50%; transform: translateX(-50%); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.gift-box {
  bottom: 0; width: 160px; height: 120px;
  background: linear-gradient(90deg, transparent 43%, var(--gold) 43% 57%, transparent 57%), var(--red);
}
.gift-lid {
  top: 34px; width: 184px; height: 40px; z-index: 2;
  background: linear-gradient(90deg, transparent 44%, #ffd76e 44% 56%, transparent 56%), #a50d26;
  transition: transform .55s cubic-bezier(.3,1.4,.6,1), opacity .55s;
}
.gift-bow { position: absolute; top: -42px; left: 50%; transform: translateX(-50%); font-size: 52px; line-height: 1; }
/* Licht, das aus der Schachtel kommt */
.gift::after {
  content: ''; position: absolute; left: 50%; top: 70px; width: 10px; height: 10px; border-radius: 50%;
  transform: translate(-50%, -50%); background: radial-gradient(circle, #fff6c8 0%, rgba(242,193,78,.6) 40%, transparent 70%);
  opacity: 0; transition: all .5s ease-out; pointer-events: none;
}
.gift.shake { animation: shake 1.2s ease-in-out; }
.gift.open { animation: none; }
.gift.open .gift-lid { transform: translate(-10%, -170px) rotate(28deg); opacity: 0; }
.gift.open::after { width: 320px; height: 320px; opacity: 1; }

@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes shake {
  0%, 100% { transform: rotate(0); }
  10%, 50% { transform: rotate(-7deg) scale(1.03); }
  30%, 70% { transform: rotate(7deg) scale(1.06); }
  85% { transform: rotate(-3deg) scale(1.1); }
}

/* Ergebnis-Karte */
.result { display: grid; gap: 8px; }
.result.pop { animation: pop .7s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.result .hint { margin: 0; }
.receiver { font-size: 2.3rem; font-weight: 800; color: var(--gold); margin: 0 0 8px; overflow-wrap: anywhere; }
.wishes { background: #0f1e33; border-radius: 12px; padding: 12px 14px; text-align: left; }
.wishes .label { margin: 0 0 6px; color: var(--muted); font-size: .9rem; }
.wish-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.wish-text.empty { color: var(--muted); font-style: italic; }
.opened { font-size: .8rem; color: var(--muted); margin: 4px 0; }

/* Konfetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 15; overflow: hidden; }
.confetti i {
  position: absolute; top: 35vh; width: 8px; height: 14px; border-radius: 2px;
  animation: confetti 2.4s cubic-bezier(.2,.7,.4,1) forwards;
}
@keyframes confetti {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; }
}

/* Link-Fenster im Admin */
.qr { width: 220px; height: 220px; margin: 0 auto; background: #fff; border-radius: 12px; padding: 8px; }
.link-url { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.warn { background: #4a2a12; color: #ffd8a8; border-radius: 10px; padding: 10px; font-size: .85rem; text-align: left; }

/* Protokoll und Notfall-Liste */
.list.log li { font-size: .85rem; color: var(--muted); display: block; }
.list.pairs { text-align: left; max-height: 50vh; overflow-y: auto; margin: 0; }
.list.pairs li { display: block; font-size: 1rem; }

/* Transparenz-Hinweis für Teilnehmer */
.notice { font-size: .85rem; border-radius: 12px; padding: 10px 12px; margin: 12px 0; text-align: left; }
.notice.ok { background: rgba(123, 211, 137, .12); color: #a8e6b3; }
.notice.warn { background: #4a2a12; color: #ffd8a8; }
.notice p { margin: 4px 0; }

/* Update-Karte */
.changelog {
  white-space: pre-wrap; font: inherit; font-size: .85rem; color: var(--muted);
  background: #0f1e33; border-radius: 12px; padding: 10px 12px; margin: 0 0 12px;
}
.changelog:empty { display: none; }
#up-info { white-space: pre-wrap; }
input[type="file"] { padding: 10px; }
#up-rollback { margin-top: 4px; }

/* Fairness-Test */
#sim-result { margin-top: 12px; }
.sim-row { border-top: 1px solid #2d456b; padding: 10px 0; }
.sim-row b { display: block; margin-bottom: 6px; }
.sim-line { display: grid; grid-template-columns: 5.5em 1fr auto; gap: 8px; align-items: center; font-size: .85rem; margin: 3px 0; }
.sim-line span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sim-bar { height: 8px; background: #0f1e33; border-radius: 99px; position: relative; overflow: hidden; }
.sim-bar::after { content: ''; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--gold); border-radius: 99px; }
.sim-val { color: var(--muted); white-space: nowrap; }

/* Fernzugriff */
.badge.off { background: #2d456b; color: var(--muted); }

/* Papier-Los: auf dem Bildschirm nie sichtbar, nur beim Drucken */
#paper-print { display: none; }
@media print {
  body.print-paper > *:not(#paper-print) { display: none !important; }
  body.print-paper #paper-print { display: block; color: #000; font-size: 14pt; }
  .paper-top { height: 120mm; text-align: center; }
  .paper-top h1 { font-size: 22pt; margin: 6mm 0 3mm; }
  .paper-emoji { font-size: 40pt; }
  .paper-steps { white-space: pre-line; text-align: left; display: inline-block; margin-top: 8mm; }
  .paper-fold { border-top: 2px dashed #000; padding-top: 2mm; text-align: center; font-size: 10pt; }
  .paper-bottom { padding-top: 25mm; text-align: center; }
  .paper-name { font-size: 32pt; font-weight: 800; margin: 4mm 0 8mm; }
  .paper-wishes { white-space: pre-wrap; text-align: left; margin: 0 15mm; }
}
