/* ── Algorithm Visualizer Styles ── */

/* Tab bar */
.viz-tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  padding-bottom: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.viz-tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.viz-tab:hover {
  color: var(--text);
  border-color: var(--accent-blue);
  background: rgba(110, 168, 254, 0.08);
}

.viz-tab-active {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
  background: rgba(110, 168, 254, 0.12);
}

/* Problem variant sub-tabs */
.viz-problem-tab-bar {
  display: flex;
  gap: 6px;
  margin: 0 0 16px 0;
  padding: 0 4px 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-wrap: wrap;
  justify-content: center;
}

.viz-problem-tab {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.viz-problem-tab:hover {
  color: var(--text);
  border-color: var(--accent-purple);
  background: rgba(187, 134, 252, 0.08);
}

.viz-problem-tab-active {
  color: var(--accent-purple);
  border-color: var(--accent-purple);
  background: rgba(187, 134, 252, 0.12);
}

/* Input panel */
.viz-input-form {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 0;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: fit-content;
  max-width: 100%;
}

.viz-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.viz-input-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-purple);
}

.viz-input {
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: 6px;
  min-width: 120px;
  outline: none;
  transition: border-color 0.2s;
}

.viz-input:focus {
  border-color: var(--accent-blue);
}

/* Main visualization area */
.viz-main {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  align-items: flex-start;
}

.viz-array-panel {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  overflow: auto;
}

.viz-state-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

/* Array cells */
.viz-cell-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.viz-cell {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: var(--code-bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  transition: all 0.25s ease;
}

.viz-cell-small {
  width: 36px;
  height: 36px;
  font-size: 0.8rem;
}

/* Cell highlight states */
.viz-cell.is-comparing {
  border-color: var(--accent-yellow);
  box-shadow: 0 0 12px rgba(241, 250, 140, 0.3);
}

.viz-cell.is-matched {
  border-color: var(--accent-green);
  box-shadow: 0 0 16px rgba(124, 237, 168, 0.4);
  transform: scale(1.05);
}

.viz-cell.is-written {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(139, 233, 253, 0.3);
}

.viz-cell.is-swapped {
  border-color: var(--accent-orange);
  box-shadow: 0 0 12px rgba(255, 184, 108, 0.3);
}

.viz-cell.is-inactive {
  opacity: 0.5;
  border-color: var(--accent-red);
  box-shadow: 0 0 8px rgba(255, 107, 107, 0.2);
}

/* Zone backgrounds — layer under action highlights */
.viz-cell.is-zone-a {
  background: #1a2a45;
}

.viz-cell.is-zone-b {
  background: #3d3818;
}

.viz-cell.is-zone-c {
  background: #351a2a;
}

/* Controls + Legends stacked layout */
.viz-controls-legends {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
}

.viz-controls-legends .viz-control-bar {
  margin-bottom: 0;
}

.viz-legends-row {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

/* Input + Controls stacked layout */
.viz-controls-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.viz-controls-row > #viz-input {
  width: 100%;
  display: flex;
  justify-content: center;
}

.viz-controls-row > .viz-controls-legends {
  width: 100%;
}

.viz-legend {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.viz-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}

.viz-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--code-bg);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.viz-legend-swatch.is-comparing {
  border-color: var(--accent-yellow);
  box-shadow: 0 0 6px rgba(241, 250, 140, 0.3);
}

.viz-legend-swatch.is-matched {
  border-color: var(--accent-green);
  box-shadow: 0 0 8px rgba(124, 237, 168, 0.4);
}

.viz-legend-swatch.is-written {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 6px rgba(139, 233, 253, 0.3);
}

.viz-legend-swatch.is-swapped {
  border-color: var(--accent-orange);
  box-shadow: 0 0 6px rgba(255, 184, 108, 0.3);
}

.viz-legend-swatch.is-inactive {
  border-color: var(--accent-red);
  box-shadow: 0 0 4px rgba(255, 107, 107, 0.2);
  opacity: 0.5;
}

