:root {
  --paper: #f4f0e6;
  --card: #fbf8f1;
  --ink: #26332b;
  --muted: #6f7a6c;
  --line: #d9d2c1;
  --green: #3f5e4a;
  --green-dark: #2c4436;
  --sage: #9db39a;
  --sage-soft: #e4eadc;
  --clay: #b5683f;
  --clay-soft: #f1e3d6;
  --stone-soft: #ece7dc;
  --serif: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

/* Ramas dibujadas en las esquinas */
.decor {
  position: fixed;
  width: 220px;
  color: var(--sage);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}
.decor.left { left: -30px; bottom: -40px; }
.decor.right { right: -40px; top: -30px; transform: rotate(180deg); }
@media (max-width: 700px) { .decor { width: 130px; opacity: 0.35; } }

/* ---------- Jardín que crece ---------- */

.garden {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
/* Punto de donde nace la planta; se rota para que crezca hacia adentro */
.plant-anchor {
  position: absolute;
  width: 0;
  height: 0;
}
.plant {
  position: absolute;
  bottom: -6px;
  left: 0;
  width: auto;
  transform: translateX(-50%) scaleX(var(--flip, 1));
  transform-origin: 50% 100%;
  color: var(--sage);
  opacity: 0.9;
}
.plant.dark { color: var(--green); opacity: 0.6; }
.plant.new { animation: grow 1.6s cubic-bezier(.2, .8, .3, 1) both; animation-delay: var(--delay, 0s); }
@keyframes grow {
  from { transform: translateX(-50%) scaleX(var(--flip, 1)) scaleY(0); opacity: 0; }
}
/* Los pétalos se colorean con variables porque el CSS no entra a los <use>.
   Al abrir todas las puertas, florece. */
.garden.bloom .plant { --petal: #ecc3ab; --petal-line: var(--clay); --petal-center: var(--clay); }
.plant { height: calc(var(--h) * var(--garden-scale, 1)); }
@media (max-width: 700px) { .garden { --garden-scale: 0.7; } }

/* Un velo de papel detrás del título para que se lea aunque haya hojas */
header {
  position: relative;
  background: radial-gradient(ellipse at center, var(--paper) 45%, rgba(244, 240, 230, 0) 72%);
  padding: 1rem 0 1.4rem;
}
footer {
  background: radial-gradient(ellipse at center, var(--paper) 35%, rgba(244, 240, 230, 0) 70%);
  padding: 0.6rem 0;
}

.sim-banner {
  position: sticky;
  top: 0;
  z-index: 15;
  background: var(--ink);
  color: var(--paper);
  text-align: center;
  font-size: 0.88rem;
  padding: 0.55rem 16px;
}
.sim-banner a { color: var(--paper); }

.screen { position: relative; z-index: 1; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--clay); min-height: 1.2em; margin: 0.6rem 0 0; font-weight: 500; }

h1, h2 {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.overline {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 8px;
  padding: 0.75rem 1.3rem;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}
button:hover { background: var(--green-dark); }
button.link {
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0.4rem;
  font-weight: 500;
}

input {
  font: inherit;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(63, 94, 74, 0.15); }

form { display: flex; gap: 0.6rem; margin-top: 1.2rem; }

/* ---------- Login ---------- */

#login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2.2rem 2rem;
}

.login-card { width: min(400px, 100%); text-align: center; }
.login-card h1 { font-size: 2.2rem; }
.login-card form { flex-direction: column; }
.login-card .sprout { width: 56px; color: var(--green); margin-bottom: 0.8rem; }

/* ---------- Calendario ---------- */

#calendar { max-width: 1040px; margin: 0 auto; padding: 3rem 16px 3rem; }

header { text-align: center; margin-bottom: 2.4rem; }
header h1 { font-size: clamp(2.2rem, 6vw, 3.4rem); }
.subtitle { font-family: var(--serif); font-style: italic; font-size: 1.2rem; color: var(--muted); margin: 0.5rem 0 1.4rem; }

.stats { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.bar {
  width: min(280px, 100%);
  height: 3px;
  background: var(--line);
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 0;
  background: var(--green);
  transition: width 0.6s ease;
}
#next-unlock { font-size: 0.9rem; margin: 0.8rem 0 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-flow: dense;
  gap: 12px;
}
@media (max-width: 800px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 9px; } }

.door {
  position: relative;
  aspect-ratio: 1;
  perspective: 700px;
  cursor: pointer;
  border-radius: 10px;
}
@media (min-width: 521px) {
  .door.wide { grid-column: span 2; aspect-ratio: 2 / 1; }
}

/* La última puerta (el premio final) ocupa 2x2 */
.door.final { grid-column: span 2; grid-row: span 2; aspect-ratio: auto; }
@media (max-width: 520px) {
  .door.final { grid-column: span 3; grid-row: auto; aspect-ratio: 3 / 1.4; }
}
.door.final .num { font-size: clamp(2.6rem, 8vw, 4.2rem); }
.door.final .front { background: var(--sage-soft) !important; border: 1px solid var(--green); }
.door.final.locked .front { border-style: solid; border-color: var(--sage); }
.door.final.locked .num { color: var(--green); opacity: 0.55; }
.final-label {
  font-family: var(--serif);
  font-style: italic;
  color: var(--green);
  font-size: 1rem;
  margin-bottom: 0.3rem;
}
.door.final .inside { font-size: clamp(3rem, 9vw, 4.5rem); }

.door .inside,
.door .front {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
}

.door .inside {
  background: var(--sage-soft);
  border: 1px solid var(--line);
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  align-content: center;
  gap: 0.2rem;
}
.door .inside small {
  font-family: var(--serif);
  font-size: 0.8rem;
  color: var(--muted);
}

.door .front {
  transform-origin: left center;
  transition: transform 0.9s cubic-bezier(.3, .9, .4, 1), box-shadow 0.2s ease;
  backface-visibility: hidden;
  border: 1px solid var(--line);
  align-content: center;
}
.door .num {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.6rem, 4.5vw, 2.4rem);
  line-height: 1;
}
.door .tag {
  position: absolute;
  bottom: 9px;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.door .tag svg { width: 12px; height: 12px; }

/* tonos alternados, apagados */
.door.c0 .front { background: var(--card); }
.door.c1 .front { background: var(--sage-soft); }
.door.c2 .front { background: var(--clay-soft); }
.door.c3 .front { background: var(--stone-soft); }

.door.locked { cursor: not-allowed; }
.door.locked .front { background: var(--paper) !important; border-style: dashed; }
.door.locked .num { color: #a9ad9f; }

.door.open .front { border-color: var(--green); }
.door.open:hover .front { box-shadow: 0 6px 16px rgba(38, 51, 43, 0.12); }
.door.open .tag { color: var(--green); }
.door.open .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: 0.25; } }

