:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-raised: #222631;
  --border: #3a3f4b;
  --text: #e6e6e6;
  --muted: #8b90a0;
  --edge: #2e323c;
  --edge-active: #c9a227;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 18px;
  flex: 1;
}

button,
.file-button {
  background: #2a2e38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  background: #343946;
}

.file-button input {
  display: none;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.canvas {
  flex: 1;
  min-width: 0;
  position: relative;
}

#tree {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#tree.panning {
  cursor: grabbing;
}

.zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
}

.zoom-controls button {
  min-width: 36px;
}

/* ---------- tree ---------- */

.edge {
  stroke: var(--edge);
  stroke-width: 4;
}

.edge.active {
  stroke: var(--edge-active);
}

.edge.progression {
  stroke-width: 3;
  stroke-dasharray: 8 5;
}

.edge.requirement {
  stroke: #d9534f;
  stroke-width: 2;
  stroke-dasharray: 2 4;
}

.edge.requirement.met {
  stroke: #e6e6e6;
}

.marker.arrow {
  fill: var(--edge);
}

.marker.arrow-active {
  fill: var(--edge-active);
}

.node {
  cursor: pointer;
  outline: none;
}

.node .shape {
  fill: var(--panel);
  stroke: var(--branch-color);
  stroke-width: 3;
  opacity: 0.6;
}

.node.allocated .shape {
  opacity: 1;
  fill: color-mix(in srgb, var(--branch-color) 45%, var(--panel));
}

.node.maxed .shape {
  fill: var(--branch-color);
  filter: drop-shadow(0 0 8px var(--branch-color));
}

.node.selected .shape,
.node:focus-visible .shape {
  stroke: #fff;
  stroke-width: 4;
  opacity: 1;
}

.node text {
  fill: var(--text);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.node .label {
  font-size: 12px;
}

.node .rank {
  font-size: 12px;
  font-weight: 600;
}

.node .sublabel {
  font-size: 10px;
  fill: var(--muted);
}

/* Milestones: diamonds, gold outline once achieved. */
.node.milestone .shape {
  stroke-width: 2;
}

.node.milestone.allocated .shape {
  fill: var(--branch-color);
  stroke: var(--edge-active);
  stroke-width: 3;
  filter: drop-shadow(0 0 8px var(--edge-active));
}

.node.milestone .label {
  font-weight: 600;
}

/* ---------- detail panel ---------- */

#panel {
  width: 380px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

#panel .muted {
  color: var(--muted);
}

#panel h2 {
  margin: 4px 0 8px;
  font-size: 22px;
}

#panel h3 {
  margin: 20px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.chips {
  display: flex;
  gap: 6px;
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--branch-color);
  border: 1px solid var(--branch-color);
}

.chip.milestone-chip {
  color: var(--edge-active);
  border-color: var(--edge-active);
}

.achieve {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
}

.achieve.achieved {
  background: color-mix(in srgb, var(--edge-active) 25%, var(--panel));
  border-color: var(--edge-active);
  color: var(--edge-active);
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 16px 0 0;
  font-size: 14px;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
}

.reqs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reqs li {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.reqs li::before {
  content: "○";
  color: var(--muted);
}

.reqs li.met::before {
  content: "✓";
  color: var(--branch-color);
}

.req-level {
  font-size: 13px;
  color: var(--muted);
}

button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--muted);
}

button.link:hover {
  background: none;
  text-decoration-color: var(--text);
}

.progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
}

.tldr {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--branch-color);
  background: var(--panel-raised);
  border-radius: 0 6px 6px 0;
  line-height: 1.45;
}

.description {
  line-height: 1.5;
  color: #c8cbd4;
}

.levels {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.level {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-raised);
}

.level.achieved {
  border-color: color-mix(in srgb, var(--branch-color) 60%, var(--border));
}

.level.current {
  box-shadow: 0 0 0 1px var(--branch-color);
}

.level-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.level-num {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.level-name {
  flex: 1;
  font-weight: 600;
}

.level-set {
  padding: 2px 10px;
  font-size: 12px;
}

.level.achieved .level-set {
  color: var(--branch-color);
  border-color: var(--branch-color);
}

.level-desc {
  margin: 8px 0 0;
  line-height: 1.45;
  color: #c8cbd4;
}

.criteria {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.45;
  font-size: 14px;
  color: var(--muted);
}

.level.achieved .criteria {
  color: #c8cbd4;
}

@media (max-width: 760px) {
  main {
    flex-direction: column;
  }

  .canvas {
    height: 55vh;
    flex: none;
  }

  #panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
