:root {
  --bg-primary: #FAFBFC;
  --bg-secondary: #F1F5F9;
  --bg-card: #FFFFFF;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --accent: #4A90D9;
  --accent-warm: #FF6B6B;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.dark-mode {
  --bg-primary: #0F172A;
  --bg-secondary: #1E293B;
  --bg-card: #1E293B;
  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-muted: #64748B;
  --border: #334155;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Bricolage Grotesque', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  padding: 1.5rem 2rem;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  font-size: 1.75rem;
  color: var(--accent);
  animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 4px var(--accent)); }
  50% { filter: drop-shadow(0 0 12px var(--accent)); }
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-warm) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 400;
}

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

.search-wrap {
  position: relative;
}

.search-input {
  padding: 0.625rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.875rem;
  width: 220px;
  transition: all 0.2s;
  font-family: inherit;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.aha-btn, .theme-toggle {
  padding: 0.625rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  transition: all 0.2s;
}

.aha-btn:hover, .theme-toggle:hover {
  background: var(--bg-secondary);
  transform: translateY(-1px);
}

/* Categories */
.categories {
  padding: 1rem 2rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.categories::-webkit-scrollbar {
  display: none;
}

.category-pill {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s;
}

.category-pill:hover {
  border-color: var(--cat-color);
  color: var(--cat-color);
}

.category-pill.active {
  background: var(--cat-color);
  border-color: var(--cat-color);
  color: white;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--cat-color) 30%, transparent);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  padding: 1.5rem 2rem;
  gap: 2rem;
}

/* Sidebar */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
}

.random-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
}

.random-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(74, 144, 217, 0.05);
}

.dice {
  font-size: 1.25rem;
}

.sidebar-section h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.sidebar-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  text-align: left;
  transition: all 0.2s;
}

.sidebar-card:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Card Gallery */
.card-gallery {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  align-content: start;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

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

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

.card:hover::before {
  transform: scaleX(1);
}

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

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.card-category {
  padding: 0.25rem 0.5rem;
  background: var(--bg-secondary);
  border-radius: 6px;
}

.card-difficulty {
  letter-spacing: 2px;
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.no-results span {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fade-in 0.2s;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-card);
  border-radius: 20px;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

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

.modal-icon {
  font-size: 2rem;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
}

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

.save-btn, .close-btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  transition: all 0.2s;
}

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

.close-btn:hover {
  background: var(--accent-warm);
  border-color: var(--accent-warm);
  color: white;
}

/* Visualization Area */
.viz-area {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  min-height: 280px;
}

.viz-container {
  width: 100%;
}

.slider-group {
  margin-bottom: 1rem;
}

.slider-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
}

.slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  -webkit-appearance: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

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

.slider-row .slider-group {
  flex: 1;
}

.chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-container {
  margin-top: 1rem;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  font-family: 'JetBrains Mono', monospace;
}

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

.legend-dot {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.legend-dashed {
  background: repeating-linear-gradient(
    to right,
    var(--text-muted) 0,
    var(--text-muted) 4px,
    transparent 4px,
    transparent 8px
  ) !important;
}

.viz-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  font-style: italic;
}

.freq-toggle {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.freq-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  background: var(--bg-card);
  border-radius: 12px;
  color: var(--text-muted);
}

.chaos-canvas {
  width: 100%;
  border-radius: 8px;
}

/* Animations */
.line-animate {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: draw-line 2s ease-out forwards;
}

@keyframes draw-line {
  to { stroke-dashoffset: 0; }
}

.coin-bounce {
  animation: coin-bounce 0.6s ease-out;
}

@keyframes coin-bounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.sun-pulse {
  animation: sun-pulse 3s ease-in-out infinite;
}

@keyframes sun-pulse {
  0%, 100% { r: 30; }
  50% { r: 35; }
}

.ray-animate {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: ray-draw 1s ease-out forwards;
}

@keyframes ray-draw {
  to { stroke-dashoffset: 0; }
}

.heat-pulse {
  animation: heat-pulse 2s ease-in-out infinite;
}

@keyframes heat-pulse {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.5; }
}

.ir-animate {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: ir-draw 1s ease-out forwards;
}

