*,
*::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%, #1a1040 0%, #0a0a14 55%, #050508 100%);
  color: #e8e8f0;
}

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

html.goian-mobile body.game-falling #scale-viewport,
html.goian-mobile body.falling-mobile-layout #scale-viewport,
body.is-mobile.game-falling #scale-viewport,
body.is-mobile.falling-mobile-layout #scale-viewport {
  height: 100dvh;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#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, #00e5ff, #d05bff, #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;
}

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

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

.preview-box canvas {
  display: block;
  margin: 0 auto;
}

.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, #00e5ff, #7b5cff);
  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, 229, 255, 0.35);
  border-radius: 0.5rem;
  box-shadow: 0 0 40px rgba(0, 229, 255, 0.12);
  line-height: 0;
}

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

#board {
  display: block;
  width: 300px;
  height: 600px;
  background: #0c0c18;
}

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;
}

body.compact-layout .board-wrap {
  width: 300px;
  height: 600px;
}

body.compact-layout .board-wrap #board {
  width: 300px !important;
  height: 600px !important;
}

/* ── Escritorio: tablero + NEXT a la derecha ── */
.falling-mobile-row {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  flex-shrink: 0;
}

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

.falling-side-panel .mobile-controls {
  display: none !important;
}

/* ── Móvil: HUD arriba, tablero+NEXT al centro, controles en footer ── */
html.goian-mobile body.falling-mobile-layout #scale-viewport,
body.is-mobile.falling-mobile-layout #scale-viewport {
  justify-content: flex-start !important;
}

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

html.goian-mobile body.falling-mobile-layout .mobile-hud.falling-mobile-hud,
html.goian-mobile body.game-falling .mobile-hud.falling-mobile-hud,
body.is-mobile.falling-mobile-layout .mobile-hud.falling-mobile-hud,
body.is-mobile.game-falling .mobile-hud.falling-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-falling .falling-hud-item,
html.goian-mobile body.falling-mobile-layout .falling-hud-item,
body.is-mobile.game-falling .falling-hud-item,
body.is-mobile.falling-mobile-layout .falling-hud-item {
  font-size: 0.74rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

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

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

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

html.goian-mobile body.falling-mobile-layout .falling-controls-wrap,
html.goian-mobile body.game-falling .falling-controls-wrap,
body.is-mobile.falling-mobile-layout .falling-controls-wrap,
body.is-mobile.game-falling .falling-controls-wrap {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  gap: 1.05rem !important;
  width: 100% !important;
  max-width: calc(100vw - 0.5rem) !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;
}

html.goian-mobile body.falling-mobile-layout .falling-controls-row,
html.goian-mobile body.game-falling .falling-controls-row,
body.is-mobile.falling-mobile-layout .falling-controls-row,
body.is-mobile.game-falling .falling-controls-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  gap: 0 !important;
}

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



html.goian-mobile body.falling-mobile-layout .falling-dpad-slot .mobile-dir-cross,
html.goian-mobile body.game-falling .falling-dpad-slot .mobile-dir-cross,
body.is-mobile.falling-mobile-layout .falling-dpad-slot .mobile-dir-cross,
body.is-mobile.game-falling .falling-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.falling-mobile-layout .falling-dpad-slot .mobile-dir-cross .pad-up,
html.goian-mobile body.game-falling .falling-dpad-slot .mobile-dir-cross .pad-up,
body.is-mobile.falling-mobile-layout .falling-dpad-slot .mobile-dir-cross .pad-up,
body.is-mobile.game-falling .falling-dpad-slot .mobile-dir-cross .pad-up {
  grid-column: 2 !important;
  grid-row: 1 !important;
}

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

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

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

html.goian-mobile body.falling-mobile-layout .falling-dpad-slot .mobile-dir-cross .pad-dir,
html.goian-mobile body.game-falling .falling-dpad-slot .mobile-dir-cross .pad-dir,
body.is-mobile.falling-mobile-layout .falling-dpad-slot .mobile-dir-cross .pad-dir,
body.is-mobile.game-falling .falling-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.falling-mobile-layout .falling-side-utils,
html.goian-mobile body.game-falling .falling-side-utils,
body.is-mobile.falling-mobile-layout .falling-side-utils,
body.is-mobile.game-falling .falling-side-utils {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  width: 100% !important;
  margin-top: 0.25rem !important;
  flex-shrink: 0 !important;
}

html.goian-mobile body.falling-mobile-layout .falling-side-utils .mobile-util-col,
html.goian-mobile body.game-falling .falling-side-utils .mobile-util-col,
body.is-mobile.falling-mobile-layout .falling-side-utils .mobile-util-col,
body.is-mobile.game-falling .falling-side-utils .mobile-util-col {
  display: flex !important;
  flex-direction: row !important;
  gap: 0.4rem !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  margin: 0 !important;
}

