:root {
  /* Identidad SFL */
  --night: #000f2e;
  --night-2: #00183f;
  --panel: #012353;
  --orange: #f69338;
  --orange-2: #ffbc78;
  --orange-dark: #ec7426;
  /* Toques navideños */
  --red: #c8102e;
  --red-dark: #8e0b20;
  --green: #1f7a4d;
  --gold: #f2c14e;
  --snow: #f4f8ff;
  --paper: #fbf6ea;
  --paper-line: #d9e3f0;
  --ink: #23263a;
  --muted: #b9c7db;
  --radius: 14px;
  --font-title: 'Mountains of Christmas', 'Georgia', serif;
  --font-hand: 'Kalam', 'Comic Sans MS', cursive;
  --font-ui: 'Exo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

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

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--snow);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(246, 147, 56, .16), transparent 70%),
    radial-gradient(ellipse 60% 40% at 10% 30%, rgba(31, 122, 77, .14), transparent 70%),
    radial-gradient(ellipse 60% 40% at 90% 60%, rgba(200, 16, 46, .12), transparent 70%),
    linear-gradient(180deg, var(--night) 0%, var(--night-2) 55%, var(--panel) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

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

header, main, footer { position: relative; z-index: 1; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Luces ---------- */
.lights {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 0 12px;
  list-style: none;
  height: 44px;
  overflow: hidden;
}
.lights::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: -14px;
  height: 30px;
  border-bottom: 2px solid #1d2b1f;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.lights li {
  position: relative;
  top: 12px;
  width: 11px;
  height: 18px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 4px 18px 3px var(--c);
  animation: twinkle 2.4s ease-in-out infinite;
  animation-delay: var(--d);
}
.lights li::before {
  content: '';
  position: absolute;
  top: -5px; left: 2px;
  width: 7px; height: 6px;
  background: #2c3a2e;
  border-radius: 2px;
}
@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; box-shadow: 0 2px 6px 0 var(--c); }
}

/* ---------- Hero ---------- */
.hero {
  max-width: 820px;
  margin: 0 auto;
  padding: 48px 20px 40px;
  text-align: center;
}
.crest {
  position: relative;
  display: inline-block;
  width: 96px;
  animation: bob 5s ease-in-out infinite;
}
.crest img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 22px rgba(246, 147, 56, .55)) drop-shadow(0 8px 18px rgba(0, 0, 0, .5));
}
.santa-hat {
  position: absolute;
  top: -28px; right: -34px;
  width: 74px;
  transform: rotate(18deg);
  z-index: 1;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .4));
}
@keyframes bob { 50% { transform: rotate(3deg) translateY(-5px); } }

.eyebrow {
  margin: 22px 0 0;
  text-transform: uppercase;
  letter-spacing: .22em;
  font-size: .8rem;
  font-weight: 800;
  color: var(--orange);
}
h1 {
  margin: 6px 0 12px;
  font-family: var(--font-title);
  font-size: clamp(3rem, 10vw, 6rem);
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 26px rgba(246, 147, 56, .5), 0 4px 0 var(--orange-dark);
}
.lead {
  max-width: 620px;
  margin: 0 auto 12px;
  font-size: 1.12rem;
  line-height: 1.65;
  color: #d7e3f5;
}
.lead strong { color: var(--orange-2); }

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 28px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 22px;
  border-radius: 999px;
  border: 2px solid transparent;
  font: 600 1rem var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:focus-visible, .seal:focus-visible { outline: 3px solid var(--orange-2); outline-offset: 3px; }
.btn {
  text-transform: uppercase;
  letter-spacing: .04em;
  border-radius: 10px;
}
.btn-primary {
  background: var(--orange);
  color: var(--night);
  font-weight: 800;
  box-shadow: 0 8px 26px rgba(246, 147, 56, .45);
}
.btn-primary:hover { background: var(--orange-2); }
.btn-ghost {
  background: rgba(255, 255, 255, .06);
  border-color: rgba(255, 255, 255, .25);
  color: #fff;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .12); }

.counter {
  margin: 26px 0 0;
  color: var(--muted);
  font-size: .95rem;
}
.counter span {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--orange);
}

