@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@300;400;500&display=swap");

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a26;
  --bg-card: #14141f;
  --border: #2a2a3a;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --accent-lime: #c8ff00;
  --accent-coral: #ff6b6b;
  --accent-blue: #4ecdc4;
  --accent-purple: #a78bfa;
  --accent-orange: #ff9f43;
  --bar-default: #3a3a52;
  --bar-comparing: var(--accent-coral);
  --bar-swapping: var(--accent-orange);
  --bar-sorted: var(--accent-lime);
  --bar-pivot: var(--accent-purple);
  --bar-active: var(--accent-blue);
  --glow-lime: 0 0 20px rgba(200, 255, 0, 0.3);
  --glow-coral: 0 0 15px rgba(255, 107, 107, 0.3);
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: "Space Grotesk", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* Grid background */
.grid-bg {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(200, 255, 0, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200, 255, 0, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 24px;
}

/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 36px;
  animation: fadeDown 0.6s ease;
}

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

.logo {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--accent-lime);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.logo::before,
.logo::after {
  content: "";
  width: 30px;
  height: 1px;
  background: var(--accent-lime);
  opacity: 0.4;
}

h1 {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 700;
  letter-spacing: -1px;
  background: linear-gradient(
    135deg,
    var(--text-primary) 0%,
    var(--text-secondary) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Algorithm Selector ── */
.algo-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 28px;
  animation: fadeDown 0.6s ease 0.1s both;
}

.algo-tab {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: transparent;
  color: var(--text-secondary);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.5px;
}

.algo-tab:hover {
  border-color: var(--accent-lime);
  color: var(--text-primary);
  background: rgba(200, 255, 0, 0.05);
}

.algo-tab.active {
  background: var(--accent-lime);
  color: var(--bg-primary);
  border-color: var(--accent-lime);
  font-weight: 600;
  box-shadow: var(--glow-lime);
}

/* ── Info Bar ── */
.info-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  animation: fadeDown 0.6s ease 0.15s both;
}

.info-description {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 600px;
  line-height: 1.6;
}

.complexity-badges {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
  animation: fadeDown 0.6s ease 0.2s both;
}

.badge {
  padding: 6px 16px;
  border-radius: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.badge-time {
  color: var(--accent-coral);
}
.badge-space {
  color: var(--accent-blue);
}
.badge-label {
  color: var(--text-muted);
  margin-right: 4px;
}

/* ── Visualization Area ── */
.viz-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 20px 20px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.6s ease 0.25s both;
}

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

.viz-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent-lime),
    transparent
  );
  opacity: 0.4;
}

.bars-wrapper {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 260px;
  padding: 0 10px;
}

.bar {
  flex: 1;
  max-width: 28px;
  min-width: 3px;
  background: var(--bar-default);
  border-radius: 3px 3px 0 0;
  transition:
    height 0.08s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
  position: relative;
}

.bar.comparing {
  background: var(--bar-comparing);
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.4);
}

.bar.swapping {
  background: var(--bar-swapping);
  box-shadow: 0 0 12px rgba(255, 159, 67, 0.4);
}

.bar.sorted {
  background: var(--bar-sorted);
  box-shadow: 0 0 8px rgba(200, 255, 0, 0.25);
}

.bar.pivot {
  background: var(--bar-pivot);
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.4);
}

.bar.active {
  background: var(--bar-active);
  box-shadow: 0 0 12px rgba(78, 205, 196, 0.4);
}

/* ── Controls ── */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  animation: fadeUp 0.6s ease 0.3s both;
}

.btn {
  padding: 10px 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 7px;
  letter-spacing: 0.3px;
}

.btn:hover {
  border-color: var(--accent-lime);
  background: rgba(200, 255, 0, 0.08);
}

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

.btn-primary {
  background: var(--accent-lime);
  color: var(--bg-primary);
  border-color: var(--accent-lime);
  font-weight: 600;
}

.btn-primary:hover {
  background: #d4ff33;
  box-shadow: var(--glow-lime);
}

.btn-primary:disabled {
  background: var(--accent-lime);
  opacity: 0.35;
}

.btn-danger {
  border-color: var(--accent-coral);
  color: var(--accent-coral);
}

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.1);
}

.btn-sound {
  border-color: var(--text-muted);
  color: var(--text-muted);
}

.btn-sound.active {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.btn-sound:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(78, 205, 196, 0.08);
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent-lime);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(200, 255, 0, 0.4);
}

/* ── Stats ── */
.stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  animation: fadeUp 0.6s ease 0.32s both;
}

.stat {
  text-align: center;
}

.stat-value {
  font-family: "JetBrains Mono", monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-lime);
}

.stat-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 2px;
}

/* ── Code Section ── */
.code-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  animation: fadeUp 0.6s ease 0.35s both;
}

