/* ───────── Modo táctil (móvil / tablet) ───────── */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.touch-mode { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch-mode #viewport-3d { touch-action: none; }

#touch-ui { position: fixed; top: 0; left: env(safe-area-inset-left); right: env(safe-area-inset-right); bottom: env(safe-area-inset-bottom); z-index: 800; pointer-events: none; font-family: inherit; }
#touch-ui.off { display: none; }
#touch-ui .hidden { display: none !important; }
.tc-zone { position: absolute; left: 0; top: 18%; width: 46%; bottom: 0; pointer-events: auto; touch-action: none; }

.tc-stick { position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.10), rgba(255,255,255,.04) 70%); border: 2px solid rgba(255,255,255,.28);
  pointer-events: none; touch-action: none; }
.tc-stick .tc-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.75), rgba(180,200,255,.35)); border: 2px solid rgba(255,255,255,.55); }
.tc-aim { margin: 0; right: 22px; bottom: 22px; width: 132px; height: 132px; pointer-events: auto;
  background: radial-gradient(circle, rgba(255,120,80,.18), rgba(255,80,60,.06) 70%); border-color: rgba(255,150,110,.55); }
.tc-aim > span { position: absolute; left: 0; right: 0; bottom: -17px; text-align: center; font-size: 10px; letter-spacing: 1.5px; color: rgba(255,200,170,.85); }

.tc-btn { position: absolute; width: 58px; height: 58px; border-radius: 50%; pointer-events: auto; touch-action: none;
  font-weight: 800; font-size: 20px; color: #fff; background: rgba(20,24,40,.62); border: 2px solid rgba(255,255,255,.4);
  box-shadow: 0 2px 10px rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 0; overflow: hidden; }