/* Pointer arrows */
.viz-pointer-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.viz-pointer-slot {
  width: 52px;
  min-height: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.viz-pointer-slot.viz-cell-small {
  width: 36px;
}

.viz-pointer {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  line-height: 1;
  white-space: nowrap;
}

.viz-pointer-green { color: var(--accent-green); }
.viz-pointer-pink { color: var(--accent-pink); }
.viz-pointer-purple { color: var(--accent-purple); }
.viz-pointer-blue { color: var(--accent-blue); }
.viz-pointer-orange { color: var(--accent-orange); }
.viz-pointer-cyan { color: var(--accent-cyan); }

/* State panel */
.viz-vars {
  margin-bottom: 12px;
}

.viz-var-row {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  padding: 3px 0;
  line-height: 1.5;
}

.viz-var-name {
  color: var(--accent-cyan);
  font-weight: 600;
}

.viz-var-value {
  color: var(--text);
}

.viz-explanation {
  font-size: 0.84rem;
  color: var(--text-dim);
  line-height: 1.55;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Control bar */
.viz-control-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-wrap: wrap;
}

.viz-btn {
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}

.viz-btn:hover {
  color: var(--text);
  border-color: var(--accent-blue);
  background: rgba(110, 168, 254, 0.08);
}

.viz-btn-run {
  background: rgba(124, 237, 168, 0.15);
  color: var(--accent-green);
  border-color: var(--accent-green);
  padding: 8px 24px;
}

.viz-btn-run:hover {
  background: rgba(124, 237, 168, 0.25);
}

.viz-step-counter {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Responsive ── */

@media (max-width: 1200px) {
  .viz-cell {
    width: 44px;
    height: 44px;
    font-size: 0.9rem;
  }
  .viz-pointer-slot {
    width: 44px;
  }
  .viz-state-panel {
    width: 190px;
  }
}

@media (max-width: 768px) {
  .viz-main {
    flex-direction: column;
  }
  .viz-state-panel {
    width: 100%;
  }
  .viz-cell {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
  }
  .viz-pointer-slot {
    width: 36px;
  }
  .viz-controls-row {
    flex-direction: column;
  }
  .viz-controls-legends {
    gap: 8px;
  }
  .viz-legends-row {
    flex-direction: column;
    gap: 8px;
  }
  .viz-control-bar {
    justify-content: center;
  }
  .viz-legend {
    justify-content: center;
  }
  .viz-step-counter {
    margin-left: 0;
    width: 100%;
    text-align: center;
    margin-top: 4px;
  }
  .viz-input-form {
    flex-direction: column;
    align-items: stretch;
  }
  .viz-input {
    min-width: 0;
    width: 100%;
  }
}

/* ── Linked List Renderer ── */

.viz-ll-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  row-gap: 10px;
}

.viz-ll-cell {
  flex-shrink: 0;
}

/* Linked list legend */
.viz-ll-legend {
  border-left: 1px solid var(--border);
  padding-left: 12px;
  margin-left: 6px;
}

.viz-legend-arrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-dim);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.viz-legend-arrow.viz-ll-back {
  color: var(--accent-orange);
}

.viz-legend-arrow.viz-ll-null {
  color: var(--accent-red);
  opacity: 0.6;
  font-size: 0.75rem;
}

.viz-legend-arrow.is-written {
  color: var(--accent-cyan);
  text-shadow: 0 0 6px rgba(139, 233, 253, 0.4);
}

/* Graph legend */
.viz-graph-legend {
  border-left: 1px solid var(--border);
  padding-left: 12px;
  margin-left: 6px;
}

.viz-legend-edge {
  width: 20px;
  height: 3px;
  background: #555570;
  border-radius: 2px;
  flex-shrink: 0;
}

.viz-legend-edge.is-comparing {
  background: var(--accent-yellow);
  box-shadow: 0 0 6px rgba(241, 250, 140, 0.4);
}

.viz-legend-edge.is-matched {
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(124, 237, 168, 0.5);
}

.viz-legend-edge.is-swapped {
  background: var(--accent-orange);
  box-shadow: 0 0 6px rgba(255, 184, 108, 0.4);
}

.viz-legend-node {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--code-bg);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.viz-legend-node.is-matched {
  border-color: var(--accent-green);
  box-shadow: 0 0 6px rgba(124, 237, 168, 0.5);
}

