/* CSS Variables & Theme System */
:root {
  --primary: #2ECC71;
  --primary-dark: #27AE60;
  --primary-light: #58D68D;
  --secondary: #3498DB;
  --accent: #E74C3C;
  --warning: #F39C12;
  
  --background: #0A0A0A;
  --background-alt: #111111;
  --surface: #1A1A1A;
  --surface-alt: #252525;
  --border: #333333;
  --text: #E0E0E0;
  --text-muted: #999999;
  --text-dim: #666666;
  
  --ball: #FF3B3B;
  --paddle: var(--primary);
  
  --shadow: rgba(0, 0, 0, 0.5);
  --glow: rgba(46, 204, 113, 0.3);
  --glass: rgba(255, 255, 255, 0.1);
  
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;
  
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s ease-out;
  --transition-slow: all 0.5s ease-in-out;
}

/* Light Theme */
body.light-theme {
  --background: #FFFFFF;
  --background-alt: #F8F9FA;
  --surface: #F0F2F5;
  --surface-alt: #E9ECEF;
  --border: #DEE2E6;
  --text: #212529;
  --text-muted: #6C757D;
  --text-dim: #ADB5BD;
  --ball: #DC3545;
  --shadow: rgba(0, 0, 0, 0.15);
  --glow: rgba(46, 204, 113, 0.2);
  --glass: rgba(0, 0, 0, 0.05);
}

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

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  font-family: var(--font-family);
  font-weight: var(--font-weight-normal);
  background: var(--background);
  color: var(--text);
  overflow: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page Loader */
.page-loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--background);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.page-loader.hidden {
  opacity: 0;
  visibility: hidden;
}

.loader-content {
  text-align: center;
}

.loader-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 1rem;
  animation: pulse 2s infinite;
}

.loader-icon svg {
  width: 100%;
  height: 100%;
  fill: var(--primary);
}

.loader-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Background Particles */
.background-particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.3;
}

.particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: var(--primary);
  border-radius: 50%;
  animation: float 10s infinite linear;
}

@keyframes float {
  0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(-10px) rotate(360deg); opacity: 0; }
}

/* Main Container */
.container {
  display: grid;
  grid-template-columns: 400px 1fr;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* Left Panel */
.left-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.left-panel::-webkit-scrollbar {
  width: 6px;
}

.left-panel::-webkit-scrollbar-track {
  background: transparent;
}

.left-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Brand Section */
.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  padding: 1rem;
  border-radius: var(--border-radius);
  transition: var(--transition);
  background: linear-gradient(135deg, var(--glass), transparent);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.brand:hover {
  background: linear-gradient(135deg, var(--glow), transparent);
  transform: translateY(-2px);
}

.brand-icon-wrapper {
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px var(--glow);
}

.brand-icon {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.brand-icon.rotate {
  transform: rotate(360deg) scale(1.1);
}

.brand-text h1 {
  font-size: 1.5rem;
  font-weight: var(--font-weight-bold);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: var(--font-weight-medium);
}

/* Status Section */
.status-section {
  background: var(--surface-alt);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.status-dot {
  width: 12px;
  height: 12px;
  background: var(--primary);
  border-radius: 50%;
  animation: pulse 2s infinite;
  box-shadow: 0 0 10px var(--glow);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.1); }
}

.network-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.stat {
  text-align: center;
  padding: 0.75rem;
  background: var(--glass);
  border-radius: var(--border-radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-value {
  display: block;
  font-size: 1.25rem;
  font-weight: var(--font-weight-bold);
  color: var(--primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Buttons */
.buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  border-radius: var(--border-radius-sm);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
  transition: var(--transition);
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  position: relative;
  overflow: hidden;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--glass), transparent);
  transition: left 0.5s;
}

.button:hover::before {
  left: 100%;
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--shadow);
}

.button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  box-shadow: 0 4px 15px var(--glow);
}