/* ---------- Formulario / carta ---------- */
.write {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 20px 70px;
}
.paper {
  position: relative;
  padding: 44px 44px 34px 72px;
  background:
    linear-gradient(90deg, transparent 52px, rgba(200, 16, 46, .45) 52px, rgba(200, 16, 46, .45) 54px, transparent 54px),
    repeating-linear-gradient(180deg, transparent 0 33px, var(--paper-line) 33px 34px),
    var(--paper);
  background-position: 0 0, 0 30px, 0 0;
  color: var(--ink);
  border-radius: 6px;
  box-shadow:
    0 1px 0 rgba(0, 0, 0, .05),
    0 30px 60px -20px rgba(0, 0, 0, .65),
    0 0 0 1px rgba(0, 0, 0, .04);
  transform: rotate(-.6deg);
  transition: transform .6s ease, opacity .6s ease;
}
.paper::after {
  /* cinta adhesiva */
  content: '';
  position: absolute;
  top: -14px; left: 50%;
  width: 130px; height: 30px;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(246, 147, 56, .6);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
}
.paper.sending { transform: rotate(-.6deg) scale(.6) translateY(80px); opacity: 0; }

.stamp {
  position: absolute;
  top: -22px; right: -16px;
  width: 78px;
  z-index: 1;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .3);
  padding: 6px 6px 4px;
  background: var(--green);
  border: 3px dotted var(--paper);
  outline: 2px solid var(--green);
  text-align: center;
  transform: rotate(5deg);
  color: #fff;
}
.stamp svg { display: block; width: 100%; height: auto; }
.stamp span {
  display: block;
  font-size: .58rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.salutation {
  margin: 0 0 4px;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.7rem;
  line-height: 34px;
}

textarea, .signature input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-hand);
  font-size: 1.25rem;
  line-height: 34px;
  resize: vertical;
}
textarea { min-height: 306px; padding: 0; }
textarea:focus, .signature input:focus { outline: none; }
textarea::placeholder, .signature input::placeholder { color: #9aa1b5; }

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
  font-size: .85rem;
}
.chars { color: #7a8196; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chars.over { color: var(--red); font-weight: 700; }
.hint { color: var(--red); font-weight: 600; font-size: .88rem; }

.signature {
  display: flex;
  align-items: baseline;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 18px;
  font-family: var(--font-hand);
  font-size: 1.3rem;
}
.signature input {
  width: min(280px, 60%);
  border-bottom: 2px dashed #b9c3d4;
  font-weight: 700;
}
.signature input:focus { border-bottom-color: var(--red); }
#name-error { display: block; text-align: right; min-height: 20px; }

.invalid { animation: shake .35s ease; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-top: 22px;
}
.rules {
  margin: 0;
  max-width: 400px;
  font-size: .82rem;
  line-height: 1.5;
  color: #5f667c;
}

.seal {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 22px 6px 6px;
  border: 0;
  border-radius: 999px;
  background: var(--night);
  color: #fff;
  font: 700 1rem var(--font-ui);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(11, 26, 46, .35);
  transition: transform .15s ease;
}
.seal:hover { transform: translateY(-2px) rotate(-1deg); }
.seal:disabled { opacity: .6; cursor: progress; transform: none; }
.seal-wax {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: 46% 54% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 35% 30%, #e43b55, var(--red) 55%, var(--red-dark));
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .15), inset 0 0 0 7px rgba(255, 255, 255, .12);
  font-size: .9rem;
  letter-spacing: .04em;
}

/* ---------- Animación del sobre ---------- */
/* Capas (de atrás a delante): fondo → carta → bolsillo (3 pliegues) → solapa → lacre */
.envelope-anim {
  --env-w: 260px;
  --env-h: 170px;
  position: absolute;
  left: 50%; top: 45%;
  width: var(--env-w); height: var(--env-h);
  margin-left: calc(var(--env-w) / -2);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, .45));
}
.env-back, .env-front, .env-flap, .env-letter { position: absolute; }