.viz-ll-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: color 0.25s ease;
  position: relative;
}

.viz-ll-arrow-small {
  width: 20px;
  font-size: 0.9rem;
}

/* Null terminator */
.viz-ll-arrow.viz-ll-null {
  color: var(--accent-red);
  opacity: 0.6;
  width: 32px;
  font-size: 0.95rem;
}

/* Backward link (reversed pointer) */
.viz-ll-arrow.viz-ll-back {
  color: var(--accent-orange);
  font-size: 1.2rem;
}

/* Skip-forward link */
.viz-ll-arrow.viz-ll-skip-fwd {
  color: var(--accent-cyan);
}

.viz-ll-skip {
  font-size: 0.55rem;
  vertical-align: super;
  margin-left: 1px;
  opacity: 0.7;
}

/* Link highlights — reuse the same classes as cell highlights */
.viz-ll-arrow.is-comparing {
  color: var(--accent-yellow);
  text-shadow: 0 0 8px rgba(241, 250, 140, 0.5);
}

.viz-ll-arrow.is-matched {
  color: var(--accent-green);
  text-shadow: 0 0 10px rgba(124, 237, 168, 0.6);
}

.viz-ll-arrow.is-written {
  color: var(--accent-cyan);
  text-shadow: 0 0 8px rgba(139, 233, 253, 0.5);
}

.viz-ll-arrow.is-swapped {
  color: var(--accent-orange);
  text-shadow: 0 0 8px rgba(255, 184, 108, 0.5);
}

.viz-ll-arrow.is-inactive {
  opacity: 0.25;
  color: var(--accent-red);
}

/* Pointer label row for linked list */
.viz-ll-pointer-row {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  flex-wrap: wrap;
  gap: 0;
  row-gap: 4px;
}

.viz-ll-ptr-slot {
  width: 52px;
  min-height: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.viz-ll-ptr-slot.viz-cell-small {
  width: 36px;
}

.viz-ll-ptr-spacer {
  width: 28px;
  flex-shrink: 0;
}

.viz-ll-ptr-spacer.viz-ll-arrow-small {
  width: 20px;
}

/* ── Graph Renderer ── */

.viz-graph-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.viz-graph-svg {
  overflow: visible;
  max-width: 100%;
}

/* Edges */
.viz-graph-edge {
  stroke: #555570;
  stroke-width: 2;
  transition: stroke 0.25s, stroke-width 0.25s;
}

.viz-graph-edge.is-comparing {
  stroke: var(--accent-yellow);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 4px rgba(241, 250, 140, 0.4));
}

.viz-graph-edge.is-matched {
  stroke: var(--accent-green);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px rgba(124, 237, 168, 0.5));
}

.viz-graph-edge.is-written {
  stroke: var(--accent-cyan);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 4px rgba(139, 233, 253, 0.4));
}

.viz-graph-edge.is-swapped {
  stroke: var(--accent-orange);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 4px rgba(255, 184, 108, 0.4));
}

.viz-graph-edge.is-inactive {
  stroke: var(--accent-red);
  stroke-width: 1.5;
  opacity: 0.3;
}

/* Nodes */
.viz-graph-node {
  fill: var(--code-bg);
  stroke: var(--border);
  stroke-width: 2.5;
  transition: all 0.25s;
}

.viz-graph-node.is-comparing {
  stroke: var(--accent-yellow);
  filter: drop-shadow(0 0 8px rgba(241, 250, 140, 0.4));
}

.viz-graph-node.is-matched {
  stroke: var(--accent-green);
  filter: drop-shadow(0 0 10px rgba(124, 237, 168, 0.5));
}

.viz-graph-node.is-written {
  stroke: var(--accent-cyan);
  filter: drop-shadow(0 0 8px rgba(139, 233, 253, 0.4));
}

.viz-graph-node.is-swapped {
  stroke: var(--accent-orange);
  filter: drop-shadow(0 0 8px rgba(255, 184, 108, 0.4));
}

.viz-graph-node.is-inactive {
  stroke: var(--accent-red);
  opacity: 0.4;
}

