:root {
  --bg: #f4efe6;
  --bg-soft: #faf8f2;
  --panel: #ece4d5;
  --ink: #38352c;
  --muted: #8c8473;
  --accent: #9a8c72;
  --line: #cdc1a8;
  --gold: #b59a6a;
  --ok: #6f7d5a;
  --err: #b06a5a;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

#app { width: 100%; max-width: 620px; }

.boot { text-align: center; font-size: 40px; color: var(--line); }

/* --- tipografia / utilidades ------------------------------------------- */
.eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent);
}
.display {
  font-size: clamp(34px, 8vw, 52px);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: 0.01em;
}
.display em { font-style: italic; color: var(--accent); }
.lead { font-size: 20px; line-height: 1.6; color: var(--ink); }
.muted { color: var(--muted); }
.center { text-align: center; }

/* --- card base --------------------------------------------------------- */
.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 40px 36px;
  box-shadow: 0 24px 60px -40px rgba(56, 53, 44, 0.55);
  animation: rise 0.6s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.rule {
  height: 1px;
  background: var(--line);
  margin: 26px 0;
}
.sprig {
  display: block;
  margin: 0 auto;
  width: 46px;
  color: var(--accent);
}

/* --- formularios / botones -------------------------------------------- */
input[type="text"] {
  width: 100%;
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--accent); }
input.code-input {
  text-align: center;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.btn {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg-soft);
  padding: 14px 26px;
  border-radius: 3px;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
}
.btn:hover { opacity: 0.86; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn-link {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.field-msg {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.04em;
  margin-top: 12px;
  min-height: 16px;
}
.field-msg.err { color: var(--err); }
.field-msg.ok { color: var(--ok); }

.shake { animation: shake 0.4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-7px); }
  40%,80% { transform: translateX(7px); }
}

/* --- cuenta atras ------------------------------------------------------ */
.countdown {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 8px 0 4px;
}
.cd-unit { text-align: center; min-width: 64px; }
.cd-num {
  font-size: 52px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.cd-lab {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 8px;
}

.story p { font-size: 18px; line-height: 1.7; margin-bottom: 10px; }
.story p:first-child { font-style: italic; color: var(--accent); }

/* --- tablero de puzzles ----------------------------------------------- */
.progress-bar {
  display: flex;
  gap: 6px;
  margin: 4px 0 28px;
}
.progress-bar span {
  flex: 1;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}
.progress-bar span.done { background: var(--gold); }

.puzzle-list { display: flex; flex-direction: column; gap: 12px; }
.puzzle-row {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 16px 18px;
  cursor: pointer;
  font-family: var(--serif);
  color: var(--ink);
  transition: border-color 0.2s, background 0.2s;
}
.puzzle-row.current { border-color: var(--accent); }
.puzzle-row.current:hover { background: var(--panel); }
.puzzle-row.solved { background: var(--panel); cursor: default; }
.puzzle-row.locked {
  cursor: default;
  opacity: 0.55;
  background: var(--bg);
  border-style: dashed;
}
.puzzle-row.locked .puzzle-seal {
  border-color: var(--line);
  color: var(--line);
}
.puzzle-seal {
  width: 38px;
  height: 38px;
  flex: none;
  border: 1px solid var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-style: italic;
  color: var(--accent);
}
.puzzle-row.solved .puzzle-seal {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--bg-soft);
  font-style: normal;
}
.puzzle-meta { flex: 1; min-width: 0; }
.puzzle-meta .t { font-size: 20px; }
.puzzle-meta .s {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.puzzle-frag {
  font-size: 24px;
  font-style: italic;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.puzzle-frag.hidden { color: var(--line); font-style: normal; }

/* --- enunciado del puzzle --------------------------------------------- */
.puzzle-body {
  font-size: 21px;
  line-height: 1.6;
  margin: 8px 0 24px;
}
.puzzle-body em { color: var(--accent); }

/* fondo difuminado (enigmas con imagen) */
.puzzle-card { position: relative; overflow: hidden; }
.puzzle-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: blur(22px) saturate(1.15);
  opacity: 0.42;
  transform: scale(1.18);
}
.puzzle-content { position: relative; z-index: 1; }
.puzzle-body small { font-size: 15px; color: var(--muted); }
.hint {
  font-style: italic;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
  border-left: 2px solid var(--line);
  padding-left: 14px;
  margin-top: 14px;
}

/* --- clave final ------------------------------------------------------- */
.key-slots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 6px;
  flex-wrap: wrap;
}
.key-slot {
  min-width: 44px;
  height: 56px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  background: var(--bg);
  padding: 0 8px;
}
.key-slot.filled { border-bottom-color: var(--gold); color: var(--ink); }

