/* Inherit base typography/colors from site */
:root {
  --bg: #0f1115;
  --fg: #e8eef2;
  --muted: #a9b2ba;
  --card: #161a22;
  --accent: #4cc9f0;
  --accent-2: #f72585;
  --accent-3: #b5179e;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
}

body {
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  font-family: 'Montserrat', 'Roboto', 'Open Sans', system-ui, -apple-system, Segoe UI, Arial, sans-serif;
}
header {
  background: linear-gradient(90deg, #111421, #181d2b);
  border-bottom: 1px solid #242a38;
}
header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}
header h1 { margin: 0; font-size: 1.35rem; }
header nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 1rem; }
header nav a { color: var(--fg); text-decoration: none; opacity: 0.9; }
header nav a:hover { color: var(--accent); }

.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }

/* Toolbar */
.viz-toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin: 1rem 0 1.25rem; }
.viz-toolbar label { color: var(--muted); }
.viz-toolbar select { background: var(--card); color: var(--fg); border: 1px solid #2a3142; border-radius: 6px; padding: .5rem .75rem; }
.btn { border: 1px solid #2a3142; color: var(--fg); background: var(--card); padding: .5rem .9rem; border-radius: 6px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0a0f14; font-weight: 600; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* Split layout */
.viz-split { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem; }
#visualization-area, #controls-area { background: var(--card); border: 1px solid #232938; border-radius: 10px; padding: 1rem; min-height: 380px; }
#visualization-area h2 { margin-top: 0; }
#controls-area h3 { margin-top: 0; color: var(--muted); }

/* Panels (pseudocode, stats, playback) */
.panel { background:#1a1f29; border:1px solid #262f3d; border-radius:8px; padding:.75rem .85rem; margin-bottom:.9rem; font-size:.85rem; }
.panel-header { font-size:.75rem; letter-spacing:.05em; text-transform:uppercase; color:var(--accent); margin-bottom:.4rem; opacity:.85; }
#pseudo-code { max-height:140px; overflow:auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; line-height:1.25; margin:0; }
.code-line { padding:2px 4px; border-radius:4px; }
.code-line.hl { background:rgba(76,201,240,.15); color:var(--accent); }
.stats-list { list-style:none; padding:0; margin:0; display:grid; gap:2px; }
.stats-list li { background:#212837; padding:2px 6px; border-radius:4px; font-variant-numeric:tabular-nums; }
.playback-controls { display:flex; gap:.5rem; flex-wrap:wrap; margin-bottom:.5rem; }
.distance-label { pointer-events:none; font-size:10px; background:#0f1115; padding:1px 4px; border-radius:4px; border:1px solid #2a3142; }

/* Array/list items */
.viz-row { display: flex; align-items: flex-end; gap: .5rem; flex-wrap: wrap; }
.cell { display: inline-flex; align-items: center; justify-content: center; min-width: 42px; height: 42px; padding: .25rem .5rem; background: #1d2230; border: 1px solid #2a3142; border-radius: 6px; font-weight: 600; }
.cell.index { font-size: .72rem; color: var(--muted); background: transparent; border: none; height: auto; }
.cell.active { outline: 2px solid var(--accent); box-shadow: 0 0 0 4px rgba(76, 201, 240, .1); }
.cell.ok { outline: 2px solid var(--ok); }
.cell.err { outline: 2px solid var(--err); }

/* Bars for sorting */
.bar-container { display: flex; align-items: flex-end; gap: 6px; height: 260px; padding: .5rem; width:100%; box-sizing:border-box; overflow:hidden; }
.bar { background: linear-gradient(180deg, #4cc9f0, #4361ee); border-radius: 4px 4px 0 0; transition: height .2s, transform .2s, width .2s; flex:0 0 auto; }
.bar.active { background: linear-gradient(180deg, #f72585, #b5179e); }
.bar.sorted { background: linear-gradient(180deg, #22c55e, #16a34a); }
.bar.depth-0 { box-shadow: 0 0 0 2px #4cc9f0 inset; }
.bar.depth-1 { box-shadow: 0 0 0 2px #f72585 inset; }
.bar.depth-2 { box-shadow: 0 0 0 2px #f59e0b inset; }
.bar.depth-3 { box-shadow: 0 0 0 2px #22c55e inset; }
.bar.depth-4 { box-shadow: 0 0 0 2px #b5179e inset; }
.bar.partition { outline:2px dashed rgba(255,255,255,.25); }

/* Depth legend & merge buffer */
.depth-legend { display:flex; gap:.5rem; flex-wrap:wrap; margin-top:.4rem; font-size:.65rem; opacity:.85; }
.depth-legend .swatch { display:inline-flex; align-items:center; gap:4px; }
.depth-legend .box { width:14px; height:14px; border-radius:4px; background:#333; box-shadow:0 0 0 2px #4cc9f0 inset; }
.depth-legend .box.d1 { box-shadow:0 0 0 2px #f72585 inset; }
.depth-legend .box.d2 { box-shadow:0 0 0 2px #f59e0b inset; }
.depth-legend .box.d3 { box-shadow:0 0 0 2px #22c55e inset; }
.depth-legend .box.d4 { box-shadow:0 0 0 2px #b5179e inset; }
.merge-buffer { display:flex; gap:6px; align-items:flex-end; height:80px; padding:.25rem .5rem; }
.merge-cell { background:#253041; border-radius:4px 4px 0 0; width:20px; text-align:center; font-size:.6rem; padding:2px 0; border:1px solid #2a3142; }

/* Linked list visuals */
.node { display: inline-flex; align-items: center; gap: 8px; padding: .4rem .6rem; border-radius: 8px; border: 1px solid #2a3142; background: #1d2230; }
.node .val { font-weight: 700; }
.arrow { width: 26px; height: 2px; background: #2a3142; position: relative; }
.arrow::after { content: ''; position: absolute; right: -3px; top: -3px; width: 8px; height: 8px; border-right: 2px solid #2a3142; border-top: 2px solid #2a3142; transform: rotate(45deg); }

/* Tree visuals */
.tree { position:relative; min-height:260px; }
.canvas-tree { position:relative; width:100%; min-height:300px; overflow:hidden; }
.tree-lines { position:absolute; left:0; top:0; width:100%; height:100%; pointer-events:none; overflow:visible; }
.tree-node { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 999px; background: #1d2230; border: 1px solid #2a3142; font-weight: 700; box-sizing:border-box; }
.tree-node.active { outline: 2px solid var(--accent); }
.tree-node.balance-neg { box-shadow: 0 0 0 2px #f59e0b inset; }
.tree-node.balance-pos { box-shadow: 0 0 0 2px #4cc9f0 inset; }
.tree-node.rbt-red { background:#b5172c; border-color:#f72585; }
.tree-node.rbt-black { background:#0f1115; border-color:#444b58; }

/* Hash table */
.hash-table { display:grid; gap:.4rem; grid-template-columns:repeat(auto-fill,minmax(110px,1fr)); }
.hash-bucket { background:#1d2230; border:1px solid #2a3142; border-radius:8px; padding:.4rem; font-size:.7rem; position:relative; }
.hash-bucket::before { content:attr(data-i); position:absolute; top:2px; right:6px; font-size:.55rem; color:var(--muted); }
.hash-chain { display:flex; flex-wrap:wrap; gap:.25rem; margin-top:.25rem; }
.hash-node { background:#212837; padding:2px 6px; border-radius:4px; font-size:.65rem; border:1px solid #2a3142; }
.hash-node.primary { background:#4361ee; }
.hash-node.probe { background:#f59e0b; }

/* Graph */
.graph-canvas { width: 100%; height: 360px; background: #121724; border: 1px dashed #2a3142; border-radius: 8px; position: relative; overflow: hidden; }
.vertex { position: absolute; width: 32px; height: 32px; border-radius: 999px; background: #1d2230; border: 2px solid #2a3142; display: grid; place-items: center; font-weight: 700; color: var(--fg); -webkit-user-select: none; user-select: none; cursor: pointer; }
.vertex.active { border-color: var(--accent); }
.edge { position: absolute; pointer-events: none; }

/* Footer */
footer { background: #0e121a; border-top: 1px solid #242a38; color: var(--muted); }
.social-links { display: flex; gap: .75rem; margin-top: .5rem; }
.social-link { color: var(--muted); }
.social-link:hover { color: var(--accent); }

/* A11y helpers */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,1px,1px); white-space: nowrap; border: 0; }

/* Responsive */
/* Mobile-first refinements */
@media (max-width: 900px) {
  .viz-split { grid-template-columns: 1fr; }
  #visualization-area, #controls-area { min-height: auto; }
  .bar-container { height: 200px; gap:4px; }
  .tree-node { width:36px; height:36px; font-size:.8rem; }
}

@media (max-width: 520px) {
  header .container { flex-direction:column; align-items:flex-start; gap:.5rem; }
  .viz-toolbar { flex-direction:column; align-items:stretch; }
  .viz-toolbar select, .viz-toolbar .btn { width:100%; }
  .playback-controls { width:100%; }
  .bar-container { gap:3px; }
}
