/* Synthwave Retro Arcade Theme - Inspired by the Iconic Arcade Aesthetic */
@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:ital,wght@0,600;0,700;0,800;1,700&family=Outfit:wght@600;700;800;900&family=Press+Start+2P&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg-deep: #060714;
  --bg-arcade: #0c0e24;
  --neon-pink: #ff2a85;
  --neon-cyan: #00f0ff;
  --neon-lime: #39ff14;
  --neon-amber: #ffb703;
  --neon-glow-pink: rgba(255, 42, 133, 0.4);
  --neon-glow-cyan: rgba(0, 240, 255, 0.4);
  --neon-glow-lime: rgba(57, 255, 20, 0.4);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Space Mono', monospace, -apple-system, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* Retro Perspective Grid Background */
.retro-grid-bg {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48vh;
  background: 
    linear-gradient(to bottom, rgba(6, 7, 20, 1) 0%, rgba(6, 7, 20, 0.1) 40%, rgba(6, 7, 20, 0.8) 100%),
    repeating-linear-gradient(to right, rgba(255, 42, 133, 0.25) 0px, rgba(255, 42, 133, 0.25) 1px, transparent 1px, transparent 60px);
  transform: perspective(300px) rotateX(65deg);
  transform-origin: bottom center;
  pointer-events: none;
  z-index: 0;
  opacity: 0.65;
}

.retro-grid-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(0, 240, 255, 0.3) 0px, rgba(0, 240, 255, 0.3) 1px, transparent 1px, transparent 40px);
}

/* Header */
header {
  border-bottom: 1px solid rgba(255, 42, 133, 0.2);
  background: rgba(6, 7, 20, 0.85);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 30;
}

/* Synthwave Typography */
.arcade-font {
  font-family: 'Press Start 2P', monospace;
}

/* Chuẩn font chữ game phong cách Arcade hỗ trợ 100% tiếng Việt */
.vn-arcade-font {
  font-family: 'Chakra Petch', 'Outfit', sans-serif;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.synth-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(2rem, 6vw, 3.8rem);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #ffffff;
  text-shadow: 
    0 0 10px rgba(0, 240, 255, 0.8),
    0 0 25px rgba(0, 240, 255, 0.6),
    0 0 45px rgba(255, 42, 133, 0.5);
  position: relative;
  display: inline-block;
}

.synth-divider {
  width: 180px;
  height: 4px;
  margin: 12px auto 0;
  background: linear-gradient(90deg, transparent, var(--neon-pink), var(--neon-cyan), transparent);
  box-shadow: 0 0 12px var(--neon-glow-pink), 0 0 16px var(--neon-glow-cyan);
  border-radius: 9999px;
}

