:root {
  --bg: #0b0b0d;
  --card: #141417;
  --ink: #f2efe8;
  --soft: #cfccc4;
  --muted: #8b887f;
  --line: rgba(242, 239, 232, 0.12);
  --lime: #c8ff2e;
  --red: #ff4b3e;
  --display: 'Unbounded', system-ui, sans-serif;
  --ui: 'Space Grotesk', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
b { font-weight: 700; }

/* ---------- Ambient layers ---------- */
.grain {
  position: fixed; inset: 0; z-index: 60; pointer-events: none; opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.ghost {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: var(--display); font-weight: 800; font-size: 36vw; letter-spacing: -0.06em; white-space: nowrap;
  color: transparent; -webkit-text-stroke: 1.5px rgba(242, 239, 232, 0.055);
  transition: opacity 0.5s, transform 0.8s cubic-bezier(.2, .9, .3, 1);
}
.ghost.out { opacity: 0; transform: scale(1.08); }
.flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 5; }
.flash.good { background: radial-gradient(60% 50% at 50% 50%, rgba(200, 255, 46, .16), transparent 70%); animation: flash .7s ease-out; }
.flash.bad { background: radial-gradient(60% 50% at 50% 50%, rgba(255, 75, 62, .18), transparent 70%); animation: flash .8s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Layout ---------- */
.app {
  position: relative; z-index: 2; max-width: 760px; margin: 0 auto;
  padding: 20px 22px calc(20px + env(safe-area-inset-bottom));
}
.screen { display: none; min-height: calc(100dvh - 40px); flex-direction: column; }
.screen.active { display: flex; animation: enter .45s cubic-bezier(.2, .9, .3, 1); }
@keyframes enter { from { opacity: 0; transform: translateY(12px); } }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 15px; color: var(--soft); transition: border-color .2s, color .2s;
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  height: 56px; padding: 0 30px; border-radius: 999px; font-weight: 700; font-size: 17px;
  transition: transform .15s, background .2s, border-color .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--lime); color: var(--bg); }
.btn.primary:hover { background: #d8ff66; }
.btn.ghost-btn { border: 1px solid var(--line); }
.btn.ghost-btn:hover { border-color: var(--ink); }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Home ---------- */
.top { display: flex; justify-content: space-between; align-items: center; }
.tag { font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); }
.hero { padding: 9vh 0 7vh; text-align: center; }
.logo {
  font-family: var(--display); font-weight: 800; line-height: .9; letter-spacing: -.06em;
  font-size: clamp(64px, 17vw, 148px);
}
.logo span { position: relative; display: inline-block; color: var(--lime); }
.logo span::after {
  content: ''; position: absolute; left: .05em; right: .08em; bottom: -.1em; height: .085em;
  border-radius: 99px; background: var(--lime); transform-origin: left;
  animation: drain 3s cubic-bezier(.55, 0, .45, 1) infinite;
}
@keyframes drain { 0%, 12% { transform: scaleX(1); } 82%, 100% { transform: scaleX(0); } }
.tagline { margin-top: 34px; font-size: clamp(18px, 3.6vw, 22px); line-height: 1.45; color: var(--soft); }
.tagline b { color: var(--ink); }
.cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 34px; }
#dictStatus { margin-top: 16px; min-height: 18px; }

