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

:root {
  --bg: #060612;
  --text: #e8ecf4;
  --muted: #9aa8c4;
  --panel: rgba(12, 16, 32, 0.82);
  --border: rgba(120, 140, 180, 0.25);
  --material: #5dade2;
  --action: #f5b041;
  --product: #1abc9c;
  --merge: #e74c3c;
  --final: #f1c40f;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: system-ui, "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  font-weight: 700;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.controls {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.controls button {
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.controls button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-reset {
  width: auto !important;
  padding: 0 0.75rem;
  font-size: 0.85rem !important;
}

.legend {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 20;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-size: 0.72rem;
  max-width: 180px;
}

.legend h2 {
  font-size: 0.78rem;
  margin-bottom: 0.4rem;
  color: var(--muted);
}

.legend ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.material { background: var(--material); box-shadow: 0 0 6px var(--material); }
.dot.action { background: var(--action); box-shadow: 0 0 6px var(--action); }
.dot.product { background: var(--product); box-shadow: 0 0 6px var(--product); }
.dot.merge { background: var(--merge); transform: rotate(45deg); border-radius: 2px; box-shadow: 0 0 6px var(--merge); }
.dot.final { background: var(--final); box-shadow: 0 0 8px var(--final); width: 12px; height: 12px; }

.legend-dash .line-dash {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px dashed rgba(180, 200, 230, 0.6);
}

.stage {
  position: fixed;
  inset: 0;
  top: 3.5rem;
}

#starfield {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.viewport-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  direction: ltr;
  touch-action: pan-x pan-y;
}

.viewport-wrap:has(.grabbing) {
  cursor: grabbing;
}

.viewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#graph {
  display: block;
  width: 1200px;
  height: 1100px;
  overflow: visible;
}

/* SVG styles */
.channel-label {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-anchor: middle;
  font-family: inherit;
}

.edge {
  fill: none;
  stroke: rgba(150, 175, 210, 0.35);
  stroke-width: 1.8;
  transition: stroke 0.2s, opacity 0.2s;
}

.edge-dashed {
  stroke-dasharray: 8 6;
  stroke: rgba(150, 175, 210, 0.5);
}

.edge.highlighted {
  stroke: rgba(200, 220, 255, 0.85);
  stroke-width: 2.5;
}

.edge.dimmed {
  opacity: 0.25;
}

.hint {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  padding: 0.5rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.path-panel {
  position: fixed;
  top: 4rem;
  left: 1rem;
  z-index: 25;
  width: min(260px, 85vw);
  max-height: 50vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  backdrop-filter: blur(8px);
}

.path-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.path-panel-head button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
}

#path-list {
  list-style: none;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#path-list li {
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.path-type {
  color: var(--muted);
  font-size: 0.68rem;
}

.controls button {
  position: relative;
  z-index: 1;
}

.node {
  cursor: pointer;
  transition: opacity 0.2s;
  touch-action: manipulation;
}

.node-hit {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}

.node.dimmed {
  opacity: 0.4;
}

.node-shape {
  stroke-width: 2;
  transition: filter 0.2s, stroke-width 0.2s;
}

.node-shape[data-type="material"] {
  fill: #1a3a5c;
  stroke: var(--material);
  filter: drop-shadow(0 0 6px rgba(93, 173, 226, 0.5));
}

.node-shape[data-type="action"] {
  fill: #4a3a10;
  stroke: var(--action);
  filter: drop-shadow(0 0 6px rgba(245, 176, 65, 0.5));
}

.node-shape[data-type="product"] {
  fill: #0e3d35;
  stroke: var(--product);
  filter: drop-shadow(0 0 8px rgba(26, 188, 156, 0.55));
}

.node-shape[data-type="final"] {
  fill: #1e4620;
  stroke: var(--final);
  filter: drop-shadow(0 0 10px rgba(241, 196, 15, 0.65));
}

.node-merge {
  fill: #4a1512;
  stroke: var(--merge);
  filter: drop-shadow(0 0 8px rgba(231, 76, 60, 0.6));
}

.node-ring {
  fill: none;
  stroke-width: 1.5;
  opacity: 0.7;
}

.node-ring[data-type="product"] { stroke: var(--product); }
.node-ring[data-type="final"] { stroke: var(--final); }

.node-label {
  fill: var(--text);
  font-size: 11px;
  text-anchor: middle;
  font-family: inherit;
  pointer-events: none;
}

.node.highlighted .node-shape,
.node.highlighted .node-merge {
  stroke-width: 3;
}

.node:focus-visible .node-shape,
.node:focus-visible .node-merge {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.tooltip {
  position: fixed;
  z-index: 30;
  max-width: 280px;
  padding: 0.55rem 0.75rem;
  background: rgba(10, 14, 28, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.tooltip strong {
  display: block;
  margin-bottom: 0.25rem;
}

#tooltip-body {
  color: var(--muted);
  line-height: 1.4;
}

#path-list li.path-current {
  color: var(--final);
  font-weight: 600;
}

@media (max-width: 768px) {
  .legend {
    bottom: auto;
    top: 3.6rem;
    right: 0.5rem;
    font-size: 0.65rem;
    padding: 0.45rem 0.6rem;
    max-width: 150px;
    z-index: 15;
  }

  .header-text .subtitle {
    display: none;
  }

  .path-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 42vh;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    z-index: 30;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  }

  .path-panel-head button {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.5rem;
  }

  #path-list {
    font-size: 0.82rem;
  }

  .tooltip.mobile-pinned {
    top: 3.75rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-width: 92vw;
    pointer-events: none;
  }

  .hint {
    bottom: max(1rem, env(safe-area-inset-bottom));
    font-size: 0.7rem;
    max-width: 92vw;
    text-align: center;
  }

  .node.highlighted .node-shape,
  .node.highlighted .node-merge {
    stroke-width: 4;
  }

  .node.dimmed {
    opacity: 0.28;
  }
}

@media (prefers-reduced-motion: reduce) {
  .edge, .node, .node-shape {
    transition: none;
  }
}
