/* ═══════════════════════════════════════════════════════════════
   GraphConnect — style.css
   Cross-browser, dark glassmorphism theme
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Palette */
  --bg: #0b0f19;
  --bg-surface: rgba(17, 24, 39, 0.75);
  --bg-glass: rgba(30, 41, 65, 0.45);
  --border-glass: rgba(99, 130, 190, 0.18);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;        /* sky-400 */
  --accent-glow: rgba(56, 189, 248, 0.35);
  --start-color: #22c55e;   /* green-500 */
  --end-color: #ef4444;     /* red-500 */
  --edge-normal: #475569;
  --edge-path: #38bdf8;
  --edge-path-glow: rgba(56, 189, 248, 0.5);
  --danger: #f43f5e;
  --visited-color: #a78bfa; /* purple-400 for step viz */
  --frontier-color: #fbbf24;/* amber-400 for step viz */

  /* Typography */
  --font: 'Inter', system-ui, -apple-system, sans-serif;

  /* Sizes */
  --node-size: 64px;
  --toolbar-h: 64px;
  --header-h: 90px;
  --result-h: 48px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Glass helper ────────────────────────────────────────────── */
.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
}

/* ── Header ──────────────────────────────────────────────────── */
#app-header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, rgba(15,23,42,0.95) 0%, transparent 100%);
  position: relative;
  z-index: 10;
  padding: 0 24px;
}

h1 {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-icon {
  display: inline-block;
  margin-right: 4px;
  animation: spin 8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Toolbar ─────────────────────────────────────────────────── */
#toolbar {
  flex-shrink: 0;
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-glass);
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 10;
}

#toolbar::-webkit-scrollbar { display: none; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.btn-row {
  display: flex;
  gap: 4px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  background: rgba(30, 41, 65, 0.5);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  user-select: none;
  white-space: nowrap;
}

.tool-btn:hover {
  background: rgba(56, 189, 248, 0.1);
  border-color: var(--accent);
  color: var(--text);
}

.tool-btn.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.tool-btn.danger { color: var(--danger); }
.tool-btn.danger:hover { border-color: var(--danger); background: rgba(244,63,94,0.12); }

.tool-btn.primary {
  background: rgba(56,189,248,0.25);
  border-color: var(--accent);
  color: var(--accent);
}

.tool-btn.small { padding: 4px 10px; font-size: 0.72rem; border-radius: 6px; }

.tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.icon { font-size: 1rem; line-height: 1; }

#zoom-level {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 130px;
  text-align: center;
}

/* ── Result bar ──────────────────────────────────────────────── */
#result-bar {
  flex-shrink: 0;
  height: var(--result-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-glass);
  z-index: 10;
}

#path-display {
  font-size: 1.05rem;
  font-weight: 600;
}

#path-text {
  color: var(--accent);
  font-weight: 700;
}

/* ── Graph canvas ────────────────────────────────────────────── */
#graph-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background-color: #0b0f19;
}

#graph-wrapper.grabbing { cursor: grabbing; }

#graph-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  transform-origin: 0 0;
  will-change: transform;
  /* transform set by JS for zoom/pan */
}

#graph-container.smooth-zoom {
  transition: transform 0.18s var(--ease);
}

#edge-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

/* individual edge lines — normal */
.edge-line {
  stroke: var(--edge-normal);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke 0.35s var(--ease), stroke-width 0.35s var(--ease), filter 0.35s var(--ease);
  pointer-events: visibleStroke;
  cursor: pointer;
}

.edge-line:hover {
  stroke: var(--text-muted);
  stroke-width: 4;
}

/* shortest-path highlighted edge */
.edge-line.path-active {
  stroke: var(--edge-path);
  stroke-width: 4;
  filter: drop-shadow(0 0 6px var(--edge-path-glow));
}

/* step viz: visited edge */
.edge-line.visited {
  stroke: var(--visited-color);
  stroke-width: 3;
  opacity: 0.7;
}

/* edge weight labels */
.edge-label {
  fill: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  pointer-events: all;
  cursor: pointer;
  transition: fill 0.3s var(--ease);
  user-select: none;
}

.edge-label.path-active {
  fill: var(--accent);
  font-size: 13px;
}

.edge-label-bg {
  fill: rgba(11, 15, 25, 0.85);
  rx: 4;
  ry: 4;
  pointer-events: none;
}

/* Animated traversal dot */
.traversal-dot {
  fill: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent));
}

/* Delete-mode highlights */
.edge-line.delete-hover {
  stroke: var(--danger) !important;
  stroke-width: 5 !important;
}

