/* ==========================================================================
   Equilibrio Ninja · PlayLab Games
   Estética: Dōjō japonés tradicional + cartoon 2D. Madera oscura, papel de
   arroz, laca roja e índigo. Tipografías: Mochiy Pop One (títulos) y Baloo 2.
   ========================================================================== */
:root {
  --tinta: #2A2233;
  --madera-osc: #3A2414;
  --madera: #6E3F1F;
  --madera-med: #9E5F2B;
  --madera-clara: #E0A35E;
  --papel: #FFF8E7;
  --papel-2: #F4E6C8;
  --rojo: #D9342B;
  --rojo-osc: #7A1512;
  --indigo: #2B3761;
  --indigo-osc: #161D38;
  --oro: #F2B83A;
  --oro-osc: #A6700F;
  --verde: #2FA35B;
  --verde-osc: #17613A;
  --morado: #7C3AA8;
  --morado-osc: #43195F;
  --cielo: #9FD8EC;
  --radio: 16px;
  --f-titulo: "Mochiy Pop One", "Baloo 2", "Trebuchet MS", sans-serif;
  --f-texto: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --fondo-app: #2E1C10;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fondo-app: #22140B; } }
:root[data-theme="dark"] { --fondo-app: #22140B; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); height: 100%; }
*, *::before, *::after { box-sizing: inherit; }
body {
  margin: 0; min-height: 100%; color: var(--tinta); font-family: var(--f-texto); font-size: 18px; line-height: 1.4;
  background-color: var(--fondo-app);
  background-image:
    radial-gradient(circle at 0 100%, transparent 18px, rgba(255,255,255,.035) 19px, rgba(255,255,255,.035) 23px, transparent 24px),
    radial-gradient(circle at 50% 100%, transparent 18px, rgba(255,255,255,.035) 19px, rgba(255,255,255,.035) 23px, transparent 24px);
  background-size: 48px 24px;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 4px solid var(--oro); outline-offset: 3px; border-radius: 10px; }
.defs-global { position: absolute; width: 0; height: 0; overflow: hidden; }

#app { min-height: 100vh; min-height: 100dvh; }
.pantalla { min-height: 100vh; min-height: 100dvh; }
.pantalla-lista { max-width: 860px; margin: 0 auto; padding: 16px 16px 40px; }
.pantalla-centro { display: flex; align-items: center; justify-content: center; padding: 20px 14px; }

/* ---------------------------------------------------------------- BOTONES */
.btn {
  --c: var(--papel); --b: #B98A52; --t: var(--tinta);
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 48px; padding: .45em 1.1em; border: 3px solid var(--b); border-radius: 14px;
  background: var(--c); color: var(--t); font-weight: 800; font-size: 1rem; letter-spacing: .01em;
  box-shadow: 0 5px 0 var(--b); transform: translateY(0); transition: transform .08s, box-shadow .08s, filter .15s;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--b); }
.btn:disabled { filter: grayscale(.7) opacity(.55); cursor: not-allowed; transform: none; box-shadow: 0 5px 0 var(--b); }
.btn-rojo { --c: var(--rojo); --b: var(--rojo-osc); --t: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn-verde { --c: var(--verde); --b: var(--verde-osc); --t: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.btn-morado { --c: var(--morado); --b: var(--morado-osc); --t: #fff; }
.btn-papel { --c: var(--papel); --b: #B98A52; }
.btn-grande { font-size: 1.35rem; min-height: 64px; padding: .4em 1.4em; border-radius: 18px; font-family: var(--f-titulo); font-weight: 400; }
.btn-cuadrado { width: 48px; padding: 0; font-size: 1.2rem; }
.btn-hud { --c: #5A331A; --b: #2E1D10; --t: var(--papel); min-height: 42px; }
.btn-hud.btn-cuadrado { width: 42px; }
.btn-control { --c: var(--papel); --b: #9E7040; min-height: 50px; font-size: .95rem; padding: .35em .8em; }
.btn-control[aria-pressed="true"] { --c: #2B3761; --b: #111733; --t: #FFE37A; }
.btn-liberar {
  --c: var(--oro); --b: var(--oro-osc); --t: #3A2106; min-height: 58px; font-size: 1.12rem; padding: .35em 1.2em;
  font-family: var(--f-titulo); font-weight: 400;
}
.btn-liberar:not(:disabled) { animation: latido 2.2s ease-in-out infinite; }
@keyframes latido { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.12) saturate(1.1); } }
.enlace { background: none; border: 0; padding: 4px 6px; color: inherit; text-decoration: underline; font-weight: 700; }

/* ---------------------------------------------------------------- INICIO */
#p-inicio { position: relative; overflow: hidden; display: flex; justify-content: center; }
.inicio-fondo {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(255, 214, 140, .28), transparent 60%),
    linear-gradient(180deg, #4E2B15 0%, transparent 30%);
}
.inicio-contenido { position: relative; width: min(760px, 100%); padding: 14px 16px 24px; display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--papel); }
.logo-playlab { width: min(210px, 48vw); height: auto; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); }
.titulo-juego {
  margin: 4px 0 0; font-family: var(--f-titulo); font-weight: 400; line-height: .95;
  font-size: clamp(2.6rem, 10vw, 4.6rem); letter-spacing: .01em; color: var(--papel);
  text-shadow: 0 4px 0 var(--rojo-osc), 0 8px 18px rgba(0,0,0,.45);
  -webkit-text-stroke: 2px var(--rojo-osc);
}
.titulo-juego .t-linea { display: inline-block; }
.titulo-juego .t-ninja { color: #FFD35C; }
.titulo-juego .t-emoji { -webkit-text-stroke: 0; font-size: .75em; vertical-align: .08em; }
.lema { margin: 10px 0 0; font-size: clamp(1.05rem, 3.6vw, 1.3rem); font-weight: 700; color: #FBE6C2; }
.escena-inicio { width: min(560px, 100%); height: auto; margin: 6px 0 4px; border-radius: 22px; background: #D9EEF0; border: 5px solid #5A331A; box-shadow: 0 10px 0 #2E1D10, 0 16px 30px rgba(0,0,0,.4); }
.inicio-botones { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 16px; width: 100%; }
.inicio-fila { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.apodo-actual { margin: 14px 0 0; color: #FBE6C2; }
.pie { margin: 12px 0 0; font-size: .85rem; color: #D9BF94; }

/* ---------------------------------------------------------------- PANELES */
.panel { width: 100%; max-width: 460px; min-width: 0; background: var(--papel); border-radius: 22px; border: 4px solid #B98A52; box-shadow: 0 8px 0 #7B4826, 0 18px 40px rgba(0,0,0,.35); padding: 24px 22px; text-align: center; }
.panel h2 { font-family: var(--f-titulo); font-weight: 400; margin: 0 0 6px; font-size: 1.5rem; }
.panel-icono { font-size: 3rem; margin: 0; }
.panel-nota { margin: 0 0 14px; }
.nick-fila { display: flex; gap: 8px; }
.nick-fila input {
  flex: 1; min-width: 0; min-height: 52px; border: 3px solid #B98A52; border-radius: 14px; padding: 0 14px;
  font-size: 1.3rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; background: #fff;
}
.nick-error { min-height: 1.4em; margin: 6px 0; color: #B0201A; font-weight: 700; font-size: .95rem; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 14px; }
.chip { border: 2px solid #D5B27C; background: #fff; border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: .9rem; min-height: 36px; }
.panel-botones { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.barra-sup { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; color: var(--papel); margin-bottom: 8px; }
.barra-sup h2 { margin: 0; font-family: var(--f-titulo); font-weight: 400; font-size: clamp(1.2rem, 4vw, 1.7rem); }
.barra-apodo { font-weight: 800; color: #FFD35C; font-size: .95rem; }
.nota-seccion { color: #E8D2AC; font-size: .95rem; margin: 8px 0 14px; }

/* ---------------------------------------------------------------- NIVELES */
.lista-niveles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tarjeta-nivel {
  --c: var(--verde);
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 16px 16px 14px; border-radius: 20px; border: 4px solid var(--c); background: var(--papel);
  box-shadow: 0 6px 0 rgba(0,0,0,.35); transition: transform .12s;
}
.tarjeta-nivel:hover { transform: translateY(-3px); }
.tarjeta-nivel:active { transform: translateY(2px); }
.tn-cinta { background: var(--c); color: #fff; font-weight: 800; border-radius: 999px; padding: 1px 12px; font-size: .85rem; }
.tn-nombre { font-family: var(--f-titulo); font-size: 1.45rem; line-height: 1.1; margin-top: 4px; }
.tn-lema { font-size: .95rem; color: #5B4A3A; }
.tn-pie { display: flex; flex-wrap: wrap; gap: 2px 10px; justify-content: space-between; width: 100%; margin-top: 6px; font-weight: 700; font-size: .9rem; }
.tn-estrellas { color: #C9C0B0; letter-spacing: 2px; }
.tn-estrellas .on { color: var(--oro); }
.tn-recomendado { position: absolute; top: -12px; right: 12px; background: var(--rojo); color: #fff; font-size: .78rem; font-weight: 800; padding: 2px 10px; border-radius: 999px; box-shadow: 0 3px 0 var(--rojo-osc); }

/* ---------------------------------------------------------------- JUEGO */
#p-juego { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; }
.hud {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 8px 12px;
  background: linear-gradient(#5A331A, #4E2B15); color: var(--papel); border-bottom: 4px solid #2E1D10;
}
.hud-titulo { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hud-juego { font-family: var(--f-titulo); font-weight: 400; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-nivel { font-size: .88rem; color: #FFD35C; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-datos { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.hud-dato { background: rgba(0,0,0,.28); border-radius: 10px; padding: 2px 10px; font-weight: 700; font-size: .95rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

.escenario { position: relative; flex: 1 1 auto; min-height: 200px; display: flex; align-items: center; justify-content: center; background: #2E1C10; overflow: hidden; }
.escena { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.bocadillo {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: min(640px, calc(100% - 24px));
  background: var(--papel); border: 3px solid #5A331A; border-radius: 18px; padding: 8px 16px; box-shadow: 0 5px 0 rgba(46,29,16,.5);
  font-weight: 700; font-size: clamp(.95rem, 2.4vw, 1.08rem); text-align: center; z-index: 3; animation: aparecer .25s ease-out;
}
.bocadillo::after { content: ""; position: absolute; bottom: -13px; left: var(--cola, 50%); border: 10px solid transparent; border-top-color: #5A331A; border-bottom: 0; transform: translateX(-50%); }
.bocadillo p { margin: 0; }
.bocadillo .bc-quien { color: var(--rojo); }
.bocadillo .bc-botones { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.bocadillo .btn { min-height: 44px; font-size: .95rem; }
@keyframes aparecer { from { opacity: 0; transform: translate(-50%, -8px) scale(.97); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
.titulo-reto {
  position: absolute; left: 12px; bottom: 10px; z-index: 2; background: rgba(46,29,16,.82); color: var(--papel);
  padding: 3px 12px; border-radius: 10px; font-weight: 800; font-size: .9rem; pointer-events: none; max-width: 60%;
}
.fulcro-mando { position: absolute; right: 10px; bottom: 10px; z-index: 3; display: flex; align-items: center; gap: 8px; background: rgba(46,29,16,.85); color: var(--papel); padding: 6px 8px; border-radius: 14px; font-weight: 800; font-size: .92rem; }
.banner-victoria {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%); z-index: 4; text-align: center; pointer-events: none;
  animation: banner .6s cubic-bezier(.2, 1.6, .4, 1);
}
.bv-titulo { margin: 0; font-family: var(--f-titulo); font-size: clamp(1.5rem, 5.5vw, 2.8rem); color: #FFD35C; -webkit-text-stroke: 2px var(--rojo-osc); text-shadow: 0 4px 0 var(--rojo-osc), 0 10px 20px rgba(0,0,0,.35); white-space: nowrap; }
.bv-sub { margin: 4px 0 0; display: inline-block; background: var(--papel); border: 3px solid #5A331A; border-radius: 12px; padding: 2px 14px; font-weight: 800; }
@keyframes banner { from { transform: translateX(-50%) scale(.3); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.panel-vision {
  background: #1B2240; color: #E8ECFF; padding: 8px 12px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: start;
  font-size: .95rem; border-top: 3px solid #0E1330; font-variant-numeric: tabular-nums;
}
.pv-lado h4 { margin: 0 0 2px; font-size: .85rem; color: #9FB0FF; font-weight: 800; }
.pv-lado ul { list-style: none; margin: 0; padding: 0; }
.pv-lado li { white-space: nowrap; }
.pv-lado .pv-total { font-weight: 800; color: #FFE37A; border-top: 1px dashed #4A5694; margin-top: 2px; padding-top: 2px; }
.pv-der { text-align: right; }
.pv-centro { text-align: center; font-weight: 800; padding: 0 6px; }
.pv-centro .pv-neto { font-size: 1.15rem; color: #FFE37A; }
.pv-centro .pv-formula { font-size: .82rem; color: #9FB0FF; font-weight: 700; }

.zona-abajo { background: linear-gradient(#6E3F1F, #4E2B15); border-top: 4px solid #2E1D10; padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
.inventario { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; min-height: 10px; }
.inventario:empty { display: none; }
.obj-btn {
  position: relative; width: 92px; height: 88px; border-radius: 16px; border: 3px solid #B98A52; background: var(--papel);
  box-shadow: 0 5px 0 #7B4826; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 4px 4px 3px;
  touch-action: none; transition: transform .1s, box-shadow .1s;
}
.obj-btn .mini { width: 62px; height: 52px; flex: 1; filter: drop-shadow(0 3px 0 rgba(0,0,0,.18)); transition: transform .15s; }
.obj-btn:hover .mini { transform: translateY(-3px) rotate(-4deg); }
.obj-btn .obj-kg { font-weight: 800; font-size: .88rem; line-height: 1; }
.obj-btn .obj-n { position: absolute; top: -9px; right: -9px; min-width: 28px; height: 28px; border-radius: 999px; background: var(--rojo); color: #fff; font-weight: 800; font-size: .9rem; display: grid; place-items: center; border: 2px solid #fff; }
.obj-btn[aria-pressed="true"] { border-color: var(--oro); background: #FFF1C4; box-shadow: 0 5px 0 var(--oro-osc), 0 0 0 5px rgba(242,184,58,.45); transform: translateY(-3px); }
.obj-btn[aria-pressed="true"] .mini { animation: bote .7s ease-in-out infinite; }
.obj-btn.gastado { opacity: .35; }
@keyframes bote { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.ayuda-obj { margin: 6px 0 2px; text-align: center; color: #F4DDB6; font-size: .88rem; }
.controles { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }

.segmentos { display: inline-flex; flex-wrap: wrap; gap: 4px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 14px; }
.seg { min-height: 42px; border: 0; border-radius: 10px; padding: 0 14px; background: transparent; color: var(--papel); font-weight: 800; }
.seg[aria-pressed="true"] { background: var(--papel); color: var(--tinta); box-shadow: 0 3px 0 #B98A52; }

/* ---------------------------------------------------------------- ESCENA SVG */
.marca-num { font: 800 15px var(--f-texto); fill: #3A2414; }
.regla-num { fill: #FFF8E7; font-size: 16px; paint-order: stroke; stroke: #3A2414; stroke-width: 4px; }
.nube { animation: nube 40s linear infinite alternate; }
.nube.n2 { animation-duration: 55s; }
.nube.n3 { animation-duration: 48s; animation-direction: alternate-reverse; }
@keyframes nube { from { translate: -30px 0; } to { translate: 40px 0; } }
.farol { animation: farol 4s ease-in-out infinite; transform-box: view-box; transform-origin: 0 0; }
.farol.f2 { animation-delay: -2s; }
@keyframes farol { 0%, 100% { rotate: -2.5deg; } 50% { rotate: 2.5deg; } }
.bandera { animation: bandera 3s ease-in-out infinite; transform-origin: 3px 12px; transform-box: view-box; }
@keyframes bandera { 0%, 100% { transform: skewY(0deg); } 50% { transform: skewY(3deg); } }
.petalo { animation: petalo 9s linear infinite; }
@keyframes petalo {
  0% { transform: translate(0, 0) rotate(0); opacity: 0; }
  8% { opacity: .9; }
  100% { transform: translate(-160px, 580px) rotate(540deg); opacity: .2; }
}
.soporte { transition: transform .55s cubic-bezier(.5, -0.3, .7, 1), opacity .5s; }
.soportes-fuera .soporte { transform: translateY(240px); opacity: 0; }

/* Maestro: estados */
.maestro .o-alerta, .maestro .o-panico, .maestro .o-feliz, .maestro .b-alerta, .maestro .b-panico, .maestro .b-feliz, .maestro .m-sudor, .maestro .c-alerta { display: none; }
.maestro.m-alerta .o-calma, .maestro.m-panico .o-calma, .maestro.m-feliz .o-calma { display: none; }
.maestro.m-alerta .b-calma, .maestro.m-panico .b-calma, .maestro.m-feliz .b-calma { display: none; }
.maestro.m-alerta .o-alerta, .maestro.m-alerta .b-alerta, .maestro.m-alerta .m-sudor, .maestro.m-alerta .c-alerta { display: inline; }
.maestro.m-panico .o-panico, .maestro.m-panico .b-panico, .maestro.m-panico .m-sudor, .maestro.m-panico .c-alerta { display: inline; }
.maestro.m-alerta .c-calma, .maestro.m-panico .c-calma { display: none; }
.maestro.m-feliz .o-feliz, .maestro.m-feliz .b-feliz { display: inline; }
.maestro .m-aura { opacity: 0; transition: opacity .5s; transform-origin: 0 430px; transform-box: view-box; }
.maestro.m-calma .m-aura, .maestro.m-feliz .m-aura { opacity: 1; animation: respira 3.2s ease-in-out infinite; }
.maestro .m-chispas { opacity: 0; transition: opacity .4s; }
.maestro.m-calma .m-chispas, .maestro.m-feliz .m-chispas { opacity: 1; animation: chispas 2.4s ease-in-out infinite; }
@keyframes respira { 0%, 100% { scale: .94; } 50% { scale: 1.06; } }
@keyframes chispas { 0%, 100% { translate: 0 0; opacity: .3; } 50% { translate: 0 -12px; opacity: 1; } }
.maestro .m-cuerpo { transform-origin: 0 520px; transform-box: view-box; }
.maestro.m-calma .m-cuerpo { animation: respiracion 3.2s ease-in-out infinite; }
@keyframes respiracion { 0%, 100% { scale: 1 1; } 50% { scale: 1.012 1.02; } }
.maestro .m-brazos-medita, .maestro .m-almohadilla { display: none; }
.maestro.m-cabeza .m-brazos-arriba { display: none; }
.maestro.m-cabeza .m-brazos-medita, .maestro.m-cabeza .m-almohadilla { display: inline; }
.maestro .m-bi { transform-origin: -48px 458px; transform-box: view-box; }
.maestro .m-bd { transform-origin: 48px 458px; transform-box: view-box; }
.maestro.m-alerta .m-bi { animation: brazoI .5s ease-in-out infinite; }
.maestro.m-alerta .m-bd { animation: brazoD .5s ease-in-out infinite; }
.maestro.m-panico .m-bi { animation: aspaI .28s ease-in-out infinite; }
.maestro.m-panico .m-bd { animation: aspaD .28s ease-in-out infinite; }
@keyframes brazoI { 50% { rotate: -6deg; } }
@keyframes brazoD { 50% { rotate: 6deg; } }
@keyframes aspaI { 0%, 100% { rotate: -4deg; } 50% { rotate: -22deg; } }
@keyframes aspaD { 0%, 100% { rotate: 4deg; } 50% { rotate: 22deg; } }
.maestro.m-cabeza.m-panico .m-bi { animation: aspaI2 .28s ease-in-out infinite; }
.maestro.m-cabeza.m-panico .m-bd { animation: aspaD2 .28s ease-in-out infinite; }
@keyframes aspaI2 { 0%, 100% { rotate: 20deg; } 50% { rotate: 70deg; } }
@keyframes aspaD2 { 0%, 100% { rotate: -20deg; } 50% { rotate: -70deg; } }
.maestro .m-cabeza-g { transform-origin: 0 450px; transform-box: view-box; transition: rotate .3s; }
.maestro.m-panico .m-cabeza-g { animation: tiembla .12s linear infinite; }
@keyframes tiembla { 0%, 100% { translate: -1.5px 0; } 50% { translate: 1.5px 0; } }
.maestro.reverencia .m-cabeza-g { animation: reverencia 1.3s ease-in-out 1; }
@keyframes reverencia { 0%, 100% { rotate: 0deg; } 35%, 65% { rotate: 0deg; translate: 0 12px; scale: 1 .96; } }
.maestro .m-cinta { transform-origin: 44px 390px; transform-box: view-box; animation: cinta 1.6s ease-in-out infinite; }
@keyframes cinta { 0%, 100% { rotate: 0deg; } 50% { rotate: 8deg; } }
.maestro { transition: transform .5s cubic-bezier(.3, 1.3, .5, 1); }

/* Objetos en la barra */
.pieza { cursor: grab; }
.pieza.fija { cursor: not-allowed; }
.pieza .candado { pointer-events: none; }
.pieza.seleccionada use { filter: drop-shadow(0 0 6px #FFD35C) drop-shadow(0 0 3px #FFD35C); }
.pieza.recien { animation: caerEn .35s cubic-bezier(.3, 1.6, .5, 1); transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes caerEn { from { translate: 0 -40px; scale: 1.1 .9; } to { translate: 0 0; scale: 1 1; } }
.cae { transition: transform 1s cubic-bezier(.45, 0, .8, .5); }
.hueco { fill: transparent; }
.hueco-marca { fill: none; stroke: #FFD35C; stroke-width: 4; stroke-dasharray: 8 6; opacity: 0; transition: opacity .2s; pointer-events: none; }
.mostrar-huecos .hueco-marca { opacity: .95; animation: girar 6s linear infinite; }
.hueco-marca.cerca { stroke: #fff; stroke-width: 6; opacity: 1; }
@keyframes girar { to { stroke-dashoffset: -140; } }
.hueco-obligado { fill: #FFD35C; opacity: .25; }
.hueco-g:focus-visible .hueco-marca { opacity: 1; stroke: #fff; }
.hueco-g:focus { outline: none; }
.fantasma { pointer-events: none; opacity: .92; }
.maestro-arrastrable { cursor: ew-resize; }

/* Visión Ninja */
.vision-flecha { stroke-linecap: round; }
.v-etq { font: 800 15px var(--f-texto); paint-order: stroke; stroke-width: 4px; stroke-linejoin: round; }
.v-masa { fill: #fff; stroke: #B0201A; }
.v-dist { fill: #1B2240; stroke: #fff; }
.v-torque { fill: #FFE37A; stroke: #1B2240; font-size: 14px; }
.v-poder-txt { font: 800 16px var(--f-texto); fill: #fff; paint-order: stroke; stroke: #1B2240; stroke-width: 4px; }

/* Partículas */
.estrella-p { animation: estrellaP 1.2s ease-out forwards; transform-box: fill-box; transform-origin: center; }
@keyframes estrellaP { from { opacity: 1; scale: .3; } 60% { opacity: 1; } to { opacity: 0; scale: 1.3; translate: var(--dx) var(--dy); rotate: 180deg; } }
.sacudida { animation: sacudida .45s ease-out; }
@keyframes sacudida { 20% { translate: -8px 3px; } 40% { translate: 7px -2px; } 60% { translate: -4px 1px; } 80% { translate: 2px 0; } }

/* ---------------------------------------------------------------- FIN */
#p-fin { text-align: center; color: var(--papel); }
.fin-cartel { margin-top: 10px; }
.fin-cartel h2 { margin: 0; font-family: var(--f-titulo); font-weight: 400; font-size: clamp(1.7rem, 6vw, 2.6rem); color: #FFD35C; -webkit-text-stroke: 1.5px var(--rojo-osc); text-shadow: 0 4px 0 var(--rojo-osc); }
.fin-sub { font-size: 1.15rem; font-weight: 700; margin: 6px 0; }
.fin-estrellas { font-size: 3rem; letter-spacing: 8px; color: #6E5A44; }
.fin-estrellas .on { color: var(--oro); text-shadow: 0 3px 0 var(--oro-osc); display: inline-block; animation: estrellaFin .5s cubic-bezier(.2, 1.8, .4, 1) backwards; }
.fin-estrellas .on:nth-child(2) { animation-delay: .2s; }
.fin-estrellas .on:nth-child(3) { animation-delay: .4s; }
@keyframes estrellaFin { from { scale: 0; rotate: -90deg; } }
.fin-datos { list-style: none; padding: 16px 18px; margin: 10px auto; max-width: 420px; background: var(--papel); color: var(--tinta); border-radius: 20px; border: 4px solid #B98A52; box-shadow: 0 6px 0 #7B4826; text-align: left; display: grid; gap: 4px; font-size: 1.05rem; }
.fin-datos .fin-puntos { font-size: 1.35rem; border-top: 2px dashed #D5B27C; padding-top: 6px; margin-top: 4px; }
.fin-mult { margin: 4px 0; color: #FFD35C; font-weight: 700; }
.fin-frase { margin: 14px auto; max-width: 520px; font-size: 1.15rem; font-weight: 700; font-style: italic; color: #FBE6C2; }
.fin-frase::before { content: "🥷 "; font-style: normal; }
.fin-guardado { min-height: 1.4em; font-weight: 700; }
.fin-botones { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }

/* ---------------------------------------------------------------- RANKING */
.rk-filtros { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; margin-bottom: 12px; }
.rk-tabla { background: var(--papel); border-radius: 20px; border: 4px solid #B98A52; box-shadow: 0 6px 0 #7B4826; overflow: hidden; }
.rk-cabecera, .rk-fila { display: grid; grid-template-columns: 64px 1fr 110px 100px; gap: 8px; padding: 8px 14px; align-items: center; }
.rk-cabecera { background: #5A331A; color: var(--papel); font-weight: 800; font-size: .9rem; }
.rk-lista { list-style: none; margin: 0; padding: 0; }
.rk-fila { border-bottom: 1px solid #EAD9B8; font-weight: 700; }
.rk-fila:nth-child(odd) { background: #FFF3DA; }
.rk-fila.yo { background: #FFE9A6; }
.rk-pos { font-family: var(--f-titulo); font-size: 1.1rem; }
.rk-nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-pts { text-align: right; font-variant-numeric: tabular-nums; }
.rk-estado { margin: 0; padding: 14px; text-align: center; font-weight: 700; }
.rk-estado:empty { display: none; }
@media (max-width: 520px) {
  .rk-cabecera, .rk-fila { grid-template-columns: 44px 1fr 72px; }
  .rk-cabecera span:nth-child(3), .rk-fila .rk-niv { display: none; }
}

/* ---------------------------------------------------------------- OPCIONES */
.opciones-lista { list-style: none; margin: 0; padding: 0; background: var(--papel); border-radius: 20px; border: 4px solid #B98A52; box-shadow: 0 6px 0 #7B4826; }
.opciones-lista li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid #EAD9B8; }
.opciones-lista li:last-child { border: 0; }
.opciones-lista small { display: block; color: #6B5A48; }
.interruptor { width: 64px; height: 36px; border-radius: 999px; border: 3px solid #B98A52; background: #D8CBB4; position: relative; flex: none; }
.interruptor::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 0 rgba(0,0,0,.2); transition: left .15s; }
.interruptor[aria-checked="true"] { background: var(--verde); border-color: var(--verde-osc); }
.interruptor[aria-checked="true"]::after { left: 31px; }

/* ---------------------------------------------------------------- MODAL / TOAST */
.capa { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(20, 12, 6, .6); animation: fundido .2s; }
@keyframes fundido { from { opacity: 0; } }
.modal-caja { width: min(480px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--papel); border-radius: 22px; border: 4px solid #B98A52; box-shadow: 0 8px 0 #7B4826; padding: 20px; text-align: center; animation: aparecerModal .3s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes aparecerModal { from { scale: .85; opacity: 0; } }
.modal-caja h2 { margin: 0 0 8px; font-family: var(--f-titulo); font-weight: 400; font-size: 1.4rem; }
.modal-caja p { margin: 6px 0; }
.modal-icono { font-size: 3rem; margin: 0; }
.modal-datos { list-style: none; padding: 10px 14px; margin: 10px 0; background: #FFF3DA; border-radius: 14px; text-align: left; display: grid; gap: 2px; font-weight: 700; }
.modal-leccion { background: #EAF6EE; border: 2px solid #9FD4B2; border-radius: 12px; padding: 8px 10px; font-weight: 700; }
.opciones-misterio { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.opciones-misterio .btn { min-width: 76px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 30px); z-index: 60; background: var(--indigo-osc); color: #fff; padding: 10px 18px; border-radius: 14px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center; }
.toast.ver { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- RESPONSIVE */
/* Etiquetas de la escena más grandes cuando la balanza se ve pequeña */
.escena.pequena .marca-num { font-size: 19px; }
.escena.pequena .regla-num { font-size: 21px; }
.escena.pequena .v-etq { font-size: 22px; }
.escena.pequena .v-torque { font-size: 20px; }
.escena.pequena .v-poder-txt { font-size: 21px; }

/* Móvil en vertical */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .pantalla-lista { padding: 12px 12px 32px; }
  .barra-sup { grid-template-columns: auto 1fr; gap: 10px; }
  .barra-sup > span:empty { display: none; }
  .barra-apodo { grid-column: 1 / -1; }
  .lista-niveles { grid-template-columns: 1fr; gap: 12px; }
  .tarjeta-nivel { padding: 12px 14px; }
  .tn-nombre { font-size: 1.3rem; }
  .panel { padding: 20px 14px; }
  .panel h2 { font-size: 1.25rem; }
  .nick-fila input { font-size: 1.1rem; }

  .hud { grid-template-columns: auto 1fr; gap: 8px; padding: 6px 10px; }
  .hud-datos { grid-column: 1 / -1; justify-content: space-between; }
  #p-juego { height: auto; min-height: 100dvh; }
  .escenario { flex: 0 0 auto; flex-direction: column; justify-content: flex-start; background: #D9EEF0; min-height: 0; }
  .escena { height: auto; aspect-ratio: 890 / 560; }
  .bocadillo { position: relative; top: auto; left: auto; transform: none; width: auto; margin: 6px 8px 8px; align-self: stretch; animation: none; order: -1; padding: 6px 12px; }
  .bocadillo::after { display: none; }
  .titulo-reto { display: none; }
  .fulcro-mando { position: static; justify-content: center; margin: 4px auto 6px; }
  .banner-victoria { top: 30%; }
  .bv-titulo { font-size: 1.45rem; -webkit-text-stroke-width: 1px; }
  .bv-sub { font-size: .9rem; }
  .panel-vision { font-size: .8rem; gap: 6px; padding: 6px 10px; }
  .pv-lado li { white-space: normal; }
  .zona-abajo { flex: 1 0 auto; }
  .obj-btn { width: 74px; height: 74px; }
  .obj-btn .mini { width: 50px; height: 42px; }
  .controles { display: grid; grid-template-columns: 1fr 1fr; }
  .btn-liberar { grid-column: 1 / -1; order: -1; }
  #btn-reiniciar { grid-column: 1 / -1; }

  .fin-cartel h2 { font-size: 1.6rem; }
  .fin-estrellas { font-size: 2.4rem; }
  .fin-datos { font-size: 1rem; padding: 12px 14px; }
  .fin-botones { display: grid; grid-template-columns: 1fr 1fr; }
  .fin-botones .btn-grande { grid-column: 1 / -1; font-size: 1.1rem; min-height: 56px; }
  .fin-botones .btn:last-child { grid-column: 1 / -1; }
  .rk-filtros .segmentos { width: 100%; }
  .rk-filtros .seg { flex: 1 1 auto; padding: 0 8px; }
  .opciones-lista li { padding: 12px; }
  .modal-caja { padding: 16px 14px; }
  .modal-caja h2 { font-size: 1.2rem; }
  .modal-icono { font-size: 2.2rem; }
  #modal-botones .btn { flex: 1 1 auto; }
}

/* Tablet en vertical: la balanza ocupa su proporción y el resto queda para los controles */
@media (min-width: 641px) and (max-width: 1100px) and (orientation: portrait) {
  .lista-niveles { grid-template-columns: 1fr 1fr; }
  #p-juego { height: auto; min-height: 100dvh; }
  .escenario { flex: 0 0 auto; flex-direction: column; justify-content: flex-start; background: #D9EEF0; min-height: 0; }
  .escena { height: auto; aspect-ratio: 1000 / 620; }
  .bocadillo { position: relative; top: auto; left: auto; transform: none; width: auto; margin: 8px 12px; align-self: stretch; animation: none; order: -1; }
  .bocadillo::after { display: none; }
  .zona-abajo { flex: 1 0 auto; padding-top: 14px; }
  .obj-btn { width: 104px; height: 98px; }
  .obj-btn .mini { width: 72px; height: 60px; }
  .btn-control, .btn-liberar { min-height: 60px; font-size: 1.1rem; }
}

/* Móvil en horizontal: balanza a la izquierda, objetos y botones a la derecha */
@media (max-height: 560px) and (orientation: landscape) {
  #p-juego { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 34%); grid-template-rows: auto minmax(0, 1fr) auto; height: 100vh; height: 100dvh; }
  .hud { grid-column: 1 / -1; padding: 4px 10px; }
  .hud .btn-hud { min-height: 36px; }
  .hud .btn-hud.btn-cuadrado { width: 36px; }
  .hud-juego { font-size: .95rem; }
  .escenario { grid-column: 1; grid-row: 2; }
  .panel-vision { grid-column: 1; grid-row: 3; font-size: .78rem; padding: 4px 10px; max-height: 30vh; overflow: auto; }
  .zona-abajo { grid-column: 2; grid-row: 2 / 4; overflow: auto; border-top: 0; border-left: 4px solid #2E1D10; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
  .inventario { gap: 8px; }
  .obj-btn { width: 66px; height: 66px; border-radius: 12px; }
  .obj-btn .mini { width: 44px; height: 36px; }
  .ayuda-obj { display: none; }
  .controles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0; }
  .btn-control { min-height: 42px; font-size: .88rem; }
  .btn-liberar { grid-column: 1 / -1; order: -1; min-height: 50px; font-size: 1rem; }
  #btn-reiniciar { grid-column: 1 / -1; }
  .bocadillo { top: 6px; padding: 4px 12px; font-size: .88rem; width: min(560px, calc(100% - 16px)); }
  .titulo-reto { display: none; }
  .fulcro-mando { bottom: 6px; right: 6px; padding: 4px 6px; font-size: .8rem; }
  .banner-victoria { top: 22%; }
  .bv-titulo { font-size: 1.6rem; }
  .modal-caja { padding: 12px 16px; }
  .modal-icono { font-size: 1.8rem; }
  .modal-datos { grid-template-columns: 1fr 1fr; }
  .lista-niveles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .inicio-contenido { padding-top: 6px; }
  .titulo-juego { font-size: 2.3rem; -webkit-text-stroke-width: 1.5px; }
  .lema { font-size: 1rem; margin-top: 4px; }
  .escena-inicio { width: min(330px, 50%); border-width: 4px; }
  .inicio-botones { margin-top: 10px; gap: 8px; }
  .logo-playlab { width: 110px; }
}

/* Menos animaciones */
.calma *, .calma *::before, .calma *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
.calma #petalos, .calma .m-chispas { display: none; }
@media (prefers-reduced-motion: reduce) {
  .petalo, .nube, .farol, .bandera { animation: none !important; }
}
