/* ─────────────────────────────────────────────────────────────────
   Graph Traversal & Pathfinding — Tal Pais
   Same instrument-panel aesthetic as the sorting visualizer.
   Dark navy · phosphor-mint accent · monospace everywhere.
   ───────────────────────────────────────────────────────────────── */

:root {
  --bg-0:        #070a10;
  --bg-1:        #0a0e14;
  --bg-2:        #0f1520;
  --bg-3:        #141c2a;
  --bg-raised:   #1a2334;
  --text:        #d4dde8;
  --text-2:      #8d9bb1;
  --text-fade:   #4f5b73;
  --rule:        rgba(255, 255, 255, 0.06);
  --rule-2:      rgba(255, 255, 255, 0.12);

  /* Phosphor accents */
  --mint:        #5be8c1;
  --mint-dim:    rgba(91, 232, 193, 0.16);
  --amber:       #ffb73a;
  --coral:       #ff7a8a;
  --purple:      #c084fc;

  /* Grid palette */
  --start:       #5be8c1;   /* mint */
  --goal:        #ff7a8a;   /* coral */
  --wall:        #2a3850;   /* darker than empty cells, blends with frame */
  --frontier:    #ffd166;   /* amber — being considered */
  --visited:     #294a3e;   /* dim mint — already explored */
  --path:        #5be8c1;   /* bright mint — final route */
  --cell-empty:  #131a26;
  --cell-line:   rgba(255, 255, 255, 0.04);

  /* Code panel */
  --code-bg:     #050810;
  --code-fg:     #cfd9e6;
  --code-fade:   #4f5b73;
  --code-line-active: rgba(91, 232, 193, 0.10);
  --kw:  #c084fc;
  --num: #ffb73a;
  --com: #5b6878;
  --fn:  #5be8c1;

  --font-display: "Major Mono Display", ui-monospace, monospace;
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --max-w:  1320px;
  --gutter: clamp(20px, 5vw, 80px);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg-1);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.022) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at 50% 0%, transparent 0%, rgba(0,0,0,0.45) 90%);
}

main, header, footer { position: relative; z-index: 2; }

::selection { background: var(--mint-dim); color: var(--text); }

a { color: var(--mint); }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-2);
  margin: 0 0 1.4em;
  display: inline-flex;
  align-items: center;
}

.led {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 6px var(--mint), 0 0 12px rgba(91, 232, 193, 0.5);
  margin-right: 12px;
  animation: pulse 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.85); }
}

/* ── masthead ──────────────────────────────────────── */

.masthead {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px var(--gutter);
  background: rgba(10, 14, 20, 0.78);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--rule);
}

.brand {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--text);
  text-transform: lowercase;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-fade);
  border-left: 1px solid var(--rule-2);
  padding-left: 14px;
}
@media (max-width: 540px) {
  .brand-sub { display: none; }
}

.nav {
  display: flex;
  gap: clamp(14px, 2.6vw, 32px);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.nav a {
  color: var(--text-2);
  text-decoration: none;
  position: relative;
  padding: 4px 0;
  transition: color 0.25s ease;
}
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--mint); }
.nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 1px;
  background: var(--mint);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.35s cubic-bezier(0.6, 0, 0.1, 1);
}
.nav a:hover::after,
.nav a.active::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* ── page wrapper ──────────────────────────────────── */

.visualization-page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: clamp(40px, 7vh, 84px) var(--gutter) clamp(40px, 6vh, 64px);
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 3vh, 30px);
}

.page-header { margin-bottom: clamp(8px, 2vh, 16px); }

.page-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(48px, 9vw, 124px);
  line-height: 0.95;
  letter-spacing: -0.005em;
  margin: 0 0 0.7em;
  color: var(--text);
  text-transform: lowercase;
}

.page-lead {
  font-family: var(--font-mono);
  font-size: clamp(14px, 1.3vw, 16px);
  line-height: 1.6;
  margin: 0;
  max-width: 64ch;
  color: var(--text-2);
}
.page-lead em {
  font-style: normal;
  color: var(--mint);
}

/* ── controls ──────────────────────────────────────── */

.controls {
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 16px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
}

.control { display: flex; flex-direction: column; gap: 8px; }

.control label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-fade);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.control label span {
  color: var(--mint);
  font-weight: 500;
  letter-spacing: 0.08em;
}

select, input[type="range"], button { font: inherit; color: inherit; }

select {
  background: var(--bg-1);
  border: 1px solid var(--rule-2);
  border-radius: 3px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'><path d='M3 5l4 4 4-4' fill='none' stroke='%235be8c1' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
select:hover { border-color: var(--mint); }
select:focus {
  outline: none;
  border-color: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-dim);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--mint);
  margin: 6px 0;
  background: transparent;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

button {
  background: var(--bg-1);
  border: 1px solid var(--rule-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  min-height: 38px;
  transition: background 0.18s, border-color 0.18s, color 0.18s, box-shadow 0.18s, transform 0.05s;
}
button:hover:not(:disabled) {
  border-color: var(--mint);
  color: var(--mint);
  box-shadow: 0 0 0 1px var(--mint-dim);
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: not-allowed; }
button.primary {
  background: var(--mint);
  border-color: var(--mint);
  color: var(--bg-0);
  box-shadow: 0 0 16px rgba(91, 232, 193, 0.25);
}
button.primary:hover:not(:disabled) {
  background: #7ff0d2;
  border-color: #7ff0d2;
  color: var(--bg-0);
  box-shadow: 0 0 22px rgba(91, 232, 193, 0.45);
}

/* ── main grid (stage + code) ──────────────────────── */

.main-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 980px) {
  .main-grid { grid-template-columns: 1.55fr 1fr; }
}

