/* =========================================================================
   Juanito el Fruterito · estilo.css
   Idea visual: etiquetas antiguas de cajas de fruta + madera de huerto.
   ========================================================================= */
@font-face { font-family: "Lilita One"; src: url("../assets/fonts/lilita-one-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Fredoka"; src: url("../assets/fonts/fredoka-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Fredoka"; src: url("../assets/fonts/fredoka-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Fredoka"; src: url("../assets/fonts/fredoka-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --tinta: #3a2214;
  --madera: #b5743a;
  --madera-clara: #e2a96a;
  --madera-osc: #6b3f17;
  --crema: #fff6dc;
  --crema-2: #f6e6bd;
  --tomate: #e8432e;
  --tomate-osc: #a92816;
  --hoja: #3f9d3a;
  --hoja-osc: #24671f;
  --sol: #ffd23a;
  --cielo: #5fc0f2;
  --display: "Lilita One", "Fredoka", "Arial Rounded MT Bold", system-ui, sans-serif;
  --texto: "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radio: 18px;
  --sombra-boton: 0 5px 0 var(--madera-osc);
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--texto); font-weight: 500; color: var(--tinta);
  background:
    radial-gradient(ellipse 60% 22% at 20% 78%, #86c662 98%, transparent 100%),
    radial-gradient(ellipse 70% 25% at 85% 80%, #9fd47a 98%, transparent 100%),
    linear-gradient(transparent 70%, #6db548 70%, #5aa63a),
    repeating-conic-gradient(from 0deg at 50% 38%, rgba(255,255,255,.16) 0 7.5deg, transparent 7.5deg 15deg),
    radial-gradient(circle at 50% 38%, #fff3b0, #a9e0fb 45%, #5fc0f2 80%);
  background-attachment: fixed;
  overflow: hidden; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
img { max-width: 100%; }
:focus-visible { outline: 4px solid var(--sol); outline-offset: 3px; }
[hidden] { display: none !important; }

#app { position: relative; height: 100%; width: 100%; }
.pantalla { position: absolute; inset: 0; display: none; flex-direction: column; }
.pantalla.activa { display: flex; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 48px; padding: .55em 1.2em; border: 3px solid var(--madera-osc); border-radius: 16px;
  font-family: var(--display); font-size: 1.15rem; letter-spacing: .01em; line-height: 1.1;
  box-shadow: var(--sombra-boton); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--madera-osc); }
.btn-grande { font-size: 1.55rem; min-height: 60px; padding: .55em 1.6em; }
.btn-tomate { background: linear-gradient(#ff6a4f, var(--tomate)); color: #fff; text-shadow: 0 2px 0 var(--tomate-osc); }
.btn-hoja { background: linear-gradient(#5cc455, var(--hoja)); color: #fff; text-shadow: 0 2px 0 var(--hoja-osc); }
.btn-crema { background: var(--crema); }
.btn-madera { background: linear-gradient(var(--madera-clara), var(--madera)); color: #fff; text-shadow: 0 2px 0 var(--madera-osc); }
.btn-toggle[aria-pressed="false"] { opacity: .55; text-decoration: line-through; }
.btn-icono {
  width: 44px; height: 44px; display: inline-grid; place-items: center; flex: none;
  border: 3px solid var(--madera-osc); border-radius: 14px; background: var(--crema);
  font-size: 1.25rem; line-height: 1; box-shadow: 0 3px 0 var(--madera-osc);
}
.btn-icono:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--madera-osc); }
.btn-icono[aria-pressed="false"] { opacity: .5; }
.enlace { background: none; border: 0; padding: 0; text-decoration: underline; font-weight: 600; }

/* ---------- Inicio ---------- */
#p-inicio { align-items: center; overflow-y: auto; overflow-x: hidden; }
.inicio-fondo { display: none; }
.inicio-cab { width: 100%; display: flex; justify-content: center; padding: 10px 16px 0; }
.logo-playlab { width: clamp(120px, 22vw, 190px); height: auto; filter: drop-shadow(0 4px 0 rgba(58,34,20,.25)); }
.inicio-cuerpo { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 4px 16px 24px; width: min(560px, 100%); }
.etiqueta-caja {
  position: relative; text-align: center; padding: 18px 26px 16px; margin-top: 4px;
  background: var(--crema); border: 4px solid var(--madera-osc); border-radius: 26px 26px 18px 18px;
  box-shadow: inset 0 0 0 5px var(--crema), inset 0 0 0 8px var(--tomate), 0 8px 0 rgba(58,34,20,.3);
  transform: rotate(-1.5deg);
}
.etiqueta-caja::before, .etiqueta-caja::after {
  content: ""; position: absolute; top: 50%; width: 26px; height: 40px; background: var(--hoja);
  border: 3px solid var(--hoja-osc); border-radius: 0 60% 0 60%; transform: translateY(-50%) rotate(-20deg);
}
.etiqueta-caja::before { left: -18px; }
.etiqueta-caja::after { right: -18px; transform: translateY(-50%) rotate(70deg); }
.titulo { margin: 0; font-family: var(--display); font-weight: 400; line-height: .9; }
.t-juanito {
  display: block; font-size: clamp(3rem, 12vw, 5.2rem); color: var(--tomate); letter-spacing: .01em;
  -webkit-text-stroke: 3px var(--tinta); paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--tinta);
}
.t-fruterito {
  display: inline-block; margin-top: 6px; font-size: clamp(1.5rem, 6vw, 2.4rem); color: #fff;
  background: var(--hoja); padding: 2px 16px 4px; border-radius: 10px; border: 3px solid var(--hoja-osc);
  text-shadow: 0 2px 0 var(--hoja-osc); transform: rotate(1.5deg);
}
.lema { margin: 10px 0 0; font-weight: 600; font-size: 1.02rem; }
.portada-juanito { width: min(300px, 70vw); height: auto; margin: -6px 0 -14px; }
.menu { display: flex; flex-direction: column; align-items: stretch; gap: 12px; width: min(380px, 100%); }
.menu-fila { display: flex; gap: 10px; }
.menu-fila .btn { flex: 1; font-size: 1.05rem; padding-inline: .6em; }
.saludo { margin: 2px 0 0; font-weight: 600; background: rgba(255,246,220,.8); padding: 6px 14px; border-radius: 99px; }
.inicio-sonido { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }

/* ---------- HUD ---------- */
#p-juego { background: transparent; }
.hud {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background:
    repeating-linear-gradient(0deg, rgba(107,63,23,.12) 0 2px, transparent 2px 9px),
    linear-gradient(#cf8e4c, var(--madera));
  border-bottom: 4px solid var(--madera-osc); box-shadow: 0 4px 0 rgba(58,34,20,.25);
}
.hud-marca { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 1.25rem; color: var(--crema); text-shadow: 0 2px 0 var(--madera-osc); white-space: nowrap; }
.hud-manzana { font-size: 1.5rem; }
.hud-datos { display: flex; gap: 8px; margin: 0 auto; }
.dato {
  display: flex; flex-direction: column; align-items: center; min-width: 78px; padding: 3px 12px 4px;
  background: var(--crema); border: 3px solid var(--madera-osc); border-radius: 12px;
}
.dato dt { font-size: .68rem; font-weight: 700; letter-spacing: .04em; color: var(--madera-osc); }
.dato dd { margin: 0; font-family: var(--display); font-size: 1.35rem; line-height: 1.05; font-variant-numeric: tabular-nums; }
.dato dd.salto { animation: salto .35s ease-out; }
@keyframes salto { 40% { transform: scale(1.25); color: var(--tomate); } }
.hud-botones { display: flex; gap: 6px; }
.escena { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; }
#lienzo { display: block; position: absolute; inset: 0; touch-action: none; cursor: crosshair; }

/* ---------- Capas y paneles ---------- */
.capa {
  position: fixed; inset: 0; z-index: 20; display: none; place-items: center; padding: 16px;
  background: rgba(40,24,10,.45); overflow-y: auto;
}
.capa.abierta { display: grid; animation: aparecer .18s ease-out; }
@keyframes aparecer { from { opacity: 0; } }
.panel {
  position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--crema); border: 4px solid var(--madera-osc); border-radius: 24px;
  box-shadow: inset 0 0 0 6px var(--crema), inset 0 0 0 9px var(--madera-clara), 0 10px 0 rgba(58,34,20,.35);
  padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.capa.abierta .panel { animation: rebote .32s cubic-bezier(.3,1.6,.5,1); }
@keyframes rebote { from { transform: scale(.8) translateY(20px); } }
.panel-chico { width: min(420px, 100%); }
.panel h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 1.9rem; color: var(--tomate); -webkit-text-stroke: 1.5px var(--tinta); paint-order: stroke fill; }
.nota { margin: 0; font-size: .95rem; }
.error { margin: 0; min-height: 1.2em; color: var(--tomate-osc); font-weight: 600; }

.apodo-fila { display: flex; gap: 8px; }
#apodo-input {
  flex: 1; min-width: 0; height: 52px; padding: 0 14px; font: 600 1.3rem var(--texto); color: var(--tinta);
  border: 3px solid var(--madera-osc); border-radius: 14px; background: #fff; -webkit-user-select: text; user-select: text;
}
.apodo-fila .btn-icono { width: 52px; height: 52px; }

.pasos { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; text-align: left; }
.pasos li { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid var(--crema-2); border-radius: 14px; padding: 8px 12px; }
.paso-ico { font-size: 1.6rem; }
.especiales { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; text-align: left; }
.especial { display: flex; gap: 10px; align-items: center; background: #fff; border-radius: 14px; padding: 6px 10px; border: 2px dashed var(--madera-clara); font-size: .9rem; }
.especial img { width: 44px; height: 44px; flex: none; }
.especial.bloqueada { opacity: .55; }

.panel-nivel .nivel-num { margin: 0; font-family: var(--display); font-size: 1.1rem; color: var(--hoja); }
.consejo { margin: 0; font-size: 1.05rem; font-weight: 600; background: #fff; border-radius: 14px; padding: 10px 12px; border: 2px solid var(--crema-2); }
.fruta-nueva { display: flex; gap: 12px; align-items: center; text-align: left; background: linear-gradient(#fff7c7, #ffe98a); border: 3px solid var(--sol); border-radius: 16px; padding: 8px 12px; animation: brillo 1.4s ease-in-out infinite; }
.fruta-nueva img { flex: none; animation: girito 2s ease-in-out infinite; }
.fruta-nueva p { margin: 0; }
.fruta-nueva-tit { font-family: var(--display); font-size: 1.1rem; color: var(--tomate); }
@keyframes brillo { 50% { box-shadow: 0 0 0 5px rgba(255,210,58,.35); } }
@keyframes girito { 50% { transform: rotate(10deg) scale(1.08); } }
.nivel-datos { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-weight: 600; }

.logo-pausa { width: 150px; height: auto; margin: -6px auto 0; }
.pausa-botones { display: flex; flex-direction: column; gap: 10px; }

.res-emoji { margin: 0; font-size: 3rem; line-height: 1; }
.res-sub { margin: 0; font-weight: 600; }
.estrellas { display: flex; justify-content: center; gap: 6px; font-size: 2.2rem; }
.estrellas span { filter: grayscale(1) opacity(.35); }
.estrellas span.ganada { filter: none; animation: estrella .5s cubic-bezier(.3,1.8,.5,1) both; animation-delay: var(--d); }
@keyframes estrella { from { transform: scale(0) rotate(-90deg); } }
.res-tabla { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; text-align: left; background: #fff; border-radius: 14px; padding: 10px 14px; border: 2px solid var(--crema-2); }
.res-tabla dt { font-weight: 600; }
.res-tabla dd { margin: 0; font-family: var(--display); font-size: 1.15rem; text-align: right; font-variant-numeric: tabular-nums; }
.res-tabla .total { font-size: 1.5rem; color: var(--tomate); }
.res-guardado { margin: 0; font-weight: 600; min-height: 1.3em; }
.res-guardado.ok { color: var(--hoja-osc); }
.res-guardado.aviso { color: var(--tomate-osc); }
.res-botones { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Ranking ---------- */
#p-ranking { align-items: center; justify-content: center; padding: 16px; }
.panel-ranking { width: min(520px, 100%); max-height: calc(100dvh - 32px); }
.panel-cab { display: flex; align-items: center; gap: 10px; }
.panel-cab h2 { flex: 1; font-size: 1.7rem; }
.logo-mini { width: 66px; height: auto; }
.pestanas { display: flex; gap: 6px; background: var(--crema-2); padding: 5px; border-radius: 14px; }
.pestana { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 8px 4px; font-weight: 700; min-height: 40px; }
.pestana.activa { background: #fff; box-shadow: 0 2px 0 var(--madera-clara); color: var(--tomate); }
.ranking-lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; min-height: 120px; overflow-y: auto; }
.ranking-lista li {
  display: grid; grid-template-columns: 2.4em 1fr auto auto; align-items: center; gap: 10px;
  background: #fff; border: 2px solid var(--crema-2); border-radius: 12px; padding: 7px 12px; text-align: left;
}
.ranking-lista li.yo { border-color: var(--sol); background: #fffbe6; }
.rk-pos { font-family: var(--display); font-size: 1.2rem; text-align: center; }
.rk-nick { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-nivel { font-size: .82rem; color: var(--madera-osc); white-space: nowrap; }
.rk-puntos { font-family: var(--display); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.ranking-vacio { padding: 20px; font-weight: 600; }
.ranking-pie { margin: 0; font-size: .85rem; color: var(--madera-osc); }

.rotar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .hud-titulo { display: none; }
}
@media (max-width: 560px) {
  .hud { gap: 6px; padding: 6px 8px; }
  .hud-manzana { display: none; }
  .hud-marca { display: none; }
  .hud-datos { gap: 4px; margin: 0; flex: 1; }
  .dato { min-width: 0; flex: 1; padding: 2px 4px 3px; border-width: 2px; border-radius: 10px; }
  .dato dt { font-size: .6rem; }
  .dato dd { font-size: 1.05rem; }
  .hud-botones { gap: 4px; }
  .hud-botones .btn-icono { width: 36px; height: 36px; font-size: 1rem; border-radius: 11px; border-width: 2px; }
  .panel { padding: 18px 16px 16px; }
  .panel h2 { font-size: 1.6rem; }
}
@media (max-width: 360px) {
  .hud-botones [data-accion="musica"], .hud-botones [data-accion="sonido"] { display: none; }
}
@media (max-height: 640px) and (min-width: 561px) {
  .portada-juanito { width: 200px; }
  .logo-playlab { width: 120px; }
}
@media (orientation: landscape) and (max-height: 480px) {
  .rotar {
    display: block; position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 30; margin: 0;
    background: var(--crema); border: 3px solid var(--madera-osc); border-radius: 99px; padding: 6px 14px; font-weight: 600; font-size: .85rem;
    animation: fuera 0s 5s forwards; pointer-events: none;
  }
  @keyframes fuera { to { visibility: hidden; } }
  .portada-juanito { display: none; }
  .hud { padding-block: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
.res-guardado:empty { display: none; }