.levels { list-style: none; border-top: 1px solid var(--line); }
.levels li {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 14px;
  padding: 17px 6px; border-bottom: 1px solid var(--line); cursor: pointer;
  transition: background .2s, padding .25s;
}
.levels li:hover:not(.locked) { background: rgba(242, 239, 232, .035); padding-left: 14px; }
.levels .num { font-family: var(--display); font-weight: 800; font-size: 20px; color: var(--muted); }
.levels li.done .num { color: var(--lime); }
.levels li.next .num { color: var(--ink); }
.levels .name { font-weight: 700; font-size: 17px; }
.levels .desc { font-size: 14px; color: var(--muted); margin-top: 3px; }
.levels .meta { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.levels li.done .meta { color: var(--soft); }
.levels li.locked { opacity: .35; cursor: not-allowed; }
.foot { margin-top: auto; padding-top: 30px; text-align: center; }

/* ---------- Game HUD ---------- */
.hud { display: grid; grid-template-columns: 42px 1fr auto auto; align-items: center; gap: 16px; }
.hud-level { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.hud-level span { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.hud-level small { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots { display: flex; gap: 6px; }
.dots i { width: 22px; height: 6px; border-radius: 9px; background: var(--line); transition: background .3s; }
.dots i.on { background: var(--lime); }
.dots i.miss { background: var(--red); }
.dots i.now { background: rgba(242, 239, 232, .4); }
.hud-right { display: flex; align-items: center; gap: 16px; }
.lives { display: flex; gap: 6px; }
.lives i { width: 10px; height: 10px; border-radius: 50%; background: var(--ink); transition: background .3s, transform .3s; }
.lives i.off { background: transparent; box-shadow: inset 0 0 0 1.5px rgba(242, 239, 232, .25); transform: scale(.8); }
.score { font-family: var(--display); font-weight: 600; font-size: 18px; min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Stage ---------- */
.stage {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 3vh 0 12vh;
}
.stage.shake { animation: shake .45s; }
.trail { min-height: 22px; margin-bottom: 14px; font-size: 15px; color: var(--muted); }
.trail span { color: var(--soft); }
.word {
  font-family: var(--display); font-weight: 800; line-height: 1.05; letter-spacing: -.045em;
  font-size: clamp(46px, 12vw, 116px); min-height: 1.1em;
}
.word.long { font-size: clamp(38px, 9.5vw, 96px); }
.word .ch { display: inline-block; animation: drop .55s cubic-bezier(.2, .9, .3, 1.25) both; }
.word .rh { color: var(--lime); }
.word.win .ch { animation: hop .5s cubic-bezier(.3, .7, .4, 1) both; }
.word.loading { font-size: 22px; font-family: var(--ui); font-weight: 500; letter-spacing: 0; color: var(--muted); }
@keyframes drop { from { opacity: 0; transform: translateY(-.45em) rotate(-10deg); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes hop { 45% { transform: translateY(-.2em); } }

.timer { position: relative; width: min(520px, 82vw); height: 6px; margin: 30px 0 20px; border-radius: 9px; background: var(--line); overflow: hidden; }
.timer i { position: absolute; inset: 0; border-radius: 9px; background: var(--ink); transform-origin: left; }
.timer.danger i { background: var(--red); }

.rules { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; min-height: 36px; }
.chip {
  display: inline-flex; align-items: center; justify-content: center; gap: .3em; line-height: 1.25; white-space: nowrap;
  padding: 8px 15px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; color: var(--soft);
  transition: border-color .2s, color .2s, background .2s; animation: enter .4s both;
}
.chip b { color: var(--ink); transition: color .2s; }
.chip.ok { border-color: var(--lime); color: var(--lime); background: rgba(200, 255, 46, .06); }
.chip.ok b { color: var(--lime); }
.chip.bad { border-color: var(--red); color: var(--red); background: rgba(255, 75, 62, .07); }
.chip.bad b { color: var(--red); }
/* Regla clave de la ronda: queda marcada toda la ronda */
.chip.clave { border-color: rgba(200, 255, 46, .55); color: var(--ink); }
.chip.clave b { color: var(--lime); }

/* Pausa de lectura (2 s antes de que arranque el contador) */
.chip { transition: border-color .2s, color .2s, background .2s, opacity .3s, font-size .3s ease, padding .3s ease; }
.stage.ready .chip { opacity: .45; }
.stage.ready .chip.clave {
  opacity: 1; font-size: 19px; padding: 11px 22px; border-width: 2px; border-color: var(--lime);
  background: rgba(200, 255, 46, .12); color: var(--ink);
  animation: enter .4s both, spot 1s ease-in-out .25s 2;
}
@keyframes spot {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(200, 255, 46, .5); }
  50% { transform: scale(1.1); box-shadow: 0 0 26px 4px rgba(200, 255, 46, .28); }
}
.timer.charge i { background: rgba(200, 255, 46, .35); }
.feedback.ready { color: var(--lime); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 13px; }
.stage.ready .answer-wrap { opacity: .5; }
.answer-wrap { transition: opacity .25s; }

.answer-wrap { position: relative; width: min(560px, 86vw); margin-top: 34px; }
.mirror {
  font-family: var(--display); font-weight: 600; letter-spacing: -.03em; white-space: nowrap; overflow: hidden;
  font-size: clamp(28px, 6.6vw, 54px); min-height: 1.35em; padding-bottom: 12px;
  border-bottom: 2px solid var(--line); transition: border-color .2s;
}
.mirror.long { font-size: clamp(22px, 5vw, 40px); }
.answer-wrap.focus .mirror { border-color: rgba(242, 239, 232, .4); }
.mirror .ph { color: rgba(242, 239, 232, .17); }
.mirror .rh { color: var(--lime); }
.mirror .txt { display: inline-block; }
.mirror .caret { display: inline-block; width: 3px; height: .85em; margin-left: 4px; vertical-align: -.06em; background: var(--lime); animation: blink 1s steps(1) infinite; }
.answer-wrap:not(.focus) .caret { opacity: 0; animation: none; }
@keyframes blink { 50% { opacity: 0; } }
.answer-wrap.win .txt { color: var(--lime); animation: fly .7s cubic-bezier(.5, 0, .3, 1) forwards; }
.answer-wrap.win .caret { opacity: 0; }
@keyframes fly { 30% { transform: translateY(4px) scale(1.04); } 100% { transform: translateY(-70px) scale(.85); opacity: 0; } }
.answer-wrap.shake { animation: shake .4s; }
@keyframes shake { 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(3px); } }

#answer {
  position: absolute; inset: 0; width: 100%; opacity: 0; border: 0; background: transparent;
  color: transparent; caret-color: transparent; font-size: 16px; cursor: text;
}

.pop {
  position: absolute; left: 50%; top: -6px; pointer-events: none; opacity: 0; white-space: nowrap;
  font-family: var(--display); font-weight: 800; font-size: 26px; color: var(--lime);
}
.pop.go { animation: pop 1s ease-out; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.5); }
  20% { opacity: 1; transform: translate(-50%, -26px) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -96px) scale(1); }
}

.feedback { min-height: 48px; margin-top: 18px; font-size: 16px; line-height: 1.5; color: var(--muted); max-width: 520px; }
.feedback.bad { color: var(--red); }
.feedback.good { color: var(--lime); font-weight: 700; }
.feedback .ex { display: block; color: var(--soft); font-weight: 400; }
.feedback .ex b { color: var(--ink); }
.hint { margin-top: 6px; font-size: 13px; color: var(--muted); }
.key { display: inline-block; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 22px;
  background: rgba(11, 11, 13, .72); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: fade .25s;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.card {
  width: min(440px, 100%); padding: 36px 28px 28px; border-radius: 28px; text-align: center;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 40px 80px rgba(0, 0, 0, .5);
  animation: rise .45s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.96); } }
