/* ============================================================
   styles.css — Graphplan Visualizer
   Aesthetic: Technical precision — circuit diagram meets
   academic notation. IBM Plex Mono for data, IBM Plex Sans
   for UI. Deep navy shell, clean white canvas.
   ============================================================ */

:root {
  --navy:       #0d1b2a;
  --navy-mid:   #172638;
  --navy-light: #1e3146;
  --accent:     #4a90d9;
  --gold:       #f5a623;
  --text-main:  #cfd7e3;
  --text-dim:   #6f8398;
  --border: rgba(120, 150, 180, 0.12);
  --canvas-bg:  #0d1b2a;
  --radius:     6px;
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
  --sans: 'IBM Plex Sans', 'Segoe UI', sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--sans);
  background: var(--navy);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ──────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  height: 58px;
  background: var(--navy);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

#title-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

#logo {
  font-size: 1.6rem;
  color: var(--accent);
  line-height: 1;
}

#title-block h1 {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-main);
}

#subtitle {
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  margin-top: 1px;
}

#subtitle a {
  color: inherit;
  text-decoration: underline;
}

/* ── Controls ─────────────────────────────────────────────── */
#controls {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.toggle input[type="checkbox"] {
  display: none;
}

.toggle-track {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--navy-light);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 9px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(14px);
  background: #fff;
}

.toggle-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--mono);
  transition: color 0.2s;
}

.toggle:hover .toggle-label {
  color: var(--text-main);
}

#btn-reset {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 5px 12px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  letter-spacing: 0.02em;
}

#btn-reset:hover {
  border-color: var(--accent);
  color: var(--text-main);
  background: rgba(74, 144, 217, 0.1);
}

/* ── Legend ───────────────────────────────────────────────── */
#legend {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 6px 24px;
  background: var(--navy-mid);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  row-gap: 4px;
}

.leg-group {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.leg-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 18px;
  flex-shrink: 0;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: var(--mono);
  white-space: nowrap;
}

.leg-item svg {
  flex-shrink: 0;
}

.leg-hint {
  margin-left: auto;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-style: italic;
  opacity: 0.7;
}

/* ── Viz canvas ───────────────────────────────────────────── */
#viz-wrap {
  flex: 1;
  overflow: auto;
  background: var(--navy);
  padding: 40px;
  justify-content: center;
}

#viz {
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  height: 100%;
  position: relative;
}

#viz svg {
  display: block;
  border-radius: 10px;
  background: var(--canvas-bg);
  box-shadow:
          0 0 0 1px rgba(0,0,0,0.12),
          0 8px 32px rgba(0,0,0,0.4);
}

/* ── Error state ──────────────────────────────────────────── */
.viz-error {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: max-content;
  min-height: 200px;
  min-width: 400px;
  padding: 10px 20px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.viz-error-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.viz-error-body {
  display: flex;
  gap: 24px;
  width: 100%;
  max-width: 900px;
  text-align: left;
}

.viz-error-body p {
  flex: 1;
  margin: 0;
}

.viz-error .err-icon {
  font-size: 2.5rem;
  opacity: 0.4;
  line-height: 1;
}

.viz-error h2 {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--text-main);
  font-weight: 500;
  margin: 0;
  text-align: center;
}

.viz-error p {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-dim);
}

.viz-error code {
  font-family: var(--mono);
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
}

/* ── Tooltip ──────────────────────────────────────────────── */
#tooltip {
  display: none;
  position: fixed;
  z-index: 9999;
  background: rgba(10, 20, 32, 0.98);
  border: 1px solid rgba(120, 150, 180, 0.18);
  color: var(--text-main);
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: 0.75rem;
  line-height: 1.6;
  pointer-events: none;
  max-width: 260px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}

#tooltip .tip-kind {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 2px;
}

#tooltip .tip-name {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-main);
  word-break: break-all;
}

#tooltip .tip-time {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 2px;
}

#tooltip .tip-goal {
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 500;
}


.node.dim circle,
.node.dim rect {
  fill: #2a3a4d;
  stroke: #1f2b3a;
}

.edge {
  opacity: 1;
}
.edge.dim {
  stroke: #2f3f55;
  stroke-opacity: 0.15;
}

.mutex-arc.dim {
  stroke: #3a3248;
  stroke-opacity: 0.15;
}

/* ── Scrollbar styling ───────────────────── */