/* ── stage (canvas grid) ───────────────────────────── */

.stage {
  background:
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 14px 14px 16px;
  position: relative;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 560 / 360;
  background: var(--bg-1);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
  border: 1px solid var(--rule-2);
}

.grid-hint {
  margin: 12px 2px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-fade);
}
.grid-hint em {
  font-style: normal;
  color: var(--text-2);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-fade);
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch {
  width: 11px; height: 11px;
  display: inline-block;
  border: 1px solid var(--rule-2);
}

/* ── code panel ────────────────────────────────────── */

.code-panel {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.code-panel::before {
  content: "// pathfinding.js";
  position: absolute;
  top: 12px;
  right: 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--code-fade);
  text-transform: lowercase;
}
.code-panel h3 {
  margin: 0 18px 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--code-fade);
}
.code {
  background: transparent;
  border: 0;
  padding: 4px 0 6px;
  margin: 0;
  overflow: auto;
  max-height: 460px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--code-fg);
}
@media (max-width: 980px) { .code { max-height: 300px; } }

.line {
  display: flex;
  padding: 0 18px 0 12px;
  white-space: pre;
  border-left: 3px solid transparent;
  transition: background 0.18s, border-left-color 0.18s;
}
.line .lineno {
  color: #2f3a4a;
  width: 28px;
  text-align: right;
  margin-right: 14px;
  flex-shrink: 0;
  user-select: none;
}
.line.active {
  background: var(--code-line-active);
  border-left-color: var(--mint);
}
.line.active .lineno { color: var(--mint); }
.line .kw  { color: var(--kw); }
.line .num { color: var(--num); }
.line .com { color: var(--com); font-style: italic; }
.line .fn  { color: var(--fn); }

/* ── narration ─────────────────────────────────────── */

.narration-bar {
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-left-width: 3px;
  border-radius: 4px;
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.5;
  min-height: 56px;
  display: flex;
  align-items: center;
  color: var(--text);
  transition: border-left-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}
.narration-bar::before {
  content: "▸ ";
  color: var(--text-fade);
  margin-right: 10px;
  font-weight: 700;
}
.narration-bar.frontier { border-left-color: var(--frontier); box-shadow: 0 0 18px rgba(255,209,102,0.08); }
.narration-bar.visit    { border-left-color: var(--mint);     box-shadow: 0 0 18px rgba(91,232,193,0.10); }
.narration-bar.path     { border-left-color: var(--mint);     box-shadow: 0 0 18px rgba(91,232,193,0.18); }
.narration-bar.done     { border-left-color: var(--coral);    box-shadow: 0 0 18px rgba(255,122,138,0.10); }
.narration-bar.phase    { border-left-color: var(--purple);   box-shadow: 0 0 18px rgba(192,132,252,0.10); }
.narration-bar.success  { border-left-color: var(--mint);     box-shadow: 0 0 18px rgba(91,232,193,0.18); }
.narration-bar.fail     { border-left-color: var(--coral);    box-shadow: 0 0 18px rgba(255,122,138,0.18); }

/* ── info ──────────────────────────────────────────── */

.info {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 720px) {
  .info { grid-template-columns: 1.6fr 1fr; }
}
.info-prose {
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 18px 22px;
}
.info-prose h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(22px, 2.4vw, 28px);
  line-height: 1.1;
  letter-spacing: 0.02em;
  margin: 0 0 0.5em;
  color: var(--text);
  text-transform: lowercase;
}
.info-prose p {
  margin: 0 0 0.8em;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}
.info-prose .complexity {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-fade);
  margin: 0;
}
.info-prose .complexity .dot { margin: 0 8px; color: var(--rule-2); }
code.complex {
  background: var(--bg-1);
  border: 1px solid var(--rule-2);
  padding: 2px 8px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--mint);
  letter-spacing: 0.06em;
}

.complexity-why {
  margin: 14px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-2);
}
.complexity-why::before {
  content: "// why";
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--mint);
  margin-bottom: 8px;
}
.complexity-why:empty { display: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat {
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 14px 14px 12px;
  text-align: left;
  position: relative;
}
.stat::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 10px;
  width: 28px;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--mint));
  opacity: 0.35;
}
.stat .k {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-fade);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-bottom: 6px;
}
.stat .v {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
  color: var(--mint);
  font-feature-settings: "tnum";
  text-shadow: 0 0 12px rgba(91, 232, 193, 0.35);
  letter-spacing: 0.02em;
  word-break: break-all;
}

/* ── colophon ──────────────────────────────────────── */

.colophon {
  border-top: 1px solid var(--rule);
  margin-top: clamp(40px, 7vh, 80px);
  padding: 22px var(--gutter) 32px;
}
.colophon-grid {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 32px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-fade);
}
.colophon-grid p { margin: 0; }
.colophon a {
  color: var(--text-2);
  text-decoration: none;
  border-bottom: 1px dashed var(--text-fade);
  padding-bottom: 1px;
  transition: color 0.25s ease, border-color 0.25s ease;
}
.colophon a:hover { color: var(--mint); border-bottom-color: var(--mint); }
.colophon em {
  font-family: var(--font-mono);
  font-style: normal;
  text-transform: none;
  letter-spacing: 0.04em;
  font-size: 11.5px;
  color: var(--text-2);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .led { animation: none; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
