:root {
  --bg: #050508;
  --surface: #0d0d1a;
  --card: #0f0f1e;
  --border: #1a1a3a;
  --accent: #00ffcc;
  --accent2: #ff00aa;
  --accent3: #ffcc00;
  --text: #e8e8ff;
  --muted: #5a5a8a;
  --glow: 0 0 20px rgba(0,255,204,0.4);
  --glow2: 0 0 20px rgba(255,0,170,0.4);
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Rajdhani', sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,255,204,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,255,204,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: gridMove 20s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes gridMove {
  0% { transform: translateY(0); }
  100% { transform: translateY(40px); }
}

header {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: clamp(30px, 8vw, 50px) 20px 20px;
}

.logo {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 5vw, 42px);
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent), 0 0 60px rgba(0,255,204,0.3);
  letter-spacing: 2px;
  animation: flicker 4s infinite;
  line-height: 1.4;
  padding: 0 10px;
}

.logo span { color: var(--accent2); text-shadow: 0 0 30px var(--accent2); }

@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.8; }
  98% { opacity: 1; }
  99% { opacity: 0.6; }
}

.subtitle {
  font-size: clamp(11px, 3vw, 14px);
  color: var(--muted);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-top: 10px;
  font-weight: 300;
  padding: 0 10px;
}

.header-line {
  width: clamp(120px, 40vw, 200px);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 16px auto 0;
}

.menu-toggle {
  display: none;
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--accent);
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  z-index: 100;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.menu-toggle:active { transform: scale(0.95); }

main {
  position: relative;
  z-index: 10;
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px 40px;
}

.section-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(8px, 2.5vw, 10px);
  color: var(--accent3);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--accent3), transparent);
  opacity: 0.4;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  min-height: 180px;
  justify-content: center;
}

.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(0,255,204,0.08), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.game-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transform: scaleX(0);
  transition: transform 0.3s ease;
  box-shadow: var(--glow);
}

.game-card:hover,
.game-card:active {
  border-color: rgba(0,255,204,0.5);
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 12px 40px rgba(0,255,204,0.15), 0 0 60px rgba(0,255,204,0.05);
}

.game-card:hover::before,
.game-card:active::before { opacity: 1; }
.game-card:hover::after,
.game-card:active::after { transform: scaleX(1); }

.game-card.available .game-name {
  color: var(--text);
}

.game-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.game-card.locked:hover,
.game-card.locked:active {
  transform: none;
  border-color: var(--border);
  box-shadow: none;
}

.game-card.locked::after { display: none; }

.game-icon {
  font-size: clamp(32px, 8vw, 42px);
  line-height: 1;
  filter: drop-shadow(0 0 8px currentColor);
  transition: transform 0.3s ease;
}

.game-card.available .game-icon { 
  animation: iconPulse 3s ease-in-out infinite;
}

.game-card:hover .game-icon,
.game-card:active .game-icon {
  transform: scale(1.15);
}

@keyframes iconPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.game-name {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(8px, 2.5vw, 10px);
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
  letter-spacing: 1px;
  word-break: break-word;
  max-width: 100%;
  padding: 0 4px;
}

.game-badge {
  font-size: clamp(9px, 2.5vw, 10px);
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.badge-play {
  background: rgba(0,255,204,0.15);
  color: var(--accent);
  border: 1px solid rgba(0,255,204,0.4);
  box-shadow: 0 0 10px rgba(0,255,204,0.1);
}

.badge-soon {
  background: rgba(90,90,138,0.2);
  color: var(--muted);
  border: 1px solid rgba(90,90,138,0.3);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: radial-gradient(circle at top, rgba(0,255,204,0.08), rgba(0,0,0,0.96) 55%);
  z-index: 1000;
  padding: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
}

.modal-overlay.open { display: block; }

.modal {
  background: var(--surface);
  border: 0;
  border-radius: 0;
  padding: calc(16px + var(--safe-area-top)) 16px calc(120px + var(--safe-area-bottom));
  max-width: none;
  width: 100%;
  height: 100%;
  max-height: none;
  overflow-y: auto;
  position: relative;
  box-shadow: none;
  animation: none;
}

@keyframes modalIn {
  from { transform: scale(0.9) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto 20px;
  max-width: 980px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, rgba(13,13,26,0.98), rgba(13,13,26,0.88));
  padding-top: 6px;
}

.modal-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(12px, 4vw, 14px);
  color: var(--accent);
  text-shadow: var(--glow);
  white-space: nowrap;
}

.btn-close {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 44px; height: 44px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.2s ease;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-close:hover, .btn-close:active { 
  border-color: var(--accent2); 
  color: var(--accent2);
  transform: scale(1.05);
}

.tetris-layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px);
  gap: 20px;
  align-items: start;
  justify-content: center;
  max-width: 980px;
  margin: 0 auto;
  padding-bottom: 8px;
}

.canvas-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  width: 100%;
}

#tetris-canvas,
#snake-canvas {
  border: 2px solid rgba(0,255,204,0.4);
  box-shadow: 0 0 30px rgba(0,255,204,0.15), inset 0 0 40px rgba(0,0,0,0.6);
  display: block;
  border-radius: 8px;
  max-width: min(100%, 420px);
  height: auto;
  touch-action: none;
  margin: 0 auto;
}

