:root {
  --bg: #f3efe4;
  --panel: #fff7ec;
  --panel-muted: #eef1ea;
  --ink: #1d2b2a;
  --muted: #5f6b66;
  --accent: #e07a5f;
  --accent-2: #3d8c7c;
  --accent-3: #f2cc8f;
  --border: rgba(29, 43, 42, 0.12);
  --shadow: 0 14px 30px rgba(29, 43, 42, 0.12);
  --map-bg: #162b2a;
  --map-edge: #56746d;
  --map-edge-soft: rgba(86, 116, 109, 0.4);
  --map-label: #f2cc8f;
  --map-node: #f6e3b8;
  --map-text: #1c1d1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 400px at 5% 0%, #f7f0df 0%, rgba(247, 240, 223, 0) 70%),
    radial-gradient(800px 500px at 90% 10%, #dde7dd 0%, rgba(221, 231, 221, 0) 70%),
    linear-gradient(180deg, #f4efe3 0%, #efe5d7 100%);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 8px 0;
}

.hero h1 {
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 2.6rem;
  margin: 0 0 8px 0;
}

.subtitle {
  max-width: 560px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 220px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 4px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(420px, 2fr) minmax(220px, 1fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: rise 0.6s ease both;
}

.panel h2 {
  margin: 0 0 12px 0;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 1.25rem;
}

.panel h3 {
  margin: 0 0 10px 0;
  font-size: 1rem;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fffaf1;
  color: var(--ink);
  font-size: 0.95rem;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.algo-btn {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fffaf1;
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.algo-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(29, 43, 42, 0.1);
}

.algo-btn.active {
  background: var(--accent-3);
  border-color: rgba(224, 122, 95, 0.6);
  box-shadow: 0 0 0 3px rgba(224, 122, 95, 0.15);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.run-btn {
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(120deg, var(--accent), #f2cc8f);
  color: #2a1d18;
  font-weight: 700;
  cursor: pointer;
}

.secondary-btn {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.note {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 14px;
  line-height: 1.5;
}

.map-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.map-head .muted {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.map-shell {
  position: relative;
  height: 520px;
  margin: 12px 0 14px;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(500px 300px at 15% 20%, rgba(61, 140, 124, 0.18), transparent 70%),
    radial-gradient(400px 260px at 80% 80%, rgba(224, 122, 95, 0.15), transparent 70%),
    linear-gradient(135deg, #162b2a 0%, #0f1f20 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#graphSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.map-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 247, 236, 0.96);
  border: 1px solid rgba(224, 122, 95, 0.4);
  color: #1d2b2a;
  font-size: 0.85rem;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  opacity: 0;
  transform: translate(-9999px, -9999px);
  transition: opacity 0.15s ease;
  display: grid;
  gap: 2px;
  z-index: 2;
}

.map-tooltip strong {
  font-size: 0.95rem;
}

.map-tooltip span {
  color: #5f6b66;
  font-size: 0.75rem;
}

.map-tooltip.visible {
  opacity: 1;
}

.compass {
  position: absolute;
  right: 20px;
  top: 20px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(242, 204, 143, 0.4);
  display: grid;
  place-items: center;
  color: var(--accent-3);
  font-weight: 600;
  font-size: 0.9rem;
  background: rgba(15, 31, 32, 0.6);
}

.compass-ring {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px dashed rgba(242, 204, 143, 0.4);
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--map-node);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.swatch.start {
  background: var(--accent-2);
}

.swatch.goal {
  background: var(--accent);
}

.swatch.path {
  background: transparent;
  border: 2px solid var(--accent);
}

.output {
  display: grid;
  gap: 10px;
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-muted);
  border: 1px solid var(--border);
  align-items: start;
}

.label {
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 0;
}

.value {
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
  min-width: 0;
  overflow-wrap: anywhere;
}

.mono {
  font-family: "Courier New", monospace;
  font-weight: 500;
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.analysis {
  margin-top: 20px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.analysis-grid h3 {
  margin: 0 0 6px 0;
  font-size: 1rem;
}

.analysis-grid p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

/* SVG styling */
.edge {
  stroke: var(--map-edge);
  stroke-width: 2.2;
  stroke-linecap: round;
}

.edge-label {
  fill: var(--map-label);
  font-size: 12px;
  font-weight: 600;
  paint-order: stroke;
  stroke: rgba(15, 31, 32, 0.6);
  stroke-width: 3px;
}

.path-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 6 6;
  filter: drop-shadow(0 0 6px rgba(224, 122, 95, 0.6));
}

.path-mask {
  fill: none;
  stroke: #ffffff;
  stroke-width: 4.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node circle {
  fill: var(--map-node);
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 2px;
}

.node-label {
  fill: var(--map-text);
  font-size: 12px;
  font-weight: 700;
}

.node.start circle {
  fill: var(--accent-2);
}

.node.goal circle {
  fill: var(--accent);
}

.node.on-path circle {
  stroke: #fff2d4;
  stroke-width: 3px;
}

.path-tracer {
  fill: #f2cc8f;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 2px;
  filter: drop-shadow(0 0 6px rgba(224, 122, 95, 0.7));
  animation: tracerPulse 1.4s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tracerPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(240px, 1fr) minmax(380px, 2fr);
  }

  .results {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .results {
    grid-column: auto;
  }

  .map-shell {
    height: 440px;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }
}
