:root {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.5rem;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  background: #f3f4f6;
  color: #111827;
  line-height: 1.5;
}

main {
  display: grid;
  gap: 1rem;
  max-width: 100%;
}

header,
section,
article,
aside {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 0.9rem;
}

h1,
h2,
h3 {
  margin-top: 0;
}

#debug-status[data-state="loading"] {
  color: #374151;
}

#debug-status[data-state="error"] {
  color: #b91c1c;
}

#debug-status[data-state="ready"] {
  color: #166534;
}

.toolbar {
  display: grid;
  gap: 0.75rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.toolbar label {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.95rem;
}

.checkbox-label {
  white-space: nowrap;
}

.search-field {
  flex: 1;
  min-width: 200px;
}

.search-field input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.95rem;
}

button,
select {
  padding: 0.45rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.95rem;
}

button:hover,
select:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

button:active {
  background: #f3f4f6;
}

.view-controls {
  justify-content: space-between;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  overflow: hidden;
}

.zoom-controls button {
  border: none;
  border-radius: 0;
  min-width: 2.2rem;
  font-weight: 700;
}

#zoom-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
  background: #f8fafc;
  border-left: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
}

.status-strip {
  background: #f8fafc;
  border-color: #cbd5e1;
}

#graph-counters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.55rem;
  font-size: 0.9rem;
  color: #374151;
}

#graph-counters li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid #dbe4ef;
  border-radius: 8px;
  background: #ffffff;
  white-space: normal;
  line-height: 1.3;
}

.graph-counter-label {
  color: #475569;
  font-size: 0.8rem;
  font-weight: 650;
}

.graph-counter-value {
  color: #0f172a;
  font-size: 0.94rem;
  font-weight: 700;
}

.visualization-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
}

.graph-panel {
  display: grid;
  gap: 0.75rem;
}

#tree-graph {
  width: 100%;
  min-height: 700px;
  height: 800px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, #ffffff 0%, #f1f5f9 100%);
  cursor: default;
  user-select: none;
}

.graph-hint {
  margin: 0.5rem 0;
  font-size: 0.92rem;
  color: #4b5563;
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 0.5rem;
  margin: 0;
  color: #374151;
  font-size: 0.86rem;
}

.legend-item {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  border: 1px solid #dbe4ef;
  border-radius: 999px;
  padding: 0.22rem 0.5rem;
  background: #f8fafc;
  white-space: nowrap;
}

.legend-swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  border: 1px solid #1f2937;
  display: inline-block;
}

.legend-swatch.root {
  background: #dc2626;
}

.legend-swatch.key {
  background: #f59e0b;
}

.legend-swatch.normal {
  background: #60a5fa;
}

.legend-line {
  width: 1.2rem;
  height: 0;
  border-top: 2px solid #6b7280;
  display: inline-block;
}

.legend-line.neighbor {
  border-top-color: #6b7280;
}

.legend-line.prerequisite-all {
  border-top-style: dashed;
  border-top-color: #d97706;
  width: 1.5rem;
}

.legend-line.prerequisite-any {
  border-top-style: dashed;
  border-top-color: #c026d3;
  width: 1.5rem;
}

.legend-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.details-panel {
  display: grid;
  gap: 0.9rem;
  align-content: start;
}

.details-panel h2,
.details-panel h3 {
  margin: 0;
  font-size: 1.1rem;
}

.details-panel h3 {
  font-size: 1rem;
  margin-top: 0.5rem;
}

#selected-node-details {
  font-size: 0.9rem;
}

#selected-node-details p {
  margin: 0.3rem 0;
}

#selected-node-details ul {
  margin: 0.5rem 0;
  padding-left: 1.2rem;
}

#search-match-list,
#selection-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.match-button {
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.6rem;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  font-size: 0.85rem;
  cursor: pointer;
}

.match-button:hover {
  background: #e0f2fe;
  border-color: #0ea5e9;
}

#tree-metadata {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 0.6rem;
}

#tree-metadata dt {
  font-weight: 600;
}

#tree-metadata dd {
  margin: 0;
  color: #374151;
}

.artifact-note {
  margin: 0;
  font-size: 0.9rem;
  color: #374151;
}

.source-section {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.source-section h2 {
  margin-top: 0;
}

.source-section ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.45rem;
}

