:root {
  --ink: #162029;
  --muted: #5d6871;
  --line: #d8dedf;
  --paper: #f6f4ef;
  --panel: #ffffff;
  --charcoal: #24323b;
  --steel: #526977;
  --teal: #1f6f73;
  --gold: #a77d32;
  --sage: #8fa293;
  --blue: #315f87;
  --danger: #9b3c36;
  --shadow: 0 18px 45px rgba(22, 32, 41, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button, input, select, textarea {
  font: inherit;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #17252d;
  color: #f7f4eb;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 18px;
  border-bottom: 1px solid rgba(255,255,255,.14);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #e6d6ad;
  color: #17252d;
  font-weight: 800;
}

.brand-title {
  font-size: 18px;
  font-weight: 750;
}

.brand-subtitle {
  color: #b8c6cb;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 4px;
  overflow: auto;
  padding-right: 4px;
}

.nav button {
  width: 100%;
  min-height: 38px;
  border: 0;
  text-align: left;
  color: #dce7e8;
  background: transparent;
  padding: 9px 10px;
  cursor: pointer;
}

.nav button.active,
.nav button:hover,
.nav button:focus-visible {
  color: #ffffff;
  background: rgba(255,255,255,.11);
  outline: 1px solid rgba(255,255,255,.18);
}

.access-note {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.18);
  padding: 14px;
  background: rgba(255,255,255,.07);
  font-size: 13px;
  color: #bfd0d3;
}

.access-note strong {
  display: block;
  margin-top: 5px;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 26px 34px 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 22px;
}

.eyebrow {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

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

h1 {
  margin-bottom: 0;
  font-size: 34px;
  letter-spacing: 0;
}

h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

h3 {
  font-size: 17px;
  margin-bottom: 8px;
}

p {
  color: var(--muted);
  line-height: 1.58;
}

.source-note {
  border-left: 4px solid var(--gold);
  background: #fbf7eb;
  color: var(--ink);
  padding: 12px 14px;
}

.source-note strong {
  color: var(--ink);
}

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

.top-actions button,
.primary-button,
.secondary-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
}

.top-actions button:first-child,
.primary-button {
  background: var(--charcoal);
  color: #ffffff;
  border-color: var(--charcoal);
}

.view {
  display: grid;
  gap: 22px;
}

.hero {
  min-height: 350px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr);
  gap: 26px;
  align-items: stretch;
}

.hero-copy {
  padding: 30px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border-top: 5px solid var(--teal);
}

.hero-copy h2 {
  font-size: 36px;
  max-width: 780px;
}

.hero-visual {
  position: relative;
  overflow: hidden;
  background: #17252d;
  color: #ffffff;
  min-height: 350px;
}

.hero-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(23,37,45,.06), rgba(23,37,45,.78));
  pointer-events: none;
}

.hero-visual img {
  width: 100%;
  height: 100%;
  min-height: 350px;
  object-fit: cover;
  display: block;
}

.visual-caption {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 24px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  z-index: 1;
}

.visual-stat {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  padding: 14px;
}

.visual-stat strong {
  display: block;
  font-size: 22px;
}

.visual-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.visual-card {
  background: #fbfaf7;
  border: 1px solid var(--line);
  overflow: hidden;
}

.visual-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
  background: #17252d;
}

.visual-card div {
  padding: 14px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card, .section, .library-item {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 20px;
}

.card strong {
  color: var(--ink);
}

.section {
  box-shadow: var(--shadow);
}

.source-boundary-card {
  border-top: 5px solid var(--gold);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  background: #edf2f1;
  border-left: 4px solid var(--teal);
  padding: 16px;
}

.metric strong {
  display: block;
  font-size: 24px;
}

.structure {
  display: grid;
  gap: 12px;
}

.node {
  border: 1px solid var(--line);
  background: #fbfaf7;
  padding: 14px 16px;
}

.node.root {
  background: var(--charcoal);
  color: #ffffff;
}

.node.root p { color: #d4dde0; }

.branch {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.arrow {
  text-align: center;
  color: var(--gold);
  font-weight: 800;
  font-size: 20px;
}

.timeline {
  display: grid;
  gap: 12px;
}

.stage {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  border: 1px solid var(--line);
  background: var(--panel);
}

.stage-label {
  background: #edf2f1;
  color: var(--teal);
  font-weight: 800;
  padding: 16px;
}

.stage-body {
  padding: 16px;
}

.library-controls {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 12px;
}

.library-controls input,
.library-controls select,
.contact-form input,
.contact-form select,
.contact-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 11px 12px;
  color: var(--ink);
}

.library-list {
  display: grid;
  gap: 12px;
}

.library-item {
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}

.library-item:hover,
.library-item:focus-visible {
  border-color: var(--teal);
  outline: 0;
  transform: translateY(-1px);
}

.library-meta,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  background: #edf2f1;
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 700;
}

.pill.gold { background: #f2ead7; color: #76551b; }
.pill.blue { background: #e7eef5; color: #315f87; }
.pill.red { background: #f2e5e4; color: var(--danger); }

.contact-form {
  display: grid;
  gap: 12px;
}

.contact-form .split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(9, 15, 19, .58);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}

.modal[hidden] { display: none; }

.modal-panel {
  width: min(620px, 100%);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  background: #ffffff;
  cursor: pointer;
  font-size: 22px;
}

.source-pill {
  border-color: rgba(42, 91, 122, .42);
  background: rgba(42, 91, 122, .08);
  color: var(--ink);
}

.source-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  padding: 11px 16px;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
}

.source-link:hover,
.source-link:focus-visible {
  background: var(--accent-dark);
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    padding: 16px;
    gap: 12px;
  }
  .brand {
    padding-bottom: 12px;
  }
  .nav {
    display: flex;
    gap: 8px;
    max-height: none;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  .nav button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }
  .access-note {
    display: none;
  }
  .hero,
  .grid.two,
  .grid.three,
  .grid.four,
  .visual-grid,
  .visual-grid.compact,
  .metric-row,
  .branch,
  .library-controls,
  .contact-form .split {
    grid-template-columns: 1fr;
  }
  .hero-visual {
    order: -1;
    height: 220px;
    min-height: 220px;
  }
  .hero-visual img {
    height: 220px;
    min-height: 220px;
    object-position: center center;
  }
}

@media (max-width: 640px) {
  .main { padding: 22px 16px 34px; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  h1 { font-size: 28px; }
  .hero-copy h2 { font-size: 28px; }
  .visual-caption { grid-template-columns: 1fr; }
  .stage { grid-template-columns: 1fr; }
}
