@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=Inter:wght@300;400;500;600;700;800&display=swap');

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

:root {
  --bg0: #06060f;
  --bg1: #0c0c1e;
  --bg2: #13132a;
  --bg3: #1b1b38;
  --bg4: #242448;
  --border: rgba(255,255,255,0.07);
  --purple: #7c3aed;
  --purple-l: #a78bfa;
  --red: #ef4444;
  --gold: #d9a406;
  --green: #22c55e;
  --cyan: #22d3ee;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #4b5563;
  --ff-head: 'Cinzel', serif;
  --ff-ui: 'Inter', sans-serif;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 4px 24px rgba(0,0,0,0.6);
  /* tablero */
  --cell-bg: #10101f;
  --cell-given: #1c1c33;
  --line: rgba(167,139,250,0.18);
  --line-strong: rgba(167,139,250,0.55);
}

html, body { height: 100%; }
body {
  background: var(--bg0); color: var(--text);
  font-family: var(--ff-ui); font-size: 15px; line-height: 1.5; min-height: 100vh;
}

.zen-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(34,211,238,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(124,58,237,0.12) 0%, transparent 55%);
}

.top-bar {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(6,6,15,0.75); backdrop-filter: blur(8px);
}
.top-brand { color: var(--text2); text-decoration: none; font-weight: 600; font-size: 14px; }
.top-brand:hover { color: var(--text); }
.top-title { font-family: var(--ff-head); font-weight: 900; letter-spacing: 6px; font-size: 16px; color: var(--cyan); }

#app { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; padding: 18px 12px 60px; }

.loading { text-align: center; padding: 80px 0; color: var(--text2); }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border: 2px solid var(--purple);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; color: var(--purple-l);
  animation: girar 1.6s ease-in-out infinite;
}
@keyframes girar { 50% { transform: rotate(180deg); border-color: var(--cyan); } 100% { transform: rotate(360deg); } }

#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 22px; border-radius: 30px; font-size: 14px; opacity: 0;
  transition: all .25s; z-index: 100; pointer-events: none; box-shadow: var(--shadow); max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--red); color: #fca5a5; }
#toast.xp { border-color: var(--gold); color: #fde68a; }

button {
  font-family: var(--ff-ui); font-size: 14px; font-weight: 600;
  border: none; border-radius: var(--r); cursor: pointer; transition: all .18s; color: var(--text);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  padding: 13px 26px; width: 100%; box-shadow: 0 4px 18px rgba(34,211,238,0.25);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-secondary { background: var(--bg3); border: 1px solid var(--border); padding: 11px 20px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 8px 14px; font-size: 13px; }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--cyan); }

/* ─── Landing ─── */
.landing-hero { text-align: center; padding: 30px 0 20px; }
.landing-hero h1 {
  font-family: var(--ff-head); font-size: clamp(34px, 7vw, 50px); font-weight: 900; letter-spacing: 5px;
  background: linear-gradient(100deg, var(--cyan) 20%, var(--purple-l) 80%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.landing-hero .tagline { color: var(--text2); font-size: 15.5px; margin-top: 4px; }

.nivel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-top: 18px; }
.nivel-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 16px; text-align: center; cursor: pointer;
  transition: border-color .2s, transform .2s;
}
.nivel-card:hover { border-color: var(--cyan); transform: translateY(-3px); }
.nivel-card .ni { font-size: 30px; }
.nivel-card .nn { font-family: var(--ff-head); letter-spacing: 1px; font-weight: 700; margin: 6px 0 2px; }
.nivel-card .nx { color: var(--gold); font-size: 13px; font-weight: 700; }
.nivel-card .nd { color: var(--text3); font-size: 11.5px; margin-top: 3px; }

.resume-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(34,211,238,0.07); border: 1px solid rgba(34,211,238,0.35);
  border-radius: var(--r-lg); padding: 14px 18px; margin-top: 16px;
}
.hint-note { color: var(--text3); font-size: 12.5px; text-align: center; margin-top: 16px; }

/* ─── Juego ─── */
.game-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.game-head .gh-nivel { font-family: var(--ff-head); letter-spacing: 2px; font-weight: 700; color: var(--purple-l); }
.game-head .gh-timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text2); }
.game-head .gh-right { margin-left: auto; display: flex; gap: 8px; }

