/* ==========================================================
   Wichteln – «Briefmarke auf Tannengrün»
   ========================================================== */

:root {
  --fir-950: #0b1c12;
  --fir-900: #102a1a;
  --fir-800: #173622;
  --fir-700: #21492e;
  --fir-400: #5d8a63;
  --red: #b3302a;
  --red-deep: #85211d;
  --red-ink: #9b2621;
  --gold: #c9a24a;
  --gold-soft: #e3c77e;
  --gold-deep: #9a7428;
  --cream: #f5ecd7;
  --cream-2: #ecdfc0;
  --paper-line: #d9c69b;
  --ink: #2b1f15;
  --ink-soft: #5c4a37;

  --display: 'Gloock', 'Times New Roman', serif;
  --script: 'Pinyon Script', cursive;
  --body: 'Spectral', Georgia, serif;
}

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

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

/* Auf grösseren Bildschirmen alles proportional grösser – nicht nur eine schmale Spalte */
@media (min-width: 700px) { html { font-size: 118.75%; } }
@media (min-width: 1100px) and (min-height: 760px) { html { font-size: 131.25%; } }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--cream);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.5;
  background-color: var(--fir-900);
  background-image:
    radial-gradient(120% 70% at 50% 0%, rgba(227, 199, 126, .10), transparent 60%),
    radial-gradient(90% 60% at 50% 110%, rgba(0, 0, 0, .45), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23c9a24a' stroke-opacity='.09' stroke-width='1'%3E%3Cpath d='M16 6v12M10 12h12M11.8 7.8l8.4 8.4M20.2 7.8l-8.4 8.4'/%3E%3Cpath d='M48 38l5 10h-10z M48 44l7 12H41z' /%3E%3C/g%3E%3C/svg%3E");
  overflow-x: hidden;
}

/* feines Papierkorn über allem */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: .16;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

#snow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 28.75rem;
  margin: 0 auto;
  padding: 1.75rem 16px 2.5rem;
}

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

.masthead {
  text-align: center;
  margin-bottom: 22px;
  animation: rise .9s cubic-bezier(.2, .7, .2, 1) both;
}
.masthead .script {
  font-family: var(--script);
  color: var(--gold-soft);
  font-size: 2.1rem;
  line-height: 1;
  margin: 0 3.5rem -6px 0;
  display: inline-block;
  transform: rotate(-4deg);
}
.masthead h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3.2rem, 17vw, 4.6rem);
  line-height: .95;
  letter-spacing: -.01em;
  margin: 0;
  color: var(--cream);
  text-shadow: 0 2px 0 var(--fir-950);
}
.masthead .year {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 0;
  color: var(--gold);
  font-family: var(--display);
  font-size: .9rem;
  letter-spacing: .32em;
  text-indent: .32em;
}
.masthead .year::before,
.masthead .year::after {
  content: '';
  height: 1px;
  width: 3.5rem;
  background: linear-gradient(90deg, transparent, var(--gold));
}
.masthead .year::after { transform: scaleX(-1); }
.masthead .year svg { width: 10px; height: 10px; fill: var(--gold); }

/* ---------- Briefmarke ---------- */

