:root {
  --bg1: #0b1d3a;
  --bg2: #16325c;
  --bg3: #3a1030;
  --card: rgba(255, 255, 255, 0.94);
  --ink: #1d2433;
  --muted: #64708a;
  --red: #d7263d;
  --red-dark: #a3172b;
  --green: #1b9e5a;
  --gold: #f4c95d;
  --line: #e4e7ef;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(5, 12, 30, 0.35);
  color-scheme: light;
}
body[data-theme="nieve"] { --bg1: #0f3b5a; --bg2: #2b7aa8; --bg3: #b8e3f5; --red: #1f6fb2; --red-dark: #154f80; }
body[data-theme="fiesta"] { --bg1: #2b0f4a; --bg2: #7a1fa2; --bg3: #ff6f61; --red: #e2336b; --red-dark: #a81d4c; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: #0b1d3a; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 700px at 80% -10%, var(--bg3), transparent 60%),
              linear-gradient(160deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  overflow-x: hidden;
}
#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.wrap { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; }
.narrow { max-width: 560px; }

h1, h2, .brand { font-family: 'Fraunces', Georgia, serif; letter-spacing: -.5px; font-weight: 700; }
h1 { font-size: clamp(2.4rem, 7vw, 4.2rem); line-height: 1.05; margin: .2em 0; color: #fff; text-shadow: 0 4px 24px rgba(0,0,0,.35); }
h2 { font-size: 1.9rem; margin: 0 0 .4em; color: var(--red-dark); }
h3 { margin: 0 0 .4em; }
a { color: var(--red); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 18px; color: #fff; }
.brand { font-size: 1.9rem; color: #fff; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 1.5em; height: 1.5em; margin: -.2em 0; filter: drop-shadow(0 2px 6px rgba(0,0,0,.35)); }
.brand b { color: var(--gold); font-weight: inherit; }
.topbar .who { font-size: .95rem; opacity: .9; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.hero { text-align: center; color: #fff; padding: 30px 0 10px; }
.hero p.lead { font-size: 1.2rem; max-width: 620px; margin: 0 auto 22px; opacity: .92; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 28px 0; }
.feature { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: var(--radius); padding: 16px; color: #fff; }
.feature .ico { font-size: 1.8rem; }
.feature b { display: block; margin: 6px 0 2px; }
.feature span { opacity: .85; font-size: .95rem; }

.card { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px; position: relative; }
.card.festive { border-top: 6px solid var(--red); }
.card.festive::before { content: ''; position: absolute; top: -6px; left: 0; right: 0; height: 6px; border-radius: var(--radius) var(--radius) 0 0;
  background: repeating-linear-gradient(90deg, var(--red) 0 22px, #fff 22px 30px, var(--green) 30px 52px, #fff 52px 60px); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }

label { display: block; font-weight: 700; font-size: .92rem; margin: 12px 0 6px; }
input, textarea, select {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 18%, transparent); }
textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row > .auto { flex: 0 0 auto; }
.hint { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer; font: inherit; font-weight: 800;
  padding: 12px 20px; border-radius: 999px; background: var(--red); color: #fff; text-decoration: none;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--red) 40%, transparent); transition: transform .12s, background .15s, box-shadow .15s;
}
.btn:hover { background: var(--red-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.btn.big { font-size: 1.15rem; padding: 16px 28px; }
.btn.green { background: var(--green); box-shadow: 0 6px 16px rgba(27,158,90,.35); }
.btn.green:hover { background: #157a46; }
.btn.gold { background: var(--gold); color: #4a3400; box-shadow: 0 6px 16px rgba(244,201,93,.45); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; border: 2px solid var(--line); }
.btn.ghost:hover { background: #f4f6fb; }
.btn.light { background: rgba(255,255,255,.16); color: #fff; box-shadow: none; border: 1px solid rgba(255,255,255,.35); }
.btn.light:hover { background: rgba(255,255,255,.28); }
.btn.small { padding: 7px 12px; font-size: .88rem; }
.btn.danger { background: transparent; color: var(--red-dark); box-shadow: none; border: 2px solid #f3c6cc; }
.btn.danger:hover { background: #fdeef0; }
.btn.wa { background: #25d366; box-shadow: none; }
.btn.wa:hover { background: #1da851; }
.btn.full { width: 100%; }

.tabs { display: flex; gap: 6px; background: #eef1f7; padding: 5px; border-radius: 999px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; font: inherit; font-weight: 800; padding: 9px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 800; padding: 4px 10px; border-radius: 999px; background: #eef1f7; color: var(--muted); }
.pill.ok { background: #e3f6ec; color: #157a46; }
.pill.warn { background: #fff4d6; color: #8a6200; }
.pill.red { background: #fde7ea; color: var(--red-dark); }

.event-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.event-meta .pill { background: rgba(255,255,255,.18); color: #fff; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #fff; flex: 0 0 38px; font-size: .95rem; }
.grow { flex: 1; min-width: 120px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.event-card { display: block; text-decoration: none; color: inherit; transition: transform .15s; }
.event-card:hover { transform: translateY(-3px); }
.event-card h3 { font-size: 1.25rem; }
.progress { height: 8px; border-radius: 99px; background: #eef1f7; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); border-radius: 99px; }

.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .ico { font-size: 3rem; }

/* Lista de deseos */
.wish { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.wish input { flex: 1; }
.wish-view { list-style: none; padding: 0; margin: 0; }
.wish-view li { padding: 10px 12px; border-radius: 12px; background: #f7f8fc; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; }
.wish-view li::before { content: '🎁'; }

/* Chat anónimo */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; padding: 10px; background: #f7f8fc; border-radius: 14px; margin-bottom: 10px; }
.bubble { max-width: 80%; padding: 9px 13px; border-radius: 16px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); white-space: pre-wrap; word-break: break-word; }
.bubble.mine { align-self: flex-end; background: var(--red); color: #fff; border-bottom-right-radius: 4px; }
.bubble:not(.mine) { border-bottom-left-radius: 4px; }
.bubble small { display: block; opacity: .7; font-size: .72rem; margin-top: 3px; }

/* PIN */
.pin-input { font-size: 2rem; letter-spacing: .5em; text-align: center; font-weight: 900; }

/* Revelación: caja de regalo */
.reveal-stage { min-height: 420px; display: grid; place-items: center; text-align: center; color: #fff; padding: 20px 0; }
.gift { position: relative; width: 200px; height: 200px; margin: 30px auto 10px; cursor: pointer; animation: wobble 2.4s ease-in-out infinite; will-change: transform; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.gift:focus-visible { outline: 4px solid var(--gold); outline-offset: 10px; border-radius: 12px; }
.gift .box { position: absolute; bottom: 0; left: 10px; width: 180px; height: 130px; background: linear-gradient(135deg, var(--red), var(--red-dark)); border-radius: 8px; box-shadow: inset 0 -12px 0 rgba(0,0,0,.12), 0 20px 40px rgba(0,0,0,.35); }
.gift .box::before { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 28px; transform: translateX(-50%); background: var(--gold); }
.gift .lid { will-change: transform; position: absolute; top: 40px; left: 0; width: 200px; height: 44px; background: linear-gradient(135deg, var(--red), var(--red-dark)); border-radius: 8px; z-index: 2; box-shadow: 0 6px 0 rgba(0,0,0,.12); transition: transform .9s cubic-bezier(.2,1.4,.4,1), opacity .9s; }
.gift .lid::before { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 28px; transform: translateX(-50%); background: var(--gold); }
.gift .bow { position: absolute; top: -34px; left: 50%; width: 90px; height: 40px; transform: translateX(-50%); }
.gift .bow::before, .gift .bow::after { content: ''; position: absolute; top: 4px; width: 42px; height: 34px; border: 9px solid var(--gold); border-radius: 50% 50% 0 50%; }
.gift .bow::before { left: 0; transform: rotate(-20deg); }
.gift .bow::after { right: 0; transform: scaleX(-1) rotate(-20deg); }
.gift.open { animation: none; cursor: default; }
.gift.open .lid { transform: translate(60px, -180px) rotate(40deg); opacity: 0; }
.gift.shake { animation: shake .3s ease-in-out 2; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg) scale(1.02); } 75% { transform: rotate(3deg) scale(1.02); } }
@keyframes shake { 0%,100% { transform: translateX(0) rotate(0); } 20% { transform: translateX(-10px) rotate(-6deg); } 40% { transform: translateX(10px) rotate(6deg); } 60% { transform: translateX(-8px) rotate(-4deg); } 80% { transform: translateX(8px) rotate(4deg); } }

.reveal-name { font-family: 'Fraunces', Georgia, serif; font-style: italic; font-size: clamp(2.8rem, 11vw, 5.5rem); color: var(--gold); text-shadow: 0 6px 30px rgba(0,0,0,.4); margin: 0; opacity: 0; transform: scale(.3) translateY(40px); }
.reveal-name.show { animation: pop 1s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes pop { to { opacity: 1; transform: scale(1) translateY(0); } }
.fade-in { animation: fadeIn .6s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.spoiler { filter: blur(7px); user-select: none; transition: filter .3s; }
.results-table { width: 100%; border-collapse: collapse; }
.results-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); }

/* Toast y diálogos */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: #1d2433; color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 700; z-index: 100; transition: transform .3s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red-dark); }
dialog { border: 0; border-radius: var(--radius); padding: 22px; max-width: 460px; width: calc(100% - 32px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 12, 30, .6); backdrop-filter: blur(3px); }
.checks label { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 8px 0; }
.checks input { width: auto; }

.switch { display: flex; align-items: center; gap: 10px; font-weight: 700; margin: 10px 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--red); }

.lights { display: flex; justify-content: center; gap: 22px; margin: 0 0 6px; }
.lights i { width: 12px; height: 18px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; animation: blink 1.6s infinite; }
.lights i:nth-child(4n+1) { background: #ff4d5e; }
.lights i:nth-child(4n+2) { background: #ffd34d; animation-delay: .4s; }
.lights i:nth-child(4n+3) { background: #4dd38a; animation-delay: .8s; }
.lights i:nth-child(4n+4) { background: #4db8ff; animation-delay: 1.2s; }
@keyframes blink { 0%, 100% { opacity: 1; box-shadow: 0 0 14px currentColor; } 50% { opacity: .35; } }

footer.foot { text-align: center; color: rgba(255,255,255,.7); font-size: .85rem; margin-top: 30px; }

@media (max-width: 560px) {
  .card { padding: 18px; }
  .list li { align-items: flex-start; }
  .wish { flex-wrap: wrap; }
  .wish .w-text { flex: 1 1 100%; }
  .wish .w-link { max-width: none !important; }
  .gift { transform: scale(.85); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- ajustes de formularios y móviles ---------- */
/* Safari en iPhone: quita el estilo nativo (sombra interior, esquinas, alto distinto),
   y 16px como mínimo para que no haga zoom al tocar un campo. */
input:not([type=checkbox]):not([type=radio]), textarea, select {
  -webkit-appearance: none; appearance: none; font-size: max(16px, 1rem); line-height: 1.35; min-height: 48px; margin: 0;
}
textarea { min-height: 80px; }
select {
  padding-right: 36px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364708a' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
}
/* La fecha en iOS se centra, ignora el ancho y se encoge si está vacía */
input[type=date] { display: block; min-width: 0; text-align: left; }
input[type=date]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type=date]::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pin-input { min-height: 60px; }
.checks input, .switch input { flex: none; }
.switch { align-items: flex-start; line-height: 1.35; }
.switch input { margin-top: 1px; }
/* Mismo ritmo vertical dentro y fuera de las cuadrículas de los formularios */
form .grid2, dialog .grid2 { row-gap: 0; column-gap: 16px; align-items: start; }
.row > div > label:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn, .actions .btn, .tabs button { white-space: nowrap; }
.topbar .brand { flex: none; }
.topbar .who { min-width: 0; }
body { min-height: 100dvh; }
dialog { max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; }

@media (max-width: 560px) {
  .wrap { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .brand { font-size: 1.55rem; }
  .topbar .who { font-size: .85rem; gap: 6px; }
  .topbar .who > span { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn.big { font-size: 1.05rem; padding: 14px 22px; }
  /* Botones de enviar y cancelar: uno encima del otro, a todo lo ancho */
  .row:has(> .btn.big) { flex-direction: column-reverse; align-items: stretch; }
  .row:has(> .btn.big) > .btn { width: 100%; }
  /* Acciones del sorteo: una por renglón, mismo ancho */
  .card > .actions:has(> .btn.small:nth-child(3)) { flex-direction: column; align-items: stretch; }
  /* Lista de deseos: cada idea separada de la siguiente */
  .wish { padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .wish .w-link { flex: 1 1 0; }
  dialog { padding: 18px; }
  dialog .row[style*="flex-end"] > .btn { flex: 1 1 auto; }
}

/* ---------- buscar por correo ---------- */
.lookup-result:empty { display: none; }
.lookup-card { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 12px; border-radius: 14px; background: #f5f7fc; border: 1px solid var(--line); flex-wrap: wrap; }

/* ---------- sorteo en vivo ---------- */
.draw-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(5, 12, 30, .78); animation: fadeIn .25s ease; }
.draw-box { width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); text-align: center; }
.draw-box h2 { margin: 0 0 12px; }
.draw-reel { height: 86px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, var(--red, #d62839), #8f1024); color: #fff; font-family: 'Fraunces', serif; font-size: clamp(1.6rem, 6vw, 2.2rem); font-weight: 800; overflow: hidden; }
.draw-status { font-weight: 700; margin: 12px 0; }
.draw-list { list-style: none; padding: 0; margin: 0 0 16px; text-align: left; }
.draw-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); opacity: .45; transition: opacity .3s; }
.draw-list li.on { opacity: 1; }
.draw-dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; flex: none; transition: background .3s; }
.draw-list li.on .draw-dot { background: #1f8a4c; box-shadow: 0 0 8px #1f8a4c; }
.draw-state { font-size: .85rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .draw-overlay { animation: none; } }

/* ---- App instalable (PWA) */
.install-bar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90;
  display: flex; align-items: center; gap: 12px; width: min(460px, calc(100% - 32px)); box-sizing: border-box;
  padding: 10px 10px 10px 12px; border-radius: 20px; color: #fff;
  background: rgba(11, 29, 58, .88); border: 1px solid rgba(255,255,255,.18); box-shadow: var(--shadow);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); animation: install-in .4s ease-out;
}
.install-bar img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.install-text b { font-size: .95rem; }
.install-text span { font-size: .82rem; opacity: .75; }
.install-bar .btn { flex: none; }
.install-close { flex: none; border: 0; background: transparent; color: #fff; opacity: .6; font-size: 1.4rem; line-height: 1; padding: 4px 6px; cursor: pointer; }
.install-close:hover { opacity: 1; }
.install-help ol { padding-left: 20px; line-height: 1.7; margin: 8px 0 0; }
.ios-share { display: inline-block; padding: 0 6px; border: 1.5px solid currentColor; border-radius: 6px; font-size: .85em; }
@keyframes install-in { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }
