/* Enigmate: noche azul, sol de mayo y celeste de bandera. */
:root {
  --bg: #0D1D38;
  --bg-glow: rgba(246, 180, 14, .13);
  --surface: #152B4F;
  --surface-2: #1B3560;
  --line: #2A4878;
  --text: #F1F5FB;
  --muted: #9DB1CC;
  --celeste: #74ACDF;
  --sol: #F6B40E;
  --sol-hover: #FFC93A;
  --sol-ink: #231800;
  --ok: #3FC27B;
  --bad: #F0705F;
  --mark: rgba(246, 180, 14, .35);
  --tile: #1E3E6E;
  --tile-alt: #234677;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, .7);
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #EAF2FA;
  --bg-glow: rgba(246, 180, 14, .22);
  --surface: #FFFFFF;
  --surface-2: #F3F7FC;
  --line: #C8D7E8;
  --text: #10264A;
  --muted: #536884;
  --celeste: #3E86C6;
  --sol: #F6B40E;
  --sol-hover: #E5A500;
  --sol-ink: #231800;
  --ok: #23955A;
  --bad: #CC3B2B;
  --mark: rgba(246, 180, 14, .5);
  --tile: #74ACDF;
  --tile-alt: #67A2D8;
  --shadow: 0 18px 36px -24px rgba(16, 38, 74, .55);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }

body {
  background:
    radial-gradient(60rem 30rem at 50% -8rem, var(--bg-glow), transparent 70%),
    var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--sol); outline-offset: 3px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Encabezado ---------- */
.top { border-bottom: 1px solid var(--line); }
.top-inner {
  max-width: 720px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font: 800 1.45rem/1 var(--display); letter-spacing: -0.02em;
}
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; color: var(--text);
  transition: border-color .15s, color .15s;
}
.icon-btn:hover { border-color: var(--sol); color: var(--sol); }
.icon-btn .dot { fill: currentColor; }

/* ---------- Juego ---------- */
.game {
  max-width: 720px; width: 100%; margin: 0 auto; padding: 26px 16px 36px;
  flex: 1; text-align: center;
}

.level-head { margin-bottom: 22px; }
.level-line {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 0; font: 800 1rem/1 var(--display); color: var(--sol); letter-spacing: .06em;
}
.level-line::before, .level-line::after {
  content: ""; width: 44px; height: 2px; border-radius: 2px; background: var(--sol); opacity: .55;
}
.level-date { margin: 8px 0 10px; color: var(--muted); font-size: .95rem; }
.level-date #countdown-top:not(:empty)::before { content: " · "; }
.level-date strong { color: var(--text); font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; padding: 3px 12px; border-radius: 999px;
  font: 700 .8rem/1.4 var(--display); letter-spacing: .03em;
  border: 1.5px solid currentColor;
}
.badge[data-level="fácil"] { color: var(--ok); }
.badge[data-level="media"] { color: var(--sol); }
.badge[data-level="difícil"] { color: var(--bad); }

/* ---------- Postal ---------- */
.postcard {
  max-width: 520px; margin: 0 auto 26px;
  background: var(--surface); padding: 10px 10px 8px; border-radius: 6px;
  box-shadow: var(--shadow);
  transform: rotate(-1deg);
}
.photo-wrap { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--tile); border-radius: 3px; }
.photo-wrap img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  /* Borrosa según la dificultad hasta que se usa la ayuda o se termina el nivel.
     El zoom leve evita que el desenfoque deje los bordes transparentes. */
  filter: blur(calc(var(--blur, 0) * 1cqw)); transform: scale(var(--zoom, 1));
  transition: filter .6s ease, transform .6s ease;
}
/* El desenfoque se mide en % del ancho de la foto, así se ve igual en celular y en compu
   (en una foto de 500 px: 4, 8 y 14 px). */
.photo-wrap { container-type: inline-size; }
.postcard[data-blur="fácil"] { --blur: 0.8; --zoom: 1.05; }
.postcard[data-blur="media"] { --blur: 1.6; --zoom: 1.08; }
.postcard[data-blur="difícil"] { --blur: 2.8; --zoom: 1.1; }
.credit { font-size: .76rem; color: var(--muted); padding: 8px 2px 0; text-align: left; line-height: 1.35; }
.credit a { color: inherit; }

