/* ── MODO CELULAR (celular horizontal) ─────────────────────────────────────────
   Se carga al final. Solo actúa con body.mobile-mode y pantallas bajas.
   Arregla: el top-bar estaba oculto (no se veían puntos/alitas/etc.), el texto de los
   botones laterales se salía de su caja, y los iconos de los botones de la derecha se
   montaban encima del texto. Orden y piezas del HUD:
     arriba-izq: estadísticas en una fila · arriba-der: perfil + DIARIO/MISIONES
     abajo-izq: botones laterales · abajo-der: menú (iconos a la izquierda, texto a la derecha) */
@media screen and (max-height:520px){

  /* ---- TOP BAR: visible y compacto ---- */
  body.mobile-mode #top-bar{display:flex;align-items:flex-start;gap:6px;}
  body.mobile-mode #top-bar>div:first-child{display:flex;flex-wrap:wrap;align-items:flex-start;gap:3px;flex:1 1 auto;min-width:0;
    max-width:calc(100vw - 150px - env(safe-area-inset-left) - env(safe-area-inset-right));}
  body.mobile-mode .stat-card{flex-direction:row;align-items:center;gap:4px;min-width:0;margin:0;padding:2px 6px 2px 4px;border-left-width:3px;}
  body.mobile-mode .stat-card:not(.stat-pink) .stat-label span{display:none;}   /* solo icono + número */
  body.mobile-mode .stat-card .stat-label{font-size:7px;}
  body.mobile-mode .stat-card .icon-small{width:12px;height:12px;margin:0;}
  body.mobile-mode .stat-card span{font-size:9px;margin-top:0;}
  /* multiplicador: fila propia DEBAJO de las divisas (label · barra de frenesí · CPS) */
  body.mobile-mode .stat-pink{flex:0 0 100%;max-width:230px;flex-direction:row;align-items:center;gap:8px;padding:2px 8px 2px 6px;}
  body.mobile-mode .stat-pink #frenzy-container{flex:1;min-width:36px;margin:0;height:4px;}
  body.mobile-mode .stat-pink>div:last-child{margin:0!important;line-height:1;white-space:nowrap;}
  body.mobile-mode .stat-pink span{font-size:7px;}

  body.mobile-mode .user-section{flex:0 0 auto;gap:4px;}
  body.mobile-mode .user-card{height:34px;padding:2px 7px;gap:6px;border-width:1px;min-width:0;}
  body.mobile-mode #user-avatar{width:26px;height:26px;}
  body.mobile-mode .user-card>div{min-width:0!important;max-width:84px;}
  body.mobile-mode #user-name-display{font-size:9px!important;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
  body.mobile-mode #user-level-display{font-size:7px!important;}
  body.mobile-mode #user-title,body.mobile-mode #user-prestitle{display:none!important;}

  /* ---- DIARIO / MISIONES: debajo del perfil, chicos ---- */
  body.mobile-mode #daily-badge,body.mobile-mode #missions-badge{padding:3px 7px;font-size:8px;min-width:78px;gap:4px;border-width:1px;border-radius:7px;}
  body.mobile-mode #daily-badge img,body.mobile-mode #missions-badge img{width:11px;height:11px;}
  body.mobile-mode #daily-badge{top:calc(42px + env(safe-area-inset-top));}
  body.mobile-mode #missions-badge{top:calc(66px + env(safe-area-inset-top));}

  /* ---- BOTONES LATERALES (izquierda): el texto cabe y se recorta con "…" ---- */
  body.mobile-mode .left-controls{gap:2px;}
  body.mobile-mode .sidebar-btn,body.mobile-mode #streak-badge{min-width:74px;width:74px;padding:3px 4px;font-size:7px;line-height:1.15;overflow:hidden;}
  body.mobile-mode .sidebar-btn>div:first-child{gap:3px!important;min-width:0;max-width:100%;}
  body.mobile-mode .sidebar-btn>div:first-child span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
  body.mobile-mode .sidebar-btn img{width:11px!important;height:11px!important;flex-shrink:0;}
  body.mobile-mode .sidebar-btn>div:not(:first-child):not(#tree-progress){font-size:7px!important;margin-top:1px!important;}
  body.mobile-mode #tree-timer-label{font-size:7px!important;}
  body.mobile-mode #tree-progress{margin-top:2px;height:2px;}

  /* ---- MENÚ DE LA DERECHA: icono en una franja a la izquierda, texto legible a la derecha ---- */
  body.mobile-mode .controls{gap:3px;}
  body.mobile-mode .controls .s-btn.btn-layered{width:96px;min-width:96px;height:26px;padding:0;font-size:7px;letter-spacing:0;}
  body.mobile-mode .controls .btn-icon-layer{left:0;top:0;transform:none;width:26px;height:100%;object-fit:contain;object-position:center top;padding:2px;}
  body.mobile-mode .controls .btn-text-layer{width:100%;min-width:0;padding:0 4px 0 28px;justify-content:flex-start;-webkit-text-stroke:.4px #000;
    text-shadow:0 1px 2px #000,0 0 3px #000;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block;line-height:26px;}

  /* ---- ESCENA: el contenedor mide exactamente la pantalla, así los personajes quedan pegados al piso
     (antes el contenedor medía 460 px en una pantalla de ~390 y los pies se cortaban) ---- */
  body.mobile-mode #main-container{width:100vw;height:100vh;height:100dvh;max-width:100vw;}
  body.mobile-mode .char-container{width:auto;bottom:calc(8vh + env(safe-area-inset-bottom));}   /* un poco más arriba del piso */
  body.mobile-mode .char-container .char-img{width:auto;height:clamp(84px,34vh,140px);max-width:30vw;object-fit:contain;object-position:bottom;}
  /* los personajes se pegan al vaso (centro de la pantalla), uno a cada lado, no a los bordes */
  body.mobile-mode #char-left{left:auto;right:calc(50% + clamp(75px,21vh,105px) + 6px);}    /* 21vh = mitad del ancho del vaso */
  body.mobile-mode #char-right{right:auto;left:calc(50% + clamp(75px,21vh,105px) + 6px);}
  body.mobile-mode #cup-wrapper{width:clamp(150px,42vh,210px);}   /* vaso más grande */
}

/* pantallas todavía más bajas (≤ 360 px de alto) */
@media screen and (max-height:360px){
  body.mobile-mode .sidebar-btn,body.mobile-mode #streak-badge{min-width:68px;width:68px;font-size:6.5px;padding:2px 3px;}
  body.mobile-mode .controls .s-btn.btn-layered{width:88px;min-width:88px;height:23px;font-size:6.5px;}
  body.mobile-mode .controls .btn-icon-layer{width:23px;}
  body.mobile-mode .controls .btn-text-layer{padding-left:25px;line-height:23px;}
  body.mobile-mode .stat-card span{font-size:8px;}
  body.mobile-mode .char-container .char-img{height:clamp(70px,32vh,110px);}
}

/* ═══════════════════════════════════════════════════════════════════════════
   SECCIONES / VENTANAS EN CELULAR HORIZONTAL
   Idea: que cada ventana quepa COMPLETA en ~390 px de alto sin depender de una barra de scroll:
   cabeceras bajas, letra y espacios menores, y listas en 2+ columnas para aprovechar el ancho.
   (Si algo aún no cabe, el scroll queda DENTRO de la ventana, nunca se corta.)
   Solo con body.mobile-mode y pantallas bajas. Los !important son a propósito: ganan a reglas #id y a overflow:hidden.
   ═══════════════════════════════════════════════════════════════════════════ */
@media screen and (max-height:520px){

  /* ---- ventana genérica ---- */
  body.mobile-mode .modal{align-items:center;padding:4px 0;padding-top:calc(4px + env(safe-area-inset-top));padding-bottom:calc(4px + env(safe-area-inset-bottom));
    padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right);}
  body.mobile-mode .modal-content{width:min(96vw,760px);padding:10px 14px;border-radius:14px;border-width:1px;
    max-height:calc(100dvh - 8px - env(safe-area-inset-top) - env(safe-area-inset-bottom))!important;overflow-y:auto!important;}
  body.mobile-mode .modal-content h2{font-size:15px;margin:0 0 6px;}
  body.mobile-mode .modal-content h3{font-size:12px;margin:4px 0;}
  body.mobile-mode .modal-content p{margin:4px 0;}
  body.mobile-mode .tabs{gap:3px;margin-bottom:8px;}
  body.mobile-mode .tab-btn{padding:6px 5px;font-size:8px;min-width:0;}
  body.mobile-mode .input-field{padding:7px 10px;font-size:12px;margin-top:6px;}
  body.mobile-mode .section-title{margin:8px 0 5px;}
  /* botón CERRAR: bajo y siempre a la vista (pegado al borde inferior de la ventana) */
  body.mobile-mode .modal-content .close-btn{position:sticky;bottom:0;z-index:7;margin-top:8px;padding:8px;font-size:10px;box-shadow:0 -6px 8px rgba(0,0,0,.45);}
  body.mobile-mode :is(#shop-modal,#inv-modal) .close-btn{width:calc(100% - 24px);margin:6px 12px 8px;padding:7px;}

  /* ---- listas: varias columnas en vez de una larguísima ---- */
  body.mobile-mode :is(div,section):has(>.item-row),
  body.mobile-mode :is(div,section):has(>.mission-row),
  body.mobile-mode :is(div,section):has(>.ranking-card),
  body.mobile-mode :is(div,section):has(>.friend-card),
  body.mobile-mode :is(div,section):has(>.lootbox-card),
  body.mobile-mode :is(div,section):has(>.sauce-upgrade-card),
  body.mobile-mode :is(div,section):has(>.gift-option){display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;align-items:stretch;}
  body.mobile-mode :is(.item-row,.mission-row,.ranking-card,.friend-card,.lootbox-card,.sauce-upgrade-card,.gift-option){margin:0;padding:8px 10px;min-width:0;}
  body.mobile-mode .ranking-card,body.mobile-mode .friend-card{gap:8px;}
  body.mobile-mode .friend-avatar{width:44px;height:44px;}
  body.mobile-mode .rank-avatar{width:34px;height:34px;}
  body.mobile-mode .rank-badge{width:28px;height:28px;font-size:12px;}
  body.mobile-mode .lootbox-img{width:46px;height:46px;}
  body.mobile-mode .stats-grid{grid-template-columns:repeat(4,1fr);gap:5px;}
  body.mobile-mode .stat-box{padding:6px 8px;}
  body.mobile-mode .stat-box-value{font-size:13px;}
  body.mobile-mode .daily-reward-grid{gap:5px;margin:8px 0;}
  body.mobile-mode .daily-cell{padding:5px 3px;}
  body.mobile-mode .daily-cell img{width:22px;height:22px;margin-bottom:2px;}
  body.mobile-mode .rank-tabs{margin-bottom:8px;}
  body.mobile-mode .prestige-banner{padding:10px;margin-bottom:8px;}
  body.mobile-mode :is(.prestige-info-box,.prestige-next-box,.prestige-warn-box,.code-hint-box,.media-section,.tree-stage-card,.tree-info-panel,.tree-stages-panel,.level-profile-banner){padding:8px 10px;margin:6px 0;}
  body.mobile-mode .spin-wheel-wrap{width:150px;height:150px;margin-bottom:10px;}
  body.mobile-mode .toggle-wrap{padding:7px 12px;}
  body.mobile-mode .tr-cases{max-height:none;}
  body.mobile-mode .tr-shelf{grid-template-columns:repeat(6,1fr);}

  /* ---- TIENDA ---- */
  body.mobile-mode #shop-modal .modal-content{border-width:3px;}
  body.mobile-mode .sh-top{padding:6px 12px 6px;border-bottom-width:3px;}
  body.mobile-mode .sh-sign h2{font-size:15px;letter-spacing:2px;}
  body.mobile-mode .sh-sub{display:none;}
  body.mobile-mode .sh-wallet{margin:4px 0;gap:4px;}
  body.mobile-mode .sh-coin{padding:2px 7px;font-size:10px;}
  body.mobile-mode .sh-nav{gap:5px;margin-top:0;}
  body.mobile-mode :is(.sh-back,.sh-pill){padding:4px 9px;font-size:8px;}
  body.mobile-mode .sh-where{font-size:9px;}
  body.mobile-mode #shop-modal .sh-tabs .tab-btn{padding:4px 9px;font-size:8px;}
  body.mobile-mode .sh-body{padding:8px 12px 2px;}
  body.mobile-mode .sh-restock{margin:0 0 8px;padding:3px 8px;font-size:9px;}
  body.mobile-mode .sh-note,body.mobile-mode .sh-strip{margin-bottom:6px;padding:5px 10px;}
  body.mobile-mode .sh-aisle{grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px 6px;}
  body.mobile-mode .sh-product{padding:8px 6px 6px;gap:3px;}
  body.mobile-mode .sh-name{font-size:11px;}
  body.mobile-mode .sh-desc{font-size:9px;}
  body.mobile-mode :is(.sh-can,.sh-pbm,.sh-btl,.sh-gls,.sh-jug,.sh-bag,.sh-cup,.sh-poster,.sh-bottle,.sh-crate-pic,.mini-crate,.mini-bag,.mini-poster,.mini-ticket){zoom:.72;}
  body.mobile-mode .sh-rail{padding:5px 6px;}
  body.mobile-mode .sh-buy{padding:5px 9px;font-size:9px;}
  body.mobile-mode .sh-price{padding:3px 7px 3px 14px;}
  body.mobile-mode .sh-map{grid-template-columns:repeat(4,1fr);gap:28px 8px;padding:22px 4px 10px;}
  body.mobile-mode .sh-sign-card{padding:8px 6px;gap:3px;}
  body.mobile-mode .sg-name{font-size:12px;}
  body.mobile-mode .sg-sample{zoom:.7;height:96px;}
  body.mobile-mode .sh-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;}
  body.mobile-mode :is(.sh-row,.sh-crate){flex-wrap:wrap;padding:8px;gap:8px;}
  body.mobile-mode .sh-rail--side{flex-direction:row;width:100%;min-width:0;align-items:center;justify-content:space-between;padding:5px 8px;}
  body.mobile-mode .sh-rail--side .sh-buy{width:auto;}

  /* ---- INVENTARIO / SÓTANO ---- */
  body.mobile-mode .ws-top{padding:8px 12px 6px;border-bottom-width:3px;}
  body.mobile-mode .ws-title-row h2{font-size:14px;letter-spacing:2px;}
  body.mobile-mode .ws-title-row svg{width:18px;height:18px;}
  body.mobile-mode .ws-sub{display:none;}
  body.mobile-mode .ws-tabs{gap:4px;}
  body.mobile-mode .ws-tabs .tab-btn{min-width:0;padding:5px 5px 5px 15px;font-size:8px;}
  body.mobile-mode .ws-body{padding:8px 12px;}
  body.mobile-mode .ws-shelf{grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:12px 8px;}
  body.mobile-mode .ws-card{padding:12px 8px 8px;gap:6px;}
  body.mobile-mode :is(.ws-jar,.ws-portrait){zoom:.8;}
  body.mobile-mode .ws-search{margin-bottom:8px;padding:6px 10px;}
  body.mobile-mode .ws-btn{padding:5px 7px;}

  /* ---- AMIGOS (SnakeBook) ---- */
  body.mobile-mode #friends-modal .modal-content.cb{width:min(98vw,960px);height:calc(100dvh - 8px - env(safe-area-inset-top) - env(safe-area-inset-bottom));padding:0;}
  body.mobile-mode .cb-nav{height:36px;gap:8px;padding:0 8px;}
  body.mobile-mode .cb-logo{font-size:15px;}
  body.mobile-mode .cb-logo-box{width:20px;height:20px;}
  body.mobile-mode .cb-tab{height:36px;min-width:48px;font-size:9px;}
  body.mobile-mode .cb-tab i{font-size:13px;}
  body.mobile-mode .cb-body{grid-template-columns:160px minmax(0,1fr);gap:8px;padding:8px;}
  body.mobile-mode .cb-box{padding:8px 10px;}
  body.mobile-mode .cb-box-title{padding-bottom:5px;margin-bottom:5px;}
  body.mobile-mode .cb-ava.xl{width:76px;height:76px;font-size:30px;}
  body.mobile-mode .cb-ava.lg{width:42px;height:42px;font-size:18px;}
  body.mobile-mode .cb-input{height:28px;margin-bottom:5px;}
  body.mobile-mode .cb-btn{height:26px;padding:0 9px;}

  /* ---- DESAFÍOS (campamento) y GRANJA: no se recortan (overflow:hidden) y se compactan ---- */
  body.mobile-mode #challenges-modal .modal-content.camp-card{width:min(760px,96vw);overflow-y:auto!important;border-width:3px;}
  body.mobile-mode #berry-tree-modal .modal-content.farm-card{width:min(760px,96vw);overflow-y:auto!important;border-width:3px;}
  body.mobile-mode .cp-head{height:70px;}
  body.mobile-mode :is(.cp-tree,.cp-tent,.cp-fire,.cp-bunk,.cp-moon){display:none;}
  body.mobile-mode .cp-sign::before,body.mobile-mode .cp-sign::after{display:none;}
  body.mobile-mode .cp-sign{top:10px;padding:4px 18px 6px;}
  body.mobile-mode .cp-sign span{font-size:16px;}
  body.mobile-mode .cp-x{width:26px;height:26px;top:8px;right:8px;}
  body.mobile-mode .cp-body{padding:8px 12px 10px;}
  body.mobile-mode .cp-motto{margin-bottom:6px;font-size:11px;}
  body.mobile-mode .cp-count{margin-bottom:8px;}
  body.mobile-mode .cp-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;}
  body.mobile-mode .cp-badge{padding:7px 8px;gap:8px;border-radius:10px;}
  body.mobile-mode .cp-patch{flex:0 0 40px;width:40px;height:40px;}
  body.mobile-mode .cp-patch-ico{width:30px;height:30px;}
  body.mobile-mode .cp-patch-ico img{width:20px;height:20px;}
  body.mobile-mode .cp-name{font-size:11px;}
  body.mobile-mode .cp-desc{font-size:9px;}
  body.mobile-mode .cp-go{padding:6px 10px;font-size:9px;}
  body.mobile-mode .cp-active{padding:8px;margin-bottom:8px;}
  body.mobile-mode .cp-ring{width:88px;height:88px;margin:6px auto;}
  body.mobile-mode .cp-ring-in b{font-size:22px;}
  body.mobile-mode .fm-sky{height:74px;}
  body.mobile-mode :is(.fm-barn,.fm-sun){display:none;}
  body.mobile-mode .fm-sign{top:10px;padding:5px 16px;}
  body.mobile-mode .fm-sign span{font-size:14px;}
  body.mobile-mode .fm-x{width:26px;height:26px;top:8px;right:8px;}
  body.mobile-mode .fm-field{padding:6px 12px 10px;}
  body.mobile-mode .fm-plot{zoom:.7;}
  body.mobile-mode .fm-stage-name{font-size:13px;margin:2px 0 6px;}
  body.mobile-mode .fm-tag{min-width:72px;padding:4px 8px;}
  body.mobile-mode .fm-tag b{font-size:12px;}
  body.mobile-mode .fm-water{margin:8px auto 4px;}
  body.mobile-mode .fm-harvest{margin-top:8px;padding:8px 24px;}
  body.mobile-mode .fm-rows-wrap{padding:8px 12px 10px;}
  body.mobile-mode .fm-rows{gap:4px;}
  body.mobile-mode .fm-row{padding:6px 2px 5px;}
  body.mobile-mode .fm-row-ico{font-size:18px;}

  /* ---- EVENTOS (feria) y FRITOLANDIA ---- */
  body.mobile-mode :is(.fair-shell,.fry-shell){width:min(98vw,960px);height:calc(100dvh - 8px - env(safe-area-inset-top) - env(safe-area-inset-bottom));border-radius:12px;}
  body.mobile-mode .fair-lights{height:12px;flex-basis:12px;background-size:40px 12px,40px 12px;background-position:0 -4px,0 -4px;}
  body.mobile-mode .fry-shell::before{height:6px;}
  body.mobile-mode .fair-shell::after,body.mobile-mode .fry-shell::after{height:10px;}
  body.mobile-mode .fair-top{padding:3px 12px 0;}
  body.mobile-mode .fry-top{padding:8px 12px 2px;}
  body.mobile-mode :is(.fair-sign,.fry-sign){font-size:15px;padding:2px 10px 3px;letter-spacing:2px;border-width:2px;}
  body.mobile-mode :is(.fair-sign small,.fry-sign small){display:none;}
  body.mobile-mode .fair-wallet{padding:2px 9px;font-size:11px;}
  body.mobile-mode :is(.fair-x,.fry-x){width:26px;height:26px;font-size:12px;}
  body.mobile-mode :is(.fair-nav,.fry-nav){padding:2px 12px 4px;gap:6px;}
  body.mobile-mode :is(.fair-navbtn,.fry-navbtn){padding:4px 14px;font-size:9px;letter-spacing:1px;}
  body.mobile-mode :is(.fair-pane,.fry-pane){padding:2px 46px 16px;}
  body.mobile-mode :is(.fair-title,.fry-pane-title){margin:0 0 8px;font-size:12px;}
  body.mobile-mode :is(.fair-title small,.fry-pane-title small){margin-top:2px;}
  body.mobile-mode .fair-rides{gap:10px;padding:2px 0 6px;}
  body.mobile-mode .fair-booth{width:150px;padding:26px 8px 8px;gap:3px;}
  body.mobile-mode .fair-booth-ico{font-size:28px;}
  body.mobile-mode .fair-booth-name{font-size:11px;}
  body.mobile-mode .fair-booth-hint{min-height:0;font-size:9px;}
  body.mobile-mode .fair-booth-meta{font-size:9px;}
  body.mobile-mode .fair-arrow,body.mobile-mode .fry-arrow{width:30px;height:44px;font-size:18px;}
  body.mobile-mode .fry-cab{width:150px;}
  body.mobile-mode .fry-screen{width:112px;height:76px;}
  body.mobile-mode .fry-panel{width:112px;height:22px;}
  body.mobile-mode .fry-belle{flex-basis:150px;}
  body.mobile-mode .fry-belle-pic{width:130px;height:150px;}
  body.mobile-mode .fry-counter{gap:10px;}
  body.mobile-mode .fry-prize{padding:10px 5px 6px;}
  body.mobile-mode .fry-prize-ico{font-size:22px;}
  /* dentro de una atracción: si el juego no cabe, se desplaza dentro de la pantalla en vez de cortarse */
  body.mobile-mode :is(.fair-stage,.fry-stage){overflow:auto;align-items:flex-start;padding:4px 0;}
  body.mobile-mode :is(.fair-stage-box,.fry-stage-box){margin:0 auto;gap:6px;}
  body.mobile-mode .sg{height:min(300px,calc(100dvh - 96px));}
  body.mobile-mode .fair-play{min-height:0;}
  body.mobile-mode .fh{padding:6px;}
  body.mobile-mode .fh-track{height:min(280px,calc(100dvh - 110px));}
}
