/* ============================================================
   CNN Visualizer — Main Stylesheet
   Dark theme, glassmorphism, smooth animations
   ============================================================ */

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

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  --bg-0: #0b0f1a;
  --bg-1: #111827;
  --bg-2: #1a2237;
  --bg-glass: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.08);

  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-3: #06b6d4;
  --accent-grad: linear-gradient(135deg, #6366f1, #8b5cf6, #06b6d4);

  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;

  --text-1: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-accent: 0 0 24px rgba(99,102,241,0.25);

  --nav-h: 64px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}
img, canvas, svg { display: block; max-width: 100%; }
button { cursor: pointer; font-family: var(--font); }
a { text-decoration: none; color: inherit; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-0); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 99px; }

/* ── Navigation ───────────────────────────────────────────── */
nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(11,15,26,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem;
  transition: background 0.3s;
}
.nav-logo {
  font-size: 1.1rem; font-weight: 700;
  background: var(--accent-grad); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  white-space: nowrap;
}
.nav-links {
  display: flex; gap: 0.25rem; list-style: none;
  overflow-x: auto; padding: 0 0.5rem;
}
.nav-links a {
  padding: 0.4rem 0.8rem; border-radius: 6px; font-size: 0.85rem;
  color: var(--text-2); transition: all 0.2s;
}
.nav-links a:hover, .nav-links a.active {
  color: var(--text-1); background: var(--bg-glass);
}
.nav-right { display: flex; align-items: center; gap: 0.75rem; }
#lang-toggle {
  background: var(--bg-glass); border: 1px solid var(--border);
  color: var(--text-1); padding: 0.35rem 0.75rem; border-radius: 6px;
  font-size: 0.85rem; font-weight: 600; transition: all 0.2s;
}
#lang-toggle:hover { background: var(--accent); border-color: var(--accent); }

/* ── Hero Section ─────────────────────────────────────────── */
#home {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--nav-h) + 2rem) 2rem 4rem;
  text-align: center;
  position: relative; overflow: hidden;
}
.hero-bg {
  position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 30%, rgba(99,102,241,0.15) 0%, transparent 70%),
              radial-gradient(ellipse 50% 40% at 80% 70%, rgba(6,182,212,0.08) 0%, transparent 60%);
}
.hero-content { position: relative; z-index: 1; max-width: 800px; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: rgba(99,102,241,0.15); border: 1px solid rgba(99,102,241,0.3);
  color: #a5b4fc; padding: 0.35rem 1rem; border-radius: 99px;
  font-size: 0.8rem; font-weight: 500; margin-bottom: 1.5rem;
  letter-spacing: 0.05em;
}
.hero-badge::before { content: "✦"; font-size: 0.7rem; }
#home h1 {
  font-size: clamp(2.5rem, 7vw, 5rem); font-weight: 900;
  line-height: 1.1; letter-spacing: -0.03em;
  background: var(--accent-grad); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  margin-bottom: 1.25rem;
}
.hero-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.2rem); color: var(--text-2);
  max-width: 560px; margin: 0 auto 2.5rem;
}
.hero-cta {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--accent-grad); color: #fff;
  padding: 0.85rem 2rem; border-radius: 10px;
  font-weight: 700; font-size: 1rem; border: none;
  box-shadow: var(--shadow-accent);
  transition: transform 0.2s, box-shadow 0.2s;
}
.hero-cta:hover { transform: translateY(-2px); box-shadow: 0 0 36px rgba(99,102,241,0.4); }
.hero-cta::after { content: "→"; }

/* CNN Pipeline diagram */
.pipeline-wrap {
  margin-top: 4rem; width: 100%; max-width: 900px;
  overflow-x: auto; padding: 1rem 0;
}
.pipeline {
  display: flex; align-items: center; gap: 0; min-width: 700px;
  justify-content: center;
}
.pipe-node {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.4rem; cursor: default;
}
.pipe-box {
  width: 90px; padding: 0.6rem 0.4rem;
  background: var(--bg-glass); border: 1px solid var(--border);
  border-radius: var(--radius-sm); text-align: center;
  font-size: 0.72rem; font-weight: 600; color: var(--text-2);
  white-space: pre-line; line-height: 1.3;
  transition: all 0.25s;
}
.pipe-node:hover .pipe-box {
  background: rgba(99,102,241,0.15); border-color: var(--accent);
  color: var(--text-1); transform: translateY(-3px);
  box-shadow: var(--shadow-accent);
}
.pipe-box.input { border-color: var(--accent-3); color: var(--accent-3); }
.pipe-box.output { border-color: var(--green); color: var(--green); }
.pipe-arrow {
  width: 36px; text-align: center;
  color: var(--text-3); font-size: 1.2rem; flex-shrink: 0;
}

