:root {
  --night-0: #070a24;
  --night-1: #0c1138;
  --night-2: #18205c;
  --gold: #d9b15a;
  --gold-light: #f4dd98;
  --gold-dark: #9c7428;
  --turq: #39c2b4;
  --turq-dark: #1d6f72;
  --parchment: #f5e7c6;
  --ink: #3b2914;
  --text: #ece6f5;
  --muted: #a9acd2;
  --f-deco: 'Cinzel Decorative', serif;
  --f-head: 'Marcellus', serif;
  --f-poem: 'Cormorant Garamond', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--f-head);
  background:
    radial-gradient(120% 60% at 50% 0%, #243088 0%, transparent 60%),
    radial-gradient(80% 50% at 85% 100%, rgba(57, 194, 180, .14) 0%, transparent 70%),
    linear-gradient(180deg, var(--night-1) 0%, var(--night-0) 100%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Cielo estrellado ---------- */
#sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.star {
  position: absolute; border-radius: 50%; background: #fff8de;
  animation: twinkle var(--d, 3s) ease-in-out var(--delay, 0s) infinite;
}
.star.big { box-shadow: 0 0 6px 1px rgba(244, 221, 152, .7); }
@keyframes twinkle { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }

.view { position: relative; z-index: 1; }

/* ---------- Tipografía común ---------- */
.eyebrow {
  margin: 0; font-family: var(--f-head); letter-spacing: .28em; text-transform: uppercase;
  font-size: .72rem; color: var(--turq);
}
.title {
  margin: .2rem 0 0; font-family: var(--f-deco); font-weight: 700;
  font-size: clamp(2.3rem, 11vw, 3.4rem); line-height: 1.05;
  background: linear-gradient(180deg, var(--gold-light) 10%, var(--gold) 55%, var(--gold-dark) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 12px rgba(217, 177, 90, .25));
}
.subtitle { margin: .7rem auto 0; max-width: 22rem; color: var(--muted); font-family: var(--f-poem); font-size: 1.15rem; line-height: 1.4; }

/* Media luna */
.crescent {
  width: 46px; height: 46px; margin: 0 auto .6rem; border-radius: 50%;
  box-shadow: 11px -7px 0 0 var(--gold-light);
  transform: translateX(-6px) rotate(-10deg);
  filter: drop-shadow(0 0 10px rgba(244, 221, 152, .55));
}

.divider { display: flex; align-items: center; gap: .6rem; justify-content: center; margin: 1rem 0; color: var(--gold); }
.divider span { height: 1px; width: 60px; background: linear-gradient(90deg, transparent, var(--gold)); }
.divider span:last-child { transform: scaleX(-1); }
.divider svg { width: 14px; height: 14px; }

/* ---------- Botones ---------- */
.btn-gold {
  border: 0; border-radius: 999px; padding: .75rem 1.5rem;
  color: #2a1b05; font-family: var(--f-head); font-size: 1rem; letter-spacing: .04em;
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 60%, #b58b37);
  box-shadow: 0 4px 18px rgba(217, 177, 90, .3), inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .15s, filter .15s;
}
.btn-gold:active { transform: scale(.96); }
.btn-gold:disabled { filter: grayscale(.6) brightness(.8); }

/* ---------- Login ---------- */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1.25rem; }
.login-card {
  width: 100%; max-width: 380px; text-align: center; padding: 2.2rem 1.5rem 1.6rem;
  border: 1px solid rgba(217, 177, 90, .45); border-radius: 180px 180px 18px 18px;
  background: linear-gradient(180deg, rgba(27, 35, 99, .75), rgba(12, 17, 56, .85));
  box-shadow: 0 0 0 6px rgba(12, 17, 56, .6), 0 0 0 7px rgba(57, 194, 180, .25), 0 20px 60px rgba(0,0,0,.5);
}
.login-text { font-family: var(--f-poem); font-size: 1.2rem; line-height: 1.45; margin: 0 0 1.2rem; }
#login-form { display: flex; flex-direction: column; gap: .8rem; }
#login-form input {
  padding: .8rem 1rem; border-radius: 12px; border: 1px solid rgba(217, 177, 90, .5);
  background: rgba(7, 10, 36, .7); color: var(--text); font: 1.1rem var(--f-poem); text-align: center;
  outline: none;
}
#login-form input:focus { border-color: var(--turq); box-shadow: 0 0 0 3px rgba(57, 194, 180, .2); }
.login-error { min-height: 1.3em; margin: .7rem 0 0; color: #f3a3a3; font-family: var(--f-poem); font-size: 1.05rem; }
.hint { margin: .3rem 0 0; color: var(--muted); font-size: .8rem; letter-spacing: .03em; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- Home ---------- */
#home { max-width: 760px; margin: 0 auto; padding: calc(2rem + env(safe-area-inset-top)) 1.1rem 0; }
.hero { text-align: center; }

.progress { margin: 1.5rem auto 0; max-width: 320px; }
.progress-track {
  height: 10px; border-radius: 99px; overflow: hidden;
  background: rgba(7, 10, 36, .8); border: 1px solid rgba(217, 177, 90, .35);
}
.progress-bar {
  height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--turq), var(--gold-light));
  box-shadow: 0 0 12px rgba(57, 194, 180, .6);
  transition: width 1s cubic-bezier(.2,.8,.2,1);
}
.progress-label { margin: .5rem 0 0; font-size: .9rem; color: var(--gold-light); letter-spacing: .06em; }

