/* ========================================
   FRAKTALE – Design System
   Modern dark theme with gradient accents
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Custom Properties --- */
:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #111128;
  --bg-card: #16163a;
  --bg-card-hover: #1e1e4a;
  --bg-code: #0d0d24;

  --text-primary: #e8e8f0;
  --text-secondary: #a0a0c0;
  --text-muted: #6a6a8a;

  --accent-purple: #a855f7;
  --accent-cyan: #22d3ee;
  --accent-mint: #34d399;
  --accent-pink: #ec4899;
  --accent-orange: #f97316;

  --gradient-primary: linear-gradient(135deg, #a855f7, #22d3ee, #34d399);
  --gradient-hero: linear-gradient(180deg, #0a0a1a 0%, #1a1a3e 50%, #0a0a1a 100%);
  --gradient-card: linear-gradient(145deg, rgba(168,85,247,0.08), rgba(34,211,238,0.08));
  --gradient-button: linear-gradient(135deg, #a855f7, #6366f1);

  --border-color: rgba(168, 85, 247, 0.2);
  --border-glow: rgba(168, 85, 247, 0.4);

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(168, 85, 247, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

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

  --header-height: 64px;
  --max-width: 1200px;

  /* Fractal depth colors */
  --depth-0: #a855f7;
  --depth-1: #8b5cf6;
  --depth-2: #6366f1;
  --depth-3: #3b82f6;
  --depth-4: #0ea5e9;
  --depth-5: #22d3ee;
  --depth-6: #14b8a6;
  --depth-7: #34d399;
  --depth-8: #4ade80;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  color: var(--accent-mint);
}

img {
  max-width: 100%;
  display: block;
}

/* --- Typography --- */
h1, h2, h3, h4, h5 {
  font-weight: 600;
  line-height: 1.3;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  color: var(--text-primary);
  margin-bottom: 0.5em;
}

h3 {
  font-size: 1.3rem;
  color: var(--accent-cyan);
  margin-bottom: 0.4em;
}

p {
  color: var(--text-secondary);
  margin-bottom: 1em;
}

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.section {
  padding: 4rem 0;
}

.section + .section {
  border-top: 1px solid var(--border-color);
}

/* --- Header / Navigation --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  height: var(--header-height);
}

.header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  font-size: 1.5rem;
}

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

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
}

.nav-links a {
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text-primary);
  background: rgba(168, 85, 247, 0.1);
}

/* Language Switcher */
.lang-switcher {
  position: relative;
}

.lang-btn {
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.lang-btn:hover {
  background: rgba(168, 85, 247, 0.25);
  border-color: var(--border-glow);
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  min-width: 140px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s;
  z-index: 200;
}

.lang-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}

.lang-option:first-child {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.lang-option:last-child {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.lang-option:hover, .lang-option.active {
  background: rgba(168, 85, 247, 0.15);
  color: var(--text-primary);
}

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

/* --- Hero Section --- */
.hero {
  position: relative;
  min-height: calc(100vh - var(--header-height));
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--gradient-hero);
  overflow: hidden;
}

.hero-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.25;
  pointer-events: none;
}

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

.hero h1 {
  margin-bottom: 1rem;
}

.hero-subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 2.5rem;
  line-height: 1.6;
}

/* --- Cards Grid --- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.card {
  background: var(--gradient-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-primary);
  opacity: 0;
  transition: opacity 0.3s;
}

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

.card:hover::before {
  opacity: 1;
}

.card-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

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

.card p {
  font-size: 0.95rem;
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 1rem;
  color: var(--accent-purple);
  font-weight: 500;
  font-size: 0.95rem;
}

.card-link:hover {
  color: var(--accent-cyan);
  gap: 0.5rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.6rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--gradient-button);
  color: white;
  box-shadow: 0 4px 16px rgba(168, 85, 247, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 4px 24px rgba(168, 85, 247, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(168, 85, 247, 0.1);
  color: var(--accent-purple);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(168, 85, 247, 0.2);
  border-color: var(--border-glow);
}

.btn-sm {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
}

.btn-icon {
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(168, 85, 247, 0.2);
  color: var(--text-primary);
}

/* --- Fractal Section --- */
.fractal-section {
  padding: 3rem 0;
}

.fractal-section + .fractal-section {
  border-top: 1px solid var(--border-color);
}

.fractal-header {
  margin-bottom: 2rem;
}

.fractal-header h2 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.fractal-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(168, 85, 247, 0.2);
  color: var(--accent-purple);
  letter-spacing: 0.03em;
}

/* Canvas + Controls */
.fractal-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.canvas-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.canvas-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-code);
}

.canvas-container canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-controls {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.control-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 60px;
}