/* Arcade Game Cards */
.arcade-card {
  background: rgba(12, 14, 36, 0.85);
  border: 2px solid rgba(255, 42, 133, 0.4);
  border-radius: 18px;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.arcade-card:hover {
  transform: translateY(-8px) scale(1.02);
  border-color: var(--neon-cyan);
  box-shadow: 0 14px 40px rgba(0, 240, 255, 0.3), 0 0 25px var(--neon-glow-cyan);
}

.arcade-card-header {
  background: rgba(20, 24, 54, 0.9);
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.arcade-card-screen {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.arcade-card-screen img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.arcade-card:hover .arcade-card-screen img {
  transform: scale(1.08);
}

.crt-scanlines {
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  background-size: 100% 3px, 3px 100%;
  pointer-events: none;
}

.arcade-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  justify-content: space-between;
}

.arcade-play-btn {
  font-family: 'Chakra Petch', 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 13px;
  background: transparent;
  color: var(--neon-cyan);
  border: 1px solid var(--neon-cyan);
  padding: 10px 16px;
  border-radius: 8px;
  text-align: center;
  text-transform: uppercase;
  transition: all 0.2s ease;
  letter-spacing: 0.08em;
  margin-top: 14px;
}

.arcade-card:hover .arcade-play-btn,
.arcade-play-btn:hover {
  background: var(--neon-cyan);
  color: #060714;
  box-shadow: 0 0 18px var(--neon-glow-cyan);
}

/* Fullscreen / Theater Arcade Modal */
.arcade-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(3, 4, 12, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.arcade-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-header {
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(12, 14, 36, 0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
  position: relative;
}

/* Close & Action Buttons inside modal */
.modal-ctrl-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 11px;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.modal-ctrl-btn:hover {
  background: var(--neon-pink);
  color: #ffffff;
  border-color: var(--neon-pink);
  box-shadow: 0 0 15px var(--neon-glow-pink);
}

/* Active Game Viewport */
.game-viewport-wrap {
  position: relative;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.9), 0 0 35px rgba(57, 255, 20, 0.3);
  border: 2px solid rgba(57, 255, 20, 0.5);
  background: #000000;
}

canvas {
  display: block;
  margin: 0 auto;
  cursor: pointer;
  touch-action: none;
}

/* In-game HUD */
.game-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.hud-pill {
  background: rgba(12, 14, 36, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 6px 14px;
  border-radius: 9999px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Overlays */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 7, 20, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  text-align: center;
  z-index: 20;
  transition: opacity 0.3s ease;
}

.game-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.btn-neon {
  background: linear-gradient(135deg, #39ff14 0%, #00f0ff 100%);
  color: #060714;
  font-family: 'Chakra Petch', 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.08em;
  padding: 13px 26px;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
  box-shadow: 0 0 25px var(--neon-glow-lime);
  transition: all 0.2s ease;
}

.btn-neon:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 35px rgba(57, 255, 20, 0.65);
}

/* 2048 Grid Styles */
.grid-2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: #0f172a;
  padding: 12px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  height: 380px;
  position: relative;
  border: 1px solid rgba(0, 240, 255, 0.2);
}

.tile-0 { background: rgba(30, 41, 59, 0.5); }
.tile-2 { background: #334155; color: #f8fafc; }
.tile-4 { background: #475569; color: #f8fafc; }
.tile-8 { background: #ea580c; color: #ffffff; box-shadow: 0 0 10px rgba(234, 88, 12, 0.4); }
.tile-16 { background: #f97316; color: #ffffff; }
.tile-32 { background: #ef4444; color: #ffffff; }
.tile-64 { background: #dc2626; color: #ffffff; }
.tile-128 { background: #eab308; color: #022c22; font-size: 1.4rem; box-shadow: 0 0 15px rgba(234, 179, 8, 0.5); }
.tile-256 { background: #facc15; color: #022c22; font-size: 1.4rem; }
.tile-512 { background: #10b981; color: #022c22; font-size: 1.4rem; }
.tile-1024 { background: #06b6d4; color: #022c22; font-size: 1.2rem; }
.tile-2048 { background: #39ff14; color: #022c22; font-size: 1.2rem; box-shadow: 0 0 25px var(--neon-glow-lime); }

/* Virtual D-Pad for Snake */
.dpad-btn {
  width: 68px;
  height: 68px;
  background: rgba(18, 24, 52, 0.95);
  border: 2px solid rgba(0, 240, 255, 0.4);
  border-radius: 20px;
  color: var(--neon-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6), inset 0 0 10px rgba(0, 240, 255, 0.12);
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease;
}

.dpad-btn:active {
  background: var(--neon-cyan);
  color: #060714;
  border-color: #ffffff;
  transform: scale(0.92);
  box-shadow: 0 0 25px var(--neon-glow-cyan);
}

/* Mini D-Pad for 2048 */
.dpad-btn-mini {
  width: 54px;
  height: 54px;
  background: rgba(18, 24, 48, 0.95);
  border: 1.5px solid rgba(0, 240, 255, 0.35);
  border-radius: 16px;
  color: var(--neon-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, background 0.08s ease;
}

.dpad-btn-mini:active {
  background: var(--neon-cyan);
  color: #060714;
  transform: scale(0.92);
}

@keyframes tilePop {
  0% { transform: scale(0.8); opacity: 0.7; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.tile-pop {
  animation: tilePop 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hidden {
  display: none !important;
}