.postcard.no-photo .photo-wrap::after {
  content: "No se pudo cargar la foto. Igual podés jugar con la pista.";
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 78%; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); color: var(--text); font-weight: 700;
}

.stamp {
  position: absolute; right: 14px; bottom: 14px;
  width: 116px; height: 116px; border-radius: 50%;
  border: 4px double currentColor; color: var(--ok);
  background: rgba(255, 255, 255, .9);
  display: grid; place-content: center; text-align: center;
  font: 800 1rem/1.05 var(--display); letter-spacing: .02em;
  transform: rotate(-14deg);
  animation: stamp .55s cubic-bezier(.2, 1.4, .4, 1) both;
}
:root:not([data-theme="light"]) .stamp { color: #1E8A51; }
.stamp.fail, :root:not([data-theme="light"]) .stamp.fail { color: #C23A2A; }
.stamp small { display: block; font-weight: 500; font-size: .74rem; margin-top: 4px; }
@keyframes stamp {
  from { transform: rotate(-32deg) scale(2.3); opacity: 0; }
  to { transform: rotate(-14deg) scale(1); opacity: 1; }
}

/* ---------- Pista ---------- */
.clue {
  max-width: 560px; margin: 0 auto 22px;
  font: 700 clamp(1.6rem, 5.4vw, 2.2rem)/1.22 var(--display);
  letter-spacing: -0.015em; text-wrap: balance;
}
.clue .len { color: var(--celeste); font-weight: 500; font-size: .7em; white-space: nowrap; vertical-align: .1em; }
.clue mark {
  background: linear-gradient(transparent 58%, var(--mark) 58%);
  color: inherit; padding: 0 2px; border-radius: 2px;
}

/* ---------- Casilleros ---------- */
.answer { position: relative; display: inline-block; margin-bottom: 20px; }
.answer input:disabled { pointer-events: none; }
.answer input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; font-size: 16px; color: transparent; caret-color: transparent;
  cursor: text;
}
.boxes {
  --n: 5; --gap: 8px;
  display: flex; flex-wrap: nowrap; justify-content: center; gap: var(--gap); pointer-events: none;
}
.box {
  /* Se achican para que la palabra entera entre en una línea, aun con 9 letras en un celular. */
  --w: min(50px, calc((100vw - 32px - (var(--n) - 1) * var(--gap)) / var(--n)));
  width: var(--w); height: calc(var(--w) * 1.16); display: grid; place-items: center;
  background: var(--surface); border: 1.5px solid var(--line); border-bottom: 3px solid var(--muted);
  border-radius: 6px;
  font: 800 calc(var(--w) * .55)/1 var(--display); text-transform: uppercase;
  transition: border-color .12s, transform .12s;
}
.box.filled { border-color: var(--celeste); border-bottom-color: var(--celeste); }
.box.active { border-bottom-color: var(--sol); box-shadow: 0 4px 0 -1px var(--sol); }
.box.given { background: var(--sol); border-color: var(--sol); color: var(--sol-ink); }
.box.right { background: var(--ok); border-color: var(--ok); color: #fff; animation: pop .35s both; }
.box.wrong { border-color: var(--bad); color: var(--bad); }
.box.right:nth-child(2) { animation-delay: .05s; } .box.right:nth-child(3) { animation-delay: .1s; }
.box.right:nth-child(4) { animation-delay: .15s; } .box.right:nth-child(5) { animation-delay: .2s; }
.box.right:nth-child(6) { animation-delay: .25s; } .box.right:nth-child(7) { animation-delay: .3s; }
.box.right:nth-child(8) { animation-delay: .35s; }
@keyframes pop { 50% { transform: scale(1.12); } }
@media (max-width: 440px) { .boxes { --gap: 5px; } }

.actions { display: flex; align-items: center; justify-content: center; gap: 18px; }
.btn-primary {
  background: var(--sol); color: var(--sol-ink); border: 0; border-radius: 8px;
  padding: 14px 30px; font: 800 1.05rem/1 var(--display);
  box-shadow: 0 4px 0 #B88500;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn-primary:hover { background: var(--sol-hover); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #B88500; }
.btn-primary.wide { width: 100%; margin-top: 4px; }
.btn-link {
  background: none; border: 0; padding: 6px 2px; color: var(--muted);
  text-decoration: underline; text-underline-offset: 4px; font-weight: 700;
}
.btn-link:hover { color: var(--text); }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 16px; font-weight: 700; font-size: .9rem;
}
.btn-ghost:hover:not(:disabled) { border-color: var(--sol); color: var(--sol); }
.btn-ghost:disabled { opacity: .4; cursor: default; }

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

.feedback { min-height: 1.5em; margin: 14px 0 6px; color: var(--muted); }
.attempts { list-style: none; padding: 0; margin: 0 0 4px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.attempts li {
  font: 700 .82rem/1 var(--display); letter-spacing: .05em;
  padding: 6px 10px; border-radius: 999px; border: 1.5px solid var(--bad); color: var(--bad);
  text-decoration: line-through;
}

/* ---------- Ayudas ---------- */
.hints { margin-top: 22px; }
.hint-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  max-width: 560px; margin: 0 auto;
}
@media (max-width: 440px) { .hint-grid { grid-template-columns: repeat(2, 1fr); } }
.hint {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 78px; padding: 12px 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  font-weight: 700; font-size: .92rem; line-height: 1.15;
  transition: border-color .15s, transform .15s, background .15s;
}
.hint svg { width: 24px; height: 24px; color: var(--celeste); }
.hint:hover:not(:disabled) { border-color: var(--sol); transform: translateY(-2px); }
.hint:hover:not(:disabled) svg { color: var(--sol); }
.hint:disabled { opacity: .38; cursor: default; }
.hint.used { opacity: 1; border-color: var(--sol); background: var(--surface-2); }
.hint.used svg { color: var(--sol); }
@media (max-width: 380px) { .hint { font-size: .84rem; } }
.hint-note { margin: 10px 0 0; font-size: .86rem; color: var(--muted); }
.hint-output { margin: 10px auto 0; min-height: 1.2em; max-width: 520px; font-weight: 700; color: var(--sol); }

/* ---------- Resultado ---------- */
.result {
  max-width: 560px; margin: 26px auto 0; padding: 24px 22px;
  background: var(--surface); border-radius: 14px; border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.result h2 { font: 800 2rem/1.05 var(--display); margin: 0 0 6px; letter-spacing: -0.02em; }
.result-answer { margin: 0 0 20px; color: var(--muted); }
.result-answer strong { color: var(--sol); font-family: var(--display); font-size: 1.2rem; letter-spacing: .04em; }
.result h3 { font: 700 1.05rem/1.2 var(--display); margin: 0 0 4px; }
.explain, .fact { text-align: left; margin-bottom: 14px; }
.explain p, .fact p { margin: 0; }
.fact { background: var(--surface-2); padding: 14px 16px; border-radius: 10px; border-left: 4px solid var(--celeste); }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 6px; }
a.btn-primary { display: inline-block; text-decoration: none; }
.result-actions .btn-ghost { padding: 12px 20px; font-size: 1rem; }
.next:empty { display: none; }
.next { margin: 14px 0 0; color: var(--muted); font-size: .95rem; }
.next a { color: var(--sol); font-weight: 700; }

/* ---------- Tira de desafíos ---------- */
.levels { margin-top: 38px; text-align: left; }
.levels-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.levels-head h2 { margin: 0; font: 800 1.2rem/1 var(--display); }
.levels-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.level-strip {
  list-style: none; margin: 0; padding: 4px 2px 12px;
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity;
  scrollbar-width: thin; scrollbar-color: var(--sol) var(--surface);
}
.level-strip a {
  scroll-snap-align: start;
  display: flex; flex-direction: column; justify-content: space-between;
  width: 64px; height: 70px; padding: 8px 9px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); text-decoration: none;
}
.level-strip a:hover { border-color: var(--celeste); }
.level-strip a[aria-current="true"] { border: 2px solid var(--sol); }
.level-strip .n { font: 800 1.15rem/1 var(--display); }
.level-strip .d { font-size: .7rem; color: var(--muted); }
.level-strip .bar { height: 3px; border-radius: 3px; background: var(--line); }
.level-strip .won .bar { background: var(--ok); }
.level-strip .lost .bar { background: var(--bad); }
.level-strip .started .bar { background: var(--sol); }
.level-strip .locked { opacity: .45; pointer-events: none; }
.level-strip .day {
  flex: none; align-self: stretch; display: flex; align-items: flex-start;
  padding: 2px 2px 0 6px; margin-left: 4px; border-left: 2px solid var(--line);
  font: 700 .78rem/1 var(--display); color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg);
}
.level-strip .day:first-child { margin-left: 0; }
.level-strip .d { text-transform: lowercase; }

