:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #60706c;
  --line: #cfd8d4;
  --paper: #fbfaf5;
  --panel: #ffffff;
  --panel-soft: #f5f7f3;
  --green: #2f7b68;
  --green-dark: #235b4f;
  --red: #b6493c;
  --amber: #b27521;
  --blue: #326b92;
  --violet: #6f5589;
  --shadow: 0 20px 60px rgba(27, 35, 31, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

a {
  color: var(--blue);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.topbar {
  position: fixed;
  z-index: 50;
  top: 0;
  left: 0;
  right: 0;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(270px, 1fr) minmax(260px, 420px) auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  background: rgba(251, 250, 245, 0.92);
  border-bottom: 1px solid rgba(207, 216, 212, 0.8);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand p,
.panel-note,
.statusbar {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.search-wrap {
  height: 44px;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: center;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search-wrap svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.jump-nav,
.control-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.jump-nav button,
.icon-button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.jump-nav button {
  padding: 0 12px;
  white-space: nowrap;
}

.icon-button {
  width: 40px;
  display: inline-grid;
  place-items: center;
}

.jump-nav button:hover,
.icon-button:hover,
.icon-button[aria-expanded="true"],
.source-link:hover {
  border-color: var(--green);
  color: var(--green-dark);
}

.icon-button[aria-expanded="true"] {
  background: rgba(47, 123, 104, 0.1);
}

.app-shell {
  height: 100%;
  padding-top: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.viewport {
  position: relative;
  min-width: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(circle, rgba(49, 64, 58, 0.18) 1px, transparent 1.3px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(207, 216, 212, 0.45) 1px, transparent 1px) 0 0 / 160px 160px,
    linear-gradient(rgba(207, 216, 212, 0.45) 1px, transparent 1px) 0 0 / 160px 160px,
    #f8f7ef;
}

.viewport:active {
  cursor: grabbing;
}

.world {
  position: absolute;
  top: 0;
  left: 0;
  width: 4300px;
  height: 2300px;
  transform-origin: 0 0;
  overflow: visible;
}

.edges {
  position: absolute;
  inset: 0;
  width: 4300px;
  height: 2300px;
  pointer-events: none;
  overflow: visible;
}

.edge-path {
  fill: none;
  stroke: rgba(47, 123, 104, 0.36);
  stroke-width: 4;
}

.edge-label {
  fill: var(--green-dark);
  paint-order: stroke;
  stroke: rgba(248, 247, 239, 0.9);
  stroke-width: 8px;
  stroke-linejoin: round;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
}

.node-layer {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.node {
  position: absolute;
  width: var(--w);
  transform: translate(var(--x), var(--y));
  border: 1px solid rgba(23, 33, 31, 0.14);
  border-top: 6px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: opacity 160ms ease, filter 160ms ease, transform 160ms ease;
  user-select: none;
}

.node.dimmed {
  opacity: 0.26;
  filter: grayscale(0.4);
}

.node.dragging {
  z-index: 12;
  box-shadow: 0 28px 80px rgba(27, 35, 31, 0.2);
}

.node-head {
  padding: 18px 20px 12px;
  background: linear-gradient(180deg, rgba(245, 247, 243, 0.85), rgba(255, 255, 255, 0));
  cursor: grab;
}

.node.dragging .node-head {
  cursor: grabbing;
}

.eyebrow,
.kicker,
.phase-tag {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 850;
  color: var(--accent);
  letter-spacing: 0.06em;
}

.node h3 {
  margin-top: 6px;
  font-size: 23px;
  line-height: 1.08;
  letter-spacing: 0;
}

.node-body {
  padding: 0 20px 20px;
  color: #24302d;
  font-size: 15px;
  line-height: 1.45;
}

.node-body p + p {
  margin-top: 10px;
}

.node-body ul {
  padding-left: 18px;
  margin: 12px 0 0;
}

.node-body li + li {
  margin-top: 7px;
}

.callout {
  margin-top: 14px;
  padding: 12px;
  border-left: 4px solid var(--accent);
  background: var(--panel-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 14px;
}

.node-links,
.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.source-link,
.chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 6px 9px;
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
}

.chip {
  color: var(--muted);
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.doc-preview {
  display: block;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.doc-preview:hover {
  border-color: var(--green);
  box-shadow: 0 16px 34px rgba(27, 35, 31, 0.1);
  transform: translateY(-2px);
}

.doc-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top;
  background: #f1f1ec;
  border-bottom: 1px solid var(--line);
}

.doc-preview span {
  display: block;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.side-panel {
  position: fixed;
  z-index: 40;
  top: 72px;
  right: 0;
  bottom: 0;
  width: min(380px, calc(100vw - 20px));
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: -22px 0 52px rgba(27, 35, 31, 0.13);
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 16px));
  transition: opacity 180ms ease, transform 180ms ease;
}

body.panel-open .side-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.panel-section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2 {
  margin-top: 4px;
  font-size: 19px;
}

.check-group {
  margin-top: 18px;
}

.check-group h3 {
  font-size: 14px;
  color: var(--green-dark);
}

.check-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 9px;
  align-items: start;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.35;
}

.check-item input {
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  accent-color: var(--green);
}

.check-item span {
  color: #283531;
}

.check-item.done span {
  color: var(--muted);
  text-decoration: line-through;
}

.source-card {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.source-card h3 {
  font-size: 14px;
}

.source-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.minimap {
  position: fixed;
  right: 16px;
  bottom: 36px;
  z-index: 25;
  width: 170px;
  height: 92px;
  border: 1px solid rgba(23, 33, 31, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 28px rgba(23, 33, 31, 0.1);
  overflow: hidden;
  pointer-events: none;
}

.mini-world {
  position: relative;
  width: 100%;
  height: 100%;
}

.mini-node {
  position: absolute;
  width: 9px;
  height: 7px;
  border-radius: 2px;
  background: var(--accent);
}

.mini-view {
  position: absolute;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: rgba(47, 123, 104, 0.08);
}

.statusbar {
  position: fixed;
  z-index: 35;
  left: 0;
  bottom: 0;
  right: 0;
  min-height: 28px;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 5px 14px;
  border-top: 1px solid rgba(207, 216, 212, 0.8);
  background: rgba(251, 250, 245, 0.92);
  backdrop-filter: blur(14px);
}

body.panel-open .statusbar {
  right: 380px;
}

body.panel-open .minimap {
  right: 400px;
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .topbar {
    position: sticky;
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .jump-nav {
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .app-shell {
    display: block;
    height: auto;
    min-height: 0;
    padding-top: 0;
  }

  .viewport {
    height: min(620px, 72vh);
  }

  .side-panel {
    top: 0;
    width: min(380px, calc(100vw - 16px));
    border-top: 0;
  }

  .minimap,
  .statusbar {
    display: none;
  }
}

@media print {
  body {
    overflow: visible;
    background: #fff;
  }

  .topbar,
  .viewport,
  .minimap,
  .statusbar {
    display: none;
  }

  .app-shell {
    display: block;
    height: auto;
    padding: 0;
  }

  .side-panel {
    border: 0;
    overflow: visible;
  }
}
