:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a26;
  --border: #2a2a3d;
  --accent: #e8ff5a;
  --accent2: #5affe0;
  --accent3: #ff5a8a;
  --text: #e8e8f0;
  --text-dim: #6a6a85;
  --highlight: rgba(232, 255, 90, 0.12);
  --highlight-border: rgba(232, 255, 90, 0.4);
  --radius: 10px;
  --mono: 'JetBrains Mono', monospace;
  --display: 'Syne', sans-serif;
}

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

html { scroll-behavior: smooth; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px;
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  height: 60px;
  background: rgba(10,10,15,0.92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}
.logo-bracket { color: var(--accent); }
.logo-text { color: var(--text); }
.logo-text .accent { color: var(--accent); }

nav {
  display: flex;
  gap: .4rem;
  flex: 1;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--display);
  font-size: .78rem;
  font-weight: 600;
  padding: .35rem .85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all .2s;
  letter-spacing: .03em;
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0f;
}

.header-tag {
  font-family: var(--mono);
  font-size: .7rem;
  color: var(--text-dim);
  white-space: nowrap;
  letter-spacing: .05em;
}

/* Main */
main { position: relative; z-index: 1; flex: 1; }

.section { display: none; padding: 2.5rem 2rem 3rem; max-width: 1200px; margin: 0 auto; }
.section.active { display: block; animation: fadeUp .4s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-hero { margin-bottom: 2rem; }
.section-hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.02em;
}
.section-hero h1 .dim { color: var(--text-dim); }
.subtitle {
  margin-top: .6rem;
  color: var(--text-dim);
  font-size: .95rem;
  font-weight: 400;
  font-family: var(--mono);
}
kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--accent);
}

/* Layout */
.viz-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  margin-bottom: 1.2rem;
}

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

.panel-label {
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: .5rem;
}

/* Code Panel */
.code-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  overflow: hidden;
}

.code-block {
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.55;
  white-space: pre;
  overflow-x: auto;
}

.code-line {
  display: block;
  padding: 1px 8px;
  border-radius: 4px;
  position: relative;
  transition: background .2s;
  white-space: pre;
  line-height: 1.55;
}

.code-line::before {
  content: attr(data-ln);
  display: inline-block;
  width: 24px;
  color: var(--text-dim);
  font-size: .72rem;
  margin-right: 12px;
  text-align: right;
  -webkit-user-select: none;
  user-select: none;
}

.code-line.empty-line {
  line-height: 0.6;
  opacity: 0;
  pointer-events: none;
}

.code-line.active {
  background: var(--highlight);
  border-left: 3px solid var(--accent);
  color: var(--accent);
  animation: linePulse .35s ease;
}

@keyframes linePulse {
  0%   { background: rgba(232,255,90,0.35); }
  100% { background: var(--highlight); }
}

.code-line.done {
  color: var(--text-dim);
}

/* Speed slider */
.speed-wrap {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-left: auto;
}

.speed-label {
  font-size: .85rem;
  line-height: 1;
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform .15s;
}

.speed-slider::-webkit-slider-thumb:hover { transform: scale(1.3); }
.speed-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

/* Syntax colors */
.kw  { color: #ff79c6; }
.fn  { color: #50fa7b; }
.str { color: #f1fa8c; }
.num { color: #bd93f9; }
.cmt { color: #44475a; font-style: italic; }

/* Diagram Panel */
.diagram-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.diagram-area {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: .4rem;
  padding: .6rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px dashed var(--border);
  position: relative;
  overflow: hidden;
}

.callout {
  margin-top: .8rem;
  padding: .6rem 1rem;
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--text);
  min-height: 36px;
  animation: fadeIn .3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

/* Array / List boxes */
.arr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: popIn .3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 1; transform: scale(1); }
}

.arr-cell {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.1rem;
  background: var(--surface2);
  transition: all .3s;
}

.arr-cell.highlight {
  border-color: var(--accent);
  background: rgba(232,255,90,0.1);
  color: var(--accent);
  box-shadow: 0 0 16px rgba(232,255,90,0.25);
}

.arr-idx {
  font-family: var(--mono);
  font-size: .65rem;
  color: var(--text-dim);
}

/* Linked List nodes */
.ll-container {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: wrap;
}

.ll-node {
  display: flex;
  align-items: center;
  animation: popIn .3s cubic-bezier(0.34,1.56,0.64,1);
}

.ll-cell {
  display: flex;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface2);
  transition: all .3s;
}

.ll-cell.highlight { border-color: var(--accent2); box-shadow: 0 0 14px rgba(90,255,224,.2); }

.ll-val {
  padding: 8px 12px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: .95rem;
  border-right: 1px solid var(--border);
}

.ll-ptr {
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--accent2);
  display: flex;
  align-items: center;
}

.ll-arrow {
  font-size: 1.3rem;
  color: var(--accent2);
  padding: 0 4px;
}

/* Stack / Queue items */
.stack-item {
  width: 160px;
  padding: 10px 16px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
  font-weight: 600;
  text-align: center;
  transition: all .3s;
  animation: slideDown .3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.stack-item.top-item {
  border-color: var(--accent);
  background: rgba(232,255,90,0.08);
  color: var(--accent);
}

.queue-item {
  padding: 10px 18px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
  font-weight: 600;
  transition: all .3s;
  animation: slideRight .3s ease;
}

@keyframes slideRight {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.queue-item.front-item {
  border-color: var(--accent2);
  background: rgba(90,255,224,.08);
  color: var(--accent2);
}

.queue-item.rear-item {
  border-color: var(--accent);
  background: rgba(232,255,90,.08);
  color: var(--accent);
}

/* Tree SVG */
#tree-svg { overflow: visible; }

.tree-edge {
  stroke: var(--border);
  stroke-width: 2;
  fill: none;
  transition: stroke .4s;
}

.tree-edge.active { stroke: var(--accent); stroke-width: 2.5; }

.tree-circle {
  fill: var(--surface2);
  stroke: var(--border);
  stroke-width: 2;
  transition: all .4s;
}

.tree-circle.highlight {
  fill: rgba(232,255,90,.1);
  stroke: var(--accent);
  filter: drop-shadow(0 0 8px rgba(232,255,90,.4));
}

.tree-circle.visited {
  fill: rgba(90,255,224,.08);
  stroke: var(--accent2);
}

.tree-text {
  fill: var(--text);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.ctrl-btn {
  font-family: var(--display);
  font-weight: 700;
  font-size: .85rem;
  padding: .55rem 1.4rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all .2s;
  letter-spacing: .03em;
}

.ctrl-btn:not(.secondary) {
  background: var(--accent);
  color: #0a0a0f;
}

.ctrl-btn:not(.secondary):hover {
  background: #fff;
  transform: translateY(-1px);
}

.ctrl-btn.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.ctrl-btn.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.step-counter {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--text-dim);
  margin-left: auto;
}

/* Footer */
footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--text-dim);
}

.gh-link {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--text-dim);
  text-decoration: none;
  transition: color .2s;
}
.gh-link:hover { color: var(--accent); }