.card .kicker { font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); }
.card h2 { margin: 12px 0 14px; font-family: var(--display); font-weight: 800; font-size: clamp(30px, 8vw, 40px); line-height: 1.05; letter-spacing: -.045em; }
.card h2 em { font-style: normal; color: var(--lime); }
.card h2 em.red { color: var(--red); }
.card p { color: var(--soft); line-height: 1.55; }
.card .example {
  margin: 20px auto 0; padding: 14px 18px; border-radius: 16px; background: rgba(242, 239, 232, .04);
  border: 1px solid var(--line); font-family: var(--display); font-weight: 600; font-size: 18px; letter-spacing: -.02em;
}
.card .example em { font-style: normal; color: var(--lime); }
.card .facts { margin-top: 16px; font-size: 14px; color: var(--muted); }
.stats { display: flex; justify-content: center; gap: 30px; margin: 22px 0 4px; }
.stats div { display: flex; flex-direction: column; gap: 4px; }
.stats b { font-family: var(--display); font-weight: 800; font-size: 28px; letter-spacing: -.03em; }
.stats span { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.squares { margin: 8px 0 4px; font-size: 30px; letter-spacing: 6px; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 26px; }
.actions .btn { width: 100%; }
.card .hint { margin-top: 12px; }

/* ---------- Name & leaderboard ---------- */
.who { cursor: default; text-align: left; }
.who.named { cursor: pointer; letter-spacing: .06em; text-transform: none; font-size: 14px; color: var(--soft); }
.who.named b { color: var(--ink); }
.who .edit { margin-left: 6px; font-size: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.who.named:hover .edit { color: var(--lime); }
.link-btn { margin-top: 18px; font-size: 15px; font-weight: 700; color: var(--soft); padding: 8px 14px; border-radius: 999px; transition: color .2s, background .2s; }
.link-btn:hover { color: var(--lime); background: rgba(200, 255, 46, .06); }

.name-input {
  display: block; width: 100%; margin-top: 22px; padding: 14px 4px 12px; text-align: center;
  font-family: var(--display); font-weight: 600; font-size: 26px; letter-spacing: -.02em; color: var(--ink);
  background: transparent; border: 0; border-bottom: 2px solid var(--line); outline: none; transition: border-color .2s;
}
.name-input:focus { border-color: var(--lime); }
.name-input::placeholder { color: rgba(242, 239, 232, .2); }
.name-input.shake { animation: shake .4s; }
.name-error { min-height: 22px; margin-top: 10px; font-size: 14px; color: var(--red) !important; }
.rank-line { margin-top: 16px; font-size: 15px; min-height: 22px; }
.rank-line b { color: var(--lime); }

.card.wide { width: min(520px, 100%); }
.tabs { display: inline-flex; gap: 4px; margin: 14px 0 6px; padding: 4px; border-radius: 999px; border: 1px solid var(--line); }
.tab { padding: 8px 20px; border-radius: 999px; font-weight: 700; font-size: 15px; color: var(--muted); transition: background .2s, color .2s; }
.tab.on { background: var(--ink); color: var(--bg); }
.board { margin-top: 14px; max-height: min(52vh, 460px); overflow-y: auto; text-align: left; }
.board-empty { padding: 34px 0; text-align: center; line-height: 1.6; }
.board-empty b { color: var(--ink); }
.board-list { list-style: none; }
.board-list li {
  display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 14px;
}
.board-list li + li { border-top: 1px solid rgba(242, 239, 232, .06); }
.board-list li.you { background: rgba(200, 255, 46, .08); box-shadow: inset 0 0 0 1px rgba(200, 255, 46, .35); }
.board-list .pos { font-family: var(--display); font-weight: 800; font-size: 15px; color: var(--muted); text-align: center; }
.board-list .podium .pos { font-size: 20px; }
.board-list .who { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-list .who em { font-style: normal; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--lime); margin-left: 6px; }
.board-list .val { text-align: right; display: flex; flex-direction: column; line-height: 1.2; }
.board-list .val b { font-family: var(--display); font-weight: 600; font-size: 16px; }
.board-list .val small { font-size: 12px; color: var(--muted); }
.board-gap { text-align: center; color: var(--muted); letter-spacing: .3em; padding: 2px 0; }
.board-count { margin-top: 12px; text-align: center; font-size: 13px; color: var(--muted) !important; }

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  .app { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
  .screen { min-height: calc(100dvh - 30px); }
  .hud { gap: 10px; grid-template-columns: 38px 1fr auto auto; }
  .icon-btn { width: 38px; height: 38px; }
  .dots i { width: 14px; }
  .hud-right { gap: 10px; }
  .lives i { width: 8px; height: 8px; }
  .score { font-size: 15px; min-width: 40px; }
  .hero { padding: 7vh 0 5vh; }
  .stage { justify-content: flex-start; padding-top: 9vh; }
  .btn { height: 52px; font-size: 16px; }
  .cta .btn { flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