/* ── Section Layout ───────────────────────────────────────── */
.section {
  padding: 5rem 2rem;
  max-width: 1100px; margin: 0 auto;
}
.section + .section { border-top: 1px solid var(--border); }
.section-header { margin-bottom: 2.5rem; }
.section-header h2 {
  font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 800;
  letter-spacing: -0.02em; margin-bottom: 0.75rem;
}
.section-header h2 span {
  background: var(--accent-grad); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
}
.section-desc { color: var(--text-2); font-size: 1.05rem; max-width: 640px; }

/* ── Glass Cards ──────────────────────────────────────────── */
.card {
  background: var(--bg-glass); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  backdrop-filter: blur(8px);
}
.info-box {
  background: rgba(99,102,241,0.07); border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius-sm); padding: 1rem 1.25rem;
  color: var(--text-2); font-size: 0.9rem; line-height: 1.6;
  margin-top: 1.25rem;
}
.info-box::before { content: "💡 "; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; border: none;
  transition: all 0.2s; white-space: nowrap;
}
.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-2); transform: translateY(-1px); }
.btn-secondary {
  background: var(--bg-glass); border: 1px solid var(--border); color: var(--text-1);
}
.btn-secondary:hover { background: rgba(255,255,255,0.08); transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

/* ── Module: Convolution ──────────────────────────────────── */
.conv-layout {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 2rem; align-items: start;
}
@media (max-width: 768px) {
  .conv-layout { grid-template-columns: 1fr; }
}
.conv-panel h4 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-3); margin-bottom: 0.75rem;
}
.kernel-grid {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 4px;
  width: 140px;
}
.kernel-cell {
  background: rgba(99,102,241,0.15); border: 1px solid rgba(99,102,241,0.3);
  border-radius: 4px; text-align: center; padding: 0.5rem 0;
  font-family: var(--mono); font-size: 0.85rem; font-weight: 500;
  color: #a5b4fc; transition: background 0.2s;
  cursor: default;
}
.filter-select-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; align-items: center; }
.filter-select-row label { color: var(--text-2); font-size: 0.9rem; }
.filter-select-row select {
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-1); border-radius: var(--radius-sm); padding: 0.4rem 0.7rem;
  font-size: 0.9rem; outline: none;
}
.stride-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
.stride-row label { color: var(--text-2); font-size: 0.9rem; }
.stride-row input[type=range] { width: 100px; accent-color: var(--accent); }
.stride-val { font-family: var(--mono); color: var(--accent); font-size: 0.9rem; min-width: 1.5rem; }
.conv-info { font-size: 0.85rem; color: var(--text-2); margin-top: 0.75rem; }
.conv-info span { color: var(--accent); font-family: var(--mono); font-weight: 600; }

/* ── Module: ReLU ─────────────────────────────────────────── */
.relu-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
@media (max-width: 640px) { .relu-layout { grid-template-columns: 1fr; } }
.relu-panel h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 0.75rem; }
.relu-formula {
  font-family: var(--mono); font-size: 1.2rem; font-weight: 700;
  color: var(--accent); margin-bottom: 1.5rem; text-align: center;
  padding: 0.75rem; background: rgba(99,102,241,0.08);
  border-radius: var(--radius-sm);
}
.bar-chart {
  display: flex; align-items: flex-end; gap: 8px;
  height: 150px; padding: 0 0.5rem;
}
.bar-wrap {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  height: 100%; justify-content: flex-end;
}
.bar {
  width: 100%; border-radius: 4px 4px 0 0;
  transition: height 0.35s cubic-bezier(.4,0,.2,1), background 0.35s;
  cursor: ns-resize; user-select: none; min-height: 2px;
}
.bar.positive { background: var(--green); }
.bar.negative { background: var(--red); }
.bar.zero { background: var(--text-3); min-height: 2px; height: 2px !important; }
.bar-label { font-family: var(--mono); font-size: 0.72rem; color: var(--text-2); }
.drag-hint { text-align: center; color: var(--text-3); font-size: 0.78rem; margin-top: 0.5rem; font-style: italic; }

/* ── Module: Pooling ──────────────────────────────────────── */
.pool-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; align-items: center; }
@media (max-width: 640px) { .pool-layout { grid-template-columns: 1fr; } }
.pool-panel h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 0.75rem; }
.pool-grid { display: grid; gap: 4px; }
.pool-grid.size-4 { grid-template-columns: repeat(4,1fr); max-width: 240px; }
.pool-grid.size-2 { grid-template-columns: repeat(2,1fr); max-width: 120px; }
.pool-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-family: var(--mono); font-size: 0.9rem; font-weight: 600;
  transition: all 0.25s; border: 2px solid transparent;
}
.pool-cell.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(99,102,241,0.5); }
.pool-cell.winner { border-color: var(--green); box-shadow: 0 0 12px rgba(16,185,129,0.5); }
.pool-cell.dimmed { opacity: 0.35; }
.pool-step-info { font-size: 0.85rem; color: var(--text-2); margin-top: 0.75rem; }
.pool-step-info span { color: var(--accent); font-weight: 600; }

