:root {
  --ground: #fafafa;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --secondary: #4a4a4a;
  --tertiary: #6b6b6b;
  --idle: #8a8a8a;
  --muted: #b0b0b0;
  --rule: #e2e2e2;
  --rule-light: #f0f0f0;
  --accent: #2a5a8a;
  --serif: "IBM Plex Serif", "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
}

/* --- Header --- */

.top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

.kicker {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tertiary);
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.search {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 220px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tertiary);
}

.search input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  padding: 6px 0 8px;
  outline: none;
}

.search input:focus {
  border-bottom-width: 2px;
}

.nav-toggle {
  display: none;
}

/* --- Layout shell --- */

.shell {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 2fr;
}

.pane {
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  padding: 18px 22px 32px;
}

.tree-pane {
  border-right: 1px solid var(--rule);
  background: var(--surface);
}

.page-pane {
  background: var(--surface);
  padding: 32px 48px 48px;
}


/* --- Tree --- */

.tree {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tree button {
  display: flex;
  align-items: baseline;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: var(--secondary);
  font: inherit;
  padding: 4px 6px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s;
}

.tree-arrow {
  flex-shrink: 0;
  position: relative;
  top: 1px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.tree button.open > .tree-arrow {
  transform: rotate(90deg);
}

.tree button:hover { background: var(--rule-light); color: var(--ink); }
.tree button:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

.tree .id {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--idle);
  margin-right: 8px;
}

.tree .domain { padding-left: 4px; color: var(--ink); font-weight: 500; }
.tree .effect { padding-left: 16px; }
.tree .component { padding-left: 28px; }
.tree .finding { padding-left: 40px; color: var(--idle); font-size: 13px; }

.tree .selected {
  color: var(--ink);
  font-weight: 500;
  background: var(--rule-light);
}


/* --- Record page (finding detail) --- */

.record-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule);
}

.record-path {
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--idle);
}

.record-title {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.record-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}

.meta-item {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.meta-item dt {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--idle);
  white-space: nowrap;
}

.meta-item dd {
  margin: 0;
  font-size: 13px;
  color: var(--secondary);
}

/* Summary */

.record-summary {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}

.record-summary p {
  margin: 0 0 10px;
  line-height: 1.6;
  color: var(--ink);
}

.record-summary p:last-child { margin-bottom: 0; }

.summary-point {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 14px;
}

.summary-point h3 {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--idle);
}

.summary-point p {
  margin: 0;
}

.record-summary .summary-source {
  margin: 18px 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--secondary);
}

.summary-source a {
  color: inherit;
  text-underline-offset: 3px;
}

.record-assay {
  font-size: 13px;
  color: var(--secondary);
}

.record-assay strong {
  font-weight: 500;
  color: var(--ink);
}

/* Sections (collapsible) */

.record-body {
  margin-bottom: 32px;
}

.record-section {
  border-bottom: 1px solid var(--rule-light);
}

.record-section:last-child { border-bottom: none; }

.section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 14px 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--ink);
}

.section-toggle:hover { color: var(--accent); }
.section-toggle:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

.section-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
  color: var(--idle);
}

.record-section.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.section-title {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
}

.section-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--idle);
}

.section-content {
  padding: 0 0 16px 22px;
  overflow: hidden;
}

.record-section.collapsed .section-content {
  display: none;
}

/* Entry (one source within a section) */

.entry {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule-light);
}

.entry:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.entry-citation {
  margin-bottom: 10px;
}

.citation-line {
  margin: 0 0 4px;
  line-height: 1.4;
}

.citation-authors {
  font-weight: 500;
  color: var(--ink);
}

.citation-title {
  display: block;
  font-style: italic;
  color: var(--secondary);
  font-size: 13px;
  margin-top: 2px;
}

.citation-venue {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--tertiary);
  margin-top: 2px;
}

a.citation-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

a.citation-link:hover .citation-authors {
  color: var(--accent);
}

a.citation-link:hover .citation-title {
  color: var(--accent);
}

.entry-context {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--secondary);
  line-height: 1.5;
}

.entry-note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--tertiary);
  line-height: 1.5;
  padding-left: 10px;
  border-left: 2px solid var(--rule);
}

/* Data table */

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.data-table tr {
  border-bottom: 1px solid var(--rule-light);
}

.data-table tr:last-child { border-bottom: none; }

.data-table td {
  padding: 6px 12px 6px 0;
  vertical-align: baseline;
}

.data-label {
  font-size: 13px;
  color: var(--secondary);
  white-space: nowrap;
  width: 1%;
}

.data-value {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.data-note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--idle);
}

/* References footer */

.record-references {
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

.record-references h3 {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--idle);
}

.record-references ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: ref;
}

.record-references li {
  counter-increment: ref;
  margin: 0 0 14px;
  padding-left: 24px;
  position: relative;
  line-height: 1.5;
}

