:root {
  --bg: #0b0c10;
  --surface: #121318;
  --text: #e6e6e6;
  --muted: #a6a6a6;
  --brand: #6bc46d; /* green-ish accent */
  --brand-ink: #0a4124;
  --border: #262733;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

:root.light {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --text: #111318;
  --muted: #475569;
  --brand: #2563eb; /* blue accent for light mode */
  --brand-ink: #0b1b3a;
  --border: #e5e7eb;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family:
    ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Noto Sans,
    Ubuntu, Cantarell, Helvetica Neue, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% -10%, #171822 0%, var(--bg) 60%);
  line-height: 1.5;
  /* Improve text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 960px;
  padding: 0 1rem;
  margin: 0 auto;
}

.site-header {
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  position: relative;
}

/* Mobile Navigation Toggle */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-around;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 20;
}

.menu-toggle-line {
  width: 100%;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: all 0.3s ease;
  transform-origin: center;
}

.menu-toggle-open .menu-toggle-line:nth-child(1) {
  transform: rotate(45deg) translate(6px, 6px);
}

.menu-toggle-open .menu-toggle-line:nth-child(2) {
  opacity: 0;
}

.menu-toggle-open .menu-toggle-line:nth-child(3) {
  transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Navigation */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }
  
  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: 1rem;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 15;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .nav-open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }
  
  .nav a {
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    display: block;
    text-align: center;
    /* Larger tap targets for mobile */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.brand {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.5px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 1rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}
.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--text);
  background: color-mix(in oklab, var(--surface) 40%, transparent);
}

.site-main .hero {
  padding: 3rem 0 2rem;
  text-align: left;
  position: relative;
  overflow: hidden;
}

/* Parallax Background */
.parallax-bg {
  position: absolute;
  top: -10%;
  left: -10%;
  right: -10%;
  bottom: -10%;
  background: linear-gradient(135deg, 
    color-mix(in oklab, var(--brand) 15%, transparent) 0%,
    color-mix(in oklab, var(--brand) 8%, transparent) 50%,
    transparent 100%);
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
  transform: scale(1.1);
  transition: transform 0.1s ease-out;
}

/* Hero content positioning */
.hero-content {
  position: relative;
  z-index: 1;
}
.hero h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}
.hero p {
  color: var(--muted);
  margin-top: 0;
}

.actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Responsive button sizing */
@media (max-width: 480px) {
  .actions {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
    min-height: 44px; /* Better mobile tap target */
  }
}