.board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  width: 100%; max-width: 520px; margin: 0 auto; aspect-ratio: 1;
  border: 2px solid var(--line-strong); border-radius: 10px; overflow: hidden;
  background: var(--cell-bg);
  user-select: none; -webkit-user-select: none;
}
.sd-cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  font-size: clamp(16px, 4.2vw, 26px); font-weight: 600; cursor: pointer;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  color: var(--cyan);
}
.sd-cell:nth-child(9n) { border-right: none; }
.sd-cell.b-right { border-right: 2px solid var(--line-strong); }
.sd-cell.b-bottom { border-bottom: 2px solid var(--line-strong); }
.sd-cell.given { background: var(--cell-given); color: var(--text); font-weight: 700; }
.sd-cell.sel { background: rgba(124,58,237,0.35) !important; }
.sd-cell.peer { background: rgba(124,58,237,0.10); }
.sd-cell.same { background: rgba(34,211,238,0.16); }
.sd-cell.conflict { color: #fca5a5 !important; }
.sd-cell.conflict::after {
  content: ''; position: absolute; inset: 8%; border-radius: 50%;
  border: 2px solid rgba(239,68,68,0.45); pointer-events: none;
}
.sd-cell.hinted { color: var(--gold); }
.sd-cell.flash { animation: cell-flash .6s; }
@keyframes cell-flash { 0% { background: rgba(217,164,6,0.6); } }
.sd-cell .notes {
  position: absolute; inset: 1px; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: clamp(7px, 1.7vw, 10px); color: var(--text3); font-weight: 600;
  pointer-events: none; line-height: 1;
}
.sd-cell .notes span { display: flex; align-items: center; justify-content: center; }

/* ─── Controles ─── */
.controls { max-width: 520px; margin: 14px auto 0; }
.numpad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.numpad button {
  aspect-ratio: 1; font-size: 20px; font-weight: 700;
  background: var(--bg3); border: 1px solid var(--border);
}
.numpad button:hover:not(:disabled) { border-color: var(--cyan); background: var(--bg4); }
.numpad button .cnt { display: block; font-size: 9px; color: var(--text3); font-weight: 600; }
.numpad button.agotado { opacity: 0.3; }
.action-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.action-row button { flex: 1; padding: 10px 8px; font-size: 13px; background: var(--bg3); border: 1px solid var(--border); }
.action-row button.on { border-color: var(--cyan); background: rgba(34,211,238,0.15); }
.action-row .btn-pista { border-color: rgba(217,164,6,0.5); color: #fde68a; }
.action-row .btn-pista:hover:not(:disabled) { background: rgba(217,164,6,0.15); }

.xp-info {
  max-width: 520px; margin: 12px auto 0; text-align: center;
  color: var(--text3); font-size: 12.5px;
}
.xp-info b { color: var(--gold); }

/* ─── Fin ─── */
.win-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(6,6,15,0.8); backdrop-filter: blur(3px); animation: fade-in .3s;
}
@keyframes fade-in { from { opacity: 0; } }
.win-card {
  background: var(--bg2); border: 1px solid rgba(34,197,94,0.5); border-radius: var(--r-lg);
  padding: 28px 34px; text-align: center; box-shadow: 0 0 60px rgba(34,197,94,0.15), var(--shadow);
  animation: pop-in .35s cubic-bezier(.2, 1.5, .4, 1); max-width: 92vw;
}
@keyframes pop-in { from { transform: scale(0.75); opacity: 0; } }
.win-card h2 { font-family: var(--ff-head); letter-spacing: 2px; margin-bottom: 6px; }
.win-card .wc-tiempo { color: var(--text2); font-size: 14px; }
.win-card .wc-xp { font-size: 17px; margin: 14px 0; line-height: 1.7; }
.win-card .wc-xp .mas { color: var(--green); font-weight: 800; }
.win-card .wc-xp .menos { color: #fca5a5; font-weight: 700; }
.win-card .wc-xp .neto { color: var(--gold); font-weight: 800; font-size: 22px; }
.win-card .wc-guest { color: var(--text2); font-size: 13px; margin: 10px 0; }
.win-card .end-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 8px; }

/* ─── Retos entre amigos ─── */
.retos { margin-top: 22px; background: var(--bg1); border: 1px solid rgba(245,158,11,0.28); border-radius: var(--r-lg); padding: 18px; }
.retos h2 { font-family: var(--ff-head); font-size: 17px; letter-spacing: 1.5px; color: #fbbf24; }
.retos-sub { color: var(--text2); font-size: 13px; margin: 2px 0 12px; }
.retos-vacio { color: var(--text2); font-size: 13.5px; }
.retos-vacio a, .rv-nota a { color: var(--cyan); }
.retos h3 { font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--text3); margin: 16px 0 8px; }
.reto-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-top: 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); }
.rc-foto { flex-shrink: 0; display: flex; margin: 4px; }
.rc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rc-info b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-info span { color: var(--text2); font-size: 12.5px; }
.btn-reto { flex-shrink: 0; padding: 9px 14px; color: #fff; font-weight: 700; background: linear-gradient(135deg, #f59e0b, #ef4444); box-shadow: 0 4px 14px rgba(239,68,68,0.25); }
.btn-reto:hover { transform: translateY(-1px); }
.reto-mio {
  display: flex; justify-content: space-between; gap: 4px 10px; flex-wrap: wrap; width: 100%; margin-top: 6px; padding: 10px 12px;
  text-align: left; font-size: 13px; font-weight: 500; background: var(--bg2); border: 1px solid var(--border);
}
.reto-mio b { color: var(--text); }
.reto-mio .rm-lider { color: var(--text2); }
.reto-mio:hover { border-color: #fbbf24; }

.rt-foto { display: block; border-radius: 50%; overflow: hidden; background: var(--bg4); flex-shrink: 0; }
.rt-foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rt-ini { width: 100%; height: 100%; display: grid; place-items: center; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--purple), var(--cyan)); }