.streak-row { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.streak { font: 800 1.05rem/1 var(--display); }
.streak-squares { display: flex; gap: 5px; }
.streak-squares i { width: 18px; height: 18px; border-radius: 3px; background: var(--line); }
.streak-squares i.won { background: var(--ok); }
.streak-squares i.lost { background: var(--bad); }
.streak-squares i.started { background: var(--sol); }

/* ---------- Diálogos ---------- */
.dlg {
  width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 16px;
  padding: 26px 22px 22px; background: var(--surface); color: var(--text);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .6);
}
.dlg::backdrop { background: rgba(5, 12, 26, .65); backdrop-filter: blur(2px); }
.dlg h2 { font: 800 1.55rem/1.1 var(--display); margin: 0 0 12px; }
.dlg ul { padding-left: 1.1em; }
.dlg li { margin-bottom: 6px; }
.close { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; font-size: 1.8rem; line-height: 1; padding: 4px 8px; color: var(--muted); }
.example { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; margin: 12px 0; border-left: 4px solid var(--sol); }
.example-clue { font: 700 1.2rem/1.2 var(--display); margin: 0 0 6px; }
.example p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 14px 4px; }
.stats strong { display: block; font: 800 1.8rem/1 var(--display); color: var(--sol); }
.stats span { font-size: .8rem; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--sol); color: var(--sol-ink); padding: 11px 18px; border-radius: 10px;
  font-weight: 700; z-index: 20; box-shadow: var(--shadow);
}