/* Labels */
.viz-graph-label {
  fill: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Weight labels */
.viz-graph-weight {
  fill: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
}

.viz-graph-weight.is-comparing { fill: var(--accent-yellow); }
.viz-graph-weight.is-matched { fill: var(--accent-green); }
.viz-graph-weight.is-written { fill: var(--accent-cyan); }

/* Pointer labels */
.viz-graph-ptr {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
}

.viz-graph-ptr-green { fill: var(--accent-green); }
.viz-graph-ptr-pink { fill: var(--accent-pink); }
.viz-graph-ptr-purple { fill: var(--accent-purple); }
.viz-graph-ptr-blue { fill: var(--accent-blue); }
.viz-graph-ptr-orange { fill: var(--accent-orange); }
.viz-graph-ptr-cyan { fill: var(--accent-cyan); }

/* ── Responsive — Linked List ── */

@media (max-width: 1200px) {
  .viz-ll-arrow {
    width: 22px;
    font-size: 0.95rem;
  }
  .viz-ll-ptr-spacer {
    width: 22px;
  }
  .viz-ll-ptr-slot {
    width: 44px;
  }
}

@media (max-width: 768px) {
  .viz-ll-arrow {
    width: 18px;
    font-size: 0.85rem;
  }
  .viz-ll-ptr-spacer {
    width: 18px;
  }
  .viz-ll-ptr-slot {
    width: 36px;
  }
}

/* ── Stack Renderer ── */

.viz-stack-wrapper {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  width: 100%;
}

.viz-stack-input {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.viz-stack-area {
  display: flex;
  gap: 16px;
  flex-shrink: 0;
}

.viz-stack-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

.viz-stack-title {
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-purple);
  margin-bottom: 8px;
}

.viz-stack-cells {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-left: 3px solid var(--accent-purple);
  border-right: 3px solid var(--accent-purple);
  border-bottom: 3px solid var(--accent-purple);
  border-radius: 0 0 6px 6px;
  padding: 4px;
  min-width: 64px;
  width: fit-content;
}

.viz-stack-cell-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.viz-stack-cell {
  width: auto;
  min-width: 56px;
  height: auto;
  min-height: 36px;
  font-size: 0.85rem;
  padding: 6px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viz-stack-indicator {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--accent-purple);
  white-space: nowrap;
  width: 44px;
  text-align: right;
}

.viz-stack-indicator-spacer {
  width: 44px;
}

.viz-stack-empty {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  opacity: 0.5;
  padding: 12px 8px;
  border: 2px dashed var(--border);
  border-radius: 6px;
  text-align: center;
}

/* ── Responsive — Stack ── */

@media (max-width: 768px) {
  .viz-stack-wrapper {
    flex-direction: column;
    align-items: center;
  }
  .viz-stack-area {
    flex-direction: row;
    justify-content: center;
  }
  .viz-stack-cell {
    width: auto;
    min-width: 40px;
    height: auto;
    min-height: 30px;
    font-size: 0.75rem;
    padding: 4px 8px;
  }
  .viz-stack-indicator {
    width: 36px;
    font-size: 0.55rem;
  }
  .viz-stack-indicator-spacer {
    width: 36px;
  }
}

/* ── Recursion Renderer ── */

.viz-recursion-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.viz-recursion-depth {
  font-size: 0.8rem;
  color: #9ca3af;
  padding: 4px 12px;
  background: rgba(99, 102, 241, 0.15);
  border-radius: 4px;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Array mode */
.viz-recursion-array-section {
  width: 100%;
}

/* Call stack mode */
.viz-recursion-stack-section {
  display: flex;
  justify-content: center;
  width: 100%;
}

.viz-recursion-stack {
  min-width: 180px;
}

/* Grid mode */
.viz-recursion-grid-section {
  display: flex;
  justify-content: center;
  width: 100%;
}

.viz-recursion-grid {
  display: grid;
  gap: 3px;
  max-width: 100%;
  width: fit-content;
}

.viz-recursion-grid-cell {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

@media (max-width: 600px) {
  .viz-recursion-grid-cell {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
  }
}
