html,
body {
  overscroll-behavior: none;
}

/* Siempre oculto en PC */
.mobile-hud,
.mobile-controls {
  display: none !important;
}

.mobile-hud {
  width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 0.35rem;
  padding: calc(0.35rem + env(safe-area-inset-top, 0)) 0.5rem 0.25rem;
  flex-shrink: 0;
  z-index: 20;
}

.mobile-stat {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.5rem;
  padding: 0.35rem 0.4rem;
  text-align: center;
}

.mobile-stat-label {
  display: block;
  font-size: 0.48rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.42);
  margin-bottom: 0.1rem;
}

.mobile-stat strong {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.mobile-controls {
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom, 0));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
  z-index: 20;
}

.mobile-controls-bar {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  max-width: 100%;
}

.mobile-controls-dual {
  gap: 0.55rem;
}

.pad-btn {
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  color: #f0f0f8;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}

.pad-btn:active,
.pad-btn.is-pressed {
  background: rgba(127, 255, 106, 0.28);
  border-color: rgba(127, 255, 106, 0.55);
  box-shadow: inset 0 0 10px rgba(127, 255, 106, 0.2);
}

.pad-btn.is-toggled {
  background: rgba(0, 219, 233, 0.25);
  border-color: rgba(0, 219, 233, 0.6);
  color: #fff;
}

.pad-dir {
  width: 52px;
  height: 52px;
  border-radius: 0.55rem;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mobile-dir-zone {
  flex-shrink: 0;
}

.mobile-dir-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.mobile-dir-row {
  display: flex;
  flex-direction: row;
  gap: 0.35rem;
}

.mobile-dir-cross {
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 0.3rem;
  width: 164px;
}

.mobile-dir-cross .pad-up { grid-column: 2; grid-row: 1; }
.mobile-dir-cross .pad-left { grid-column: 1; grid-row: 2; }
.mobile-dir-cross .pad-right { grid-column: 3; grid-row: 2; }
.mobile-dir-cross .pad-down { grid-column: 2; grid-row: 3; }

.mobile-diag {
  display: grid;
  grid-template-columns: 52px 52px;
  gap: 0.35rem;
  width: auto;
}

.mobile-diag .pad-dir {
  font-size: 0.82rem;
}

.mobile-player-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.mobile-action-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-shrink: 0;
  min-width: 72px;
}

.mobile-util-col {
  display: flex;
  flex-direction: row;
  gap: 0.35rem;
  flex-shrink: 0;
  align-items: center;
}

.mobile-btn-row {
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  flex-wrap: wrap;
}

.pad-fire,
.pad-action {
  min-height: 48px;
  min-width: 64px;
  padding: 0.45rem 0.75rem;
  border-radius: 0.6rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.pad-fire {
  width: auto;
  max-width: none;
  min-height: 52px;
  min-width: 72px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff6b4a, #cc3318);
  border-color: rgba(255, 120, 80, 0.6);
  color: #fff;
}

.pad-fire.is-pressed {
  background: linear-gradient(180deg, #ff8a6a, #dd4428);
}

.pad-util {
  width: 44px;
  height: 44px;
  min-height: 44px;
  min-width: 44px;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ── Solo celular real (clase puesta por JS) ── */
html.goian-mobile,
body.is-mobile {
  touch-action: manipulation;
}

html.goian-mobile #scale-viewport,
html.goian-mobile .app.mobile-shell,
body.is-mobile #scale-viewport,
body.is-mobile .app.mobile-shell {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  width: 100% !important;
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  padding: 0 !important;
}

html.goian-mobile #game-stage,
body.is-mobile #game-stage {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  width: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: hidden !important;
  transform: none !important;
}

html.goian-mobile #game-root,
body.is-mobile #game-root {
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0 !important;
  padding: 0.15rem !important;
  width: 100% !important;
  max-width: 100% !important;
}

html.goian-mobile .panel-left,
html.goian-mobile .panel-right,
html.goian-mobile aside.panel,
html.goian-mobile .sidebar,
body.is-mobile .panel-left,
body.is-mobile .panel-right,
body.is-mobile aside.panel,
body.is-mobile .sidebar {
  display: none !important;
}

html.goian-mobile .mobile-hud,
body.is-mobile .mobile-hud {
  display: grid !important;
}

html.goian-mobile .mobile-controls,
body.is-mobile .mobile-controls {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
}

html.goian-mobile .mobile-controls-bar,
body.is-mobile .mobile-controls-bar {
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: center !important;
}

html.goian-mobile .mobile-controls-dual,
body.is-mobile .mobile-controls-dual {
  gap: 0.45rem !important;
}

html.goian-mobile .pad-dir,
body.is-mobile .pad-dir {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

html.goian-mobile .pad-fire,
body.is-mobile .pad-fire {
  min-height: 48px;
  min-width: 68px;
  padding: 0.4rem 0.85rem;
}

html.goian-mobile .pad-util,
body.is-mobile .pad-util {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
}

html.goian-mobile.layout-only .mobile-controls,
body.is-mobile.layout-only .mobile-controls {
  display: none !important;
}

html.goian-mobile .board-frame,
html.goian-mobile .board-wrap,
body.is-mobile .board-frame,
body.is-mobile .board-wrap {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 auto !important;
}

html.goian-mobile .board-wrap canvas,
html.goian-mobile #board,
body.is-mobile .board-wrap canvas,
body.is-mobile #board {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
}

/* Falling Blocks: tamaños fijos del tablero (no estirar canvas) */
html.goian-mobile body.game-falling .board-frame,
html.goian-mobile body.falling-mobile-layout .board-frame,
html.goian-mobile body.game-falling .board-wrap,
html.goian-mobile body.falling-mobile-layout .board-wrap,
body.is-mobile.game-falling .board-frame,
body.is-mobile.falling-mobile-layout .board-frame,
body.is-mobile.game-falling .board-wrap,
body.is-mobile.falling-mobile-layout .board-wrap {
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
}

html.goian-mobile body.game-falling .board-wrap canvas,
html.goian-mobile body.game-falling #board,
html.goian-mobile body.falling-mobile-layout .board-wrap canvas,
html.goian-mobile body.falling-mobile-layout #board,
body.is-mobile.game-falling .board-wrap canvas,
body.is-mobile.game-falling #board,
body.is-mobile.falling-mobile-layout .board-wrap canvas,
body.is-mobile.falling-mobile-layout #board {
  width: 176px !important;
  height: 352px !important;
  max-width: 190px !important;
  min-width: 158px !important;
}

html.goian-mobile body.game-snake .board-wrap,
html.goian-mobile body.snake-mobile-layout .board-wrap,
body.is-mobile.game-snake .board-wrap,
body.is-mobile.snake-mobile-layout .board-wrap {
  width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  height: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  max-width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
}

html.goian-mobile body.game-snake .board-wrap canvas,
html.goian-mobile body.game-snake #board,
html.goian-mobile body.snake-mobile-layout .board-wrap canvas,
html.goian-mobile body.snake-mobile-layout #board,
body.is-mobile.game-snake .board-wrap canvas,
body.is-mobile.game-snake #board,
body.is-mobile.snake-mobile-layout .board-wrap canvas,
body.is-mobile.snake-mobile-layout #board {
  width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  height: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  max-width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
}