.ranking { list-style: none; margin: 14px 0 4px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; background: var(--bg3); border: 1px solid var(--border); }
.ranking li.primero { border-color: rgba(217,164,6,0.5); background: rgba(217,164,6,0.08); }
.ranking li.yo { border-color: var(--cyan); }
.ranking .tjm { flex-shrink: 0; }
.rk-n { width: 24px; flex-shrink: 0; text-align: center; font-weight: 800; color: var(--text2); }
.rk-nombre { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-nombre em { margin-left: 4px; font-style: normal; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--cyan); }
.rk-t { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; font-weight: 800; font-variant-numeric: tabular-nums; }
.rk-t small { font-size: 10.5px; font-weight: 600; color: var(--gold); }

.reto-vista { max-width: 520px; margin: 20px auto 0; padding: 22px; background: var(--bg2); border: 1px solid rgba(245,158,11,0.35); border-radius: var(--r-lg); }
.rv-cab { display: flex; align-items: center; gap: 14px; }
.rv-cab > .tjm, .rv-cab > .rt-foto { flex-shrink: 0; margin: 6px; }
.rv-kicker { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: #fbbf24; }
.rv-cab h2 { font-family: var(--ff-head); font-size: 19px; letter-spacing: .5px; line-height: 1.3; margin: 2px 0; }
.rv-cab p, .rv-nota { color: var(--text2); font-size: 13px; }
.reto-vista .end-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 14px; }
a.btn-primary { display: block; text-align: center; text-decoration: none; color: var(--text); border-radius: var(--r); font-weight: 600; }

.game-head .gh-reto { font-size: 13px; color: #fbbf24; }
.game-head .gh-reto b { font-variant-numeric: tabular-nums; }
.game-head .gh-timer.pasado { color: #f87171; }
.resume-box.es-reto { background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.4); }
.win-card { max-height: 92vh; overflow-y: auto; }
.win-card.es-reto { width: 420px; border-color: rgba(245,158,11,0.55); box-shadow: 0 0 60px rgba(245,158,11,0.15), var(--shadow); }
.win-card .wc-lider { margin-top: 4px; font-size: 13.5px; color: #fbbf24; }
.win-card .wc-reto { margin: 6px 0 12px; font-size: 13px; color: var(--text2); }

/* ─── Carrera en vivo (js/vivo.js) ─── */
.sec-titulo { margin: 26px 0 0; font-family: var(--ff-head); font-size: 16px; letter-spacing: 1.5px; color: var(--purple-l); }
.vivo-box {
  display: flex; align-items: center; gap: 16px 20px; flex-wrap: wrap; margin-top: 16px; padding: 18px;
  border-radius: var(--r-lg); border: 1px solid rgba(34,211,238,0.35);
  background: radial-gradient(ellipse at 0% 0%, rgba(34,211,238,0.14), transparent 60%), var(--bg1);
}
.vb-txt { flex: 1 1 260px; }
.vb-txt h2 { font-family: var(--ff-head); font-size: 17px; letter-spacing: 1.5px; color: var(--cyan); }
.vb-txt p { color: var(--text2); font-size: 13px; margin-top: 2px; }
.vb-acc { display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 260px; justify-content: flex-end; }
.btn-vivo { padding: 11px 18px; color: #04121a; font-weight: 800; background: linear-gradient(135deg, #67e8f9, var(--cyan)); box-shadow: 0 4px 16px rgba(34,211,238,0.3); }
.btn-vivo:hover:not(:disabled) { transform: translateY(-1px); }
.vb-codigo { display: flex; gap: 6px; }
.vb-codigo input {
  width: 108px; padding: 9px 10px; border-radius: var(--r); border: 1px solid var(--border); background: var(--bg2);
  color: var(--text); font: 700 14px var(--ff-ui); letter-spacing: 3px; text-transform: uppercase; text-align: center;
}

.vivo-sala { max-width: 560px; margin: 16px auto 0; padding: 22px; background: var(--bg2); border: 1px solid rgba(34,211,238,0.3); border-radius: var(--r-lg); }
.vivo-sala .rv-kicker { color: var(--cyan); }
.vivo-sala h2 { font-family: var(--ff-head); font-size: 19px; line-height: 1.3; margin: 4px 0; }
.vivo-sala h3 { font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--text3); margin: 18px 0 8px; }
.vs-codigo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding: 10px 12px; border-radius: var(--r); background: var(--bg3); }
.vs-codigo-lbl { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text3); }
.vs-codigo b { font-size: 20px; letter-spacing: 4px; color: var(--cyan); margin-right: auto; font-variant-numeric: tabular-nums; }
.vs-jugadores { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.vs-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 8px 12px; font-size: 13px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); }
.pill.sel { color: var(--text); border-color: var(--cyan); background: rgba(34,211,238,0.14); }
.vs-bots { display: flex; align-items: center; gap: 8px; }
.vs-bots span { margin-right: 6px; font-weight: 600; }
.vs-bots .btn-ghost { width: 38px; padding: 6px 0; font-size: 18px; line-height: 1; }
.vs-empezar { margin-top: 20px; }
.vs-espera { margin-top: 18px; padding: 16px; text-align: center; color: var(--text2); background: var(--bg3); border-radius: var(--r); }
.vs-salir { width: 100%; margin-top: 10px; }

