/* ───────── Base (mobile-first) ───────── */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--amber); color: var(--ink);
  font: 400 17px/1.45 var(--font-body); -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
.card-dark :focus-visible { outline-color: var(--gold); }
.mono { font-family: var(--font-code); }
.tmp { color: var(--cyan); }
.kw { color: var(--gold); }
.lbl { color: var(--coral); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.kicker { margin: 0 0 6px; font: 700 12px/1.3 var(--font-body); letter-spacing: .18em; text-transform: uppercase; color: var(--ink); }
.card-dark { background: var(--navy); color: var(--paper); border-radius: 22px; padding: 18px; box-shadow: 0 10px 24px rgba(15, 20, 40, .22); }

.btn {
  display: block; width: 100%; min-height: 54px; border: 0; border-radius: 16px;
  font: 700 18px var(--font-body); transition: transform .12s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primario { background: var(--indigo); color: var(--paper); }
.btn.secundario { background: var(--navy); color: var(--paper); margin-top: 18px; }
.btn:disabled { opacity: .45; }

/* ───────── Jugador ───────── */
body.jugador { display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--amber); border-bottom: 2px solid rgba(22, 20, 43, .12);
}
.brand { font: 700 18px var(--font-title); color: var(--indigo); white-space: nowrap; }
.dots { list-style: none; display: flex; gap: 6px; margin: 0 auto; padding: 0; }
.dots li { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); background: transparent; position: relative; }
.dots li.actual { background: var(--indigo); border-color: var(--indigo); transform: scale(1.15); }
.dots li.bien { background: #0B5B34; border-color: #0B5B34; }
.dots li.mal { background: #8A1C0A; border-color: #8A1C0A; }
.dots li.bien::after, .dots li.mal::after { position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; font-weight: 700; color: #fff; }
.dots li.bien::after { content: '✓'; }
.dots li.mal::after { content: '✗'; }
.timer { background: var(--navy); color: var(--paper); padding: 4px 10px; border-radius: 999px; font-size: 15px; font-variant-numeric: tabular-nums; }

main { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 18px 16px 24px; outline: none; }
.entra { animation: entra .35s var(--ease) both; }
@keyframes entra { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* Inicio */
.intro { padding-top: 6vh; text-align: center; }
.brace-title { margin: 4px 0 14px; font: 700 clamp(40px, 12vw, 60px)/1 var(--font-title); color: var(--indigo); }
.brace-title span { font-size: 1.15em; }
.lead { font-size: 18px; margin: 0 0 16px; }
.reglas { list-style: none; padding: 0; margin: 0 0 26px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.reglas li { background: var(--amber-soft); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.entrada { text-align: left; background: var(--navy); color: var(--paper); border-radius: 22px; padding: 20px; display: grid; gap: 10px; }
.entrada label { font-weight: 700; font-size: 15px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.entrada input {
  min-height: 52px; border-radius: 14px; border: 2px solid var(--navy-line); background: var(--navy-2);
  color: var(--paper); padding: 0 14px; font-size: 18px;
}
.entrada input:focus { border-color: var(--gold); outline: none; }
.entrada .btn.primario { background: var(--gold); color: var(--navy); margin-top: 6px; }
.error { margin: 0; min-height: 1.2em; color: var(--coral); font-size: 14px; }

/* Reto */
.titulo { margin: 0 0 6px; font: 700 clamp(26px, 7.5vw, 34px)/1.1 var(--font-title); color: var(--indigo); }
.consigna { margin: 0 0 16px; font-size: 17px; }
.tablero { display: grid; gap: 14px; }
.expr { margin: 0; text-align: center; font-size: 22px; font-weight: 700; }
.sub { margin: 0; font: 700 12px var(--font-body); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.pool { display: flex; flex-wrap: wrap; gap: 8px; }
.pool.centro { justify-content: center; }
.chip {
  min-height: 46px; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--navy-line);
  background: var(--navy-2); color: var(--paper); font-weight: 600; font-size: 16px;
}
.chip.op, .chip.mono { min-width: 56px; font-size: 20px; font-weight: 700; }
.chip.ir { border-style: dashed; border-color: var(--gold); }
.chip:disabled { opacity: .3; }
.chip.usada { display: none; }
.chip:active:not(:disabled) { background: var(--indigo); }

/* Reto 1 */
.pipe { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.slot {
  width: 100%; min-height: 44px; display: flex; align-items: center; gap: 12px; text-align: left;
  border-radius: 12px; border: 2px dashed var(--navy-line); background: transparent; color: var(--muted); padding: 6px 12px;
}
.slot .n { width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--navy-2); font-weight: 700; font-size: 14px; }
.slot.lleno { border-style: solid; border-color: var(--cyan); color: var(--paper); background: var(--navy-2); }
.slot:disabled { cursor: default; }

/* Estado de corrección (no depende solo del color: borde + icono) */
.bien { border-color: var(--green) !important; }
.mal { border-color: var(--coral) !important; }
.slot.bien::after, .slot.mal::after, .fila.bien::after, .fila.mal::after, .opcion.bien::after, .opcion.mal::after { margin-left: auto; font-weight: 700; }
.slot.bien::after, .fila.bien::after, .opcion.bien::after { content: '✓'; color: var(--green); }
.slot.mal::after, .fila.mal::after, .opcion.mal::after { content: '✗'; color: var(--coral); }

/* Reto 2 */
.arbol { width: 100%; max-width: 360px; justify-self: center; overflow: visible; }
.arbol line { stroke: var(--muted); stroke-width: 3; }
.arbol .hoja rect { fill: var(--cyan); }
.arbol text { font: 700 22px var(--font-code); text-anchor: middle; dominant-baseline: central; fill: var(--navy); pointer-events: none; }
.slot-op { cursor: pointer; outline: none; }
.slot-op circle { fill: var(--navy-2); stroke: var(--muted); stroke-width: 3; stroke-dasharray: 6 5; }
.slot-op text { fill: var(--muted); }
.slot-op.lleno circle { fill: var(--gold); stroke: var(--gold); stroke-dasharray: none; }
.slot-op.lleno text { fill: var(--navy); font-size: 26px; }
.slot-op.sel circle { stroke: var(--paper); stroke-width: 4; stroke-dasharray: none; animation: latido 1.2s ease-in-out infinite; }
.slot-op:focus-visible circle { stroke: var(--paper); stroke-width: 5; }
.slot-op.bien circle { stroke: var(--green); stroke-width: 5; stroke-dasharray: none; }
.slot-op.mal circle { stroke: var(--coral); stroke-width: 5; stroke-dasharray: 4 3; }
@keyframes latido { 50% { stroke-opacity: .35; } }

/* Reto 3 */
.codigo { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 21px; }
.codigo li { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; white-space: pre; }
.codigo.corto { font-size: 18px; gap: 4px; }
.codigo .pos { color: var(--muted); font-size: 15px; margin-right: 10px; }
.hueco {
  min-width: 56px; min-height: 44px; margin: 0 4px; border-radius: 10px; border: 2px dashed var(--muted);
  background: var(--navy-2); color: var(--paper); font: 700 20px var(--font-code); padding: 0 8px;
}
.hueco.lleno { border-style: solid; border-color: var(--cyan); }
.hueco.sel { border-color: var(--paper); border-style: solid; box-shadow: 0 0 0 3px rgba(244, 241, 255, .25); }

/* Reto 4 */
.triples { width: 100%; border-collapse: separate; border-spacing: 0 6px; font: 600 18px var(--font-code); text-align: center; }
.triples th { font: 700 12px var(--font-body); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.triples td { background: var(--navy-2); padding: 10px 6px; }
.triples td:first-child { border-radius: 10px 0 0 10px; color: var(--muted); }
.triples td:last-child { border-radius: 0 10px 10px 0; }
.triples td.op { color: var(--gold); }
.hueco-celda { outline: 2px dashed var(--gold); outline-offset: -4px; color: var(--violet); }
.hueco-celda.bien { outline: 3px solid var(--green); }
.hueco-celda.mal { outline: 3px solid var(--coral); }
.opciones { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opcion {
  min-height: 54px; border-radius: 14px; border: 2px solid var(--navy-line); background: var(--navy-2);
  color: var(--paper); font-size: 21px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.opcion.sel { border-color: var(--gold); background: #2D3766; }
.opcion.bien::after, .opcion.mal::after { margin-left: 0; }

/* Reto 5 */
.envs { display: flex; gap: 8px; justify-content: center; }
.env { background: var(--paper); color: var(--navy); border-radius: 999px; padding: 4px 14px; font-weight: 700; font-size: 17px; }
.traza { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fila {
  width: 100%; min-height: 50px; display: flex; align-items: center; gap: 8px; text-align: left;
  border: 2px solid var(--navy-line); background: var(--navy-2); color: var(--paper); border-radius: 12px; padding: 6px 10px; font-size: 16px;
}
.fila .orden { width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center; font: 700 14px var(--font-body); border: 2px dashed var(--muted); }
.fila.sel { border-color: var(--gold); }
.fila.sel .orden { background: var(--gold); color: var(--navy); border: 0; }
.fila .lblc { min-width: 30px; color: var(--muted); }
.fila.fin { opacity: .75; border-style: dashed; }
.resultado-x { margin: 0; text-align: center; font-size: 20px; color: var(--green); }
.resultado-x b { color: var(--paper); }

.bloqueado .chip, .bloqueado .pool { display: none; }

/* Barra inferior con feedback y botón */
.acciones {
  position: sticky; bottom: 0; z-index: 3; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 10px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--amber) 80%, rgba(255, 189, 89, 0));
  display: grid; gap: 10px;
}
.feedback { display: none; border-radius: 16px; padding: 12px 14px; font-size: 15px; }
.feedback.visible { display: block; animation: entra .3s var(--ease) both; }
.feedback.bien { background: #DDF7E8; border: 2px solid #0B5B34; }
.feedback.mal { background: #FFE1D8; border: 2px solid #8A1C0A; }
.feedback p { margin: 0 0 4px; }
.feedback p:last-child { margin: 0; }
.fb-titulo { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.icono { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 14px; }
.feedback.bien .icono { background: #0B5B34; }
.feedback.mal .icono { background: #8A1C0A; }
.fb-sol .mono { background: var(--navy); color: var(--paper); border-radius: 6px; padding: 1px 6px; font-size: 13px; line-height: 1.7; -webkit-box-decoration-break: clone; box-decoration-break: clone; }

/* Resultado final */
.final { text-align: center; padding-top: 4vh; }
.marcador {
  --p: 0; width: 170px; height: 170px; margin: 12px auto 10px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--indigo) calc(var(--p) * 360deg), var(--amber-soft) 0);
}
.marcador .num {
  width: 136px; height: 136px; border-radius: 50%; background: var(--navy); color: var(--paper);
  display: flex; align-items: baseline; justify-content: center; padding-top: 40px; font: 700 56px/1 var(--font-title);
}
.marcador small { font-size: 24px; color: var(--muted); }
.tiempo { margin: 0; font-size: 18px; }
.posicion { margin: 10px 0 0; font-size: 22px; }
.posicion b { color: var(--indigo); font-size: 30px; font-family: var(--font-title); }
.mensaje { margin: 12px 0; font-size: 18px; font-weight: 600; }
.detalle { list-style: none; padding: 0; margin: 0 auto 16px; max-width: 360px; display: grid; gap: 6px; text-align: left; }
.detalle li { background: var(--navy); color: var(--paper); border-radius: 12px; padding: 10px 14px; border-left: 6px solid; }
.detalle li.bien { border-color: var(--green); }
.detalle li.mal { border-color: var(--coral); }
.detalle li span { font-weight: 700; margin-right: 6px; }
.detalle li.bien span { color: var(--green); }
.detalle li.mal span { color: var(--coral); }
.nota { font-size: 14px; color: var(--ink-soft); margin: 8px 0 0; }
.nota.aviso { color: #7A1206; font-weight: 600; }

@media (min-width: 700px) {
  body { font-size: 18px; }
  main { padding-top: 32px; }
}

/* ───────── Podio (proyector) ───────── */
body.podio { min-height: 100vh; padding: clamp(16px, 3vw, 48px); display: grid; grid-template-rows: auto 1fr auto; gap: clamp(14px, 2vw, 28px); }
.podio .cab { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.podio .cab .kicker { font-size: clamp(12px, 1.1vw, 20px); }
.podio h1 { margin: 0; font: 700 clamp(34px, 4.6vw, 80px)/1 var(--font-title); color: var(--indigo); }
.sala-tag { background: var(--navy); color: var(--gold); font: 700 clamp(14px, 1.2vw, 22px) var(--font-code); border-radius: 999px; padding: 8px 18px; }
.escena { display: grid; grid-template-columns: minmax(260px, 30%) 1fr; gap: clamp(14px, 2vw, 32px); min-height: 0; }
.unirse .sub { font-size: clamp(14px, 1.2vw, 22px); }
.unirse { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.qr { background: #fff; border-radius: 18px; padding: 14px; width: 100%; max-width: 360px; aspect-ratio: 1; }
.qr svg { width: 100%; height: 100%; display: block; }
.url { font: 700 clamp(15px, 1.3vw, 24px) var(--font-code); color: var(--gold); word-break: break-all; }
.contadores { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.contadores span { background: var(--navy-2); border-radius: 12px; padding: 8px 14px; font-size: clamp(14px, 1.1vw, 20px); color: var(--muted); }
.contadores b { color: var(--paper); font-size: 1.4em; margin-right: 4px; }
.tabla-card { display: flex; flex-direction: column; min-height: 0; }
.tabla-card .sub { font-size: clamp(12px, .9vw, 16px); margin-bottom: 10px; }
.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; overflow: auto; }
.ranking li {
  display: grid; grid-template-columns: 2.4em 1fr auto auto; align-items: center; gap: 14px;
  background: var(--navy-2); border-radius: 14px; padding: clamp(8px, .9vw, 14px) 16px; font-size: clamp(16px, 1.5vw, 28px);
}
.ranking li.nuevo { animation: nuevo .8s var(--ease) both; }
@keyframes nuevo { from { opacity: 0; transform: translateX(-24px); background: var(--indigo); } to { opacity: 1; transform: none; } }
.ranking .p { font: 700 1em var(--font-title); color: var(--gold); }
.ranking .nom { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .ac { font-weight: 700; color: var(--cyan); }
.ranking .tm { color: var(--muted); font-variant-numeric: tabular-nums; }
.vacio { color: var(--muted); text-align: center; padding: 40px 0; font-size: clamp(16px, 1.4vw, 24px); }
.pie { display: flex; gap: 12px; justify-content: flex-end; }
.pie .btn { width: auto; padding: 0 28px; }
.btn.oro { background: var(--indigo); color: var(--paper); min-height: 60px; font-size: clamp(18px, 1.4vw, 24px); }
.btn.oscuro { background: var(--navy); color: var(--paper); }

.podio-overlay {
  position: fixed; inset: 0; z-index: 10; background: var(--amber); display: grid; grid-template-rows: auto 1fr auto;
  padding: clamp(16px, 3vw, 48px); gap: 16px;
}
.podio-overlay h2 { margin: 0; text-align: center; font: 700 clamp(34px, 4.6vw, 80px)/1 var(--font-title); color: var(--indigo); }
.gradas { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: clamp(10px, 2vw, 32px); max-width: 1200px; width: 100%; margin: 0 auto; }
.grada { display: flex; flex-direction: column; align-items: center; gap: 10px; opacity: 0; transform: translateY(40px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
.grada.visible { opacity: 1; transform: none; }
.grada .quien { text-align: center; }
.grada .quien b { display: block; font-size: clamp(18px, 2.2vw, 40px); color: var(--ink); overflow-wrap: anywhere; }
.grada .quien span { font-size: clamp(14px, 1.3vw, 24px); color: var(--ink-soft); }
.grada .bloque {
  width: 100%; border-radius: 20px 20px 0 0; background: var(--navy); color: var(--gold);
  display: grid; place-items: start center; padding-top: 16px; font: 700 clamp(40px, 6vw, 110px)/1 var(--font-title);
}
.grada.g1 .bloque { height: clamp(200px, 38vh, 440px); background: var(--indigo); }
.grada.g2 .bloque { height: clamp(150px, 27vh, 320px); }
.grada.g3 .bloque { height: clamp(110px, 19vh, 230px); }
.grada.g1 .quien b { font-size: clamp(22px, 2.8vw, 52px); color: var(--indigo); }

@media (max-width: 800px) {
  .escena { grid-template-columns: 1fr; }
  .qr { max-width: 240px; }
}