.stamp {
  --r: 7px;
  --s: 21px;
  position: relative;
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(140% 90% at 50% 0%, rgba(255, 255, 255, .55), transparent 55%),
    radial-gradient(100% 100% at 100% 100%, rgba(154, 116, 40, .12), transparent 60%);
  padding: calc(var(--r) + 14px);
  -webkit-mask:
    radial-gradient(circle at 50% 0, #0000 var(--r), #000 calc(var(--r) + .5px)) 0 0 / var(--s) var(--r) round no-repeat,
    radial-gradient(circle at 50% 100%, #0000 var(--r), #000 calc(var(--r) + .5px)) 0 100% / var(--s) var(--r) round no-repeat,
    radial-gradient(circle at 0 50%, #0000 var(--r), #000 calc(var(--r) + .5px)) 0 0 / var(--r) var(--s) no-repeat round,
    radial-gradient(circle at 100% 50%, #0000 var(--r), #000 calc(var(--r) + .5px)) 100% 0 / var(--r) var(--s) no-repeat round,
    linear-gradient(#000 0 0) 50% 50% / calc(100% - 2 * var(--r)) calc(100% - 2 * var(--r)) no-repeat;
  mask:
    radial-gradient(circle at 50% 0, #0000 var(--r), #000 calc(var(--r) + .5px)) 0 0 / var(--s) var(--r) round no-repeat,
    radial-gradient(circle at 50% 100%, #0000 var(--r), #000 calc(var(--r) + .5px)) 0 100% / var(--s) var(--r) round no-repeat,
    radial-gradient(circle at 0 50%, #0000 var(--r), #000 calc(var(--r) + .5px)) 0 0 / var(--r) var(--s) no-repeat round,
    radial-gradient(circle at 100% 50%, #0000 var(--r), #000 calc(var(--r) + .5px)) 100% 0 / var(--r) var(--s) no-repeat round,
    linear-gradient(#000 0 0) 50% 50% / calc(100% - 2 * var(--r)) calc(100% - 2 * var(--r)) no-repeat;
  animation: rise .9s .12s cubic-bezier(.2, .7, .2, 1) both;
}

.stamp-inner {
  position: relative;
  border: 1px solid var(--gold-deep);
  outline: 3px double var(--gold);
  outline-offset: 4px;
  padding: 26px 20px 24px;
  min-height: 300px;
}

/* Eckornamente */
.stamp-inner > .corner {
  position: absolute;
  width: 22px;
  height: 22px;
  fill: var(--red);
}
.corner.tl { top: 6px; left: 6px; }
.corner.tr { top: 6px; right: 6px; transform: scaleX(-1); }
.corner.bl { bottom: 6px; left: 6px; transform: scaleY(-1); }
.corner.br { bottom: 6px; right: 6px; transform: scale(-1, -1); }

/* Wertangabe wie bei einer Briefmarke */
.denomination {
  position: absolute;
  top: -1px;
  right: 34px;
  background: var(--red);
  color: var(--cream);
  font-family: var(--display);
  font-size: .78rem;
  letter-spacing: .14em;
  padding: 3px 9px 4px;
}

/* ---------- Typografie im Inneren ---------- */

.kicker {
  font-family: var(--script);
  color: var(--red);
  font-size: 1.9rem;
  line-height: 1.1;
  margin: 0;
}
.title {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.85rem;
  line-height: 1.1;
  margin: 2px 0 10px;
  color: var(--ink);
}
.lead {
  margin: 0 0 18px;
  color: var(--ink-soft);
}
.center { text-align: center; }

.rule {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gold-deep);
  margin: 18px 0;
}
.rule::before, .rule::after { content: ''; flex: 1; height: 1px; background: currentColor; opacity: .55; }
.rule svg { width: 12px; height: 12px; fill: currentColor; }

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

.field { display: block; margin: 0 0 18px; }
.field > span {
  display: block;
  font-family: var(--display);
  font-size: .78rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.input {
  width: 100%;
  font: inherit;
  font-size: 1.35rem;
  font-style: italic;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  padding: 6px 2px 5px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: #a8957a; }
.input:focus { border-bottom-color: var(--red); background: linear-gradient(transparent 70%, rgba(201, 162, 74, .18) 70%); }

.input.pin {
  font-family: var(--display);
  font-style: normal;
  font-size: 2.4rem;
  letter-spacing: .5em;
  text-indent: .5em;
  text-align: center;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 12px 18px;
  border: 0;
  border-radius: 0;
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: .06em;
  color: var(--cream);
  background: var(--red);
  cursor: pointer;
  box-shadow: inset 0 0 0 3px var(--red), inset 0 0 0 4px var(--gold-soft);
  transition: background .2s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--red-deep); box-shadow: inset 0 0 0 3px var(--red-deep), inset 0 0 0 4px var(--gold-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px dashed var(--red); outline-offset: 3px; }

.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}
.btn.ghost:hover { background: rgba(43, 31, 21, .06); }
.btn.green { background: var(--fir-700); box-shadow: inset 0 0 0 3px var(--fir-700), inset 0 0 0 4px var(--gold-soft); }
.btn.green:hover { background: var(--fir-800); }
.btn.small { min-height: 40px; width: auto; font-size: .95rem; padding: 8px 14px; }

.linkish {
  background: none;
  border: 0;
  padding: 4px 0;
  font: inherit;
  font-style: italic;
  color: var(--red-ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Namens-Etiketten zum Antippen */
.names {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 4px 0 20px;
  padding: 0;
  list-style: none;
}
.names button {
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  background: var(--cream-2);
  border: 0;
  padding: 4px 12px 5px 16px;
  cursor: pointer;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
  transition: background .15s, color .15s;
}
.names button:hover, .names button[aria-pressed='true'] { background: var(--fir-700); color: var(--cream); }
.names-label { font-size: .9rem; color: var(--ink-soft); font-style: italic; margin: 0 0 4px; }

/* Meldungen */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 16px;
  padding: 10px 12px;
  border-left: 3px solid var(--red);
  background: rgba(179, 48, 42, .07);
  color: var(--red-ink);
  font-style: italic;
}
.notice svg { flex: none; width: 18px; height: 18px; margin-top: 3px; fill: currentColor; }
.notice.info { border-left-color: var(--fir-700); color: var(--fir-700); background: rgba(33, 73, 46, .07); }
.notice[hidden] { display: none; }

.footnote {
  text-align: center;
  margin-top: 22px;
  color: rgba(245, 236, 215, .55);
  font-size: .85rem;
  font-style: italic;
}

/* ---------- Ansichten ---------- */

.view[hidden] { display: none !important; }
.view { animation: fade .45s ease both; }

/* ---------- Geschenk ---------- */

.gift-stage {
  position: relative;
  width: min(74vw, 17.5rem);
  aspect-ratio: 260 / 300;
  margin: 4px auto 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.gift-stage:focus-visible { outline: 2px dashed var(--red); outline-offset: 6px; }
.gift-stage > svg, .gift-stage > .tag {
  position: absolute;
}
.gift-stage > svg { inset: 0; width: 100%; height: 100%; overflow: visible; }

.gift-stage.idle > svg { animation: wiggle 3.6s ease-in-out infinite; transform-origin: 50% 95%; }

.gift-front .lid { transform-box: view-box; transform-origin: 130px 140px; }
.gift-front .bow { transform-box: view-box; transform-origin: 130px 118px; }

.gift-stage.opening .gift-front .bow {
  animation: untie .65s cubic-bezier(.5, 0, .75, 0) forwards;
}
.gift-stage.opening .gift-front .lid {
  animation: lidoff 1s .45s cubic-bezier(.3, .1, .3, 1) forwards;
}
.gift-stage.opening .tag {
  animation: tagrise 1.1s 1.05s cubic-bezier(.2, 1.3, .4, 1) forwards;
}
.gift-stage.opened .gift-front .bow,
.gift-stage.opened .gift-front .lid { opacity: 0; }
.gift-stage.opened .tag { transform: translateY(-108%) rotate(-2deg); }

.tag {
  left: 23%;
  width: 54%;
  top: 50%;
  height: 40%;
  transform: translateY(0);
  transform-origin: 50% 0;
  filter: drop-shadow(0 0 1px rgba(154, 116, 40, .9)) drop-shadow(0 6px 8px rgba(43, 31, 21, .22));
}
.tag-paper {
  position: absolute;
  inset: 0;
  background-color: #fbf3df;
  background-image:
    linear-gradient(90deg, var(--red) 0 5px, transparent 5px calc(100% - 5px), var(--red) calc(100% - 5px)),
    repeating-linear-gradient(0deg, transparent 0 13px, rgba(201, 162, 74, .28) 13px 14px);
  clip-path: polygon(18% 0, 82% 0, 100% 16%, 100% 100%, 0 100%, 0 16%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 14% 6% 0;
  text-align: center;
}
.tag-paper::before {
  /* Lochöse */
  content: '';
  position: absolute;
  top: 5%;
  left: 50%;
  width: 11px;
  height: 11px;
  margin-left: -5.5px;
  border-radius: 50%;
  background: var(--fir-800);
  box-shadow: 0 0 0 2px var(--gold);
}
.tag .tag-kicker {
  font-family: var(--script);
  color: var(--fir-700);
  font-size: clamp(1rem, 5vw, 1.35rem);
  line-height: 1;
  margin-top: 4px;
}
.tag .tag-name {
  font-family: var(--display);
  color: var(--red);
  font-size: clamp(1.4rem, 8vw, 2.1rem);
  line-height: 1.02;
  margin-top: 4px;
  word-break: break-word;
  hyphens: auto;
}

.sparkle {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 12px;
  height: 12px;
  pointer-events: none;
  fill: var(--gold);
  animation: sparkle 1.3s cubic-bezier(.15, .7, .3, 1) forwards;
}

.gift-hint {
  text-align: center;
  font-family: var(--script);
  color: var(--red);
  font-size: 1.7rem;
  margin: 0;
  animation: breathe 2.4s ease-in-out infinite;
}

.reveal-text { text-align: center; margin: 4px 0 0; }
.reveal-text .who {
  font-family: var(--display);
  font-size: 2.2rem;
  line-height: 1.05;
  color: var(--red);
  display: block;
  margin-top: 2px;
  word-break: break-word;
}
.reveal-after { opacity: 0; transform: translateY(10px); transition: opacity .6s, transform .6s; }
.reveal-after.show { opacity: 1; transform: none; }

/* PIN-Anzeige */
.pin-box {
  margin: 20px 0 6px;
  padding: 16px 14px 14px;
  background: var(--fir-800);
  color: var(--cream);
  text-align: center;
  box-shadow: inset 0 0 0 4px var(--fir-800), inset 0 0 0 5px var(--gold);
}
.pin-box .label {
  font-family: var(--display);
  font-size: .75rem;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--gold-soft);
}
.pin-box .digits {
  font-family: var(--display);
  font-size: 3rem;
  letter-spacing: .32em;
  text-indent: .32em;
  line-height: 1.1;
  margin: 4px 0;
  user-select: all;
}
.pin-box p { margin: 0 0 12px; font-size: .95rem; color: rgba(245, 236, 215, .85); }
.pin-box .btn.small { background: transparent; color: var(--gold-soft); box-shadow: inset 0 0 0 1px var(--gold); }

/* geschlossenes Geschenk (warten) */
.wait-gift { width: 8rem; display: block; margin: 0 auto 10px; }

/* ---------- Animationen ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes breathe { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

@keyframes wiggle {
  0%, 72%, 100% { transform: rotate(0); }
  76% { transform: rotate(-3.5deg); }
  80% { transform: rotate(3deg); }
  84% { transform: rotate(-2deg); }
  88% { transform: rotate(1deg); }
}
@keyframes untie {
  0% { transform: scale(1) rotate(0); opacity: 1; }
  30% { transform: scale(1.12) rotate(-6deg); opacity: 1; }
  100% { transform: scale(.1) rotate(40deg) translateY(-30px); opacity: 0; }
}
@keyframes lidoff {
  0% { transform: none; opacity: 1; }
  25% { transform: translateY(-26px) rotate(-4deg); opacity: 1; }
  100% { transform: translate(-190px, -120px) rotate(-38deg); opacity: 0; }
}
@keyframes tagrise {
  0% { transform: translateY(0) rotate(0); }
  70% { transform: translateY(-112%) rotate(3deg); }
  85% { transform: translateY(-106%) rotate(-3deg); }
  100% { transform: translateY(-108%) rotate(-2deg); }
}
@keyframes sparkle {
  0% { transform: translate(-50%, -50%) scale(.2) rotate(0); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(var(--sc)) rotate(var(--rot)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

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

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  padding: 0;
  color: var(--ink);
  background: var(--cream);
  border-radius: 0;
}
dialog::backdrop { background: rgba(11, 28, 18, .78); }
dialog .dlg {
  margin: 8px;
  padding: 20px 18px 18px;
  border: 1px solid var(--gold-deep);
  outline: 3px double var(--gold);
  outline-offset: 3px;
}
dialog h2 { font-family: var(--display); font-weight: 400; font-size: 1.6rem; margin: 0 0 8px; line-height: 1.1; }
dialog p { margin: 0 0 14px; color: var(--ink-soft); }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.dlg-actions .btn { min-height: 48px; font-size: 1rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ==========================================================
   Admin – «Wichtel-Werkstatt»
   ========================================================== */

.ledger { list-style: none; margin: 0 0 18px; padding: 0; border-top: 2px solid var(--ink); }
.ledger li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 0;
  border-bottom: 1px solid var(--paper-line);
}
.ledger .num {
  font-family: var(--display);
  color: var(--gold-deep);
  width: 1.6em;
  flex: none;
  font-size: .95rem;
}
.ledger .nm {
  flex: 1;
  min-width: 0;
  font-size: 1.15rem;
  font-style: italic;
  overflow-wrap: anywhere;
}
.ledger .nm input { font-size: 1.1rem; padding: 2px; }
.ledger .acts { display: flex; gap: 2px; flex: none; }
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--red); }
.icon-btn.ok:hover { color: var(--fir-700); }

.seal {
  flex: none;
  font-family: var(--display);
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  padding: 3px 8px;
  transform: rotate(-4deg);
}
.seal.done { color: var(--red); box-shadow: inset 0 0 0 1.5px var(--red); }
.seal.open { color: var(--ink-soft); box-shadow: inset 0 0 0 1px var(--paper-line); transform: none; }
.seal.locked { color: var(--cream); background: var(--red-deep); }

.add-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; }
.add-row .field { flex: 1; margin: 0; }
.add-row .btn { width: auto; min-height: 46px; padding: 8px 16px; }

.progress {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0 4px;
}
.progress svg { width: 22px; height: 22px; }

.status-line {
  font-family: var(--display);
  font-size: 1.05rem;
  margin: 0 0 4px;
}
.status-line strong { color: var(--red); font-weight: 400; }

.stack > * + * { margin-top: 10px; }

.share-url {
  display: block;
  font-family: var(--body);
  font-size: .95rem;
  word-break: break-all;
  background: var(--cream-2);
  padding: 8px 10px;
  margin: 0 0 10px;
  color: var(--ink);
}
.danger-zone { margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--paper-line); }