html.goian-mobile .controls-hint,
html.goian-mobile .hint-bar,
html.goian-mobile .hud-controls,
html.goian-mobile .stats-bar,
body.is-mobile .controls-hint,
body.is-mobile .hint-bar,
body.is-mobile .hud-controls,
body.is-mobile .stats-bar {
  display: none !important;
}

/* ── Salir de pantalla completa (dentro del juego / iframe) ── */
.mobile-exit-fs {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.4rem);
  right: 0.45rem;
  z-index: 40;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(8, 10, 18, 0.82);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

html.goian-fs-active .mobile-exit-fs,
html.goian-mobile-fullscreen .mobile-exit-fs {
  display: inline-flex !important;
}

/* ── Pantalla completa en móvil (solo juego directo, sin iframe) ── */
html.goian-mobile-fullscreen:not(.goian-fs-active),
html.goian-mobile-fullscreen:not(.goian-fs-active) body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

html.goian-mobile-fullscreen .goian-mobile-fullscreen-target,
html.goian-mobile-fullscreen #scale-viewport.goian-mobile-fullscreen-target,
html.goian-mobile-fullscreen .app.goian-mobile-fullscreen-target {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
  width: 100% !important;
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0 !important;
  background: #0a0818 !important;
}

html.goian-fs-active #scale-viewport,
html.goian-fs-active .app.mobile-shell {
  width: 100% !important;
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
}

