:root {
  --bg-color: #0d0e15;
  --panel-bg: rgba(22, 24, 38, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --accent-color: #ff2a5f;
  --accent-glow: rgba(255, 42, 95, 0.4);
  --success-color: #39ff14;
  --text-primary: #f5f6f9;
  --text-muted: #8d92ac;
  --font-retro: 'Press Start 2P', monospace;
  --font-sans: 'Outfit', sans-serif;
  --tv-bezel-color: #302f35;
  --tv-screen-bg: #111;
}

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

body {
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(circle at 50% 20%, #1c1f36 0%, var(--bg-color) 80%),
    radial-gradient(circle at 10% 80%, #171120 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, #0d1a29 0%, transparent 50%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  padding: 20px;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.app-container {
  width: 100%;
  max-width: 1400px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

/* Header Styles */
.main-header {
  text-align: center;
  margin-bottom: 10px;
}

.logo-text {
  font-family: var(--font-retro);
  font-size: 3rem;
  letter-spacing: -2px;
  color: #fff;
  text-shadow: 
    0 0 10px var(--accent-glow),
    3px 3px 0px var(--accent-color),
    -3px -3px 0px #00f0ff;
  animation: logo-shimmer 4s infinite alternate;
}

@keyframes logo-shimmer {
  0%, 100% { text-shadow: 0 0 10px var(--accent-glow), 3px 3px 0px var(--accent-color), -3px -3px 0px #00f0ff; }
  50% { text-shadow: 0 0 20px var(--accent-glow), 4px 4px 0px var(--accent-color), -4px -4px 0px #00f0ff; }
}

.subtitle {
  font-family: var(--font-retro);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
  letter-spacing: 1px;
}

/* Layout Grid */
.game-layout {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  gap: 30px;
  align-items: start;
}

/* Panels (Sidebars) */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-title {
  font-family: var(--font-retro);
  font-size: 0.9rem;
  color: #fff;
  border-bottom: 2px solid var(--panel-border);
  padding-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Control Elements */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-group label {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.btn {
  font-family: var(--font-sans);
  font-weight: 800;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.btn-danger {
  background: var(--accent-color);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
  background: #ff4575;
}

.btn-danger:active {
  transform: translateY(1px);
}

/* Toggle Switches */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-primary);
  padding: 6px 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
  cursor: pointer;
}

.toggle-row input {
  display: none;
}

.toggle-row input + .switch::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #2a2e45;
  border-radius: 24px;
  transition: background-color 0.2s;
}

.toggle-row input + .switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background-color: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toggle-row input:checked + .switch::before {
  background-color: var(--accent-color);
}

.toggle-row input:checked + .switch::after {
  transform: translateX(24px);
}

/* Instructions */
.instructions {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.instructions h3 {
  color: #fff;
  font-size: 0.9rem;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.instructions ul {
  list-style-position: inside;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* TV Console Cabinet */
.tv-console-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.tv-cabinet {
  background-color: var(--tv-bezel-color);
  background-image: 
    linear-gradient(90deg, rgba(0,0,0,0.1) 0%, transparent 10%, transparent 90%, rgba(0,0,0,0.2) 100%),
    linear-gradient(180deg, #44434a 0%, #201f24 100%);
  border: 12px solid #1a191d;
  border-radius: 40px;
  padding: 24px;
  width: 100%;
  max-width: 680px;
  box-shadow: 
    0 25px 60px -10px rgba(0, 0, 0, 0.8),
    inset 0 4px 6px rgba(255,255,255,0.1),
    inset 0 -4px 6px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
}

/* TV Screen Wrapper */
.tv-screen-wrapper {
  background: var(--tv-screen-bg);
  border: 14px solid #232227;
  border-radius: 24px;
  position: relative;
  overflow: hidden;
  aspect-ratio: 256 / 224;
  box-shadow: 
    inset 0 0 40px rgba(0, 0, 0, 1),
    0 4px 10px rgba(0,0,0,0.3);
}

/* Game Canvas styling */
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background-color: #000;
  transition: opacity 0.5s ease;
}

/* CRT Overlay Screen Effects */
.crt-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

.scanlines {
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.04), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.04));
  background-size: 100% 4px, 6px 100%;
}

.vignette {
  background: radial-gradient(circle, transparent 50%, rgba(0,0,0,0.7) 120%);
  box-shadow: inset 0 0 60px rgba(0,0,0,0.9);
}

.curvature::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 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));
  z-index: 11;
  background-size: 100% 2px, 3px 100%;
  pointer-events: none;
}

.flicker {
  background: rgba(18, 16, 16, 0.1);
  opacity: 0;
  animation: crt-flicker 0.15s infinite;
}

@keyframes crt-flicker {
  0% { opacity: 0.07; }
  50% { opacity: 0.09; }
  100% { opacity: 0.06; }
}

.glow {
  background: radial-gradient(circle at center, rgba(255,255,255,0.03) 0%, transparent 70%);
  box-shadow: inset 0 0 40px rgba(255,255,255,0.05);
}

.static {
  background-image: repeating-radial-gradient(rgba(255,255,255,0.1), rgba(0,0,0,0.8) 2px);
  opacity: 0;
  transition: opacity 0.2s ease;
  background-size: 4px 4px;
  z-index: 12;
}

/* ==========================================
   MOBILE TOUCH CONTROLS
   ========================================== */
.mobile-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 12px 8px 4px;
  gap: 16px;
}

.dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  gap: 3px;
}

.dpad-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.6);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dpad-btn:active,
.dpad-btn.active {
  background: var(--accent-color);
  color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 12px var(--accent-glow);
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.center-dot {
  grid-column: 2; grid-row: 2;
  background: rgba(255,255,255,0.03);
  border-radius: 50%;
  cursor: default;
  pointer-events: none;
}
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

.action-buttons {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.action-btn {
  width: 56px;
  height: 56px;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-family: var(--font-retro);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.action-btn.btn-a {
  background: rgba(255, 42, 95, 0.2);
  border-color: rgba(255, 42, 95, 0.4);
}

.action-btn.btn-b {
  background: rgba(57, 255, 20, 0.15);
  border-color: rgba(57, 255, 20, 0.3);
}

.action-btn:active,
.action-btn.active {
  transform: scale(0.88);
}

.action-btn.btn-a:active,
.action-btn.btn-a.active {
  background: var(--accent-color);
  box-shadow: 0 0 16px var(--accent-glow);
}

.action-btn.btn-b:active,
.action-btn.btn-b.active {
  background: var(--success-color);
  color: #000;
  box-shadow: 0 0 16px rgba(57, 255, 20, 0.5);
}

/* TV Cabinet Bezel Bottom Controls */
.tv-bezel-bottom {
  border-top: 4px solid #28272c;
  padding-top: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tv-brand {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #1a191d;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.05);
}

.tv-controls-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.dial-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dial {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #1e1d21;
  border: 3px solid #141316;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.1);
  position: relative;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.dial::after {
  content: "";
  position: absolute;
  top: 3px; left: calc(50% - 2px);
  width: 4px; height: 8px;
  background: #ff2a5f;
  border-radius: 2px;
}

.dial-channel { transform: rotate(45deg); }
.dial-volume { transform: rotate(120deg); }

.dial-label {
  font-size: 0.6rem;
  font-weight: 800;
  color: #555;
}

.power-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  background-color: #222;
  box-shadow: 0 0 2px rgba(0,0,0,0.5);
  transition: all 0.3s ease;
}

.power-indicator.active {
  background-color: var(--success-color);
  box-shadow: 0 0 8px var(--success-color);
}

.speaker-grill {
  display: flex;
  gap: 3px;
  height: 25px;
}

.speaker-grill span {
  width: 3px;
  height: 100%;
  background: #1a191d;
  border-radius: 1.5px;
}

/* CRT Screen Power Off Dot Animation */
.crt-power-off-dot {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 6px; height: 6px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 10px #fff, 0 0 30px #fff;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

/* Right Sidebar Scoreboard & Leaderboard */
.score-display {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.score-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-item .label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.score-item .value {
  font-size: 1.2rem;
  letter-spacing: 1px;
}

.text-retro {
  font-family: var(--font-retro);
  color: var(--success-color);
  text-shadow: 0 0 5px rgba(57, 255, 20, 0.3);
}

.leaderboard-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.leaderboard-section h3 {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  font-family: var(--font-retro);
  font-size: 0.65rem;
  padding: 8px 12px;
  background: rgba(0,0,0,0.15);
  border: 1px solid rgba(255,255,255,0.03);
  border-radius: 6px;
}

.leaderboard-list .rank {
  color: var(--text-muted);
  margin-right: 8px;
}

.leaderboard-list .name {
  flex-grow: 1;
  color: #fff;
}

.leaderboard-list .score {
  color: var(--success-color);
}

/* Footer styling */
.main-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
  border-top: 1px solid var(--panel-border);
  padding-top: 20px;
}

.main-footer a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 600;
}

.main-footer a:hover {
  text-decoration: underline;
}

/* Game Instructions Styling */
.inst-game-title {
  color: var(--accent-color);
  font-size: 0.8rem;
  font-family: var(--font-retro);
  margin-bottom: 12px;
  border-bottom: 1px dashed rgba(255, 42, 95, 0.3);
  padding-bottom: 6px;
}
.inst-set ul {
  list-style-type: square;
  padding-left: 15px;
}
.inst-set li {
  margin-bottom: 6px;
  line-height: 1.3;
}
.inst-set strong {
  color: #fff;
}


/* ==========================================
   RESPONSIVE BREAKPOINTS
   ========================================== */

/* Tablet and smaller desktop */
@media (max-width: 1200px) {
  .game-layout {
    grid-template-columns: 1fr;
    max-width: 700px;
    margin: 0 auto;
  }
  .sidebar {
    order: 2;
  }
  .tv-console-container {
    order: 1;
  }
  .leaderboard-panel {
    order: 3;
  }
}

/* Mobile / Phone */
@media (max-width: 768px) {
  body {
    padding: 8px;
    align-items: flex-start;
  }

  .app-container {
    gap: 16px;
  }

  .main-header {
    margin-bottom: 4px;
  }

  .logo-text {
    font-size: 1.6rem;
    letter-spacing: -1px;
  }

  .subtitle {
    font-size: 0.55rem;
    margin-top: 4px;
  }

  .game-layout {
    gap: 12px;
    max-width: 100%;
  }

  .panel {
    padding: 14px;
    gap: 12px;
    border-radius: 12px;
  }

  .panel-title {
    font-size: 0.7rem;
    padding-bottom: 8px;
  }

  /* TV Cabinet mobile */
  .tv-cabinet {
    border-width: 6px;
    border-radius: 20px;
    padding: 10px;
    gap: 10px;
    max-width: 100%;
  }

  .tv-screen-wrapper {
    border-width: 8px;
    border-radius: 14px;
  }

  /* Mobile controls visible */
  .mobile-controls {
    display: flex !important;
  }

  /* Reduce TV bezel controls on mobile */
  .tv-bezel-bottom {
    padding-top: 8px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .tv-brand {
    font-size: 0.55rem;
    letter-spacing: 1px;
  }

  .tv-controls-row {
    gap: 10px;
  }

  .dial {
    width: 22px;
    height: 22px;
  }

  .dial::after {
    top: 2px;
    width: 3px;
    height: 6px;
  }

  .dial-label {
    font-size: 0.5rem;
  }

  .speaker-grill {
    height: 18px;
  }

  .speaker-grill span {
    width: 2px;
  }

  /* Instructions compact */
  .instructions {
    padding: 10px;
    font-size: 0.75rem;
  }

  .inst-game-title {
    font-size: 0.6rem;
  }

  /* Score display compact */
  .score-item .value {
    font-size: 0.9rem;
  }

  .score-item .label {
    font-size: 0.65rem;
  }

  .leaderboard-list li {
    padding: 6px 8px;
    font-size: 0.55rem;
  }

  .leaderboard-list .rank {
    margin-right: 4px;
  }

  .btn {
    padding: 10px 14px;
    font-size: 0.75rem;
  }

  .toggle-row {
    font-size: 0.8rem;
  }

  .switch {
    width: 40px;
    height: 20px;
  }

  .toggle-row input + .switch::after {
    width: 16px;
    height: 16px;
  }

  .toggle-row input:checked + .switch::after {
    transform: translateX(20px);
  }

  .main-footer {
    font-size: 0.65rem;
    padding-top: 12px;
  }
}

/* Extra small phones */
@media (max-width: 480px) {
  body {
    padding: 4px;
  }

  .logo-text {
    font-size: 1.2rem;
  }

  .subtitle {
    font-size: 0.45rem;
    margin-top: 2px;
  }

  .tv-cabinet {
    border-width: 4px;
    border-radius: 14px;
    padding: 6px;
    gap: 6px;
  }

  .tv-screen-wrapper {
    border-width: 6px;
    border-radius: 10px;
  }

  /* Bigger D-pad on tiny phones */
  .dpad-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
  }

  .dpad {
    grid-template-columns: 40px 40px 40px;
    grid-template-rows: 40px 40px 40px;
    gap: 2px;
  }

  .action-btn {
    width: 50px;
    height: 50px;
    font-size: 0.7rem;
  }

  .panel {
    padding: 10px;
    gap: 8px;
  }

  /* Hide some non-essential UI on very small screens */
  .control-group label {
    font-size: 0.7rem;
  }

  .instructions h3 {
    font-size: 0.75rem;
  }

  .leaderboard-section h3 {
    font-size: 0.7rem;
  }
}

/* Landscape mobile: optimize for horizontal viewing */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 4px;
  }

  .main-header {
    display: none;
  }

  .game-layout {
    gap: 8px;
  }

  .sidebar {
    display: none;
  }

  .tv-cabinet {
    border-width: 4px;
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    max-width: 90vh;
  }

  .tv-screen-wrapper {
    border-width: 4px;
    border-radius: 8px;
  }

  .tv-bezel-bottom {
    display: none;
  }

  .mobile-controls {
    display: flex !important;
    padding: 4px 8px 0;
  }

  .dpad-btn {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
  }

  .dpad {
    grid-template-columns: 36px 36px 36px;
    grid-template-rows: 36px 36px 36px;
    gap: 1px;
  }

  .action-btn {
    width: 44px;
    height: 44px;
    font-size: 0.65rem;
  }

  .main-footer {
    display: none;
  }
}