@keyframes ir-draw {
  to { stroke-dashoffset: 0; }
}

.trap-animate {
  stroke-dasharray: 100;
  stroke-dashoffset: -100;
  animation: trap-draw 1s ease-out forwards;
}

@keyframes trap-draw {
  to { stroke-dashoffset: 0; }
}

.curve-draw {
  stroke-dasharray: 500;
  stroke-dashoffset: 500;
  animation: curve-draw 1.5s ease-out forwards;
}

@keyframes curve-draw {
  to { stroke-dashoffset: 0; }
}

.equilibrium-pulse {
  animation: eq-pulse 1.5s ease-in-out infinite;
}

@keyframes eq-pulse {
  0%, 100% { r: 10; opacity: 1; }
  50% { r: 14; opacity: 0.8; }
}

.inject-animate {
  animation: inject 1s ease-out forwards;
}

@keyframes inject {
  0% { transform: translateX(-30px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

.pathogen-float {
  animation: pathogen-float 2s ease-in-out infinite;
}

@keyframes pathogen-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.immune-appear {
  animation: immune-appear 0.5s ease-out forwards;
  opacity: 0;
}

@keyframes immune-appear {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.antibody-spawn {
  animation: antibody-spawn 0.4s ease-out forwards;
  opacity: 0;
}

@keyframes antibody-spawn {
  from { transform: scale(0) rotate(-180deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.memory-glow {
  animation: memory-glow 2s ease-in-out infinite;
}

@keyframes memory-glow {
  0%, 100% { filter: drop-shadow(0 0 2px #A78BFA); }
  50% { filter: drop-shadow(0 0 8px #A78BFA); }
}

.shield-draw {
  stroke-dasharray: 400;
  stroke-dashoffset: 400;
  animation: shield-draw 1s ease-out forwards;
}

@keyframes shield-draw {
  to { stroke-dashoffset: 0; }
}

.wave-animate {
  animation: wave-flow 1.5s ease-in-out infinite;
}

@keyframes wave-flow {
  0% { transform: translateX(-10px); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: translateX(10px); opacity: 0; }
}

.bit-appear {
  animation: bit-appear 0.3s ease-out forwards;
  opacity: 0;
}

@keyframes bit-appear {
  to { opacity: 1; }
}

.bar-grow {
  animation: bar-grow 0.4s ease-out forwards;
  transform-origin: bottom;
  transform: scaleY(0);
}

@keyframes bar-grow {
  to { transform: scaleY(1); }
}

/* Step Content */
.step-content {
  text-align: center;
  margin-bottom: 1.5rem;
}

.step-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.step-desc {
  color: var(--text-secondary);
}

/* Progress Dots */
.progress-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

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

.dot.active {
  border-color: var(--accent);
  background: var(--accent);
  transform: scale(1.2);
}

.dot.completed {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Step Navigation */
.step-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.step-btn {
  padding: 0.625rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  transition: all 0.2s;
}

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

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

.step-btn.primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

.step-indicator {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

/* Key Insight */
.key-insight {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.1) 0%, rgba(251, 191, 36, 0.05) 100%);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 12px;
  margin-bottom: 1rem;
}

.insight-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.insight-text {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.5;
}

/* Card Navigation */
.card-nav {
  display: flex;
  justify-content: space-between;
  position: absolute;
  left: 1rem;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.nav-arrow {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.nav-arrow:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Footer */
.footer {
  padding: 1.5rem 2rem;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
}

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

.footer a:hover {
  text-decoration: underline;
}

/* Mobile Styles */
@media (max-width: 600px) {
  .header {
    padding: 1rem;
  }
  
  .header-controls {
    width: 100%;
    justify-content: space-between;
  }
  
  .search-input {
    flex: 1;
    width: auto;
  }
  
  .categories {
    padding: 0.75rem 1rem;
  }
  
  .main-content {
    padding: 1rem;
  }
  
  .card-gallery {
    grid-template-columns: 1fr;
  }
  
  .modal-content {
    padding: 1rem;
    max-height: 95vh;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
  }
  
  .card-nav {
    position: static;
    transform: none;
    margin-top: 1rem;
    padding: 0;
  }
  
  .slider-row {
    flex-direction: column;
  }
}