:fullscreen #scale-viewport,
:fullscreen .app.mobile-shell,
:-webkit-full-screen #scale-viewport,
:-webkit-full-screen .app.mobile-shell {
  width: 100% !important;
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  display: flex !important;
  flex-direction: column !important;
  background: #0a0818 !important;
}

/* ── Juegos con panel lateral (Falling Blocks, Snake, …) ── */
html.goian-mobile body.falling-mobile-layout .board-frame,
html.goian-mobile body.falling-mobile-layout .board-wrap,
html.goian-mobile body.snake-mobile-layout .board-frame,
html.goian-mobile body.snake-mobile-layout .board-wrap,
body.is-mobile.falling-mobile-layout .board-frame,
body.is-mobile.falling-mobile-layout .board-wrap,
body.is-mobile.snake-mobile-layout .board-frame,
body.is-mobile.snake-mobile-layout .board-wrap {
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
}

html.goian-mobile body.falling-mobile-layout .board-wrap,
html.goian-mobile body.game-falling .board-wrap,
body.is-mobile.falling-mobile-layout .board-wrap,
body.is-mobile.game-falling .board-wrap {
  width: 176px !important;
  height: 352px !important;
  max-width: 190px !important;
  min-width: 158px !important;
}

html.goian-mobile body.falling-mobile-layout .board-wrap canvas,
html.goian-mobile body.falling-mobile-layout #board,
html.goian-mobile body.game-falling .board-wrap canvas,
html.goian-mobile body.game-falling #board,
body.is-mobile.falling-mobile-layout .board-wrap canvas,
body.is-mobile.falling-mobile-layout #board,
body.is-mobile.game-falling .board-wrap canvas,
body.is-mobile.game-falling #board {
  width: 176px !important;
  height: 352px !important;
  max-width: 190px !important;
  min-width: 158px !important;
}

html.goian-mobile body.falling-mobile-layout .board-wrap canvas,
html.goian-mobile body.falling-mobile-layout #board,
html.goian-mobile body.snake-mobile-layout .board-wrap canvas,
html.goian-mobile body.snake-mobile-layout #board,
html.goian-mobile body.game-snake .board-wrap canvas,
html.goian-mobile body.game-snake #board,
body.is-mobile.falling-mobile-layout .board-wrap canvas,
body.is-mobile.falling-mobile-layout #board,
body.is-mobile.snake-mobile-layout .board-wrap canvas,
body.is-mobile.snake-mobile-layout #board,
body.is-mobile.game-snake .board-wrap canvas,
body.is-mobile.game-snake #board {
  max-width: none !important;
}

/* ── Snake: controles bajo el tablero (respaldo si style.css en caché) ── */
html.goian-mobile body.game-snake #scale-viewport,
html.goian-mobile body.snake-mobile-layout #scale-viewport,
body.is-mobile.game-snake #scale-viewport,
body.is-mobile.snake-mobile-layout #scale-viewport {
  justify-content: flex-start !important;
  align-items: center !important;
}

html.goian-mobile body.game-snake #game-stage,
html.goian-mobile body.snake-mobile-layout #game-stage,
body.is-mobile.game-snake #game-stage,
body.is-mobile.snake-mobile-layout #game-stage {
  flex: 0 0 auto !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: flex-start !important;
  width: 100% !important;
}

html.goian-mobile body.game-snake #scale-viewport > .mobile-controls,
html.goian-mobile body.snake-mobile-layout #scale-viewport > .mobile-controls,
body.is-mobile.game-snake #scale-viewport > .mobile-controls,
body.is-mobile.snake-mobile-layout #scale-viewport > .mobile-controls {
  display: none !important;
}

html.goian-mobile body.game-snake #game-stage > .mobile-controls,
html.goian-mobile body.snake-mobile-layout #game-stage > .mobile-controls,
body.is-mobile.game-snake #game-stage > .mobile-controls,
body.is-mobile.snake-mobile-layout #game-stage > .mobile-controls {
  display: flex !important;
  flex-shrink: 0 !important;
  width: 100% !important;
  max-width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  margin: 0.4rem auto 0 !important;
  padding: 0.15rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0px)) !important;
  background: transparent !important;
  border-top: none !important;
}

