/* ===== Shared Design System: Classical Neural Networks Applets ===== */

/* --- CSS Custom Properties --- */
:root {
  --bg: #fafbfc;
  --bg-alt: #f1f5f9;
  --text: #1e293b;
  --text-light: #64748b;
  --heading: #0f172a;
  --accent: #4f46e5;
  --accent-light: #e0e7ff;
  --def: #3b82f6;
  --thm: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --code-bg: #f1f5f9;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --positive: #3b82f6;
  --negative: #dc2626;
  --active: #059669;
  --inactive: #94a3b8;
}

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

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* --- Navigation Bar --- */
.nav-bar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-bar a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: opacity 0.15s;
}

.nav-bar a:hover { opacity: 0.7; }

.nav-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--heading);
}

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

/* --- Page Container --- */
.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- Page Header --- */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 0.4rem;
}

.page-header .subtitle {
  font-size: 1rem;
  color: var(--text-light);
  line-height: 1.5;
}

.chapter-badge {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

/* --- Layout: Main + Sidebar --- */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
}

/* --- Canvas Container --- */
.canvas-container {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
}

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

/* --- Control Panel --- */
.control-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}

.control-panel h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--heading);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* --- Slider Group --- */
.slider-group {
  margin-bottom: 1rem;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.slider-group .value {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

.slider-group input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.slider-group input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.btn:hover { background: var(--bg-alt); border-color: #cbd5e1; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }

.btn-success {
  background: var(--thm);
  color: white;
  border-color: var(--thm);
}
.btn-success:hover { background: #047857; }

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.75rem; }

.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* --- Toggle Switch --- */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.toggle-track {
  width: 44px;
  height: 24px;
  background: var(--inactive);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
}

.toggle-track.on { background: var(--active); }

.toggle-thumb {
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-track.on .toggle-thumb { transform: translateX(20px); }

.toggle-label {
  font-size: 0.85rem;
  font-weight: 500;
}

.toggle-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  min-width: 1.2em;
  text-align: center;
}

/* --- Info Cards --- */
.info-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.info-card h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--heading);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.6rem;
}

.info-card .equation {
  font-size: 1.1rem;
  text-align: center;
  padding: 0.6rem;
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
}

/* --- Value Display --- */
.value-display {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.6rem;
}

.value-item {
  text-align: center;
  padding: 0.5rem;
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
}

.value-item .label {
  font-size: 0.7rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

/* --- Truth Table --- */
.truth-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.truth-table th {
  background: var(--bg-alt);
  padding: 0.4rem 0.6rem;
  text-align: center;
  font-weight: 600;
  color: var(--heading);
  border-bottom: 2px solid var(--border);
}

.truth-table td {
  padding: 0.4rem 0.6rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
}

.truth-table tr.active {
  background: var(--accent-light);
  font-weight: 700;
}

.truth-table td.output-1 { color: var(--active); font-weight: 700; }
.truth-table td.output-0 { color: var(--inactive); }

/* --- Preset Buttons --- */
.preset-group {
  margin-bottom: 1rem;
}

.preset-group .label {
  font-size: 0.75rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

/* --- Status Bar --- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 1rem;
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.8rem;
}

.status-bar .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--active);
}

.status-bar .dot.idle { background: var(--inactive); }
.status-bar .dot.running { background: var(--warn); animation: pulse 1s infinite; }
.status-bar .dot.done { background: var(--active); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Description Section --- */
.description {
  margin-bottom: 1.5rem;
  padding: 1rem 1.2rem;
  background: white;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
}

.description strong { color: var(--heading); }

/* --- Section Divider --- */
.section-divider {
  margin: 2rem 0;
  border: none;
  border-top: 1px solid var(--border);
}

/* --- Gallery Cards (index.html) --- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.2rem;
}

.gallery-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

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

.gallery-card .card-icon {
  width: 48px;
  height: 48px;
  background: var(--accent-light);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  font-size: 1.4rem;
}

.gallery-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 0.4rem;
}

.gallery-card p {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.5;
  flex: 1;
}

.gallery-card .card-chapter {
  margin-top: 0.8rem;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

/* --- Tabs --- */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
}

.tab-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* --- Neuron SVG styles --- */
.neuron-active { fill: var(--active); }
.neuron-inactive { fill: var(--inactive); }
.signal-on { stroke: var(--active); stroke-width: 2.5; }
.signal-off { stroke: var(--inactive); stroke-width: 1.5; stroke-dasharray: 4 3; }

/* --- Responsive --- */
@media (max-width: 600px) {
  .page-container { padding: 1rem; }
  .page-header h1 { font-size: 1.4rem; }
  .gallery-grid { grid-template-columns: 1fr; }
  .nav-bar { padding: 0.5rem 1rem; }
  .nav-title { font-size: 0.85rem; }
}