/* ---------- Festejo ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 15; }
.confetti i {
  position: absolute; top: -16px; width: 9px; height: 15px; border-radius: 2px;
  animation: fall var(--t, 2.2s) cubic-bezier(.25, .6, .45, 1) forwards;
}
@keyframes fall {
  to { transform: translate(var(--x, 0), 105vh) rotate(var(--r, 540deg)); opacity: .9; }
}

.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 18px 16px 26px; border-top: 1px solid var(--line); }
.foot p { margin: 0; }
.foot p + p { margin-top: 4px; }
.cafecito {
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 8px;
  padding: 10px 18px; border-radius: 999px; border: 1.5px solid var(--sol);
  color: var(--sol); text-decoration: none; font: 700 .95rem/1 var(--display);
  transition: background .15s, color .15s;
}
.cafecito:hover { background: var(--sol); color: var(--sol-ink); }
.foot .cafecito-nota { margin-bottom: 14px; font-size: .85rem; }

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

/* ---------- Cuenta ---------- */
.login-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
  border: 1.5px solid var(--sol); border-radius: 999px; background: transparent; color: var(--sol);
  font: 700 .95rem/1 var(--display);
}
.login-btn:hover { background: var(--sol); color: var(--sol-ink); }
.login-btn svg { width: 18px; height: 18px; }
.avatar { padding: 0; overflow: hidden; border-color: var(--sol); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar span { font: 800 1rem/1 var(--display); color: var(--sol); }
@media (max-width: 400px) { .login-btn span { display: none; } .login-btn { width: 40px; padding: 0; justify-content: center; } }

/* Sin sesión: se guarda en el navegador. Con sesión: en la cuenta. Sin Firebase configurado: no se ofrece entrar. */
.save-hint, .stats-cta, .stats-cloud { display: none; }
.cuentas-activas:not(.con-sesion) .save-hint,
.cuentas-activas:not(.con-sesion) .stats-cta { display: block; }
.con-sesion .stats-cloud { display: block; }
.con-sesion .stats-local { display: none; }
.stats-cta { margin-top: -6px; }
.stats-cta .btn-link { padding: 0; font-size: inherit; color: var(--sol); }
.save-hint { margin: 16px 0 0; padding-top: 14px; border-top: 1px dashed var(--line); color: var(--muted); font-size: .92rem; }
.save-hint .btn-link { display: block; margin: 6px auto 0; color: var(--sol); }
.cuenta-nombre { font: 800 1.2rem/1.2 var(--display); margin: 0 0 2px; }
.btn-ghost.wide { width: 100%; padding: 12px; margin-top: 6px; font-size: 1rem; }