/* --- recompensa -------------------------------------------------------- */
.reward-img {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
}
.chest {
  font-size: 64px;
  text-align: center;
  animation: glow 2.4s ease-in-out infinite;
}
@keyframes glow {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
.reveal { animation: reveal 1.1s ease both; }
@keyframes reveal {
  from { opacity: 0; transform: scale(0.94); filter: blur(6px); }
  to { opacity: 1; transform: scale(1); filter: blur(0); }
}

.stack > * + * { margin-top: 14px; }
.row-2 { display: flex; gap: 10px; }
.row-2 > * { flex: 1; }

@media (max-width: 480px) {
  body { padding: 14px; }
  .card { padding: 30px 22px; }
  .countdown { gap: 10px; }
  .cd-unit { min-width: 54px; }
  .cd-num { font-size: 40px; }
}

/* ======================================================================= */
/*  ENIGMA 3 · foto visible + varias preguntas                             */
/* ======================================================================= */
.puzzle-foto {
  display: block;
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--line);
  margin: 4px 0 22px;
  box-shadow: 0 16px 36px -26px rgba(56, 53, 44, 0.7);
  animation: fotoIn 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes fotoIn {
  from { opacity: 0; transform: scale(0.92) rotate(-1.5deg); filter: blur(8px); }
  to { opacity: 1; transform: scale(1) rotate(0); filter: blur(0); }
}
.qfields { display: flex; flex-direction: column; gap: 16px; }
.qfield { display: flex; flex-direction: column; gap: 7px; }
.qlabel {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ======================================================================= */
/*  ENIGMA 4 · corazones flotantes                                         */
/* ======================================================================= */
.hearts {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.hearts span {
  position: absolute;
  bottom: -42px;
  color: #cf8d8d;
  animation-name: floatUp;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}
@keyframes floatUp {
  0% { transform: translateY(0) rotate(-10deg) scale(0.7); }
  18% { transform: translateY(-16vh) rotate(8deg) scale(1); }
  100% { transform: translateY(-135vh) rotate(26deg) scale(1); }
}

/* ======================================================================= */
/*  PULIDO Y ANIMACIONES                                                   */
/* ======================================================================= */

/* fondo con un poco de profundidad */
body {
  background:
    radial-gradient(120% 80% at 50% 0%, #fbf9f3 0%, var(--bg) 55%, #ece4d4 100%);
  background-attachment: fixed;
}

/* entrada de pantalla mas suave */
.card {
  animation: cardIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: box-shadow 0.4s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* botones: elevacion + barrido de luz */
.btn {
  position: relative;
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.25s ease, opacity 0.2s ease;
  box-shadow: 0 6px 16px -10px rgba(56, 53, 44, 0.9);
}
.btn::after {
  content: "";
  position: absolute;
  top: 0;
  left: -130%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    100deg,
    transparent,
    rgba(255, 255, 255, 0.28),
    transparent
  );
  transform: skewX(-18deg);
}
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 22px -12px rgba(56, 53, 44, 0.95);
}
.btn:hover:not(:disabled)::after { animation: shine 0.7s ease; }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.99); }
@keyframes shine {
  to { left: 130%; }
}
.btn-link { transition: color 0.2s ease, letter-spacing 0.2s ease; }
.btn-link:hover { color: var(--ink); letter-spacing: 0.19em; }

/* inputs: foco con brillo dorado */
input[type="text"] {
  transition: border-color 0.2s ease, box-shadow 0.25s ease, background 0.2s ease;
}
input[type="text"]:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(181, 154, 106, 0.16);
  background: var(--bg-soft);
}

