:root {
  --bg-gradient: linear-gradient(135deg, #020813 0%, #051937 50%, #004d7a 100%);
  --neon-blue: #00f0ff;
  --neon-teal: #00f5d4;
  --neon-pink: #ff007f;
  --neon-purple: #9d4edd;
  --glass-bg: rgba(5, 25, 55, 0.4);
  --glass-border: rgba(0, 240, 255, 0.15);
  --glass-border-hover: rgba(0, 240, 255, 0.4);
  --text-primary: #ffffff;
  --text-muted: #8eb3cf;
  --font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Water Atmosphere Background Elements */
.water-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.wave {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 200%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(0, 245, 212, 0.03) 0%, transparent 70%);
  transform-origin: center bottom;
  animation: waveMotion 20s infinite linear;
}

.wave:nth-child(2) {
  animation: waveMotion 25s infinite linear reverse;
  opacity: 0.7;
}

.bubble {
  position: absolute;
  bottom: -50px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.05) 70%, rgba(0, 240, 255, 0.2) 100%);
  border-radius: 50%;
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5), 0 0 10px rgba(0, 240, 255, 0.2);
  animation: rise 12s infinite linear;
}

@keyframes rise {
  0% {
    transform: translateY(0) translateX(0) scale(1);
    opacity: 0;
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(-110vh) translateX(var(--drift, 50px)) scale(1.1);
    opacity: 0;
  }
}

@keyframes waveMotion {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Main Container Layout */
.game-container {
  position: relative;
  width: 100%;
  max-width: 1200px;
  height: 95vh;
  max-height: 850px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  z-index: 10;
}

/* Glassmorphism panel styling */
.panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px 0 rgba(0, 8, 20, 0.37);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
  border-color: var(--glass-border-hover);
  box-shadow: 0 8px 32px 0 rgba(0, 240, 255, 0.1);
}

/* Side Panels Content */
.left-panel {
  justify-content: flex-start;
  gap: 20px;
}

.right-panel {
  justify-content: space-between;
}

.title-area {
  text-align: center;
  margin-bottom: 10px;
}

.title-logo {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(to right, var(--neon-blue), var(--neon-teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
  letter-spacing: 1px;
  line-height: 1.2;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 5px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  margin-bottom: 15px;
}

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

.stat-val {
  font-size: 1.8rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
  font-variant-numeric: tabular-nums;
}

.stat-val.highlight {
  color: var(--neon-teal);
  text-shadow: 0 0 10px rgba(0, 245, 212, 0.4);
}

/* Next / Held Pieces Preview */
.preview-box {
  background: rgba(2, 8, 19, 0.4);
  border: 1px solid rgba(0, 240, 255, 0.1);
  border-radius: 12px;
  padding: 10px;
  height: 110px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.preview-canvas {
  width: 100%;
  height: 100%;
}

/* Center Play Area */
.play-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
}

.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

#gameCanvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  aspect-ratio: 11 / 7;
  background: rgba(1, 10, 25, 0.6);
  border: 1px solid rgba(0, 240, 255, 0.1);
  border-radius: 24px;
  box-shadow: inset 0 0 40px rgba(0, 240, 255, 0.05), 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* Controls / Instructions list */
.controls-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.control-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}

.key-badge {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 2px 6px;
  color: #fff;
  font-family: monospace;
  font-size: 0.75rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

/* Audio Selector */
.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  width: 100%;
}

.track-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s ease;
}

.track-btn:hover {
  background: rgba(0, 240, 255, 0.1);
  border-color: rgba(0, 240, 255, 0.3);
}

.track-btn.active {
  background: rgba(0, 245, 212, 0.15);
  border-color: var(--neon-teal);
  color: var(--neon-teal);
  font-weight: 600;
  box-shadow: 0 0 10px rgba(0, 245, 212, 0.1);
}

.vol-slider-container {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 5px;
  min-width: 0;
  width: 100%;
}

.vol-slider {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  height: 4px;
  border-radius: 2px;
  outline: none;
}