.grid {
  list-style: none; padding: 0; margin: 2rem 0 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem .7rem;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 1.4rem 1rem; } }
@media (max-width: 340px) { .grid { grid-template-columns: repeat(2, 1fr); } }

.card {
  position: relative; display: block; width: 100%; aspect-ratio: 100 / 130; padding: 0;
  border: 0; background: none; color: inherit;
  transition: transform .2s;
  animation: rise .6s backwards; animation-delay: calc(var(--i) * 40ms);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.card:active { transform: scale(.95); }
.card > svg.frame { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.card { --a-fill: #151c56; --a-stroke: #d9b15a; --a-inner: rgba(57, 194, 180, .5); }

.card-body {
  position: absolute; inset: 22% 8% 8%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
}
.card-icon { width: 22px; height: 22px; color: var(--gold-light); display: grid; place-items: center; font-size: 1.25rem; line-height: 1; }
.card-icon svg { width: 100%; height: 100%; }
.card-day { font-family: var(--f-deco); font-size: 1.75rem; color: var(--gold-light); line-height: 1.1; margin-top: .2rem; }
.card-month { font-size: .66rem; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); }

/* Bloqueada */
.card.locked { --a-fill: rgba(12, 17, 56, .75); --a-stroke: rgba(217, 177, 90, .35); --a-inner: rgba(57, 194, 180, .15); }
.card.locked .card-day { color: rgba(244, 221, 152, .45); }
.card.locked .card-icon { color: rgba(169, 172, 210, .55); width: 18px; height: 18px; }

/* Disponible para abrir */
.card.ready > svg.frame { filter: drop-shadow(0 0 10px rgba(244, 221, 152, .55)); animation: glow 2.4s ease-in-out infinite; }
.card.ready .card-icon { color: var(--gold-light); animation: spin 12s linear infinite; }
.card.ready .card-month { color: var(--turq); }
@keyframes glow { 50% { filter: drop-shadow(0 0 18px rgba(244, 221, 152, .85)); } }
@keyframes spin { to { transform: rotate(360deg); } }
.badge {
  position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  padding: .15rem .55rem; border-radius: 99px; white-space: nowrap;
  font-size: .62rem; letter-spacing: .12em; text-transform: uppercase;
  background: var(--turq); color: var(--night-1);
}

/* Abierta */
.card.opened { --a-fill: #13465a; --a-stroke: #f4dd98; --a-inner: rgba(244, 221, 152, .45); }
.card.opened .card-icon { width: auto; height: auto; font-size: 1.3rem; }

.skyline { margin-top: 2.5rem; position: relative; text-align: center; }
.skyline svg { display: block; width: 100%; height: 70px; }
.skyline p {
  margin: 0; padding: .6rem 0 calc(4.5rem + env(safe-area-inset-bottom)); background: var(--night-0);
  font-size: .75rem; letter-spacing: .12em; color: rgba(169, 172, 210, .6);
}

/* ---------- Overlay de una noche ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(100% 60% at 50% 0%, rgba(36, 48, 136, .97), rgba(7, 10, 36, .98) 70%);
  animation: fade .35s;
}
@keyframes fade { from { opacity: 0; } }
.overlay-inner { max-width: 520px; margin: 0 auto; padding: calc(1rem + env(safe-area-inset-top)) 1.1rem calc(3rem + env(safe-area-inset-bottom)); text-align: center; }
.close {
  display: block; margin: 0 0 1rem; padding: .4rem .2rem; border: 0; background: none;
  color: var(--gold-light); font-size: 1rem; letter-spacing: .05em;
}
.night-title { margin: .25rem 0 1.4rem; font-family: var(--f-deco); font-weight: 400; font-size: 1.6rem; color: var(--gold-light); }

/* Pergamino */
.scroll { position: relative; margin: 0 auto; width: 100%; max-width: 420px; }
.rod {
  position: relative; z-index: 2; height: 18px; margin: 0 -6px; border-radius: 9px;
  background: linear-gradient(180deg, #8a5a2b, #5a3615 55%, #3c220c);
  box-shadow: 0 3px 8px rgba(0,0,0,.5);
}
.rod::before, .rod::after {
  content: ''; position: absolute; top: -4px; width: 16px; height: 26px; border-radius: 6px;
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 50%, var(--gold-dark));
}
.rod::before { left: -10px; }
.rod::after { right: -10px; }

.paper {
  position: relative; overflow: hidden; max-height: 0; margin: -4px 0;
  background:
    radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(156, 116, 40, .28) 100%),
    linear-gradient(180deg, #efdcb0, var(--parchment) 15%, var(--parchment) 85%, #efdcb0);
  box-shadow: inset 0 0 30px rgba(120, 80, 20, .25);
}
.scroll.open .paper { animation: unroll 1.5s cubic-bezier(.45, .05, .25, 1) forwards; }
.scroll.instant .paper { animation-duration: .5s; }
@keyframes unroll { from { max-height: 0; } to { max-height: 900px; } }

.paper-inner {
  margin: 14px; padding: 1.4rem 1rem; border: 1px solid rgba(156, 116, 40, .5);
  outline: 1px solid rgba(156, 116, 40, .25); outline-offset: 4px;
}
.paper-ornament { color: var(--gold-dark); font-size: 1.5rem; line-height: 1; opacity: .8; }
.paper-ornament.flip { transform: rotate(180deg); }

.poem {
  margin: 1rem 0; color: var(--ink); font-family: var(--f-poem); font-weight: 500;
  font-size: clamp(1.25rem, 5.2vw, 1.45rem); line-height: 1.5;
}
.poem .line { display: block; min-height: 1.5em; text-wrap: balance; opacity: 0; transform: translateY(6px); }
.scroll.open .poem .line { animation: line-in .7s forwards; animation-delay: calc(1.1s + var(--i) * .22s); }
.scroll.instant .poem .line { animation-delay: calc(.3s + var(--i) * .05s); }
@keyframes line-in { to { opacity: 1; transform: none; } }

.finale-line {
  margin: 1.5rem 0 0; font-family: var(--f-poem); font-style: italic; font-size: 1.25rem; line-height: 1.5;
  color: var(--gold-light); opacity: 0; animation: line-in 1.2s 3.4s forwards;
}

/* Reacciones y comentario */
.after { margin-top: 1.8rem; opacity: 0; animation: line-in .8s forwards; animation-delay: var(--after-delay, 2.4s); text-align: left; }
.after-label { display: block; margin: 0 0 .55rem; font-size: .78rem; letter-spacing: .18em; text-transform: uppercase; color: var(--turq); text-align: center; }
.reactions { display: flex; justify-content: center; gap: .7rem; margin-bottom: 1.4rem; }
.reactions button {
  width: 56px; height: 56px; border-radius: 50%; font-size: 1.6rem;
  background: rgba(7, 10, 36, .6); border: 1px solid rgba(217, 177, 90, .35);
  transition: transform .2s, background .2s, box-shadow .2s;
}
.reactions button[aria-checked="true"] {
  background: rgba(57, 194, 180, .2); border-color: var(--gold-light);
  box-shadow: 0 0 16px rgba(244, 221, 152, .5); transform: scale(1.12);
}
#comment {
  width: 100%; resize: vertical; padding: .8rem 1rem; border-radius: 14px;
  border: 1px solid rgba(217, 177, 90, .4); background: rgba(7, 10, 36, .6);
  color: var(--text); font: 1.1rem/1.45 var(--f-poem); outline: none;
}
#comment:focus { border-color: var(--turq); box-shadow: 0 0 0 3px rgba(57, 194, 180, .2); }
.save-row { display: flex; align-items: center; justify-content: flex-end; gap: 1rem; margin-top: .9rem; }
.save-status { color: var(--gold-light); font-size: .9rem; }

/* ---------- Modo admin ---------- */
.admin-panel {
  margin: 1.6rem auto 0; max-width: 520px; padding: 1rem 1.1rem; text-align: left;
  border: 1px dashed rgba(57, 194, 180, .6); border-radius: 16px; background: rgba(7, 10, 36, .6);
}
.admin-badge { margin: 0; color: var(--turq); font-size: .85rem; letter-spacing: .1em; text-transform: uppercase; text-align: center; }
.admin-note { margin: .4rem 0 0; color: var(--muted); font-family: var(--f-poem); font-size: 1.05rem; text-align: center; }
.admin-title { margin: 1rem 0 .5rem; font: 400 1.1rem var(--f-head); color: var(--gold-light); letter-spacing: .05em; }
.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.activity li { padding: .55rem .7rem; border-radius: 10px; background: rgba(27, 35, 99, .55); font-size: .9rem; line-height: 1.35; }
.activity .when { color: var(--muted); font-size: .78rem; }
.activity .comment { display: block; margin-top: .2rem; font-family: var(--f-poem); font-size: 1.08rem; color: var(--text); white-space: pre-line; }
.activity .empty { color: var(--muted); font-family: var(--f-poem); font-size: 1.05rem; background: none; padding: 0; }
.ro-info { margin: 1.4rem 0 0; color: var(--turq); font-size: .9rem; letter-spacing: .04em; }
.is-admin .reactions button { cursor: default; }
.is-admin #save { display: none; }
.logout { margin-top: .6rem; border: 0; background: none; color: rgba(169, 172, 210, .6); text-decoration: underline; font-size: .75rem; letter-spacing: .1em; }

/* ---------- Confeti / estrellas ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 2rem); padding: .75rem 1.2rem; border-radius: 14px;
  background: rgba(12, 17, 56, .95); border: 1px solid rgba(217, 177, 90, .5);
  font-family: var(--f-poem); font-size: 1.1rem; text-align: center; color: var(--gold-light);
  transition: opacity .3s, transform .3s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Barra de modo prueba ---------- */
.devbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .6rem calc(.5rem + env(safe-area-inset-bottom));
  background: rgba(60, 20, 20, .92); border-top: 1px dashed #f3a3a3;
  font: 12px system-ui, sans-serif; color: #ffd9d9;
}
.devbar input, .devbar button {
  font: 12px system-ui, sans-serif; padding: .3rem .5rem; border-radius: 6px;
  border: 1px solid #f3a3a3; background: #2a0f0f; color: #ffd9d9;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition: none !important; }
  .paper { max-height: none; }
}