/* tablero: filas entran escalonadas */
.puzzle-list .puzzle-row {
  animation: rowIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: border-color 0.2s ease, background 0.2s ease,
    transform 0.18s ease, box-shadow 0.25s ease;
}
.puzzle-list .puzzle-row:nth-child(1) { animation-delay: 0.05s; }
.puzzle-list .puzzle-row:nth-child(2) { animation-delay: 0.12s; }
.puzzle-list .puzzle-row:nth-child(3) { animation-delay: 0.19s; }
.puzzle-list .puzzle-row:nth-child(4) { animation-delay: 0.26s; }
.puzzle-list .puzzle-row:nth-child(5) { animation-delay: 0.33s; }
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: translateX(0); }
}
.puzzle-row.current:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -16px rgba(56, 53, 44, 0.8);
}
.puzzle-row .puzzle-seal { transition: transform 0.25s ease, background 0.2s ease; }
.puzzle-row.current:hover .puzzle-seal { transform: rotate(-8deg) scale(1.08); }
.puzzle-row.solved .puzzle-seal { animation: sealPop 0.45s ease both; }
@keyframes sealPop {
  0% { transform: scale(0); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* barra de progreso: las piezas hechas crecen */
.progress-bar span { transition: background 0.4s ease; }
.progress-bar span.done { animation: barFill 0.5s ease both; }
@keyframes barFill {
  from { transform: scaleX(0.2); opacity: 0.4; }
  to { transform: scaleX(1); opacity: 1; }
}

/* cuenta atras: los segundos laten */
.cd-num { transition: transform 0.2s ease; }
.countdown .cd-unit:last-child .cd-num { animation: tick 1s ease-in-out infinite; }
@keyframes tick {
  0%, 70%, 100% { transform: scale(1); }
  82% { transform: scale(1.13); }
}

/* ramita: vaiven suave */
.sprig { animation: sway 5s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

/* pieza de clave revelada: sello que cae */
.key-slot.filled { animation: stamp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes stamp {
  0% { opacity: 0; transform: scale(1.8) rotate(-12deg); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* cofre final */
.chest-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 130px;
}
.chest-rays {
  position: absolute;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(181, 154, 106, 0.4), transparent 62%);
  animation: rays 2.8s ease-in-out infinite;
}
@keyframes rays {
  0%, 100% { transform: scale(0.85); opacity: 0.55; }
  50% { transform: scale(1.15); opacity: 1; }
}
.chest {
  position: relative;
  animation: glow 2.4s ease-in-out infinite, chestIn 0.9s ease both;
}
@keyframes chestIn {
  from { opacity: 0; transform: scale(0.4) rotate(-20deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

/* destello al abrir el cofre */
.flash {
  position: fixed;
  inset: 0;
  background: #fffdf7;
  z-index: 9999;
  pointer-events: none;
  animation: flashOut 0.7s ease forwards;
}
@keyframes flashOut {
  0% { opacity: 0.92; }
  100% { opacity: 0; }
}

/* ======================================================================= */
/*  EL VALE EN 3D                                                          */
/* ======================================================================= */
.vale-stage {
  width: 100%;
  perspective: 1250px;
  padding: 20px 6px 8px;
}
.vale-card {
  position: relative;
  transform-style: preserve-3d;
  border-radius: 7px;
  overflow: hidden;
  will-change: transform;
  box-shadow:
    0 32px 64px -28px rgba(56, 53, 44, 0.72),
    0 10px 24px -14px rgba(56, 53, 44, 0.55);
  animation: valeIn 1s ease both;
}
@keyframes valeIn {
  from { opacity: 0; filter: blur(12px); }
  to { opacity: 1; filter: blur(0); }
}
/* el vale, dibujado con HTML/CSS · escala con container queries */
.vale {
  container-type: inline-size;
  width: 100%;
  display: flex;
  background: #faf8f2;
  color: #3a372f;
  font-family: var(--serif);
}
.vale .sprig { animation: none; }
.vale-side {
  width: 19%;
  flex: none;
  background: #ece5d7;
  border-right: 1px solid #d8cdb7;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4.5cqi 0;
}
.vale-num-label {
  font-family: var(--sans);
  font-size: 2cqi;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #a89c87;
}
.vale-num { font-size: 11cqi; font-style: italic; line-height: 1; margin-top: 0.5cqi; }
.vale-side .sprig { width: 9cqi; margin: 4cqi 0; color: #a89c87; }
.vale-vert {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-style: italic;
  font-size: 3cqi;
  letter-spacing: 0.24em;
  color: #8c8473;
  margin-top: auto;
}
.vale-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4.5cqi;
  padding: 5cqi 5.5cqi;
}
.vale-head { display: flex; gap: 4cqi; }
.vale-head-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7cqi;
  border-bottom: 1px solid #cdc1a8;
  padding-bottom: 1.4cqi;
}
.vale-right { text-align: right; }
.vale-k {
  font-family: var(--sans);
  font-size: 1.7cqi;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #a89c87;
}
.vale-v { font-size: 3.7cqi; font-style: italic; }
.vale-concepto-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.6cqi;
  padding: 1cqi 0;
}
.vale-concepto { font-size: 8.6cqi; line-height: 1.08; font-weight: 500; }
.vale-concepto i { font-style: italic; font-weight: 400; color: #9a8c72; }
.vale-sub { font-size: 2.7cqi; font-style: italic; color: #8c8473; }
.vale-foot {
  display: flex;
  gap: 3cqi;
  border-top: 1px solid #cdc1a8;
  padding-top: 2.4cqi;
}
.vale-foot-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7cqi;
}
.vale-foot-col + .vale-foot-col {
  border-left: 1px solid #e0d6c0;
  padding-left: 3cqi;
}
.vale-fv { font-size: 2.5cqi; font-style: italic; line-height: 1.3; }
.vale-holo {
  position: absolute;
  top: 0;
  left: -50%;
  width: 200%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(
    105deg,
    transparent 38%,
    rgba(255, 255, 255, 0.62) 48%,
    rgba(255, 248, 230, 0.28) 54%,
    transparent 64%
  );
}
.vale-edge {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 7px;
  box-shadow:
    inset 0 0 0 1px rgba(181, 154, 106, 0.55),
    inset 0 0 34px -10px rgba(255, 255, 255, 0.6);
}

/* respeta a quien prefiere menos movimiento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