.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  background: var(--neon-blue);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 5px var(--neon-blue);
  transition: transform 0.1s ease;
}

.vol-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Modals & Overlays (No JS popups) */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(2, 8, 19, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-title {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 10px;
  letter-spacing: 2px;
  background: linear-gradient(to right, var(--neon-blue), var(--neon-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay-text {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 30px;
  max-width: 300px;
  line-height: 1.5;
}

/* Elegant glass buttons */
.btn {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid var(--neon-blue);
  border-radius: 12px;
  color: #fff;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.15);
  margin: 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  background: var(--neon-blue);
  color: #020813;
  box-shadow: 0 0 25px var(--neon-blue);
  transform: translateY(-2px);
}

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

.btn-secondary {
  border-color: var(--neon-teal);
  background: rgba(0, 245, 212, 0.05);
  box-shadow: 0 0 15px rgba(0, 245, 212, 0.1);
}

.btn-secondary:hover {
  background: var(--neon-teal);
  border-color: var(--neon-teal);
  color: #020813;
  box-shadow: 0 0 25px var(--neon-teal);
}

.btn-danger {
  border-color: var(--neon-pink);
  background: rgba(255, 0, 127, 0.05);
  box-shadow: 0 0 15px rgba(255, 0, 127, 0.1);
}

.btn-danger:hover {
  background: var(--neon-pink);
  border-color: var(--neon-pink);
  color: #fff;
  box-shadow: 0 0 25px var(--neon-pink);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 250px;
}

/* Main menu hero art */
#menuOverlay {
  background: rgba(2, 8, 19, 0.82);
  overflow: hidden;
  justify-content: center;
  padding: 18px 24px;
}

.menu-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  height: 100%;
  max-height: 100%;
}

.menu-hero-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(0, 240, 255, 0.25);
  box-shadow:
    0 0 30px rgba(0, 240, 255, 0.15),
    0 0 60px rgba(255, 0, 127, 0.08);
  animation: menuHeroFloat 5s ease-in-out infinite;
}

.menu-hero-img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 180px;
  max-height: 52vh;
  object-fit: cover;
  object-position: center 40%;
  animation: menuHeroDrift 14s ease-in-out infinite alternate;
  will-change: transform;
}

@keyframes menuHeroFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes menuHeroDrift {
  0% { transform: scale(1.04) translate(0, 0); }
  100% { transform: scale(1.1) translate(-1.2%, -0.8%); }
}

.menu-hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 22px;
  background: linear-gradient(
    180deg,
    rgba(2, 8, 19, 0.55) 0%,
    transparent 35%,
    transparent 55%,
    rgba(2, 8, 19, 0.88) 100%
  );
}

.menu-title {
  font-size: 2.1rem;
  margin-bottom: 0;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.8);
}

.menu-play-btn {
  margin: 0;
  padding: 14px 40px;
  font-size: 1.05rem;
  letter-spacing: 1.5px;
  box-shadow:
    0 0 25px rgba(0, 240, 255, 0.35),
    0 4px 20px rgba(0, 0, 0, 0.5);
}

.menu-play-btn:hover {
  transform: translateY(-3px) scale(1.02);
}

.menu-dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(5, 25, 55, 0.65);
  border: 1px solid rgba(0, 240, 255, 0.15);
  backdrop-filter: blur(8px);
}

.menu-tagline {
  margin: 0;
  max-width: none;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.3px;
}