.btn {
  appearance: none;
  border: 1px solid color-mix(in oklab, var(--brand) 40%, var(--border));
  background: linear-gradient(180deg, color-mix(in oklab, var(--brand) 18%, var(--surface)), var(--surface));
  color: var(--text);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
  /* Ensure minimum tap target size */
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

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

.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.btn-secondary {
  background: color-mix(in oklab, var(--surface) 85%, black);
  border-color: var(--border);
}

.card {
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.tile {
  background: color-mix(in oklab, var(--surface) 95%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  padding: 1.5rem 0;
  color: var(--muted);
}

/* 404 page center layout */
.center-404 {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1rem;
}

/* Small utility for code look */
code {
  background: color-mix(in oklab, var(--surface) 60%, transparent);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Experiments Section */
.experiments {
  margin-top: 3rem;
}

.experiments h3 {
  margin-bottom: 0.5rem;
}

.experiments > p {
  color: var(--muted);
  margin-bottom: 2rem;
}

.experiment-card {
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
}

.experiment-card h4, .experiment-card h5 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.experiment-card > p {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

/* Canvas Particle Animation */
.canvas-container {
  position: relative;
  height: 300px;
  background: color-mix(in oklab, var(--surface) 40%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1rem;
}

#particleCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.particle-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

/* Carousel Styles */
.carousel-container {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 40%, transparent);
  margin-bottom: 1rem;
}

.carousel-track {
  display: flex;
  transition: transform 0.3s ease-out;
  touch-action: pan-y;
  cursor: grab;
}

.carousel-track:active {
  cursor: grabbing;
}

.carousel-slide {
  min-width: 100%;
  padding: 2rem;
  box-sizing: border-box;
}

.slide-content {
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}

.slide-content h5 {
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--text);
}

.slide-content p {
  color: var(--muted);
  margin: 0;
}

.carousel-indicators {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background: color-mix(in oklab, var(--surface) 20%, transparent);
}

.carousel-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.carousel-indicator:hover,
.carousel-indicator:focus-visible {
  border-color: var(--brand);
  outline: none;
}

.carousel-indicator.active {
  background: var(--brand);
  border-color: var(--brand);
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 0 1rem;
  }
  
  .hero h2 {
    font-size: 1.75rem;
  }
  
  .experiment-card {
    padding: 1.25rem;
  }
  
  .carousel-slide {
    padding: 1.5rem;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: 2rem 0 1.5rem;
  }
  
  .hero h2 {
    font-size: 1.5rem;
  }
  
  .experiment-card {
    padding: 1rem;
  }
  
  .carousel-slide {
    padding: 1rem;
  }
  
  .canvas-container {
    height: 200px;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .parallax-bg {
    transform: none !important;
  }
  
  .carousel-track {
    transition: none;
  }
  
  .btn {
    transition: none;
  }
  
  .menu-toggle-line {
    transition: none;
  }
  
  .nav {
    transition: none;
  }
  
  .carousel-indicator {
    transition: none;
  }
}

/* Focus Styles */
*:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .btn {
    border-width: 2px;
  }
  
  .experiment-card,
  .carousel-container,
  .canvas-container {
    border-width: 2px;
  }
}

/* Advanced Experiment Styles */
.webgl-container,
.audio-container,
.camera-container,
.physics-container,
.ml-container {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 1rem 0;
  background: var(--surface);
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.ml-demo-selector {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.ml-visualization {
  width: 100%;
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  margin: 1rem;
  position: relative;
  overflow: hidden;
}

.status-indicator {
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
}

.status-indicator.loading {
  background: #fef3c7;
  color: #92400e;
  border-color: #fbbf24;
}

.status-indicator.active {
  background: #d1fae5;
  color: #065f46;
  border-color: #10b981;
}

.status-indicator.error {
  background: #fee2e2;
  color: #991b1b;
  border-color: #f87171;
}

.webgl-container canvas,
.audio-container canvas,
.camera-container canvas,
.physics-container canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}

.camera-container video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1rem;
  padding: 1rem;
  background: color-mix(in oklab, var(--surface) 50%, transparent);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.control-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
}

.slider {
  appearance: none;
  width: 100px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.checkbox {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  margin: 0;
}

.checkbox:checked {
  background: var(--brand);
  border-color: var(--brand);
}

.checkbox:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--bg);
  font-size: 12px;
  font-weight: bold;
}

.select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 120px;
}

.select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.file-input {
  display: none;
}

.file-input + label,
.file-input-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  transition: all 0.2s ease;
}

.file-input + label:hover,
.file-input-trigger:hover {
  background: var(--border);
}

/* Performance indicator */
.fps-counter {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: monospace;
  z-index: 10;
}

/* Loading states */
.loading-spinner {
  border: 2px solid var(--border);
  border-top: 2px solid var(--brand);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
}

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

/* Mobile responsiveness for new experiments */
@media (max-width: 768px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  
  .control-label {
    justify-content: space-between;
  }
  
  .slider {
    width: 100%;
    max-width: 200px;
  }
  
  .webgl-container,
  .audio-container,
  .camera-container,
  .physics-container,
  .ml-container {
    min-height: 250px;
  }
  
  .ml-demo-selector {
    flex-direction: column;
    gap: 0.5rem;
  }
}

@media (max-width: 480px) {
  .webgl-container,
  .audio-container,
  .camera-container,
  .physics-container {
    min-height: 200px;
  }
  
  .controls {
    padding: 0.75rem;
  }
}