.button.secondary {
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.button.large {
  padding: 1.25rem 2rem;
  font-size: 1.1rem;
}

.button-icon {
  font-size: 1rem;
}

.play-button {
  background: linear-gradient(135deg, var(--accent), #C0392B);
  color: white;
  border: none;
  box-shadow: 0 4px 20px rgba(231, 76, 60, 0.3);
  font-size: 1rem;
  font-weight: var(--font-weight-semibold);
}

/* Controls */
.controls {
  background: var(--surface-alt);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.control-group {
  margin-bottom: 1.5rem;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Theme Toggle */
.theme-toggle {
  width: 60px;
  height: 30px;
  background: var(--surface);
  border-radius: 15px;
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}

.theme-slider {
  width: 26px;
  height: 26px;
  background: var(--primary);
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: var(--transition);
  box-shadow: 0 2px 5px var(--shadow);
}

body.light-theme .theme-slider {
  transform: translateX(30px);
}

/* Difficulty Selector */
.difficulty-selector {
  display: flex;
  gap: 0.5rem;
}

.difficulty-btn {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.8rem;
  font-weight: var(--font-weight-medium);
}

.difficulty-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Leaderboard */
.leaderboard {
  background: var(--surface-alt);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.leaderboard h3 {
  margin-bottom: 1rem;
  font-weight: var(--font-weight-semibold);
  color: var(--text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.stat-item {
  text-align: center;
  padding: 1rem 0.5rem;
  background: var(--glass);
  border-radius: var(--border-radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-number {
  display: block;
  font-size: 1.5rem;
  font-weight: var(--font-weight-bold);
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.stat-text {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Right Panel - FIXED */
.right-panel {
  background: var(--background);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Game Header - FIXED */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  z-index: 10;
}

.game-title h2 {
  font-size: 1.5rem;
  font-weight: var(--font-weight-bold);
  margin-bottom: 0.25rem;
}

.game-title p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.fps-counter {
  background: var(--surface-alt);
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius-sm);
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  color: var(--primary);
  border: 1px solid var(--border);
}

/* Game Wrapper - COMPLETELY FIXED */
.game-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 1rem;
  min-height: 0;
  overflow: hidden;
}

/* Canvas - FIXED */
canvas {
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 40px var(--shadow), 0 0 20px var(--glow);
  transition: var(--transition);
  max-width: calc(100% - 2rem);
  max-height: calc(100% - 8rem);
  width: auto;
  height: auto;
  display: block;
  z-index: 5;
}

canvas:hover {
  box-shadow: 0 15px 50px var(--shadow), 0 0 30px var(--glow);
}

/* Overlay - COMPLETELY FIXED */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  border-radius: inherit;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

/* Show overlay when active */
.overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}

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

.overlay-content {
  text-align: center;
  max-width: 90%;
  width: 100%;
  max-width: 400px;
  padding: 2rem 1.5rem;
  background: var(--surface);
  border-radius: var(--border-radius);
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  transform: translateY(20px);
  transition: transform 0.3s ease-in-out;
}

.overlay.active .overlay-content {
  transform: translateY(0);
}

.overlay-content h2 {
  font-size: 1.75rem;
  margin-bottom: 1rem;
  font-weight: var(--font-weight-bold);
  color: var(--text);
}

.overlay-content p {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 1rem;
  line-height: 1.5;
}

/* Scoreboard - FIXED */
.scoreboard {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: var(--surface-alt);
  padding: 0.75rem 1.5rem;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px var(--shadow);
  z-index: 100;
}

.score-item {
  text-align: center;
}

.score-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.score-value {
  font-size: 2rem;
  font-weight: var(--font-weight-bold);
  color: var(--primary);
}

.score-divider {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: var(--font-weight-bold);
}

/* Game Effects */
.game-effects {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.effect-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--primary);
  border-radius: 50%;
  animation: effectFade 0.5s ease-out forwards;
}

@keyframes effectFade {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.3);
  }
}

/* Footer */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem 2rem;
  z-index: 100;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.footer-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-content a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

.footer-content a:hover {
  color: var(--primary-light);
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
}

.footer-links a:hover {
  color: var(--primary);
}

/* Responsive Design - IMPROVED */
@media (max-width: 1024px) {
  .container {
    grid-template-columns: 300px 1fr;
  }
  
  .left-panel {
    padding: 1.5rem;
    gap: 1.5rem;
  }
  
  .game-wrapper {
    padding: 1rem;
  }
  
  canvas {
    max-width: calc(100% - 1rem);
    max-height: calc(100% - 6rem);
  }
  
  .game-header {
    padding: 1rem 1.5rem;
  }
}

@media (max-width: 768px) {
  body {
    overflow-y: auto;
  }
  
  .container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: 100vh;
  }
  
  .left-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 1rem;
    height: auto;
    max-height: none;
  }
  
  .left-panel > * {
    flex-shrink: 0;
  }
  
  .brand {
    min-width: 200px;
  }
  
  .buttons {
    min-width: 180px;
  }
  
  .controls {
    min-width: 200px;
  }
  
  .leaderboard {
    min-width: 250px;
  }
  
  .right-panel {
    min-height: 70vh;
  }
  
  .game-header {
    padding: 1rem;
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .game-wrapper {
    padding: 1rem 0.5rem;
    min-height: 60vh;
  }
  
  canvas {
    width: 100%;
    max-width: calc(100vw - 2rem);
    max-height: calc(60vh - 4rem);
  }
  
  .overlay-content {
    padding: 1.5rem 1rem;
    margin: 0 1rem;
  }
  
  .overlay-content h2 {
    font-size: 1.5rem;
  }
  
  .overlay-content p {
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
  }
  
  .scoreboard {
    position: relative;
    transform: none;
    margin-bottom: 1rem;
    gap: 1rem;
    padding: 0.5rem 1rem;
    width: fit-content;
    align-self: center;
  }
  
  .score-value {
    font-size: 1.5rem;
  }
  
  footer {
    position: relative;
  }
  
  .footer-content {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .left-panel {
    flex-direction: column;
    height: auto;
    max-height: none;
    overflow-y: visible;
    overflow-x: hidden;
    padding: 0.75rem;
  }
  
  .left-panel > * {
    flex-shrink: 1;
    min-width: auto;
  }
  
  .brand {
    padding: 0.75rem;
  }
  
  .brand-text h1 {
    font-size: 1.25rem;
  }
  
  .buttons {
    gap: 0.5rem;
  }
  
  .button {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
  }
  
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .game-wrapper {
    padding: 0.5rem;
    min-height: 50vh;
  }
  
  canvas {
    max-width: calc(100vw - 1rem);
    max-height: calc(50vh - 2rem);
  }
  
  .overlay-content {
    padding: 1rem 0.75rem;
    margin: 0 0.5rem;
  }
  
  .overlay-content h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
  }
  
  .overlay-content p {
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
  }
  
  .scoreboard {
    padding: 0.5rem 0.75rem;
    gap: 0.75rem;
  }
  
  .score-value {
    font-size: 1.25rem;
  }
  
  .score-label {
    font-size: 0.7rem;
  }
}

/* Landscape Mobile Orientation */
@media (max-width: 768px) and (orientation: landscape) {
  .container {
    grid-template-rows: auto 1fr;
  }
  
  .left-panel {
    max-height: 120px;
    flex-direction: row;
    overflow-x: auto;
  }
  
  .right-panel {
    min-height: calc(100vh - 140px);
  }
  
  .game-wrapper {
    flex-direction: column;
    padding: 0.5rem;
    min-height: calc(100vh - 200px);
  }
  
  canvas {
    max-height: calc(100vh - 240px);
    max-width: calc(100vw - 2rem);
  }
  
  .scoreboard {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
  }
}

/* Fix for very small screens */
@media (max-height: 600px) {
  .overlay-content {
    padding: 1rem;
  }
  
  .overlay-content h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
  }
  
  .overlay-content p {
    font-size: 0.85rem;
    margin-bottom: 1rem;
  }
  
  .game-wrapper {
    padding: 0.5rem;
    min-height: calc(100vh - 150px);
  }
  
  canvas {
    max-height: calc(100vh - 200px);
  }
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 5px var(--glow);
  }
  50% {
    box-shadow: 0 0 20px var(--glow), 0 0 30px var(--glow);
  }
}

.animate-in {
  animation: slideIn 0.5s ease-out;
}

.animate-out {
  animation: slideOut 0.3s ease-in;
}

/* Utility Classes */
.hidden {
  display: none !important;
}

.visible {
  display: block !important;
}

.fade-in {
  opacity: 0;
  animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.blur {
  filter: blur(5px);
  transition: filter 0.3s ease;
}

.no-blur {
  filter: blur(0);
}

/* Show overlay utility */
.show-overlay .overlay {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}

/* Focus States */
.button:focus,
.difficulty-btn:focus,
.theme-toggle:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: var(--primary);
  color: white;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--surface);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}