.game-head .gh-vivo { font-size: 11.5px; font-weight: 800; letter-spacing: .1em; color: #04121a; background: var(--cyan); padding: 3px 8px; border-radius: 100px; }
.vivo-rivales { max-width: 520px; margin: 0 auto 10px; display: flex; flex-direction: column; gap: 5px; }
.vr-fila { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--border); font-size: 13px; }
.vr-fila.yo { border-color: rgba(34,211,238,0.5); }
.vr-fila.fin { border-color: rgba(217,164,6,0.45); }
.vr-fila.rendido { opacity: .55; }
.vr-cara { display: flex; flex-shrink: 0; margin: 2px; }
.vr-bot { display: grid !important; place-items: center; font-size: 15px; }
.vr-nombre { width: 30%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.vr-nombre em { font-style: normal; font-size: 10px; font-weight: 800; text-transform: uppercase; color: var(--cyan); }
.vr-barra { flex: 1; height: 7px; border-radius: 100px; background: var(--bg4); overflow: hidden; }
.vr-barra i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), var(--cyan)); transition: width .45s ease; }
.vr-fila.fin .vr-barra i { background: linear-gradient(90deg, #f59e0b, #fde68a); }
.vr-estado { min-width: 62px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text2); }
.vr-fila.fin .vr-estado { color: #fde68a; }
.vivo-aviso { display: none; max-width: 520px; margin: 0 auto 10px; padding: 9px 12px; border-radius: 10px; text-align: center; font-size: 13.5px; font-weight: 600; color: #fde68a; background: rgba(217,164,6,0.1); border: 1px solid rgba(217,164,6,0.35); }
.vivo-aviso.on { display: block; }
.board { position: relative; }
.board.bloqueado .sd-cell { cursor: default; }
.vivo-cuenta {
  position: absolute; inset: 0; z-index: 5; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: rgba(6,6,15,0.82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.vivo-cuenta.on { display: flex; }
.vivo-cuenta span { font-family: var(--ff-head); font-size: clamp(60px, 18vw, 110px); font-weight: 900; color: var(--cyan); text-shadow: 0 0 40px rgba(34,211,238,0.5); animation: pop-in .35s cubic-bezier(.2, 1.5, .4, 1); }
.vivo-cuenta small { color: var(--text2); font-size: 14px; }
.win-card.es-vivo { width: 420px; border-color: rgba(34,211,238,0.5); box-shadow: 0 0 60px rgba(34,211,238,0.15), var(--shadow); }
.win-card .vs-pills { justify-content: center; margin-bottom: 4px; }

@media (max-width: 560px) {
  #app { padding: 12px 8px 40px; }
  .vb-acc { justify-content: stretch; }
  .btn-vivo { flex: 1 1 100%; }
  .vb-codigo { flex: 1; }
  .vb-codigo input { flex: 1; width: auto; }
  .vivo-sala { padding: 16px; }
  .vr-nombre { width: 26%; }
  .reto-vista { padding: 16px; }
  .rv-cab h2 { font-size: 16.5px; }
  .top-title { letter-spacing: 3px; font-size: 14px; }
}