/* ── Node styling ────────────────────────────────────────────── */
.node {
  position: absolute;
  width: var(--node-size);
  height: var(--node-size);
  border-radius: 50%;
  border: 2px solid rgba(148, 163, 184, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  cursor: grab;
  user-select: none;
  z-index: 5;
  transition: transform 0.15s var(--ease), box-shadow 0.3s var(--ease), border-color 0.3s var(--ease);
  /* subtle inner glow */
  box-shadow:
    inset 0 0 16px rgba(0,0,0,0.25),
    0 2px 8px rgba(0,0,0,0.3);
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.12), transparent 60%), var(--node-bg, #334155);
}

.node:hover {
  transform: scale(1.08);
  border-color: var(--accent);
  box-shadow:
    inset 0 0 16px rgba(0,0,0,0.25),
    0 0 18px var(--accent-glow);
}

.node:active, .node.dragging {
  cursor: grabbing;
  transform: scale(1.12);
}

/* Source + End colours */
.node.start {
  --node-bg: var(--start-color);
  border-color: rgba(34,197,94,0.5);
}

.node.end {
  --node-bg: var(--end-color);
  border-color: rgba(239,68,68,0.5);
}

/* Path-active glow */
.node.path-active {
  border-color: var(--accent);
  box-shadow:
    inset 0 0 16px rgba(0,0,0,0.2),
    0 0 22px var(--accent-glow),
    0 0 44px rgba(56,189,248,0.15);
  animation: nodePulse 1.5s ease-in-out infinite alternate;
}

@keyframes nodePulse {
  from { box-shadow: inset 0 0 16px rgba(0,0,0,0.2), 0 0 22px var(--accent-glow); }
  to { box-shadow: inset 0 0 16px rgba(0,0,0,0.2), 0 0 36px var(--accent-glow), 0 0 60px rgba(56,189,248,0.1); }
}

/* Step viz: visited */
.node.step-visited {
  border-color: var(--visited-color);
  box-shadow: 0 0 14px rgba(167,139,250,0.4);
}

/* Step viz: frontier */
.node.step-frontier {
  border-color: var(--frontier-color);
  box-shadow: 0 0 14px rgba(251,191,36,0.4);
}

/* Delete-mode hover */
.node.delete-hover {
  border-color: var(--danger) !important;
  box-shadow: 0 0 20px rgba(244,63,94,0.5) !important;
}

/* Edge-add selection ring */
.node.edge-select {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

/* Snap grid (drawn by JS on canvas bg) */
#graph-wrapper.grid-on {
  background-image:
    linear-gradient(rgba(148,163,184,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148,163,184,0.08) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* ── Side panel (algorithm steps) ────────────────────────────── */
#steps-panel {
  position: fixed;
  top: 0; right: 0;
  width: 320px;
  height: 100%;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--border-glass);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.35s var(--ease);
}

#steps-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-glass);
}

.panel-header h4 {
  font-size: 0.95rem;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.close-btn:hover { color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  font-size: 0.8rem;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: var(--border-glass) transparent;
}

.step-item {
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: rgba(30,41,65,0.35);
  border-left: 3px solid transparent;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.step-item.current {
  background: rgba(56,189,248,0.08);
  border-left-color: var(--accent);
}

.step-item.done {
  opacity: 0.55;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border-glass);
}

#step-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ── Weight modal ────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  transition: opacity 0.25s var(--ease);
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  padding: 24px;
  min-width: 280px;
  text-align: center;
}

.modal-content h4 {
  margin-bottom: 14px;
  font-weight: 700;
}

#weight-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  background: rgba(15,23,42,0.8);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  text-align: center;
  outline: none;
  margin-bottom: 14px;
}

#weight-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ── Instructions (bottom-left) ──────────────────────────────── */
#instructions {
  position: fixed;
  bottom: 16px;
  left: 16px;
  padding: 10px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 340px;
  z-index: 50;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --node-size: 50px;
    --toolbar-h: auto;
    --header-h: 70px;
  }

  h1 { font-size: 1.2rem; }
  #subtitle { font-size: 0.7rem; }

  #toolbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 8px;
  }

  .toolbar-label { display: none; }
  .btn-text { display: none; }

  .tool-btn { padding: 6px 8px; }

  #steps-panel { width: 100%; }

  #instructions { max-width: 220px; font-size: 0.7rem; }
}

@media (max-width: 480px) {
  :root {
    --node-size: 42px;
  }

  .node { font-size: 0.85rem; }
  .edge-label { font-size: 10px; }
}