.record-references li::before {
  content: counter(ref) ".";
  position: absolute;
  left: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--idle);
  top: 2px;
}

.record-references li:last-child { margin-bottom: 0; }

.ref-authors {
  font-weight: 500;
}

.ref-title {
  color: var(--secondary);
}

.ref-venue {
  font-size: 13px;
  color: var(--tertiary);
}

a.ref-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

a.ref-link:hover .ref-authors {
  color: var(--accent);
}

a.ref-link:hover .ref-title {
  color: var(--accent);
}

/* Empty / stub states */

.record-empty {
  padding: 32px 0;
  color: var(--idle);
  font-style: italic;
}

.empty {
  color: var(--idle);
  font-style: italic;
}

/* Intro pages (domain / effect / component) */

.intro p { max-width: 38em; }

.intro .meta {
  margin: 0 0 22px;
  color: var(--secondary);
}

.intro .meta span + span::before {
  content: " · ";
  color: var(--idle);
}

.block {
  margin: 0 0 20px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--rule-light);
}

.block:last-child { border-bottom: 0; }

.block h3 {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--idle);
}

.block p { margin: 0 0 8px; }
.block p:last-child { margin-bottom: 0; }

/* Links in page */

.page a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 3px;
}

.page a:hover { text-decoration: underline; }

/* Responsive */

@media (max-width: 780px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    min-height: 100dvh;
    display: block;
    overflow-x: hidden;
  }

  .top {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px 16px;
    padding: 14px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  }

  .top-title {
    min-width: 0;
  }

  .kicker {
    margin-bottom: 1px;
    font-size: 9px;
  }

  h1 {
    font-size: clamp(20px, 6vw, 24px);
    line-height: 1.15;
  }

  .search {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    gap: 2px;
    font-size: 9px;
  }

  .search input {
    min-height: 40px;
    padding: 6px 0;
    font-size: 16px;
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--rule);
    border-radius: 3px;
    background: var(--surface);
    color: var(--secondary);
    font-family: var(--sans);
    font-size: 12px;
    cursor: pointer;
  }

  .nav-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .nav-toggle span {
    display: none;
  }

  body.nav-open .nav-toggle {
    border-color: var(--ink);
    color: var(--ink);
    background: var(--rule-light);
  }

  .shell {
    display: block;
    min-height: 0;
  }

  .pane {
    min-height: 0;
    overflow: visible;
  }

  .tree-pane {
    display: none;
    max-height: min(58dvh, 520px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px max(10px, env(safe-area-inset-right)) 18px max(10px, env(safe-area-inset-left));
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    box-shadow: 0 8px 18px rgb(0 0 0 / 5%);
  }

  body.nav-open .tree-pane {
    display: block;
  }

  .tree button {
    min-height: 42px;
    align-items: center;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .tree .domain { padding-left: 6px; }
  .tree .effect { padding-left: 18px; }
  .tree .component { padding-left: 30px; }
  .tree .finding {
    padding-left: 42px;
    font-size: 13px;
  }

  .page-pane {
    padding: 24px max(18px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  }

  .record-header {
    margin-bottom: 20px;
    padding-bottom: 18px;
  }

  .record-path {
    overflow-wrap: anywhere;
  }

  .record-title {
    margin-bottom: 14px;
    font-size: clamp(22px, 7vw, 27px);
  }

  .record-meta {
    display: grid;
    gap: 8px;
  }

  .meta-item {
    display: grid;
    grid-template-columns: 6.5rem minmax(0, 1fr);
    gap: 8px;
  }

  .meta-item dd {
    overflow-wrap: anywhere;
  }

  .summary-point {
    grid-template-columns: 1fr;
    gap: 3px;
    margin-bottom: 18px;
  }

  .summary-point h3 {
    margin-top: 0;
  }

  .record-summary p,
  .entry-context,
  .entry-note {
    font-size: 14px;
  }

  .section-toggle {
    min-height: 48px;
    padding: 12px 0;
  }

  .section-title {
    line-height: 1.35;
  }

  .section-count {
    flex-shrink: 0;
    font-size: 10px;
  }

  .section-content {
    padding: 0 0 18px;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    padding: 10px 0;
  }

  .data-table td {
    padding: 0;
  }

  .data-label {
    margin-bottom: 2px;
    white-space: normal;
  }

  .data-value {
    overflow-wrap: anywhere;
  }

  .data-note {
    margin-top: 3px;
  }

  .record-references li {
    padding-left: 20px;
  }
}

@media (max-width: 380px) {
  .top {
    padding-left: 14px;
    padding-right: 14px;
  }

  .page-pane {
    padding-left: 15px;
    padding-right: 15px;
  }

  .tree .id {
    margin-right: 4px;
  }

  .meta-item {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
