*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Sora', system-ui, sans-serif;
  background: radial-gradient(ellipse at 30% 20%, #102018 0%, #0a0a14 55%, #050508 100%);
  color: #e8e8f0;
}

:root {
  --snake-board-mobile: min(400px, calc(100vw - 0.5rem));
}

#scale-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game-stage {
  transform-origin: center center;
  will-change: transform;
}

#game-root {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1.25rem;
  padding: 1rem;
  flex-shrink: 0;
}

.panel {
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-shrink: 0;
}

.panel h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #00e676, #00e5ff, #ffe600);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-block {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.65rem;
  padding: 0.65rem 0.75rem;
}

.stat-block.small {
  flex: 1;
}

.stat-row {
  display: flex;
  gap: 0.5rem;
}

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

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.stat-value.accent {
  color: #ffe600;
}

.info-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.65rem;
  padding: 0.75rem;
  text-align: center;
}

.info-label {
  display: block;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 0.5rem;
}

.fruit-preview {
  width: 48px;
  height: 48px;
  margin: 0 auto 0.4rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7799, #ff3355 55%, #cc0022);
  box-shadow: 0 0 16px rgba(255, 51, 85, 0.45);
  position: relative;
}

.fruit-preview::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 14px;
  width: 10px;
  height: 6px;
  border-radius: 50%;
  background: #00e676;
  transform: rotate(-25deg);
}

.info-value {
  font-size: 0.85rem;
  font-weight: 700;
  color: #00e676;
}

.speed-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.speed-fill {
  height: 100%;
  width: 20%;
  border-radius: inherit;
  background: linear-gradient(90deg, #00e676, #00e5ff);
  transition: width 0.25s ease;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #e8e8f0;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-primary {
  background: linear-gradient(90deg, #00e676, #00b8d4);
  border-color: transparent;
  color: #0a0a14;
  font-weight: 700;
}

.btn-primary:hover {
  transform: scale(1.02);
}

.controls-hint {
  font-size: 0.78rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.55);
}

.board-frame {
  flex-shrink: 0;
  border: 3px solid rgba(0, 230, 118, 0.4);
  border-radius: 0.5rem;
  box-shadow: 0 0 40px rgba(0, 230, 118, 0.12);
  line-height: 0;
}

.board-wrap {
  position: relative;
  width: 400px;
  height: 400px;
  overflow: hidden;
  border-radius: 0.35rem;
  background: #0c1210;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
}

#board {
  display: block;
  width: 400px;
  height: 400px;
  background: #0c1210;
}

body.compact-layout #game-root {
  gap: 0.5rem;
  padding: 0.5rem;
}

body.compact-layout .panel-left,
body.compact-layout .panel-right {
  display: none;
}

body.compact-layout .board-frame {
  border-width: 2px;
}

/* ── Móvil: HUD arriba, tablero + controles juntos debajo ── */
html.goian-mobile body.snake-mobile-layout #scale-viewport,
html.goian-mobile body.game-snake #scale-viewport,
body.is-mobile.snake-mobile-layout #scale-viewport,
body.is-mobile.game-snake #scale-viewport {
  justify-content: flex-start !important;
  align-items: center !important;
}

html.goian-mobile body.snake-mobile-layout .mobile-hud,
html.goian-mobile body.game-snake .mobile-hud,
body.is-mobile.snake-mobile-layout .mobile-hud,
body.is-mobile.game-snake .mobile-hud {
  flex-shrink: 0 !important;
  padding-bottom: 0.15rem !important;
}

html.goian-mobile body.snake-mobile-layout .mobile-hud.snake-mobile-hud,
html.goian-mobile body.game-snake .mobile-hud.snake-mobile-hud,
body.is-mobile.snake-mobile-layout .mobile-hud.snake-mobile-hud,
body.is-mobile.game-snake .mobile-hud.snake-mobile-hud {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  align-items: center !important;
  gap: 0.2rem 0.45rem !important;
  grid-template-columns: none !important;
  padding: calc(0.3rem + env(safe-area-inset-top, 0)) 0.5rem 0.2rem !important;
}

html.goian-mobile body.game-snake .snake-hud-item,
html.goian-mobile body.snake-mobile-layout .snake-hud-item,
body.is-mobile.game-snake .snake-hud-item,
body.is-mobile.snake-mobile-layout .snake-hud-item {
  font-size: 0.74rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

html.goian-mobile body.game-snake .snake-hud-sep,
html.goian-mobile body.snake-mobile-layout .snake-hud-sep,
body.is-mobile.game-snake .snake-hud-sep,
body.is-mobile.snake-mobile-layout .snake-hud-sep {
  color: rgba(255, 255, 255, 0.32);
  font-size: 0.72rem;
  line-height: 1;
  user-select: none;
}

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

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

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

html.goian-mobile body.snake-mobile-layout .snake-controls-row,
html.goian-mobile body.game-snake .snake-controls-row,
body.is-mobile.snake-mobile-layout .snake-controls-row,
body.is-mobile.game-snake .snake-controls-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
  max-width: var(--snake-board-mobile) !important;
  flex-shrink: 0 !important;
  margin: 0.45rem auto 0 !important;
  padding: 0 0.35rem calc(0.35rem + env(safe-area-inset-bottom, 0px)) !important;
  gap: 1rem !important;
}

html.goian-mobile body.snake-mobile-layout .snake-dpad-slot,
html.goian-mobile body.game-snake .snake-dpad-slot,
body.is-mobile.snake-mobile-layout .snake-dpad-slot,
body.is-mobile.game-snake .snake-dpad-slot {
  flex: 0 0 auto !important;
}