.env-back {
  inset: 0;
  z-index: 1;
  border-radius: 6px;
  background: linear-gradient(180deg, #b99c6b, #cdb48a);
}

.env-letter {
  z-index: 2;
  left: 14px; right: 14px; top: 10px;
  height: calc(var(--env-h) - 20px);
  border-radius: 3px;
  background:
    linear-gradient(90deg, transparent 18px, rgba(200, 16, 46, .4) 18px, rgba(200, 16, 46, .4) 19px, transparent 19px),
    repeating-linear-gradient(180deg, transparent 0 13px, #d9e3f0 13px 14px),
    var(--paper);
  transform: translateY(-115px);
}

.env-front {
  inset: 0;
  z-index: 3;
  border-radius: 6px;
  /* bolsillo: todo salvo la "V" superior por donde entra la carta */
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  background:
    linear-gradient(to top right, #ead7b2 49.5%, transparent 50%) left / 50% 100% no-repeat,
    linear-gradient(to top left, #e3cea6 49.5%, transparent 50%) right / 50% 100% no-repeat,
    #ead7b2;
}
.env-front::after {
  /* pliegue inferior */
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(0 100%, 50% 46%, 100% 100%);
  background: linear-gradient(0deg, #f4e7cc, #efdfc0);
}

.env-flap {
  left: 0; right: 0; top: 0;
  height: 100%;
  z-index: 0; /* abierta: detrás de la carta */
  clip-path: polygon(0 0, 100% 0, 50% 58%);
  background: linear-gradient(180deg, #dcc59b, #d2b989);
  transform-origin: top;
  transform: rotateX(180deg);
}

.env-wax {
  position: absolute;
  left: 50%; top: calc(var(--env-h) * .58 - 23px);
  width: 46px; height: 46px;
  margin-left: -23px;
  z-index: 5;
  display: grid; place-items: center;
  border-radius: 46% 54% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 35% 30%, #e43b55, var(--red) 55%, var(--red-dark));
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .15);
  font: 800 .75rem var(--font-ui);
  color: #fff;
  opacity: 0;
  transform: scale(2);
}

.envelope-anim.play { animation: env-in 2.8s ease forwards; }
.envelope-anim.play .env-letter { animation: letter-in .6s .3s ease-in forwards; }
.envelope-anim.play .env-flap { animation: flap-close .45s 1s ease-in-out forwards; }
.envelope-anim.play .env-wax { animation: wax-in .3s 1.5s cubic-bezier(.3, 1.6, .5, 1) forwards; }

@keyframes env-in {
  0% { opacity: 0; transform: translateY(30px) scale(.9); }
  10% { opacity: 1; transform: translateY(0) scale(1); }
  70% { opacity: 1; transform: translateY(0) rotate(0); }
  100% { opacity: 0; transform: translate(60vw, -90vh) rotate(25deg) scale(.4); }
}
@keyframes letter-in { to { transform: translateY(0); } }
@keyframes flap-close {
  0% { transform: rotateX(180deg); z-index: 0; }
  49% { z-index: 0; }
  50% { z-index: 4; }
  100% { transform: rotateX(0deg); z-index: 4; }
}
@keyframes wax-in { to { opacity: 1; transform: scale(1); } }

/* ---------- Muro de cartas ---------- */
.wall {
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 20px 60px;
}
.wall h2 {
  margin: 0;
  text-align: center;
  font-family: var(--font-title);
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  color: #fff;
  text-shadow: 0 0 20px rgba(246, 147, 56, .4);
}
.wall-sub { text-align: center; color: var(--muted); margin: 6px 0 36px; }

.letters {
  columns: 3 300px;
  column-gap: 26px;
}
.note {
  position: relative;
  break-inside: avoid;
  margin: 0 0 28px;
  padding: 30px 24px 18px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 4px;
  box-shadow: 0 16px 34px -16px rgba(0, 0, 0, .6);
  transform: rotate(var(--r, 0deg));
  transition: transform .2s ease;
}
.note:hover { transform: rotate(0deg) translateY(-3px); }
.note:nth-child(3n + 2) { background: #fff3f3; }
.note:nth-child(3n + 3) { background: #f1f8f2; }
.note.new { animation: drop-in .7s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes drop-in {
  from { opacity: 0; transform: translateY(-40px) rotate(-8deg) scale(.9); }
}
.pin {
  position: absolute;
  top: -9px; left: 50%;
  width: 20px; height: 20px;
  margin-left: -10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff6b81, var(--red) 60%, var(--red-dark));
  box-shadow: 0 3px 5px rgba(0, 0, 0, .35);
}
.note:nth-child(3n + 2) .pin { background: radial-gradient(circle at 35% 30%, #6fe0a5, var(--green) 60%, #0f4d2f); }
.note:nth-child(3n + 3) .pin { background: radial-gradient(circle at 35% 30%, var(--orange-2), var(--orange) 60%, var(--orange-dark)); }

.note-hello {
  margin: 0 0 6px;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.15rem;
}
.note-body {
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1.08rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.note-body.clamped {
  max-height: 13.5em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent);
  mask-image: linear-gradient(180deg, #000 70%, transparent);
}
.note-more {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--red);
  font: 600 .9rem var(--font-ui);
  cursor: pointer;
}
.note-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed #cdd3df;
}
.note-name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--red-dark);
  overflow-wrap: anywhere;
}
.note-name::before { content: '— '; }
.note-date { font-size: .78rem; color: #7a8196; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); font-size: 1.1rem; }
.more-wrap { text-align: center; margin-top: 10px; }

/* ---------- Pie ---------- */
.foot-logo {
  display: block;
  margin: 0 auto 10px;
  opacity: .9;
}
.foot {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  padding-bottom: 24px;
}
.ground {
  position: relative;
  height: 90px;
  margin-bottom: 18px;
  background:
    radial-gradient(ellipse 30% 60px at 15% 100%, #fff 98%, transparent),
    radial-gradient(ellipse 35% 70px at 55% 100%, #f2f6ff 98%, transparent),
    radial-gradient(ellipse 30% 55px at 90% 100%, #fff 98%, transparent);
  overflow: hidden;
}
.car {
  position: absolute;
  bottom: 22px;
  left: -160px;
  width: 120px;
  animation: drive 14s linear infinite;
}
.car svg { display: block; width: 100%; }
.boost {
  position: absolute;
  left: -46px; top: 26px;
  width: 54px; height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--gold), #fff);
  filter: blur(1px);
  animation: flicker .12s infinite alternate;
}
@keyframes drive {
  0% { left: -160px; }
  60%, 100% { left: calc(100% + 60px); }
}
@keyframes flicker { to { opacity: .55; transform: scaleX(.8); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  z-index: 10;
  max-width: min(92vw, 480px);
  padding: 14px 20px;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
  transform: translate(-50%, calc(100% + 60px));
  visibility: hidden;
  transition: transform .35s ease, visibility 0s .35s;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; transition: transform .35s ease; }
.toast.error { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .paper { padding: 44px 20px 26px 40px; }
  .paper { background:
      linear-gradient(90deg, transparent 26px, rgba(200, 16, 46, .45) 26px, rgba(200, 16, 46, .45) 28px, transparent 28px),
      repeating-linear-gradient(180deg, transparent 0 33px, var(--paper-line) 33px 34px),
      var(--paper); }
  .stamp { width: 60px; top: -18px; right: -6px; }
  .form-footer { flex-direction: column; align-items: stretch; }
  .seal { justify-content: center; }
  .signature { flex-wrap: wrap; }
  .signature input { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
  #snow { display: none; }
}

/* Hashtags en las cartas */
.note-body .hashtag {
  font-weight: 700;
  color: var(--orange-dark);
}

/* Buzón cerrado (se activa desde /admin) */
.closed-notice {
  max-width: 560px;
  margin: 0 auto;
  padding: 40px 32px 34px;
  text-align: center;
  color: var(--ink);
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .65);
  transform: rotate(-.6deg);
}
.closed-icon { font-size: 3.2rem; line-height: 1; }
.closed-notice h2 {
  margin: 14px 0 8px;
  font-family: var(--font-title);
  font-size: 2.4rem;
  color: var(--red-dark);
}
.closed-notice p {
  margin: 0 auto 22px;
  max-width: 400px;
  font-family: var(--font-hand);
  font-size: 1.2rem;
  line-height: 1.5;
}
.closed-notice .btn-ghost {
  color: var(--night);
  border-color: rgba(0, 15, 46, .25);
  background: rgba(0, 15, 46, .05);
}