.depth-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: rgba(168, 85, 247, 0.2);
  outline: none;
}

.depth-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gradient-button);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(168, 85, 247, 0.4);
}

.depth-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-purple);
  cursor: pointer;
  border: none;
}

.depth-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-cyan);
  min-width: 24px;
  text-align: center;
}

.info-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.info-chip {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(168, 85, 247, 0.08);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
}

.info-chip strong {
  color: var(--accent-mint);
}

.play-controls {
  display: flex;
  gap: 0.5rem;
}

/* --- Code Editor Panel --- */
.editor-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(168, 85, 247, 0.05);
}

.editor-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
}

.editor-wrapper {
  position: relative;
  flex: 1;
  min-height: 250px;
}

.editor-textarea {
  width: 100%;
  height: 100%;
  min-height: 250px;
  background: var(--bg-code);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  border: none;
  outline: none;
  resize: vertical;
  padding: 1rem;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.editor-textarea::placeholder {
  color: var(--text-muted);
}

.editor-error {
  padding: 0.6rem 1rem;
  background: rgba(239, 68, 68, 0.1);
  border-top: 1px solid rgba(239, 68, 68, 0.2);
  color: #ef4444;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  display: none;
}

.editor-error.visible {
  display: block;
}

/* --- Tutorial Steps --- */
.tutorial-section {
  margin-top: 2.5rem;
}

.tutorial-section > h3 {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tutorial-step {
  background: var(--gradient-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.tutorial-step-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gradient-button);
  color: white;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step-content h4 {
  color: var(--text-primary);
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.step-content p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.tutorial-editor-area {
  padding: 0 1.5rem 1.25rem;
}

.tutorial-canvas-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.75rem;
}

.tutorial-canvas {
  aspect-ratio: 1;
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.tutorial-canvas canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Collapsible hint / solution */
.collapsible {
  border-top: 1px solid var(--border-color);
}

.collapsible-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--accent-purple);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.collapsible-trigger:hover {
  background: rgba(168, 85, 247, 0.05);
  color: var(--accent-cyan);
}

.collapsible-trigger .arrow {
  transition: transform 0.2s;
}

.collapsible-trigger.open .arrow {
  transform: rotate(90deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.collapsible-content.open {
  max-height: 600px;
}

.collapsible-body {
  padding: 0 1.5rem 1.25rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.collapsible-body pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  overflow-x: auto;
  color: var(--text-primary);
}

/* --- Theory Page --- */
.theory-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 1.5rem;
}

.theory-box {
  background: var(--gradient-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
}

.theory-box h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.theory-box pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin: 0.75rem 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-x: auto;
}

.callstack-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.callstack-canvas {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  aspect-ratio: 4/3;
}

.callstack-canvas canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Pseudo-code blocks */
.pseudo-code {
  margin: 1rem 0;
}

/* Theory feature lists (pros/cons) */
.theory-features {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.feature-icon {
  font-weight: bold;
  flex-shrink: 0;
  width: 1.2em;
  text-align: center;
  color: var(--accent-mint);
}

.feature-item.negative .feature-icon {
  color: #f87171;
}

/* Callstack layout */
.callstack-section {
  background: linear-gradient(180deg, transparent, rgba(168, 85, 247, 0.03));
}

.callstack-left,
.callstack-right {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.callstack-left h3,
.callstack-right h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
}

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

/* Comparison grid */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 1.5rem;
}

.comparison-card {
  background: var(--gradient-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
}

.comparison-card h3 {
  margin-bottom: 1rem;
  font-size: 1rem;
}

/* --- Footer --- */
#site-footer {
  border-top: 1px solid var(--border-color);
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

#site-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

#site-footer a:hover {
  color: var(--accent-purple);
}

/* --- Utilities --- */
.text-gradient {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-center {
  text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .fractal-workspace {
    grid-template-columns: 1fr;
  }

  .theory-columns,
  .callstack-area,
  .comparison-grid {
    grid-template-columns: 1fr;
  }

  .tutorial-canvas-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .nav-links {
    display: none;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: rgba(10, 10, 26, 0.95);
    backdrop-filter: blur(16px);
    flex-direction: column;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
  }

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

  .nav-toggle {
    display: block;
  }

  .hero {
    min-height: 70vh;
  }

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

  .section {
    padding: 2.5rem 0;
  }
}

@media (max-width: 480px) {
  :root {
    --header-height: 56px;
  }

  .container {
    padding: 0 1rem;
  }
}

/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(168, 85, 247, 0.15); }
  50% { box-shadow: 0 0 30px rgba(168, 85, 247, 0.3); }
}

.animate-in {
  animation: fadeInUp 0.6s ease forwards;
}

.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