.door.solved .front { transform: rotateY(-100deg); }

.door.shake { animation: shake 0.35s; }
@keyframes shake {
  25%, 75% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
}

footer { text-align: center; margin-top: 3rem; }
#signature { font-family: var(--serif); font-style: italic; }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(38, 51, 43, 0.45);
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal-card {
  position: relative;
  width: min(540px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2.2rem 1.8rem 1.8rem;
  text-align: center;
  box-shadow: 0 20px 50px rgba(38, 51, 43, 0.25);
  animation: rise 0.3s ease;
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.modal-card.shake { animation: shake 0.35s; }

.close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  background: transparent;
  color: var(--muted);
}
.close:hover { background: var(--stone-soft); }

.day-badge {
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.question { font-family: var(--serif); font-size: 1.4rem; line-height: 1.35; margin: 0.8rem 0 0; white-space: pre-wrap; }
.hint {
  margin: 1rem 0 0;
  padding: 0.7rem 1rem;
  background: var(--sage-soft);
  border-radius: 8px;
  font-size: 0.92rem;
  text-align: left;
}

.reward-emoji { font-size: 3.2rem; margin: 0.9rem 0 0.4rem; }
#r-title { font-size: 1.9rem; }
.reward-message { font-size: 1.05rem; line-height: 1.6; margin: 0.9rem 0 0; white-space: pre-wrap; }

.reward-media:empty { display: none; }
.reward-media { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1.2rem; }
.reward-media img,
.reward-media video { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 8px; }
.reward-media video { background: #000; }
.reward-media iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 8px; }

@media (max-width: 520px) {
  form { flex-direction: column; }
}

/* ---------- Aviso y hojas ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 120px);
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1.2rem;
  border-radius: 8px;
  font-size: 0.92rem;
  z-index: 20;
  transition: transform 0.3s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

.leaf {
  position: fixed;
  top: -30px;
  z-index: 30;
  width: 18px;
  color: var(--sage);
  pointer-events: none;
  animation: drift linear forwards;
}
@keyframes drift {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 0.9; }
  50% { transform: translate(40px, 55vh) rotate(160deg); }
  100% { transform: translate(-20px, 110vh) rotate(320deg); opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
