/* ========== RESET & BASE ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: #1a1a3e;
  --text-primary: #e0e0ff;
  --text-secondary: #a0a0c0;
  --accent: #00d4ff;
  --accent2: #ff006e;
  --accent3: #7b61ff;
  --gold: #ffd700;
  --success: #00ff88;
  --danger: #ff4444;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --radius: 12px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-mono: 'Courier New', 'Consolas', monospace;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent2);
}

h1, h2, h3 {
  font-weight: 700;
  line-height: 1.2;
}

/* ========== ACCESSIBILITY ========== */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #000;
  padding: 12px 24px;
  border-radius: 0 0 8px 8px;
  z-index: 10000;
  font-weight: 700;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
}

*:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ========== NAVBAR ========== */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(10, 10, 26, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  transition: all var(--transition);
}

.navbar.scrolled {
  background: rgba(10, 10, 26, 0.98);
  box-shadow: 0 4px 30px rgba(0,0,0,0.3);
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 0.75rem 0;
}

.nav-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.nav-menu {
  list-style: none;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-menu a {
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  display: block;
}

.nav-menu a:hover,
.nav-menu a:focus {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
}

.nav-toggles {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.language-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.language-switcher label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#lang-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}

#lang-select:focus {
  border-color: var(--accent);
}

.toggle-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.toggle-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: rgba(0, 212, 255, 0.08);
}

.toggle-btn.active {
  background: rgba(0, 212, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
}

/* ========== MAIN SECTIONS ========== */
main {
  margin-top: 64px;
}

section {
  min-height: 100vh;
  padding: 5rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.demo-section {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.demo-section h2 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--accent), var(--accent3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.demo-section > p {
  color: var(--text-secondary);
  text-align: center;
  max-width: 700px;
  margin-bottom: 2rem;
  font-size: 1.05rem;
}

.demo-canvas {
  display: block;
  margin: 0 auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #000;
  max-width: 100%;
}

/* ========== HERO ========== */
.hero-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #151535 0%, var(--bg-primary) 70%);
}

.hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 800px;
  padding: 2rem;
}

.hero-content h1 {
  font-size: clamp(2.5rem, 7vw, 5rem);
  font-weight: 900;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 50%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleGlow 4s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.3); }
}

.hero-content p {
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.hero-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ========== VISUALS SECTION ========== */
.vis-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.vis-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition);
}

.vis-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.vis-btn.active {
  background: rgba(0, 212, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

#visual-canvas {
  width: 90%;
  max-width: 900px;
  height: 450px;
}

.vis-info {
  margin-top: 1rem;
  color: var(--text-secondary);
  text-align: center;
  font-size: 0.95rem;
  max-width: 700px;
}

/* ========== GAME SECTION ========== */
.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 700px;
}

.game-hud {
  display: flex;
  gap: 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.game-hud span:first-child {
  color: var(--accent);
}

.game-canvas {
  width: 90%;
  max-width: 700px;
  height: 400px;
  cursor: none;
}

.game-controls {
  display: flex;
  gap: 1rem;
}

.action-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent3));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.8rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.action-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(0, 212, 255, 0.5);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ========== DATA VIZ / ALGORITHMS ========== */
.algo-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.algo-controls select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}

.sort-canvas {
  width: 90%;
  max-width: 800px;
  height: 350px;
}

.stats-panel {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  width: 90%;
  max-width: 800px;
}

.stats-panel h3 {
  margin-bottom: 1rem;
  color: var(--accent);
  font-size: 1.1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-item {
  font-family: var(--font-mono);
  font-size: 1rem;
}

.stat-label {
  color: var(--text-secondary);
}

.stat-item span:last-child {
  color: var(--gold);
  font-weight: 700;
}

/* ========== AUDIO SECTION ========== */
.audio-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 800px;
}

.audio-controls .action-btn {
  margin-bottom: 0.5rem;
}

.freq-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.freq-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  min-width: 55px;
}

.freq-btn:hover {
  border-color: var(--accent3);
  color: var(--text-primary);
  background: rgba(123, 97, 255, 0.1);
}

.freq-btn:active {
  background: rgba(123, 97, 255, 0.25);
  transform: scale(0.95);
}

.audio-canvas {
  width: 90%;
  max-width: 800px;
  height: 300px;
  margin-top: 0.5rem;
}

/* ========== ABOUT SECTION ========== */
.about-section {
  background: var(--bg-primary);
}

.about-content {
  max-width: 800px;
  text-align: center;
  margin-bottom: 2rem;
}

.about-content p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.tech-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1.5rem;
  max-width: 900px;
  width: 100%;
  padding: 0 1rem;
}

.tech-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  transition: all var(--transition);
}

.tech-item:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
}

.tech-item .tech-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.tech-item .tech-name {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.95rem;
}

/* ========== FOOTER ========== */
.footer {
  text-align: center;
  padding: 3rem 2rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
}

.footer p {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 0.75rem;
}

.footer-links a {
  font-size: 0.9rem;
}

/* ========== DARK THEME ========== */
body.dark-mode {
  --bg-primary: #050510;
  --bg-secondary: #0a0a1e;
  --bg-card: #111128;
  --text-primary: #d0d0e8;
  --text-secondary: #8888a8;
  --border: rgba(255,255,255,0.05);
}

/* ========== LOW-SPEC MODE ========== */
body.low-spec {
  --transition: 0.15s ease;
}

body.low-spec .hero-content h1 {
  animation: none;
}

body.low-spec .vis-info,
body.low-spec .stats-panel,
body.low-spec .about-content {
  transition: opacity 0.3s;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .nav-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(10, 10, 26, 0.98);
    padding: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .nav-menu.open {
    display: flex;
  }

  .hamburger {
    display: block;
  }

  .nav-toggles {
    flex-direction: column;
    gap: 0.5rem;
  }

  .hero-content h1 {
    font-size: 2rem;
  }

  #visual-canvas,
  .game-canvas,
  .sort-canvas,
  .audio-canvas {
    height: 300px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .tech-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  section {
    padding: 3rem 1rem;
  }
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
  width: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}