.tetris-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 180px;
}

.panel-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.panel-label {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(6px, 2vw, 7px);
  color: var(--muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.panel-value {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(12px, 4vw, 14px);
  color: var(--accent);
  text-shadow: var(--glow);
  word-break: break-all;
}

#next-canvas {
  display: block;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: 100%;
  height: auto;
}

.tetris-controls {
  margin-top: 4px;
}

.ctrl-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.ctrl-key {
  background: var(--border);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(5px, 1.8vw, 6px);
  padding: 5px 8px;
  border-radius: 5px;
  border-bottom: 2px solid rgba(0,0,0,0.5);
  white-space: nowrap;
  min-width: 32px;
  text-align: center;
  user-select: none;
}

.ctrl-desc {
  font-size: clamp(10px, 3vw, 11px);
  color: var(--muted);
  font-weight: 600;
}

.btn-start {
  width: 100%;
  background: linear-gradient(135deg, rgba(0,255,204,0.2), rgba(0,255,204,0.08));
  border: 1px solid rgba(0,255,204,0.5);
  color: var(--accent);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(9px, 3vw, 10px);
  padding: 14px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 1px;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-start:hover,
.btn-start:active {
  background: linear-gradient(135deg, rgba(0,255,204,0.3), rgba(0,255,204,0.15));
  box-shadow: var(--glow), 0 0 30px rgba(0,255,204,0.2);
  transform: scale(1.02);
}

.game-over-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.9);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  border-radius: 8px;
  z-index: 10;
  padding: 20px;
}

.game-over-overlay.show { display: flex; }

.go-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 5vw, 16px);
  color: var(--accent2);
  text-shadow: var(--glow2);
  animation: goBlink 0.8s infinite;
  text-align: center;
}

@keyframes goBlink {
  0%,100% { opacity: 1; } 50% { opacity: 0.4; }
}

footer {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 24px 20px;
  color: var(--muted);
  font-size: clamp(10px, 3vw, 12px);
  letter-spacing: 2px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

@media (max-width: 768px) {
  main {
    padding: 10px 12px 30px;
  }

  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .game-card {
    min-height: 160px;
    padding: 20px 12px;
  }

  .modal {
    padding: calc(12px + var(--safe-area-top)) 12px calc(110px + var(--safe-area-bottom));
  }

  .tetris-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .tetris-panel {
    min-width: 100%;
    order: -1;
  }
}

@media (max-width: 480px) {
  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .game-card {
    min-height: 150px;
    padding: 18px 10px;
    border-radius: 10px;
  }

  .game-icon {
    font-size: clamp(28px, 7vw, 36px);
  }

  .game-card::after {
    height: 2px;
  }

  .modal {
    padding: calc(10px + var(--safe-area-top)) 10px calc(104px + var(--safe-area-bottom));
  }

  .canvas-wrap {
    width: 100%;
  }

  #tetris-canvas {
    max-width: 280px;
    width: 100%;
  }

  .ctrl-item {
    margin-bottom: 6px;
  }
}

@media (max-width: 360px) {
  .games-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .game-card {
    min-height: 140px;
    flex-direction: row;
    justify-content: flex-start;
    padding: 16px;
    gap: 16px;
    text-align: left;
  }

  .game-icon {
    font-size: 28px;
    flex-shrink: 0;
  }

  .game-name {
    text-align: left;
    flex: 1;
  }

  .game-badge {
    flex-shrink: 0;
  }

  .tetris-layout {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    display: flex;
    justify-content: center;
  }

  #tetris-canvas {
    max-width: 240px;
  }

  .panel-box {
    padding: 12px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .tetris-layout {
    grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px);
    justify-content: center;
  }

  #tetris-canvas {
    max-height: 55vh;
    width: auto;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .tetris-panel {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
  }

  .panel-box {
    padding: 10px;
    min-width: 80px;
  }

  .tetris-controls {
    display: none;
  }
}

/* ===== TOUCH CONTROLS - FLOTANTES ===== */
.touch-controls {
  display: none;
}

@media (pointer: coarse), (max-width: 600px) {
  .touch-controls {
    display: flex;
    position: fixed;
    bottom: max(24px, var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1005;
    gap: 8px;
    pointer-events: none;
    flex-direction: column;
  }
  
  .touch-controls > * {
    pointer-events: auto;
  }
  
  .tetris-controls {
    display: none;
  }
  
  #tetris-canvas,
  #snake-canvas {
    max-width: 260px;
  }
}

.touch-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.touch-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(0,255,204,0.5);
  background: rgba(15,15,30,0.85);
  color: var(--text);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.touch-btn:active, .touch-btn.pressed {
  background: rgba(0,255,204,0.25);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(0.92);
}

.touch-btn.drop {
  background: rgba(255,0,170,0.2);
  border-color: rgba(255,0,170,0.6);
  color: var(--accent2);
}

.touch-btn.drop:active, .touch-btn.drop.pressed {
  background: rgba(255,0,170,0.4);
  border-color: var(--accent2);
}

.touch-btn.rotate {
  background: rgba(204,68,255,0.2);
  border-color: rgba(204,68,255,0.5);
  color: #cc44ff;
}

.touch-btn.rotate:active, .touch-btn.rotate.pressed {
  background: rgba(204,68,255,0.35);
  border-color: #cc44ff;
}