.tc-ic { display: flex; align-items: center; justify-content: center; width: 72%; height: 72%; line-height: 0; pointer-events: none; }
.tc-ic svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.tc-btn small { font-size: 8px; letter-spacing: .5px; margin-top: -2px; opacity: .85; pointer-events: none; }
.tc-btn i { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-style: normal; font-size: 14px; font-weight: 900; color: #ffd36a; background: rgba(2,6,23,.68); border-radius: 50%; pointer-events: none; }
.tc-btn.cooling i:not(:empty) { display: flex; }
.tc-btn.down { background: rgba(255,200,90,.45); border-color: #ffd36a; transform: scale(.94); }
.tc-btn.cooling { opacity: .55; }
.tc-btn.no-resource { filter: grayscale(.75) brightness(.72); border-color: rgba(248,113,113,.65); }
.tc-btn.combo-proc { border-color: #fbbf24; background: rgba(245,158,11,.32); }
.tc-btn.ward-on { border-color: #38bdf8; background: rgba(56,189,248,.32); }
.tc-btn.charge-active { border-color: #38bdf8; background: rgba(14,165,233,.45); transform: scale(1.06); }
/* disposición alrededor del joystick derecho */
.tc-q { right: 168px; bottom: 30px; }
.tc-e { right: 152px; bottom: 98px; }
.tc-r { right: 98px; bottom: 152px; }
.tc-f { right: 30px; bottom: 168px; }
.tc-dash { right: 218px; bottom: 98px; width: 50px; height: 50px; font-size: 18px; }
/* acciones rápidas */
.tc-charge { right: 232px; bottom: 28px; width: 56px; height: 56px; border-color: rgba(120,190,255,.7); }
.tc-use { left: 20px; bottom: 28px; width: 62px; height: 62px; font-size: 22px; border-color: rgba(255,210,90,.9); }
.tc-heal { right: 166px; bottom: 162px; width: 48px; height: 48px; border-color: rgba(255,120,140,.7); }
.tc-sh { right: 214px; bottom: 158px; width: 48px; height: 48px; font-size: 18px; border-color: rgba(120,220,255,.8); }
.tc-pause { left: 10px; top: calc(8px + env(safe-area-inset-top)); width: 44px; height: 44px; font-size: 16px; opacity: .88; }
.tc-bag { left: 62px; top: calc(8px + env(safe-area-inset-top)); width: 44px; height: 44px; font-size: 18px; opacity: .88; }
.tc-map { left: 114px; top: calc(8px + env(safe-area-inset-top)); width: 44px; height: 44px; font-size: 18px; opacity: .88; }
.tc-rotate { display: none; }

#touch-ui.portrait .tc-zone, #touch-ui.portrait .tc-stick, #touch-ui.portrait .tc-btn { display: none; }
#touch-ui.portrait .tc-rotate { display: block; position: fixed; inset: 0; z-index: 9900; background: rgba(5,6,12,.92); color: #fff; font-size: 20px; text-align: center; padding-top: 40vh; pointer-events: auto; }

/* HUD compacto en móvil: las habilidades pasan a los botones táctiles */
body.touch-mode #btn-open-ingame-menu { display: none !important; }
body.touch-mode #hud-killfeed { top: calc(56px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); max-width: 190px; font-size: 10px; }
body.touch-mode .tm-top.ffa { position: fixed; top: calc(6px + env(safe-area-inset-top)); left: 62px; right: 178px; transform: none; width: auto; max-width: none; padding: 4px 8px; gap: 6px; font-size: 11px; justify-content: space-between; }
body.touch-mode .tm-top.ffa > span:first-child, body.touch-mode .tm-top.ffa .ffa-h { display: none; }
body.touch-mode .ffa-board { top: calc(6px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); width: 162px; max-height: 106px; overflow: hidden; padding: 4px 6px; font-size: 10px; scrollbar-width: none; }
body.touch-mode .ffa-board .ffa-bh, body.touch-mode .ffa-board .ffa-br { grid-template-columns: 16px minmax(56px, 1fr) 22px 30px; gap: 3px; }
body.touch-mode #bottom-hud { left: 42%; bottom: calc(8px + env(safe-area-inset-bottom)); transform: translateX(-50%) scale(.66); transform-origin: bottom center; pointer-events: none; }
body.touch-mode #bottom-hud .skill-slot, body.touch-mode .keycap, body.touch-mode .keycap-row { display: none !important; }
body.touch-mode #network-status-banner { font-size: 11px; }
body.touch-mode #arena-enemy-frame { transform: scale(.8); transform-origin: top right; }
/* menús y ventanas desplazables en pantallas pequeñas */
@media (max-width: 900px), (max-height: 560px) {
  .modal-backdrop { padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .modal-card, .mode-select-grid, .mm-wrap, .game-menu-screen { max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .mm-btn, .btn-ui, .btn-launch-mode, select, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) { min-height: 44px; font-size: 16px; }
}
@media (max-height: 520px) {
  .tc-btn { width: 50px; height: 50px; font-size: 17px; }
  .tc-q { right: 146px; bottom: 20px; } .tc-e { right: 132px; bottom: 78px; } .tc-r { right: 86px; bottom: 126px; } .tc-f { right: 26px; bottom: 142px; }
  .tc-aim { width: 114px; height: 114px; right: 18px; bottom: 18px; }
  .tc-dash { right: 192px; bottom: 80px; width: 46px; height: 46px; }
  .tc-charge { right: 206px; bottom: 20px; width: 48px; height: 48px; }
  .tc-heal { right: 144px; bottom: 136px; width: 44px; height: 44px; }
  .tc-sh { right: 202px; bottom: 136px; width: 44px; height: 44px; font-size: 17px; }
  .tc-pause, .tc-bag, .tc-map { width: 44px; height: 44px; }
}

/* Apuntado arrastrando una habilidad */
.tc-sk { width: 138px; height: 138px; margin: -69px 0 0 -69px; background: radial-gradient(circle, rgba(250,204,21,.22), rgba(250,204,21,.05) 70%); border-color: rgba(250,204,21,.7); box-shadow: 0 0 18px rgba(250,204,21,.25); }
.tc-sk .tc-knob { background: radial-gradient(circle at 35% 30%, #fff6c8, rgba(250,204,21,.55)); border-color: rgba(255,240,170,.9); }

/* Zonas seguras (notch / esquinas redondeadas / barra de inicio) y altura real de pantalla en móviles */
html, body { height: 100%; min-height: -webkit-fill-available; }
body.touch-mode #top-bar { top: calc(8px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); right: calc(10px + env(safe-area-inset-right)); }
@media (max-height: 420px) { body.touch-mode #bottom-hud { transform: translateX(-50%) scale(.58); } }
#dungeon-minimap.tc-mm-big { position: fixed !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; z-index: 880 !important; background: rgba(8,6,15,.95); padding: 10px; border-radius: 12px; border: 2px solid #6d28d9; pointer-events: auto !important; }
#dungeon-minimap.tc-mm-big #dungeon-minimap-canvas { width: min(72vh, 280px) !important; height: min(72vh, 280px) !important; }
.tc-mm-x { display: none; position: absolute; top: 6px; right: 6px; width: 42px; height: 42px; border-radius: 50%; border: 2px solid #cbd5e1; background: rgba(15,23,42,.95); color: #fff; font-size: 18px; font-weight: 800; cursor: pointer; z-index: 5; }
#dungeon-minimap.tc-mm-big .tc-mm-x { display: grid; place-items: center; }

/* ── Cripta en móvil: panel y minimapa compactos (antes tapaban los botones) y aviso del jefe más pequeño ── */
body.touch-mode #dungeon-status-panel { min-width: 0 !important; padding: 4px 6px !important; gap: 1px !important; }
body.touch-mode #dungeon-status-panel > div { font-size: 9px !important; }
body.touch-mode #dungeon-status-panel span { font-size: 9px !important; }
body.touch-mode #dungeon-minimap-canvas { width: 76px !important; height: 76px !important; margin: 0 auto; }
body.touch-mode #dungeon-status-panel > div:nth-child(4) { display: none !important; }
body.touch-mode #dungeon-status-panel > div { white-space: nowrap; }
body.touch-mode #dungeon-minimap > div { display: none !important; }
body.touch-mode #dungeon-boss-frame { transform: scale(.6); transform-origin: top center; max-width: 520px; }
body.touch-mode #dungeon-boss-frame > div:last-child { display: none; }

/* ── Cripta/arena móvil: etiqueta ATACAR visible, badge corto, minimapa pequeño ── */
body.touch-mode .tc-aim > span { bottom: -13px; font-size: 9px; }
body.touch-mode .tc-aim { bottom: calc(26px + env(safe-area-inset-bottom)); }
body.touch-mode .ingame-mode-badge { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
body.touch-mode #w-prompt kbd, body.touch-mode .keycap, body.touch-mode .skill-key-badge, body.touch-mode .w-slot .ky { display: none !important; }
body.touch-mode .tc-btn small { font-size: 8px; max-width: 54px; overflow: hidden; white-space: nowrap; }
.tc-btn, .tc-stick, .tc-zone { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }

/* Rendimiento móvil: los filtros de desenfoque y las mezclas sobre el canvas WebGL cuestan muchísimo en GPUs de gama baja */
body.touch-mode *, body.touch-mode *::before, body.touch-mode *::after { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; mix-blend-mode: normal !important; }
body.touch-mode [style*="blur("], body.touch-mode .vignette, body.touch-mode #vignette, body.touch-mode .overhead-unit-bars, body.touch-mode .skill-slot.combo-proc::after { filter: none !important; }
body.touch-mode .hp-fill, body.touch-mode .hp-ghost { transition: none !important; }
body.touch-mode .status-icons i, body.touch-mode .skill-slot.combo-proc { animation: none !important; }

/* ════════ Móvil: interfaz más limpia (menos elementos y más transparencia) ════════ */
/* botones de habilidad: solo icono (el nombre sobra; se aprende y se ve en el cooldown) */
body.touch-mode .tc-btn:not(.tc-use):not(.tc-charge) small { display: none; }
body.touch-mode .tc-btn { background: rgba(20,24,40,.45); border-width: 1.5px; }
body.touch-mode .tc-btn.cooling { opacity: .45; }
body.touch-mode .tc-stick { opacity: .75; }
/* textos flotantes: más pequeños y sin los avisos de habilidades ajenas */
body.touch-mode .floating-combat-text:not(.fct) { font-size: 12px !important; letter-spacing: 0; opacity: .92; }
body.touch-mode .floating-combat-text.big-crit:not(.fct) { font-size: 14px !important; }
body.touch-mode .fct.other { display: none; }
/* Cripta: aviso del jefe pequeño, insignia fuera y panel mínimo (solo minimapa + cierre) */
body.touch-mode .ingame-mode-badge { display: none; }
body.touch-mode #dungeon-boss-frame { transform: scale(.5); }
body.touch-mode #dungeon-status-panel > div:nth-child(n+2) { font-size: 8px !important; }
body.touch-mode #dungeon-status-panel > div:nth-child(3) { display: none !important; }
/* modo calma: lo que no es vital se atenúa si llevas unos segundos sin combatir */
body.touch-mode #dungeon-status-panel, body.touch-mode #w-risk, body.touch-mode #w-quest, body.touch-mode #w-track, body.touch-mode #w-threat,
body.touch-mode #w-feed, body.touch-mode #w-btn-players, body.touch-mode .emo-btn, body.touch-mode #emo-btn, body.touch-mode #arena-enemy-frame { transition: opacity .6s; }
body.touch-mode.hud-calm #dungeon-status-panel, body.touch-mode.hud-calm #w-risk, body.touch-mode.hud-calm #w-quest, body.touch-mode.hud-calm #w-track,
body.touch-mode.hud-calm #w-threat, body.touch-mode.hud-calm #w-feed, body.touch-mode.hud-calm #w-btn-players, body.touch-mode.hud-calm .emo-btn,
body.touch-mode.hud-calm #emo-btn { opacity: .38; }
body.touch-mode.hud-calm .tc-btn:not(.tc-use) { opacity: .6; }