/* ── Module: Fully Connected ──────────────────────────────── */
#fc-canvas-wrap {
  width: 100%; overflow: hidden; border-radius: var(--radius-sm);
}
#fc-canvas { width: 100%; }
.fc-info {
  margin-top: 0.75rem; min-height: 2rem;
  font-size: 0.88rem; color: var(--text-2);
  text-align: center;
}

/* ── Module: MNIST ────────────────────────────────────────── */
.mnist-layout { display: grid; grid-template-columns: auto 1fr; gap: 2.5rem; align-items: start; }
@media (max-width: 640px) { .mnist-layout { grid-template-columns: 1fr; } }
.canvas-wrap {
  position: relative; display: inline-block;
}
#draw-canvas {
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  cursor: crosshair; touch-action: none; background: #000;
  display: block;
}
.canvas-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: var(--text-3); font-size: 0.85rem;
  pointer-events: none; border-radius: var(--radius-sm);
}
.mnist-result {
  font-size: 3rem; font-weight: 900; text-align: center;
  background: var(--accent-grad); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  line-height: 1; margin: 0.5rem 0;
}
.mnist-status { font-size: 0.85rem; color: var(--text-2); text-align: center; margin-bottom: 0.75rem; min-height: 1.5rem; }
.confidence-bars { display: flex; flex-direction: column; gap: 5px; }
.conf-row { display: flex; align-items: center; gap: 8px; }
.conf-digit { font-family: var(--mono); font-size: 0.85rem; width: 18px; color: var(--text-2); }
.conf-bar-wrap { flex: 1; height: 14px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.conf-bar { height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.4s cubic-bezier(.4,0,.2,1); }
.conf-bar.top { background: var(--accent-grad); }
.conf-pct { font-family: var(--mono); font-size: 0.75rem; color: var(--text-2); width: 38px; text-align: right; }
.conf-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 0.5rem; margin-top: 1rem; }

/* ── Tooltip System ───────────────────────────────────────── */
.info-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  background: rgba(99,102,241,0.18); border: 1px solid rgba(99,102,241,0.4);
  color: #a5b4fc; font-size: 10px; font-weight: 800; font-style: normal;
  cursor: help; margin-left: 5px; flex-shrink: 0;
  vertical-align: middle; line-height: 1;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  user-select: none; position: relative; top: -1px;
}
.info-icon:hover, .info-icon.active {
  background: var(--accent); border-color: var(--accent);
  color: #fff; transform: scale(1.15);
}

/* Global floating tooltip */
#cnn-tooltip {
  position: fixed; z-index: 9999;
  max-width: 300px; min-width: 200px;
  background: #1a2237;
  border: 1px solid rgba(99,102,241,0.35);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55), 0 0 0 1px rgba(99,102,241,0.08);
  pointer-events: none;
  opacity: 0; transform: translateY(6px) scale(0.97);
  transition: opacity 0.18s, transform 0.18s;
  backdrop-filter: blur(12px);
}
#cnn-tooltip.visible {
  opacity: 1; transform: translateY(0) scale(1);
}
#cnn-tooltip .tip-title {
  font-size: 0.82rem; font-weight: 700; color: #a5b4fc;
  margin-bottom: 0.4rem; line-height: 1.3;
  text-transform: uppercase; letter-spacing: 0.04em;
}
#cnn-tooltip .tip-body {
  font-size: 0.82rem; color: var(--text-2); line-height: 1.6;
}

/* MNIST progress bar */
.train-progress-wrap {
  margin: 0.75rem 0 0; display: none;
}
.train-progress-wrap.visible { display: block; }
.train-progress-bar {
  height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden;
}
.train-progress-fill {
  height: 100%; border-radius: 99px;
  background: var(--accent-grad);
  transition: width 0.3s ease;
  width: 0%;
}
.train-progress-label {
  font-size: 0.78rem; color: var(--text-3); margin-top: 0.3rem; text-align: center;
}

/* ── Footer ───────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  padding: 2rem; text-align: center;
  color: var(--text-3); font-size: 0.85rem;
}
footer a { color: var(--accent); }
footer a:hover { text-decoration: underline; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp 0.6s ease both; }
.fade-up-2 { animation: fadeUp 0.6s 0.15s ease both; }
.fade-up-3 { animation: fadeUp 0.6s 0.3s ease both; }

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(99,102,241,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(99,102,241,0); }
  100% { box-shadow: 0 0 0 0 rgba(99,102,241,0); }
}
.pulse { animation: pulse-ring 2s infinite; }

/* reveal on scroll */
.reveal { opacity: 0; transform: translateY(32px); transition: opacity 0.7s ease, transform 0.7s ease; }
.reveal.visible { opacity: 1; transform: none; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .nav-links { display: none; }
  .section { padding: 3.5rem 1.25rem; }
}