html.goian-mobile body.snake-mobile-layout .snake-utils-slot,
html.goian-mobile body.game-snake .snake-utils-slot,
body.is-mobile.snake-mobile-layout .snake-utils-slot,
body.is-mobile.game-snake .snake-utils-slot {
  flex: 0 0 auto !important;
  margin-left: auto !important;
}

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

html.goian-mobile body.snake-mobile-layout .board-frame,
html.goian-mobile body.game-snake .board-frame,
body.is-mobile.snake-mobile-layout .board-frame,
body.is-mobile.game-snake .board-frame {
  width: fit-content !important;
  max-width: fit-content !important;
  margin: 0 auto !important;
  flex: 0 0 auto !important;
  border-width: 2px !important;
  box-shadow: 0 0 20px rgba(0, 230, 118, 0.14) !important;
  overflow: hidden !important;
  display: inline-flex !important;
}

html.goian-mobile body.snake-mobile-layout .board-wrap,
html.goian-mobile body.game-snake .board-wrap,
body.is-mobile.snake-mobile-layout .board-wrap,
body.is-mobile.game-snake .board-wrap {
  width: var(--snake-board-mobile) !important;
  height: var(--snake-board-mobile) !important;
  max-width: var(--snake-board-mobile) !important;
  min-width: 0 !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
}

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.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 {
  width: var(--snake-board-mobile) !important;
  height: var(--snake-board-mobile) !important;
  max-width: var(--snake-board-mobile) !important;
  min-width: 0 !important;
  margin: 0 !important;
}

html.goian-mobile body.snake-mobile-layout .snake-dpad-slot .mobile-dir-cross,
html.goian-mobile body.game-snake .snake-dpad-slot .mobile-dir-cross,
body.is-mobile.snake-mobile-layout .snake-dpad-slot .mobile-dir-cross,
body.is-mobile.game-snake .snake-dpad-slot .mobile-dir-cross {
  display: grid !important;
  grid-template-columns: 44px 44px 44px !important;
  grid-template-rows: 44px 44px 44px !important;
  gap: 0.3rem !important;
  width: auto !important;
}

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

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

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

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

html.goian-mobile body.snake-mobile-layout .snake-dpad-slot .mobile-dir-cross .pad-dir,
html.goian-mobile body.game-snake .snake-dpad-slot .mobile-dir-cross .pad-dir,
body.is-mobile.snake-mobile-layout .snake-dpad-slot .mobile-dir-cross .pad-dir,
body.is-mobile.game-snake .snake-dpad-slot .mobile-dir-cross .pad-dir {
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  font-size: 0.9rem !important;
}

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

html.goian-mobile body.snake-mobile-layout .pad-util,
html.goian-mobile body.game-snake .pad-util,
body.is-mobile.snake-mobile-layout .pad-util,
body.is-mobile.game-snake .pad-util {
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
}

/* Respaldo táctil: no depende de que mobile.js haya corrido */
@media (pointer: coarse) {
  body.game-snake #scale-viewport {
    justify-content: flex-start !important;
    align-items: center !important;
    height: 100% !important;
  }

  body.game-snake #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;
  }

  body.game-snake #scale-viewport > .mobile-controls {
    display: none !important;
  }

  body.game-snake #game-stage > .mobile-controls {
    display: none !important;
  }

  body.game-snake .snake-controls-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    max-width: var(--snake-board-mobile) !important;
    margin: 0.45rem auto 0 !important;
    padding: 0 0.35rem calc(0.35rem + env(safe-area-inset-bottom, 0px)) !important;
    gap: 1rem !important;
  }

  body.game-snake .snake-utils-slot {
    margin-left: auto !important;
  }

  body.game-snake .board-frame,
  body.game-snake .board-wrap {
    width: auto !important;
    max-width: none !important;
  }

  body.game-snake .board-wrap,
  body.game-snake .board-wrap canvas,
  body.game-snake #board {
    width: var(--snake-board-mobile) !important;
    height: var(--snake-board-mobile) !important;
    max-width: var(--snake-board-mobile) !important;
  }

  body.game-snake .snake-dpad-slot .mobile-dir-cross {
    display: grid !important;
    grid-template-columns: 44px 44px 44px !important;
    grid-template-rows: 44px 44px 44px !important;
    gap: 0.3rem !important;
    width: auto !important;
  }

  body.game-snake .snake-dpad-slot .mobile-dir-cross .pad-up { grid-column: 2 !important; grid-row: 1 !important; }
  body.game-snake .snake-dpad-slot .mobile-dir-cross .pad-left { grid-column: 1 !important; grid-row: 2 !important; }
  body.game-snake .snake-dpad-slot .mobile-dir-cross .pad-right { grid-column: 3 !important; grid-row: 2 !important; }
  body.game-snake .snake-dpad-slot .mobile-dir-cross .pad-down { grid-column: 2 !important; grid-row: 3 !important; }

  body.game-snake .snake-dpad-slot .mobile-dir-cross .pad-dir {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
  }

  body.game-snake .snake-utils-slot .mobile-util-col {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.4rem !important;
    align-items: center !important;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(5, 12, 8, 0.85);
  backdrop-filter: blur(4px);
  border-radius: 0.35rem;
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  font-size: 1.5rem;
  color: #00e676;
}

#gameover-overlay h2 {
  color: #ff6b8a;
  margin-bottom: 0.65rem;
}

.overlay p {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
  max-width: 85%;
  line-height: 1.45;
}