/**
 * TETRIS CLÁSICO ESTILO WINDOWS 90s
 * main.css - Layout del escritorio Windows 95, estructura de juego, responsividad y controles táctiles.
 */

/* ==========================================================================
   RESET Y ESCRITORIO RETRO
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--win-desktop-teal, #008080);
  font-family: "MS Sans Serif", Tahoma, "Segoe UI", sans-serif;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Contenedor del escritorio */
.retro-desktop {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 12px;
  position: relative;
}

/* Iconos nostálgicos decorativos en el escritorio (visibles en pantallas grandes) */
.desktop-icons-area {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  pointer-events: none;
  z-index: 1;
}

.desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 68px;
  text-align: center;
  cursor: pointer;
  pointer-events: auto;
}

.desktop-icon svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(1px 1px 0px rgba(0,0,0,0.5));
}

.desktop-icon-label {
  color: #ffffff;
  font-size: 11px;
  margin-top: 4px;
  text-shadow: 1px 1px 1px #000000;
  padding: 1px 3px;
  border: 1px dotted transparent;
}

.desktop-icon:hover .desktop-icon-label {
  background-color: #000080;
  border-color: #ffffff;
}

/* ==========================================================================
   CONTENEDOR DEL JUEGO
   ========================================================================== */
.game-container {
  display: flex;
  gap: 12px;
  padding: 6px;
  background-color: var(--win-gray);
  z-index: 10;
}

/* Área del tablero (Canvas 10x20) */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-frame {
  padding: 3px;
  background-color: #000000;
  display: inline-block;
}

#boardCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background-color: #000000;
}

/* Barra lateral derecha (Sidebar) */
.sidebar-area {
  width: 175px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Recuadro de pieza siguiente */
.next-piece-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.next-canvas-frame {
  padding: 3px;
  background-color: #000000;
  margin: 2px auto 4px auto;
}

#nextCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background-color: #000000;
}

/* Indicadores estadísticos (Puntuación, Líneas, Nivel) */
.stat-item {
  margin-bottom: 6px;
}

.stat-item:last-child {
  margin-bottom: 0;
}

.stat-label {
  font-size: 11px;
  font-weight: bold;
  color: #000000;
  margin-bottom: 2px;
  display: block;
}

/* Botones de acción */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.action-buttons .win-btn {
  width: 100%;
}

/* ==========================================================================
   CONTROLES TÁCTILES PARA MÓVILES Y PANTALLAS TÁCTILES
   ========================================================================== */
.touch-controls {
  display: none; /* Oculto en escritorio; se activa por media query o táctil */
  margin-top: 12px;
  width: 100%;
  max-width: 440px;
  padding: 8px;
  background-color: var(--win-gray);
  z-index: 20;
}

.touch-controls-layout {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.touch-dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 4px;
}

.touch-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.touch-btn {
  background-color: var(--win-gray);
  border-top: 2px solid var(--win-light);
  border-left: 2px solid var(--win-light);
  border-right: 2px solid var(--win-dark);
  border-bottom: 2px solid var(--win-dark);
  box-shadow: 1px 1px 0px var(--win-black);
  font-family: var(--font-retro);
  font-weight: bold;
  font-size: 14px;
  color: var(--win-black);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.touch-btn:active {
  border-top: 2px solid var(--win-dark);
  border-left: 2px solid var(--win-dark);
  border-right: 2px solid var(--win-light);
  border-bottom: 2px solid var(--win-light);
  box-shadow: none;
  background-color: #b0b0b0;
}

.touch-btn-action {
  padding: 8px 16px;
  font-size: 13px;
}

/* ==========================================================================
   RESPONSIVIDAD Y ADAPTACIÓN A PANTALLAS PEQUEÑAS
   ========================================================================== */
@media (max-width: 768px) {
  .desktop-icons-area {
    display: none;
  }
}

@media (max-width: 640px) {
  .retro-desktop {
    padding: 4px;
    justify-content: flex-start;
  }

  .win-window {
    width: 100%;
    max-width: 360px;
  }

  .game-container {
    gap: 8px;
    padding: 4px;
  }

  .sidebar-area {
    width: 120px;
  }

  #boardCanvas {
    width: 190px !important;
    height: 380px !important;
  }

  .digital-lcd {
    font-size: 14px;
    letter-spacing: 1px;
    padding: 2px 4px;
  }

  .digital-lcd-small {
    font-size: 12px;
  }

  .action-buttons .win-btn {
    padding: 3px 6px;
    font-size: 11px;
  }

  .touch-controls {
    display: block;
  }
}

/* Mostrar controles táctiles en dispositivos con capacidad táctil confirmada */
@media (pointer: coarse) {
  .touch-controls {
    display: block;
  }
}