/* Interactive Mode */
.mode-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: .8rem;
}

.mode-toggle-btn {
  font-family: var(--mono);
  font-size: .78rem;
  font-weight: 600;
  padding: .4rem 1rem;
  background: transparent;
  border: 1.5px solid var(--accent2);
  color: var(--accent2);
  border-radius: 6px;
  cursor: pointer;
  transition: background .2s, color .2s;
  letter-spacing: .04em;
}
.mode-toggle-btn:hover,
.mode-toggle-btn.active {
  background: var(--accent2);
  color: var(--bg);
}

.interactive-mode.hidden { display: none; }

.code-editor {
  width: 100%;
  min-height: 220px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.6;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .8rem 1rem;
  resize: vertical;
  outline: none;
  transition: border-color .2s;
  tab-size: 4;
}
.code-editor:focus { border-color: var(--accent2); }

.interactive-code-view {
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: .4rem;
}

.editor-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: .6rem;
}

.run-btn {
  font-family: var(--mono);
  font-size: .82rem;
  font-weight: 700;
  padding: .45rem 1.2rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
  letter-spacing: .04em;
}
.run-btn:hover { opacity: .85; }
.run-btn:active { transform: scale(.97); }
.run-btn:disabled { opacity: .4; cursor: not-allowed; }

.pyodide-status {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--text-dim);
}
.pyodide-status.ready { color: var(--accent2); }
.pyodide-status.error { color: #ff5a5a; }

.panel-hint {
  font-family: var(--mono);
  font-size: .65rem;
  color: var(--text-dim);
  margin-left: .6rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
.panel-hint code {
  color: var(--accent2);
  background: var(--surface2);
  padding: 1px 4px;
  border-radius: 3px;
}

.diagram-placeholder {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: .8rem;
}
/* Search diagram */
.search-bars {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  padding: 2rem 1rem 0.5rem;
  flex-wrap: wrap;
}

.search-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.search-ptr {
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-ptr-label {
  font-family: var(--mono);
  font-size: .65rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .05em;
}

.search-box {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: .8rem;
  font-weight: 600;
  border-radius: 4px;
  border: 1.5px solid var(--border);
  transition: background .25s, border-color .25s, opacity .25s;
}

.search-box--default {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

.search-box--active {
  background: rgba(232, 255, 90, 0.08);
  border-color: var(--accent);
  color: var(--accent);
}

.search-box--mid {
  background: rgba(255, 90, 138, 0.15);
  border-color: var(--accent3);
  color: var(--accent3);
}

.search-box--found {
  background: rgba(90, 255, 224, 0.2);
  border-color: var(--accent2);
  color: var(--accent2);
  box-shadow: 0 0 12px rgba(90, 255, 224, 0.3);
}

.search-box--eliminated {
  background: var(--surface);
  border-color: transparent;
  color: var(--text-dim);
  opacity: 0.35;
}

/* Sorting bars */
.sort-bars {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem 0.5rem 0;
  min-height: 180px;
  flex-wrap: wrap;
}

.sort-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sort-bar {
  width: 36px;
  border-radius: 4px 4px 0 0;
  transition: height .3s, background .3s, border-color .3s;
  border: 1.5px solid transparent;
}

.sort-bar--default {
  background: var(--surface2);
  border-color: var(--border);
}

.sort-bar--comparing {
  background: rgba(232, 255, 90, 0.15);
  border-color: var(--accent);
}

.sort-bar--swapping {
  background: rgba(255, 90, 138, 0.2);
  border-color: var(--accent3);
}

.sort-bar--sorted {
  background: rgba(90, 255, 224, 0.15);
  border-color: var(--accent2);
}

.sort-bar--key {
  background: rgba(189, 147, 249, 0.2);
  border-color: #bd93f9;
}

.sort-label {
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-dim);
}

/* Inline hint (interactive mode warning) */
.inline-hint {
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--accent3);
  padding: .4rem .6rem;
  margin-top: .3rem;
  background: rgba(255, 90, 138, 0.06);
  border-radius: 6px;
  border-left: 3px solid var(--accent3);
}

/* Keyboard shortcut hint */
.kbd-hint {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--text-dim);
  margin-left: auto;
}