.menu-tracks-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.menu-tracks-row .track-btn {
  font-size: 0.68rem;
  padding: 7px 6px;
  text-align: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.menu-vols .vol-slider-container {
  margin-top: 0;
  font-size: 0.72rem;
  gap: 6px;
}

.menu-vols .vol-slider-container span {
  min-width: 34px;
  text-align: right;
}

/* Touch Controls (Virtual Gamepad) */
.mobile-controls {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  padding: 10px;
  z-index: 20;
  position: absolute;
  bottom: 10px;
  left: 0;
}

.touch-btn {
  background: rgba(5, 25, 55, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: #fff;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  cursor: pointer;
  touch-action: manipulation;
}

.touch-btn:active {
  background: var(--neon-blue);
  color: #000;
  border-color: var(--neon-blue);
  box-shadow: 0 0 15px var(--neon-blue);
}

/* High Score Board */
.high-score-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 15px;
}

.high-score-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.high-score-item.first {
  background: rgba(0, 245, 212, 0.08);
  border: 1px solid rgba(0, 245, 212, 0.2);
  color: var(--neon-teal);
  font-weight: 600;
}

/* Floating HUD panel styling (Desktop) */
.hud-panel {
  position: absolute;
  top: 25px;
  width: 145px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 50;
  pointer-events: auto;
}

.left-hud {
  left: 20px;
}

.right-hud {
  right: 20px;
}

.hud-box {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 10px;
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  box-shadow: 0 4px 20px rgba(0, 8, 20, 0.4);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  min-width: 0;
  overflow: hidden;
}

.hud-box:hover {
  border-color: var(--glass-border-hover);
  box-shadow: 0 4px 20px rgba(0, 240, 255, 0.15);
}

.hud-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
  text-align: center;
  font-weight: 600;
}

.hud-val {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.1);
}

.hud-val.highlight {
  color: var(--neon-teal);
  text-shadow: 0 0 10px rgba(0, 245, 212, 0.35);
}

.stat-item {
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
}

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

.hud-panel .preview-box {
  height: 80px;
}

.hud-panel .track-btn {
  padding: 5px 8px;
  font-size: 0.72rem;
  margin-bottom: 4px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  justify-content: center;
}

.hud-panel .vol-slider-container {
  margin-top: 4px;
  gap: 6px;
  padding: 0 1px;
}

.hud-panel .vol-slider-container span {
  flex: 0 0 auto;
  min-width: 32px;
  font-size: 0.65rem;
  text-align: right;
}

.hud-panel .vol-slider {
  flex: 1 1 0;
  min-width: 0;
}

.controls-list-brief {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.controls-list-brief div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.03);
  padding-bottom: 3px;
}

.controls-list-brief div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

/* Responsive Scaling for Desktop vs. Mobile */
@media (max-width: 900px) {
  body {
    align-items: flex-start;
    overflow-y: auto;
  }
  
  .game-container {
    flex-direction: column;
    height: auto;
    max-height: none;
    padding: 10px;
    gap: 10px;
  }

  .title-area {
    margin-bottom: 5px;
  }

  .play-area {
    width: 100%;
    position: relative;
    padding-bottom: 75px; /* Leave space for touch controls */
  }

  .board-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: auto;
  }

  #gameCanvas {
    aspect-ratio: 11 / 7;
    width: 100%;
    max-height: 50vh;
  }

  .hud-panel {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
  }

  .hud-box {
    flex: 1;
    min-width: 100px;
    padding: 8px;
    margin-bottom: 0;
  }

  .hud-panel .preview-box {
    height: 65px;
  }

  .controls-box {
    display: none; /* Hide keys on mobile */
  }

  .mobile-controls {
    display: grid;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(2, 8, 19, 0.9);
    border-top: 1px solid var(--glass-border);
    padding: 10px;
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.5);
  }
  
  .overlay {
    padding: 20px;
  }
  
  .overlay-title {
    font-size: 2rem;
  }

  #menuOverlay {
    padding: 12px;
    justify-content: center;
  }

  .menu-hero-img {
    max-height: 38vh;
    min-height: 140px;
  }

  .menu-title {
    font-size: 1.5rem;
  }

  .menu-play-btn {
    padding: 12px 28px;
    font-size: 0.95rem;
  }

  .menu-tagline {
    font-size: 0.75rem;
  }

  .menu-tracks-row .track-btn {
    font-size: 0.62rem;
    padding: 6px 4px;
  }

  .menu-dock {
    padding: 10px;
    gap: 6px;
  }
}