* {
  scrollbar-width: auto;
  scrollbar-color: var(--accent) var(--navy-mid);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--navy-mid);
}

::-webkit-scrollbar-thumb {
  background-color: var(--navy-light);
  border-radius: var(--radius);
  border: 2px solid var(--navy-mid);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--accent);
}

::-webkit-scrollbar-corner {
  background: var(--navy-mid);
}

/* ── Animation bar ───────────────────────────────────────── */
#anim-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 48px;
  background: var(--navy-mid);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

#anim-bar.anim-bar--visible {
  display: flex;
}

/* Step buttons */
.sa-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.sa-btn:hover {
  border-color: var(--accent);
  color: var(--text-main);
  background: rgba(74,144,217,0.1);
}
.sa-btn-play {
  padding: 4px 14px;
  font-size: 0.9rem;
}

/* Step counter */
#sa-counter {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  flex-shrink: 0;
  min-width: 80px;
}

/* Scrubber — takes all remaining space */
#sa-scrub {
  flex: 1;
  min-width: 60px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Right group */
#anim-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Speed slider */
#sa-speed {
  width: 72px;
  accent-color: var(--accent);
  cursor: pointer;
}

.sa-speed-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Status text */
#sa-status {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  min-width: 400px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}
#sa-status[data-kind="ok"]     { color: #4caf82; }
#sa-status[data-kind="fail"]   { color: #c45454; }
#sa-status[data-kind="warn"]   { color: #c4843a; }
#sa-status[data-kind="reject"] { color: #c45454; }
#sa-status[data-kind="try"]    { color: #c4b03a; }
#sa-status[data-kind="info"]   { color: var(--accent); }

/* ── Topbar separator ────────────────────────────────────── */
.ctrl-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Search-overlay node classes ─────────────────────────── */
/*
 * SVG presentation attributes (fill=, stroke=) have lower specificity
 * than CSS class rules, so these cleanly override graph.js colours.
 *
 * Priority stack (highest → lowest):
 *   sa-mutex / sa-cutoff  >  sa-tried  >  sa-selected
 *   >  sa-goal  >  sa-for-goal  >  sa-dim
 */

/* Active goal: gold ring */
.node.sa-goal circle {
  fill:   #c49a28;
  stroke: #8a6a14;
  stroke-width: 3;
}
.node.sa-goal rect {
  /* goals are always props; rect rule is a safe fallback */
  fill:   #c49a28;
  stroke: #8a6a14;
}

/* Currently being tried: muted amber */
.node.sa-tried rect {
  fill:   #7a6820;
  stroke: #5a4c14;
  stroke-width: 2;
}
.node.sa-tried circle {
  fill:   #7a6820;
  stroke: #5a4c14;
  stroke-width: 2;
}

/* Committed (selected or in solution): emerald */
.node.sa-selected rect {
  fill:   #1e6040;
  stroke: #14432c;
  stroke-width: 2;
}
.node.sa-selected circle {
  fill:   #1e6040;
  stroke: #14432c;
  stroke-width: 2;
}

/* Mutex-rejected: crimson */
.node.sa-mutex rect {
  fill:   #6e1e1e;
  stroke: #501414;
  stroke-width: 2;
}

/* Cutoff-rejected: burnt orange */
.node.sa-cutoff rect {
  fill:   #6e3a10;
  stroke: #502808;
  stroke-width: 2;
}

/* The prop that is the current "target" of a try */
.node.sa-for-goal circle {
  fill:   #2a4060;
  stroke: #3a5880;
  stroke-width: 2.5;
  stroke-dasharray: 4 2;
}

/* Failure state: everything dims with a red tint */
.node.sa-failure circle,
.node.sa-failure rect {
  fill:   #2a1818;
  stroke: #3a1c1c;
  opacity: 0.6;
}

/* Dim: everything else during active search */
.node.sa-dim circle,
.node.sa-dim rect {
  fill:   #141d28;
  stroke: #0f1620;
  opacity: 0.35;
}

/* ── Search-overlay edge classes ─────────────────────────── */
.edge.sa-edge-active {
  stroke-width: 2.2;
  opacity: 1;
}

.edge.sa-edge-dim {
  opacity: 0.06;
}

/* ── Search-overlay mutex-arc class ─────────────────────── */
.mutex-arc.sa-arc-dim {
  opacity: 0.05;
}