code {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

.graph-node {
  cursor: pointer;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.graph-node circle {
  stroke: #0f172a;
  stroke-width: 1.6;
  transition:
    stroke-width 0.2s,
    stroke 0.2s,
    filter 0.2s;
}

.graph-node .node-label {
  font-size: var(--graph-label-font-size, 13px);
  fill: #0f172a;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-weight: 650;
  letter-spacing: 0.01em;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 2.4px;
  stroke-linejoin: round;
  text-rendering: optimizeLegibility;
}

.graph-node.normal circle {
  fill: #93c5fd;
}

.graph-node.key circle {
  fill: #fbbf24;
}

.graph-node.root circle {
  fill: #f87171;
}

.graph-node.selected circle {
  stroke-width: 3.5;
  stroke: #020617;
  filter: drop-shadow(0 0 9px rgba(2, 6, 23, 0.35));
}

.graph-node.hovered circle {
  stroke-width: 3;
  stroke: #2563eb;
  filter: drop-shadow(0 0 8px rgba(37, 99, 235, 0.5));
}

.graph-node.search-match circle {
  stroke: #059669;
  stroke-width: 2.8;
}

.graph-node.dimmed {
  opacity: 0.3;
}

.graph-edge {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
  transition:
    stroke-width 0.2s,
    opacity 0.2s,
    filter 0.2s;
}

.graph-edge-underlay {
  fill: none;
  stroke: rgba(248, 250, 252, 0.95);
  stroke-width: 5.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  opacity: 0.78;
}

.graph-edge-underlay.highlighted {
  opacity: 1;
  stroke-width: 6;
}

.graph-edge-underlay.dimmed {
  opacity: 0.1;
}

.graph-edge-hit-area {
  fill: none;
  stroke: transparent;
  stroke-width: 11;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
}

.neighbor-edge {
  stroke: #64748b;
  stroke-width: 2.15;
  opacity: 0.72;
}

.neighbor-edge.highlighted {
  stroke-width: 3.15;
  stroke: #2563eb;
  filter: drop-shadow(0 0 3px rgba(37, 99, 235, 0.38));
  opacity: 1;
}

.neighbor-edge.dimmed {
  opacity: 0.16;
}

.prerequisite-edge-all {
  stroke: #d97706;
  stroke-width: 2.25;
  stroke-dasharray: 7 4;
  opacity: 0.72;
}

.prerequisite-edge-all.highlighted {
  stroke-width: 3;
  filter: drop-shadow(0 0 3px rgba(217, 119, 6, 0.38));
  opacity: 1;
}

.prerequisite-edge-all.dimmed {
  opacity: 0.16;
}

.prerequisite-edge-any {
  stroke: #c026d3;
  stroke-width: 2.25;
  stroke-dasharray: 7 4;
  opacity: 0.72;
}

.prerequisite-edge-any.highlighted {
  stroke-width: 3;
  filter: drop-shadow(0 0 3px rgba(192, 38, 211, 0.34));
  opacity: 1;
}

.prerequisite-edge-any.dimmed {
  opacity: 0.16;
}

.graph-edge:hover {
  opacity: 1;
  stroke-width: 3.25;
  filter: drop-shadow(0 0 3px rgba(15, 23, 42, 0.28));
}

#tree-graph.dense-edges .graph-edge-underlay {
  opacity: 0.88;
}

#tree-graph.dense-edges .graph-edge {
  opacity: 0.6;
}

#tree-graph.dense-edges .neighbor-edge {
  stroke-width: 1.95;
}

#tree-graph.dense-edges .prerequisite-edge-all,
#tree-graph.dense-edges .prerequisite-edge-any {
  stroke-width: 2.05;
}

.edge-label {
  pointer-events: none;
  user-select: none;
  opacity: 0.96;
}

.edge-labels {
  pointer-events: none;
}

.edge-label rect {
  fill: rgba(255, 255, 255, 0.97);
  stroke: #94a3b8;
  stroke-width: 1.1;
  rx: 4;
  ry: 4;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.18));
}

.edge-label-all rect {
  stroke: #d97706;
}

.edge-label-any rect {
  stroke: #c026d3;
}

.edge-label text {
  fill: #0f172a;
  text-anchor: middle;
  dominant-baseline: middle;
  font-size: var(--edge-label-font-size, 11px);
  font-weight: 800;
  letter-spacing: 0.02em;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 1.75px;
  text-rendering: optimizeLegibility;
}

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

  .view-controls {
    justify-content: flex-start;
    gap: 0.55rem;
  }

  #graph-counters {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  #tree-graph {
    min-height: 520px;
  }
}

@media (max-width: 760px) {
  body {
    padding: 0.9rem;
  }

  .toolbar-row {
    gap: 0.45rem;
  }

  .view-controls {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .view-controls > button,
  .zoom-controls {
    width: 100%;
  }

  #graph-counters {
    grid-template-columns: 1fr;
  }

  .legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
    font-size: 0.82rem;
  }

  .legend-item {
    border-radius: 8px;
    padding: 0.18rem 0.42rem;
  }
}