html.goian-mobile body.falling-mobile-layout .falling-actions-row,
html.goian-mobile body.game-falling .falling-actions-row,
body.is-mobile.falling-mobile-layout .falling-actions-row,
body.is-mobile.game-falling .falling-actions-row {
  display: flex !important;
  justify-content: center !important;
  width: 100% !important;
  margin-top: 0.4rem !important;
  padding-top: 0.15rem !important;
}

html.goian-mobile body.falling-mobile-layout .falling-actions-slot .mobile-action-col,
html.goian-mobile body.game-falling .falling-actions-slot .mobile-action-col,
body.is-mobile.falling-mobile-layout .falling-actions-slot .mobile-action-col,
body.is-mobile.game-falling .falling-actions-slot .mobile-action-col {
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.55rem !important;
  min-width: 0 !important;
}



html.goian-mobile body.falling-mobile-layout #game-root,
html.goian-mobile body.game-falling #game-root,
body.is-mobile.falling-mobile-layout #game-root,
body.is-mobile.game-falling #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.falling-mobile-layout .falling-mobile-row,
html.goian-mobile body.game-falling .falling-mobile-row,
body.is-mobile.falling-mobile-layout .falling-mobile-row,
body.is-mobile.game-falling .falling-mobile-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: flex-start !important;
  justify-content: center !important;
  gap: 0.55rem !important;
  width: auto !important;
  max-width: calc(100vw - 0.5rem) !important;
  margin: 0 auto !important;
  position: relative !important;
  isolation: isolate !important;
}

html.goian-mobile body.falling-mobile-layout .board-frame,
html.goian-mobile body.game-falling .board-frame,
body.is-mobile.falling-mobile-layout .board-frame,
body.is-mobile.game-falling .board-frame {
  width: fit-content !important;
  max-width: fit-content !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
  border-width: 2px !important;
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.14) !important;
  overflow: hidden !important;
  position: relative !important;
  z-index: 1 !important;
  display: inline-flex !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;
  margin: 0 !important;
  flex: 0 0 auto !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;
  margin: 0 !important;
}

html.goian-mobile body.falling-mobile-layout .falling-side-panel,
html.goian-mobile body.game-falling .falling-side-panel,
body.is-mobile.falling-mobile-layout .falling-side-panel,
body.is-mobile.game-falling .falling-side-panel {
  width: 96px !important;
  min-width: 96px !important;
  max-width: 96px !important;
  flex: 0 0 96px !important;
  gap: 0.3rem !important;
  align-items: stretch !important;
  position: relative !important;
  z-index: 2 !important;
  overflow: visible !important;
  flex-shrink: 0 !important;
}

html.goian-mobile body.falling-mobile-layout .falling-side-next,
html.goian-mobile body.game-falling .falling-side-next,
body.is-mobile.falling-mobile-layout .falling-side-next,
body.is-mobile.game-falling .falling-side-next {
  padding: 0.28rem 0.3rem;
}

html.goian-mobile body.falling-mobile-layout .falling-side-next canvas,
html.goian-mobile body.game-falling .falling-side-next canvas,
body.is-mobile.falling-mobile-layout .falling-side-next canvas,
body.is-mobile.game-falling .falling-side-next canvas {
  width: 80px !important;
  height: 68px !important;
  max-width: 100% !important;
  display: block !important;
  margin: 0 auto !important;
}

body:not(.falling-mobile-layout):not(.is-mobile) .falling-side-utils,
body.game-falling:not(.falling-mobile-layout):not(.is-mobile) .falling-side-utils {
  display: none;
}

html.goian-mobile body.falling-mobile-layout .falling-actions-slot .pad-action,
html.goian-mobile body.game-falling .falling-actions-slot .pad-action,
body.is-mobile.falling-mobile-layout .falling-actions-slot .pad-action,
body.is-mobile.game-falling .falling-actions-slot .pad-action {
  min-height: 36px !important;
  padding: 0.35rem 0.55rem !important;
  font-size: 0.58rem !important;
}

html.goian-mobile body.falling-mobile-layout .falling-side-utils .pad-util,
html.goian-mobile body.game-falling .falling-side-utils .pad-util,
body.is-mobile.falling-mobile-layout .falling-side-utils .pad-util,
body.is-mobile.game-falling .falling-side-utils .pad-util {
  width: 38px !important;
  height: 38px !important;
  min-width: 38px !important;
  min-height: 38px !important;
}

.line-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 20px #00e5ff, 0 0 40px #d05bff;
  pointer-events: none;
  animation: pop 0.9s ease-out forwards;
  white-space: nowrap;
}

.line-popup.hidden {
  display: none;
}

@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}

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

.overlay.hidden {
  display: none;
}

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

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

.overlay p {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}