html.goian-mobile body.game-snake .board-frame,
html.goian-mobile body.snake-mobile-layout .board-frame,
html.goian-mobile body.game-snake .board-wrap,
html.goian-mobile body.snake-mobile-layout .board-wrap,
body.is-mobile.game-snake .board-frame,
body.is-mobile.snake-mobile-layout .board-frame,
body.is-mobile.game-snake .board-wrap,
body.is-mobile.snake-mobile-layout .board-wrap {
  width: auto !important;
  max-width: none !important;
}

html.goian-mobile body.game-snake .board-wrap,
html.goian-mobile body.snake-mobile-layout .board-wrap,
body.is-mobile.game-snake .board-wrap,
body.is-mobile.snake-mobile-layout .board-wrap {
  width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  height: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  max-width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
}

html.goian-mobile body.game-snake .board-wrap canvas,
html.goian-mobile body.game-snake #board,
html.goian-mobile body.snake-mobile-layout .board-wrap canvas,
html.goian-mobile body.snake-mobile-layout #board,
body.is-mobile.game-snake .board-wrap canvas,
body.is-mobile.game-snake #board,
body.is-mobile.snake-mobile-layout .board-wrap canvas,
body.is-mobile.snake-mobile-layout #board {
  width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  height: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
  max-width: var(--snake-board-mobile, min(400px, calc(100vw - 0.5rem))) !important;
}

html.goian-mobile body.game-snake .mobile-controls-bar,
html.goian-mobile body.snake-mobile-layout .mobile-controls-bar,
body.is-mobile.game-snake .mobile-controls-bar,
body.is-mobile.snake-mobile-layout .mobile-controls-bar {
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 0.75rem !important;
  width: 100% !important;
}

html.goian-mobile body.game-snake .mobile-dir-cross,
html.goian-mobile body.snake-mobile-layout .mobile-dir-cross,
body.is-mobile.game-snake .mobile-dir-cross,
body.is-mobile.snake-mobile-layout .mobile-dir-cross {
  display: grid !important;
  grid-template-columns: 40px 40px 40px !important;
  grid-template-rows: 40px 40px 40px !important;
  gap: 0.28rem !important;
  width: auto !important;
  flex: 0 0 auto !important;
}

html.goian-mobile body.game-snake .mobile-dir-cross .pad-up,
html.goian-mobile body.snake-mobile-layout .mobile-dir-cross .pad-up,
body.is-mobile.game-snake .mobile-dir-cross .pad-up,
body.is-mobile.snake-mobile-layout .mobile-dir-cross .pad-up {
  grid-column: 2 !important;
  grid-row: 1 !important;
}

html.goian-mobile body.game-snake .mobile-dir-cross .pad-left,
html.goian-mobile body.snake-mobile-layout .mobile-dir-cross .pad-left,
body.is-mobile.game-snake .mobile-dir-cross .pad-left,
body.is-mobile.snake-mobile-layout .mobile-dir-cross .pad-left {
  grid-column: 1 !important;
  grid-row: 2 !important;
}

html.goian-mobile body.game-snake .mobile-dir-cross .pad-right,
html.goian-mobile body.snake-mobile-layout .mobile-dir-cross .pad-right,
body.is-mobile.game-snake .mobile-dir-cross .pad-right,
body.is-mobile.snake-mobile-layout .mobile-dir-cross .pad-right {
  grid-column: 3 !important;
  grid-row: 2 !important;
}

html.goian-mobile body.game-snake .mobile-dir-cross .pad-down,
html.goian-mobile body.snake-mobile-layout .mobile-dir-cross .pad-down,
body.is-mobile.game-snake .mobile-dir-cross .pad-down,
body.is-mobile.snake-mobile-layout .mobile-dir-cross .pad-down {
  grid-column: 2 !important;
  grid-row: 3 !important;
}

html.goian-mobile body.game-snake .mobile-util-col,
html.goian-mobile body.snake-mobile-layout .mobile-util-col,
body.is-mobile.game-snake .mobile-util-col,
body.is-mobile.snake-mobile-layout .mobile-util-col {
  flex-direction: column !important;
  flex: 0 0 auto !important;
  width: auto !important;
  gap: 0.35rem !important;
  align-items: center !important;
  justify-content: center !important;
  margin-left: auto !important;
}

