:root {
  --paper: #f8f7f3;
  --surface: #ffffff;
  --soft: #eef1f3;
  --ink: #172638;
  --muted: #596574;
  --line: #cbd2d8;
  --accent: #9a4f3a;
  --accent-soft: #f1e4df;
  --map-indoor: #b77716;
  --map-land: #4e7a54;
  --map-water: #3578a8;
  --map-air: #705eaa;
  --focus: #1d5f8b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101820;
    --surface: #16222d;
    --soft: #1d2c38;
    --ink: #edf2f5;
    --muted: #b7c1c9;
    --line: #44515d;
    --accent: #df957e;
    --accent-soft: #3b2b29;
    --map-indoor: #d49b3c;
    --map-land: #7cac80;
    --map-water: #67a5ce;
    --map-air: #a393d5;
    --focus: #83bfe6;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: Charter, "Bitstream Charter", "Iowan Old Style", Georgia, serif;
}

body {
  margin: 0;
}

a {
  color: inherit;
}

button,
a {
  outline-offset: 3px;
}

button:focus-visible,
a:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 3px solid var(--focus);
}

.page-shell {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.025em;
}

h1 {
  max-width: 760px;
  font-size: clamp(1.5rem, 2.7vw, 2.2rem);
  line-height: 1.15;
}

h2 {
  font-size: clamp(1.5rem, 2.8vw, 2.25rem);
  line-height: 1.15;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.map-instruction {
  max-width: 360px;
  margin: 0;
  color: var(--muted);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 0.88rem;
  line-height: 1.55;
  text-align: right;
}

.research-map {
  position: relative;
}

.system-context {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 86%, var(--soft));
}

.system-context__group {
  min-width: 0;
}

.system-context__group h2 {
  margin: 0 0 9px;
  color: var(--muted);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.system-context__items {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
}

.system-context__item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font: 650 0.78rem/1.2 Inter, "Segoe UI", sans-serif;
}

.system-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.map-stage {
  width: 100%;
}

.research-map__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.research-map__mobile {
  display: none;
}

.map-family-label {
  fill: var(--muted);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.map-family-rule {
  stroke: var(--line);
  stroke-width: 1;
}

.map-link {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.35;
  opacity: 0.68;
  vector-effect: non-scaling-stroke;
  transition: opacity 210ms ease, stroke 210ms ease, stroke-width 210ms ease;
}

.map-link.is-active {
  stroke: var(--accent);
  stroke-width: 2.6;
  opacity: 1;
}

.map-link.is-muted {
  opacity: 0.1;
}

.leaf-node,
.project-node {
  cursor: pointer;
}

.leaf-surface {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1;
  transition: fill 210ms ease, stroke 210ms ease, opacity 210ms ease;
}

.leaf-node:hover .leaf-surface,
.leaf-node:focus-visible .leaf-surface,
.leaf-node.is-active .leaf-surface {
  fill: var(--accent-soft);
  stroke: var(--accent);
}

.leaf-node.is-muted,
.project-node.is-muted {
  opacity: 0.26;
}

.leaf-label {
  fill: var(--ink);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}

.leaf-chevron {
  fill: var(--accent);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 18px;
  font-weight: 700;
  pointer-events: none;
}

.project-hit-area {
  fill: transparent;
}

.project-core {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 1.3;
  transition: fill 210ms ease, stroke 210ms ease, stroke-width 210ms ease;
}

.project-code {
  fill: var(--ink);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
  text-anchor: middle;
}

.environment-ring {
  stroke: var(--surface);
  stroke-width: 1.5;
}

.environment-ring[data-environment="indoor"] {
  fill: var(--map-indoor);
}

.environment-ring[data-environment="land"] {
  fill: var(--map-land);
}

.environment-ring[data-environment="water"] {
  fill: var(--map-water);
}

.environment-ring[data-environment="air"] {
  fill: var(--map-air);
}

.project-halo {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  opacity: 0;
  transition: opacity 210ms ease;
}

.project-node:hover .project-halo,
.project-node:focus-visible .project-halo,
.project-node.is-active .project-halo {
  opacity: 1;
}

.project-focus-label {
  fill: var(--ink);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--paper);
  stroke-width: 6px;
  stroke-linejoin: round;
}

.project-guide-label {
  fill: var(--muted);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 12px;
  text-anchor: middle;
}

.map-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 1.35fr);
  align-items: start;
  gap: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.environment-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.environment-filter button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: 600 0.78rem/1.2 Inter, "Segoe UI", sans-serif;
}

.environment-filter button:hover,
.environment-filter button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.environment-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--swatch, var(--ink));
}

.selection-summary {
  min-height: 90px;
  padding-left: 22px;
  border-left: 2px solid var(--accent);
  font-family: Inter, "Segoe UI", sans-serif;
}

.selection-summary h3 {
  margin: 0 0 6px;
  font-family: Charter, "Bitstream Charter", "Iowan Old Style", Georgia, serif;
  font-size: 1.18rem;
  line-height: 1.25;
}

.selection-summary p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.selection-summary .summary-meta {
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 650;
}

.selection-summary .summary-areas {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 650;
}

.selection-summary a {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.project-index {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.project-index__item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.project-index__item:hover,
.project-index__item.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.project-index__item.is-muted {
  opacity: 0.32;
}

.project-index__code {
  color: var(--accent);
  font: 750 0.7rem/1 Inter, "Segoe UI", sans-serif;
}

.project-index__title {
  overflow: hidden;
  font: 650 0.78rem/1.25 Inter, "Segoe UI", sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-index__status {
  color: var(--muted);
  font: 650 0.64rem/1 Inter, "Segoe UI", sans-serif;
  text-transform: uppercase;
}

.dependency-error {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  color: var(--ink);
  font-family: Inter, "Segoe UI", sans-serif;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 28px, 720px);
    padding-top: 22px;
  }

  .section-heading {
    display: block;
  }

  .map-instruction {
    margin-top: 14px;
    text-align: left;
  }

  .map-footer {
    grid-template-columns: 1fr;
  }

  .selection-summary {
    min-height: 0;
    padding-left: 0;
    padding-top: 14px;
    border-left: 0;
    border-top: 2px solid var(--accent);
  }

  .system-context {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .project-index {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  .research-map__svg {
    display: none;
  }

  .research-map__mobile {
    display: grid;
    gap: 16px;
  }

  .project-index {
    grid-template-columns: 1fr;
  }

  .mobile-family h3 {
    margin: 0 0 8px;
    color: var(--muted);
    font: 750 0.7rem/1.2 Inter, "Segoe UI", sans-serif;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .mobile-family__items {
    display: grid;
    gap: 7px;
  }

  .mobile-leaf {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--surface);
    color: var(--ink);
    font: 650 0.8rem/1.3 Inter, "Segoe UI", sans-serif;
    text-align: left;
  }

  .mobile-leaf:hover,
  .mobile-leaf.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .mobile-leaf.is-muted {
    opacity: 0.32;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
