:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --bg-hover: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(42, 157, 143, 0.4);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Townscaper curated palette accents */
  --accent-terracotta: #e76f51;
  --accent-ochre: #f4a261;
  --accent-yellow: #e9c46a;
  --accent-teal: #2a9d8f;
  --accent-navy: #1d3557;
  --accent-cyan: #38bdf8;
  --accent-coral: #fb7185;
  --accent-purple: #818cf8;
  --accent-green: #4ade80;

  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
}

[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-glass: rgba(0, 0, 0, 0.03);
  --bg-hover: rgba(0, 0, 0, 0.06);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-glow: rgba(42, 157, 143, 0.5);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
}

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

html {
  scroll-behavior: smooth;
}

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

/* Background aesthetic ambient mesh */
.ambient-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
  background: 
    radial-gradient(circle at 15% 20%, rgba(231, 111, 81, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 85% 30%, rgba(42, 157, 143, 0.18) 0%, transparent 45%),
    radial-gradient(circle at 50% 80%, rgba(29, 53, 87, 0.25) 0%, transparent 50%);
}

/* Navigation */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: rgba(11, 15, 25, 0.8);
  border-bottom: 1px solid var(--border-subtle);
  transition: all 0.3s ease;
}

[data-theme="light"] .navbar {
  background: rgba(241, 245, 249, 0.85);
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent-terracotta), var(--accent-ochre));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(231, 111, 81, 0.35);
  color: white;
  font-weight: 800;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.brand-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  background: rgba(42, 157, 143, 0.2);
  color: var(--accent-teal);
  border: 1px solid rgba(42, 157, 143, 0.3);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  transition: color 0.2s ease;
  position: relative;
  padding: 0.4rem 0;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--accent-teal);
}

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

.btn-icon {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--bg-hover);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

/* Layout container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  position: relative;
  z-index: 1;
}

/* Hero Section */
.hero {
  padding: 5rem 0 3.5rem;
  text-align: center;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  border-radius: var(--radius-full);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--accent-ochre);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 5vw, 4.25rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 1.25rem;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.hero-gradient {
  background: linear-gradient(135deg, var(--accent-terracotta) 0%, var(--accent-ochre) 40%, var(--accent-teal) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-desc {
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  color: var(--text-secondary);
  max-width: 760px;
  margin: 0 auto 2.5rem;
  font-weight: 400;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  flex-wrap: wrap;
  margin-top: 2rem;
}

.stat-badge {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  padding: 1rem 1.75rem;
  border-radius: var(--radius-md);
  text-align: left;
  box-shadow: var(--shadow-sm);
  min-width: 170px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-teal);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* Sections */
.section {
  padding: 4.5rem 0;
  border-top: 1px solid var(--border-subtle);
}

.section-header {
  margin-bottom: 2.5rem;
}

.section-tag {
  color: var(--accent-teal);
  text-transform: uppercase;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
  display: block;
}

.section-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 750px;
}

/* Grid split layout */
.interactive-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .interactive-grid {
    grid-template-columns: 1fr;
  }
}

/* Cards & Containers */
.canvas-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: relative;
}

.canvas-toolbar {
  padding: 0.85rem 1.25rem;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

[data-theme="light"] .canvas-toolbar {
  background: rgba(0, 0, 0, 0.03);
}

.toolbar-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-title span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent-teal);
  color: white;
  border-color: var(--accent-teal);
}

.btn-primary:hover {
  background: #238276;
  color: white;
  box-shadow: 0 4px 12px rgba(42, 157, 143, 0.4);
}

.btn-terracotta {
  background: var(--accent-terracotta);
  color: white;
  border-color: var(--accent-terracotta);
}

.btn-terracotta:hover {
  background: #d45d3f;
  color: white;
  box-shadow: 0 4px 12px rgba(231, 111, 81, 0.4);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.select-input {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--accent-teal);
}

.canvas-viewport {
  position: relative;
  width: 100%;
  height: 480px;
  background: #060911;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-theme="light"] .canvas-viewport {
  background: #e2e8f0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-hint {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* Info Explainer Panel */
.info-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.info-card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.info-card-title svg {
  color: var(--accent-ochre);
}

.info-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
}

.info-card p:last-child {
  margin-bottom: 0;
}

.step-list {
  list-style: none;
  counter-reset: step-counter;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.step-item {
  position: relative;
  padding-left: 2.25rem;
}

.step-item::before {
  counter-increment: step-counter;
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 0.15rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(42, 157, 143, 0.2);
  border: 1px solid var(--accent-teal);
  color: var(--accent-teal);
  font-size: 0.75rem;
  font-weight: 800;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
  font-size: 0.92rem;
}

.step-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Palette Swatches */
.palette-picker {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.swatch:hover {
  transform: scale(1.15);
}

.swatch.active {
  border-color: white;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  transform: scale(1.15);
}

/* Code Snippets */
.code-container {
  position: relative;
  background: #07090e;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 1rem;
}

.code-header {
  padding: 0.6rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.code-content {
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  color: #e2e8f0;
  overflow-x: auto;
}

.code-content pre {
  margin: 0;
}

.code-keyword { color: #f472b6; }
.code-func { color: #38bdf8; }
.code-type { color: #facc15; }
.code-string { color: #4ade80; }
.code-comment { color: #64748b; font-style: italic; }

/* 8-corner bitmask visualizer */
.bitmask-inspector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.bit-digits {
  display: flex;
  gap: 0.35rem;
}

.bit-digit {
  width: 24px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-weight: 700;
  border: 1px solid var(--border-subtle);
  transition: all 0.15s ease;
}

.bit-digit.active {
  background: var(--accent-teal);
  color: white;
  border-color: var(--accent-teal);
  box-shadow: 0 0 8px rgba(42, 157, 143, 0.5);
}

/* Model stats badge grid */
.model-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}

.model-stat-box {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

.model-stat-num {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-ochre);
}

.model-stat-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Optimization Cards */
.optimization-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.opt-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.opt-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-glow);
}

.opt-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: rgba(42, 157, 143, 0.15);
  border: 1px solid rgba(42, 157, 143, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-teal);
  margin-bottom: 1.25rem;
}

.opt-card.highlight .opt-icon {
  background: rgba(231, 111, 81, 0.15);
  border-color: rgba(231, 111, 81, 0.3);
  color: var(--accent-terracotta);
}

.opt-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.opt-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

.opt-pill-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

/* Replication code tabs */
.tab-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.tab-btn.active {
  color: var(--accent-teal);
  background: rgba(42, 157, 143, 0.15);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Footer */
footer {
  border-top: 1px solid var(--border-subtle);
  padding: 3.5rem 0 2rem;
  background: var(--bg-secondary);
  margin-top: 4rem;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
}

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

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

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  transition: color 0.2s ease;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
  .nav-links {
    display: none;
  }
  .hero-stats {
    gap: 1rem;
  }
  .canvas-viewport {
    height: 360px;
  }
}