.code-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}
.dot-red {
  background: #ff5f57;
}
.dot-yellow {
  background: #ffbd2e;
}
.dot-green {
  background: #28c840;
}

.code-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 10px;
}

.code-block {
  padding: 20px 22px;
  overflow-x: auto;
  max-height: 380px;
  overflow-y: auto;
}

.code-block pre {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-secondary);
  white-space: pre;
  tab-size: 4;
}

.code-block .kw {
  color: #c792ea;
}
.code-block .fn {
  color: #82aaff;
}
.code-block .str {
  color: #c3e88d;
}
.code-block .num {
  color: #f78c6c;
}
.code-block .cm {
  color: #546e7a;
  font-style: italic;
}
.code-block .op {
  color: #89ddff;
}
.code-block .var {
  color: #eeffff;
}

/* ── Legend ── */
.legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 18px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid rgba(42, 42, 58, 0.5);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Mode Navigation ── */
.mode-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 36px;
  animation: fadeDown 0.6s ease;
}

.mode-btn {
  padding: 10px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.mode-btn:hover {
  border-color: var(--accent-lime);
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--accent-lime);
  color: var(--bg-primary);
  border-color: var(--accent-lime);
  font-weight: 700;
  box-shadow: var(--glow-lime);
}

/* ── DS Visualization Container ── */
.ds-viz-container {
  min-height: 320px;
  display: flex;
  flex-direction: column;
}

#dsVizArea {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  padding: 10px;
}

/* ── Stack ── */
.stack-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 260px;
  justify-content: center;
  padding: 10px 60px 10px 10px;
}

.stack-node {
  width: 140px;
  height: 46px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  position: relative;
  transition: all 0.3s ease;
}

.stack-top-label {
  position: absolute;
  left: calc(100% + 10px);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--accent-lime);
  letter-spacing: 1px;
  white-space: nowrap;
}

.stack-top-label::before {
  content: '← ';
}

/* ── Queue ── */
.queue-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.queue-track {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 4px;
  max-width: 100%;
}

.queue-node-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.queue-ptr-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  height: 14px;
}

.queue-node {
  width: 64px;
  height: 64px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.queue-arrow {
  font-size: 16px;
  color: var(--border);
  flex-shrink: 0;
  margin-top: 20px;
}

/* ── Linked List ── */
.ll-svg-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 10px 0;
}

.ll-svg-wrap svg { display: block; margin: 0 auto; }

/* ── BST ── */
.bst-svg-wrap {
  width: 100%;
  overflow: auto;
  padding: 10px;
}

.bst-svg-wrap svg { display: block; margin: 0 auto; }

/* ── DS node highlight states ── */
.node-inserting {
  background: rgba(255, 159, 67, 0.15) !important;
  border-color: var(--accent-orange) !important;
  color: var(--accent-orange) !important;
  box-shadow: 0 0 15px rgba(255, 159, 67, 0.3) !important;
}

.node-active {
  background: rgba(200, 255, 0, 0.12) !important;
  border-color: var(--accent-lime) !important;
  color: var(--accent-lime) !important;
  box-shadow: 0 0 15px rgba(200, 255, 0, 0.3) !important;
}

.node-found {
  background: rgba(78, 205, 196, 0.12) !important;
  border-color: var(--accent-blue) !important;
  color: var(--accent-blue) !important;
  box-shadow: 0 0 15px rgba(78, 205, 196, 0.3) !important;
}

.node-deleting {
  background: rgba(255, 107, 107, 0.12) !important;
  border-color: var(--accent-coral) !important;
  color: var(--accent-coral) !important;
  box-shadow: 0 0 15px rgba(255, 107, 107, 0.3) !important;
}

/* ── DS Empty State ── */
.ds-empty {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 60px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* ── DS Controls ── */
.ds-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  animation: fadeUp 0.6s ease 0.3s both;
}

.ds-input {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  width: 90px;
  outline: none;
  transition: border-color 0.2s ease;
  text-align: center;
}

.ds-input:focus { border-color: var(--accent-lime); }

.ds-input::placeholder {
  color: var(--text-muted);
  font-size: 11px;
}

/* ── DS Message ── */
.ds-message {
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 20px;
  margin-bottom: 20px;
  transition: color 0.3s ease;
}

.ds-message.success { color: var(--accent-lime); }
.ds-message.error   { color: var(--accent-coral); }
.ds-message.info    { color: var(--accent-blue); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .container {
    padding: 20px 14px;
  }
  .bars-wrapper {
    height: 180px;
  }
  .controls {
    gap: 8px;
  }
  .btn {
    padding: 8px 14px;
    font-size: 11px;
  }
  input[type="range"] {
    width: 70px;
  }
  .stats {
    gap: 16px;
  }
}
