:root {
  /* Color Palette */
  --primary-hue: 250;
  --secondary-hue: 45;

  --bg-dark: hsl(var(--primary-hue), 50%, 5%);
  --bg-gradient-1: hsl(var(--primary-hue), 60%, 10%);
  --bg-gradient-2: hsl(var(--primary-hue), 60%, 20%);

  --accent-primary: hsl(var(--primary-hue), 80%, 60%);
  --accent-secondary: hsl(var(--secondary-hue), 90%, 60%);
  --accent-glow: hsl(var(--secondary-hue), 100%, 70%);

  --text-main: hsl(0, 0%, 100%);
  --text-muted: hsl(var(--primary-hue), 20%, 80%);

  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

  /* Spacing & Layout */
  --container-width: 1200px;
  --header-height: 80px;
  --border-radius: 16px;

  /* Typography */
  --font-main: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
  --font-display: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

/* Light Theme */
body.light-theme {
  --bg-dark: hsl(0, 0%, 98%);
  --bg-gradient-1: hsl(var(--primary-hue), 30%, 95%);
  --bg-gradient-2: hsl(var(--primary-hue), 30%, 90%);

  --accent-primary: hsl(var(--primary-hue), 70%, 50%);
  --accent-secondary: hsl(var(--secondary-hue), 80%, 50%);
  --accent-glow: hsl(var(--secondary-hue), 90%, 60%);

  --text-main: hsl(0, 0%, 10%);
  --text-muted: hsl(var(--primary-hue), 20%, 40%);

  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}

body.light-theme {
  background-image: radial-gradient(
      circle at 10% 20%,
      rgba(78, 84, 200, 0.15) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 90% 80%,
      rgba(255, 209, 102, 0.15) 0%,
      transparent 40%
    );
}

body.light-theme header {
  background: rgba(255, 255, 255, 0.8);
}

body.light-theme canvas {
  background: rgba(0, 0, 0, 0.05);
}

body.light-theme .bar {
  background: linear-gradient(to top, var(--accent-primary), #8b7ce7);
}

body.light-theme .bar.highlight {
  background: linear-gradient(to top, var(--accent-secondary), #ffd966);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  background-image: radial-gradient(
      circle at 10% 20%,
      rgba(78, 84, 200, 0.4) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 90% 80%,
      rgba(255, 209, 102, 0.2) 0%,
      transparent 40%
    );
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.7;
  overflow-x: hidden;
  letter-spacing: -0.01em;
  font-weight: 400;
}

/* Layout */
.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 30, 0.8);
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(
    to right,
    var(--accent-primary),
    var(--accent-secondary)
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Main Content */
main {
  padding: 40px 0;
}

.hero-section {
  text-align: center;
  margin-bottom: 60px;
  animation: fadeIn 1s ease-out;
}

h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 800;
  margin-bottom: 1rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-family: var(--font-display);
}

.subtitle {
  font-size: 1.2rem;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto;
  font-weight: 400;
  line-height: 1.6;
  letter-spacing: -0.01em;
}

/* Glass Card */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius);
  box-shadow: var(--glass-shadow);
  padding: 30px;
  margin-bottom: 30px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.5);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Visualization Area */
.visualization-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
}

@media (min-width: 900px) {
  .visualization-container {
    grid-template-columns: 3fr 1fr;
  }
}

.visuals-column {
  display: flex;
  flex-direction: column;
  gap: 30px;
  min-width: 0; /* Prevent grid blowout */
}

.chart-wrapper {
  min-height: 350px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 12px;
  padding: 50px 20px 20px 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  /* Prevent layout shift */
  position: relative;
  max-width: 100%;
  width: 100%;
}

/* Custom scrollbar for chart */
.chart-wrapper::-webkit-scrollbar {
  height: 8px;
}

.chart-wrapper::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.chart-wrapper::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: 4px;
}

.chart-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--accent-secondary);
}

/* Spiral Canvas */
.spiral-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  position: relative;
}

.card-header {
  width: 100%;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 15px;
  margin-bottom: 20px;
  color: var(--accent-secondary);
}

canvas {
  max-width: 100%;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
}

/* Bars */
.bar {
  width: 45px;
  min-width: 45px;
  flex-shrink: 0;
  background: linear-gradient(to top, var(--accent-primary), #6c5ce7);
  border-radius: 8px 8px 0 0;
  position: relative;
  transition: height 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  min-height: 10px;
  scroll-snap-align: start;
  padding-top: 6px;
}

.bar::after {
  content: attr(data-value);
  position: absolute;
  top: -28px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-secondary);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.bar:hover::after {
  opacity: 1;
  transform: translateY(0);
}

/* Addition formula label inside bar */
.bar-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: rgba(255, 255, 255, 0.95);
  background: rgba(0, 0, 0, 0.4);
  padding: 3px 5px;
  border-radius: 3px;
  white-space: nowrap;
  font-weight: 500;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.3px;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar.highlight {
  background: linear-gradient(to top, var(--accent-secondary), #ffeaa7);
  box-shadow: 0 0 20px var(--accent-glow);
  z-index: 10;
}

.bar.pulse {
  animation: pulse 1s ease-out;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(106, 90, 205, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 20px 10px rgba(106, 90, 205, 0);
  }
}

/* Controls */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font-display);
}

.btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-main);
}

.btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  border: none;
}

.btn-primary:hover {
  background: #5a4bcf;
  /* Darker shade of primary */
}

.btn-danger {
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.3);
}

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.3);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.9rem;
}

/* Inputs */
.input-row {
  display: flex;
  gap: 10px;
}

.glass-input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 10px;
  border-radius: 8px;
  width: 100%;
  font-family: var(--font-mono);
  text-align: center;
}

.glass-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.stat-item {
  background: rgba(0, 0, 0, 0.2);
  padding: 15px;
  border-radius: 12px;
  text-align: center;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-secondary);
  display: block;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Phi Display */
.phi-display {
  text-align: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 15px;
  border-radius: 12px;
}

.phi-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.8rem;
  color: var(--accent-secondary);
  font-weight: 700;
}

.phi-target {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Math Equation */
.math-display {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  text-align: center;
  padding: 20px;
  margin-top: 20px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
}

.variable {
  color: var(--accent-primary);
}

.operator {
  color: var(--text-muted);
}

.number {
  color: var(--accent-secondary);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-out forwards;
}

/* Footer */
footer {
  text-align: center;
  padding: 60px 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.3), transparent);
  border-top: 1px solid var(--glass-border);
  margin-top: 80px;
  position: relative;
}

footer::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 3px;
  background: linear-gradient(
    to right,
    var(--accent-primary),
    var(--accent-secondary)
  );
  border-radius: 2px;
}

footer p {
  line-height: 1.8;
  margin-bottom: 10px;
}

footer a {
  color: var(--accent-secondary);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.3s ease;
}

footer a:hover {
  color: var(--accent-primary);
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 900px) {
  .visualization-container {
    grid-template-columns: 1fr;
  }

  .visuals-column {
    order: 1;
  }

  .controls-panel {
    order: 2;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .glass-card {
    flex: 1;
    min-width: 250px;
  }
}

@media (max-width: 768px) {
  .control-group {
    flex: 1;
    min-width: 200px;
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 2rem;
  }
  .bar {
    width: 30px;
  }
  .controls-panel {
    flex-direction: column;
  }
  .glass-card {
    width: 100%;
  }

  .button-row {
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-main);
  }
}

/* Advanced Animations & Effects */
.glass-card {
  transform-style: preserve-3d;
  perspective: 1000px;
  will-change: transform;
}

.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: all 0.8s cubic-bezier(0.5, 0, 0, 1);
}

.reveal.active {
  opacity: 1;
  transform: translateY(0);
}

/* Background Canvas */
#bgCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  pointer-events: none;
}

/* Noise Texture */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: -1;
}

/* Button Row Fix */
.button-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.button-row .btn {
  flex: 1;
  padding: 10px;
  font-size: 0.9rem;
}

/* Speed Slider */
.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
  transition: all 0.3s ease;
}

.speed-slider:hover {
  background: rgba(255, 255, 255, 0.15);
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.speed-slider::-webkit-slider-thumb:hover {
  background: var(--accent-secondary);
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.speed-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: none;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.speed-slider::-moz-range-thumb:hover {
  background: var(--accent-secondary);
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Nature Grid Styling */
.nature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 25px;
  margin-top: 20px;
}

.nature-item {
  background: rgba(0, 0, 0, 0.2);
  padding: 25px;
  border-radius: 12px;
  text-align: center;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.nature-item:hover {
  transform: translateY(-5px);
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.nature-icon {
  font-size: 3rem;
  margin-bottom: 15px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.nature-item h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-secondary);
  margin-bottom: 10px;
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

.nature-item p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
}

@media (max-width: 768px) {
  .nature-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

/* Fun Fact Styling */
.fun-fact-container {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.fun-fact-text {
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 20px;
  font-style: italic;
  color: var(--text-main);
}

/* Quiz Styling */
.quiz-container {
  max-width: 800px;
  margin: 0 auto;
}

.quiz-question {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 25px;
  color: var(--text-main);
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}

@media (min-width: 600px) {
  .quiz-options {
    grid-template-columns: 1fr 1fr;
  }
}

.quiz-option {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  padding: 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  font-family: var(--font-main);
  color: var(--text-muted);
}

.quiz-option:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(5px);
  color: var(--text-main);
}

.quiz-option.correct {
  background: rgba(46, 204, 113, 0.2);
  border-color: #2ecc71;
  color: #2ecc71;
}

.quiz-option.incorrect {
  background: rgba(231, 76, 60, 0.2);
  border-color: #e74c3c;
  color: #e74c3c;
}

.quiz-feedback {
  margin-top: 20px;
  font-weight: 600;
  min-height: 24px;
}

.quiz-feedback.success {
  color: #2ecc71;
}

.quiz-feedback.error {
  color: #e74c3c;
}
