:root {
  --ink: #1a2c2c;
  --muted: #5e8e91;
  --panel: #e8e2d9;
  --panel-strong: #ffffff;
  --edge: #cfc8bd;
  --accent: #133f41;

  --domain-cardiovascular: #d66052;
  --domain-metabolic: #5d9a67;
  --domain-musculoskeletal: #6287b7;
  --domain-cognitiveneurological: #8b77b8;
  --domain-autoimmuneinflammatory: #b98550;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Sora", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, #ffffff 0%, transparent 42%),
    radial-gradient(circle at 88% 12%, #f4f0ea 0%, transparent 38%),
    linear-gradient(110deg, #ece6dc 0%, #e8e2d9 40%, #e3ddd4 100%);
  min-height: 100%;
  overflow-x: hidden;
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px clamp(12px, 3vw, 40px) 28px;
  overflow-x: clip;
}

.hero {
  position: relative;
  margin-bottom: 10px;
}

.hero-top {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.hero-title {
  flex: 0 0 auto;
}

.hero-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
  margin-left: auto;
}

.kicker {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
}

.hero h1 {
  margin: 2px 0 4px;
  font-size: clamp(1.3rem, 2.2vw, 1.8rem);
  line-height: 1.15;
}

.subtitle {
  margin: 0;
  color: #56665f;
  font-size: 0.95rem;
}

.subtitle-hint {
  margin: 4px 0 0;
  color: #7a8a82;
  font-size: 0.82rem;
}

/* hero-right removed — logo sits directly in hero-top, legend moved to methodology */

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.graph-col {
  min-width: 0;
}

#quick-find {
  border: 1px solid #9bb8ba;
  border-radius: 6px;
  padding: 5px 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 1rem;
  flex: 1;
  min-width: 0;
}

#quick-find:focus {
  outline: 2px solid #6d9ea1;
  outline-offset: 1px;
}

#quick-find.no-match {
  border-color: #b44a44;
  box-shadow: 0 0 0 2px #f5d9d6;
}

#clear-focus {
  border: 1px solid #477b7e;
  border-radius: 6px;
  padding: 5px 10px;
  background: #dce9ea;
  color: #1a2c2c;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}

#clear-focus:hover {
  background: #cfe0e2;
}

.certainty-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid #bccecf;
  color: #2f4a49;
  background: #f4f8f8;
  position: relative;
  cursor: default;
}

.legend-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: auto;
  width: max-content;
  max-width: 200px;
  white-space: normal;
  background: #1a2c2c;
  color: #f0f4f4;
  font-size: 0.66rem;
  font-weight: 400;
  padding: 5px 10px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  z-index: 10;
  pointer-events: none;
}

.legend-tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 14px;
  border: 5px solid transparent;
  border-bottom-color: #1a2c2c;
}

.legend-item:hover .legend-tooltip {
  display: block;
}

.legend-item.weight-3 {
  border-left: 3px solid #133f41;
}

.legend-item.weight-2 {
  border-left: 2px dashed #133f41;
}

.legend-item.weight-1 {
  border-left: 2px dotted #133f41;
}

.hero-details {
  margin-top: 8px;
}

.hero-details summary {
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 600;
  color: #5e8e91;
  letter-spacing: 0.02em;
}

.hero-details-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
  border: 1px solid #d2dcdd;
  border-radius: 10px;
  background: #fafcfc;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: #304643;
}

.hero-details-body p {
  margin: 0 0 4px;
}

.hero-details-body p:last-child {
  margin-bottom: 0;
}

.hero-details-body ul {
  margin: 0;
  padding-left: 16px;
  color: #405350;
}

.hero-details-body li {
  margin-bottom: 3px;
}

.hero-details-col {
  min-width: 0;
}

/* ── Main stage: graph + card panel ── */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.graph-card,
.info-card {
  border: 1px solid #b8cdcf;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f0ece4 100%);
  box-shadow: 0 6px 18px #5b898c20;
}

.component-card {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 8px 20px #132f3218;
  padding: 14px;
}

.graph-card {
  position: relative;
  overflow: hidden;
}

.fatal-banner {
  margin: 10px 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d4a7a2;
  background: #fff1ef;
  color: #7a2720;
  font-size: 0.84rem;
  font-weight: 600;
}

#graph {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: #1f2a27f7;
  color: #fff;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.78rem;
  max-width: 280px;
  opacity: 0;
  transform: translate3d(0, 0, 0);
  transition: opacity 0.12s ease;
  z-index: 50;
}

.cards-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding-right: 2px;
  transition: margin-top 0.25s ease;
}

.info-card {
  padding: 16px;
}

.info-card h2,
.info-card h3 {
  margin: 0 0 10px;
}

.info-card h3 {
  margin-top: 0;
  font-size: 0.95rem;
}

.focus-content {
  font-size: 0.92rem;
  color: #374151;
  line-height: 1.45;
  min-height: 120px;
}

.focus-content p {
  margin: 0 0 6px;
}

.focus-content p:last-child {
  margin-bottom: 0;
}

.card-eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #9ca3af;
  font-weight: 700;
}

.card-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
  color: #111827;
}

.card-subtext {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: #6b7280;
}

.edu-block {
  border-left: 3px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 10px;
}

.edu-title {
  margin: 0 0 4px;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
  font-weight: 700;
}

.edu-text {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.42;
  color: #334155;
}

.edu-bullets {
  margin: 0;
  padding-left: 16px;
  font-size: 0.76rem;
  line-height: 1.42;
  color: #334155;
}
.edu-bullets li {
  margin-bottom: 3px;
}
.edu-bullets li:last-child {
  margin-bottom: 0;
}

/* --- Body-system impact section (condition cards) --- */
.body-impact-section {
  margin-top: 10px;
}
.body-impact-row {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 3px solid #e2e8f0;
}
.body-impact-domain {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.body-impact-text {
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.4;
  color: #475569;
}

/* --- Custom red-flag block (symptom cards) --- */
.custom-flag-block {
  margin-top: 12px;
  border-left: 3px solid #c0392b;
  background: #fdf2f2;
  border-radius: 8px;
  padding: 10px 12px;
}
.custom-flag-title {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #922b21;
  display: flex;
  align-items: center;
  gap: 6px;
}
.flag-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c0392b;
  flex-shrink: 0;
}
.custom-flag-text {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.42;
  color: #4a1c17;
}

/* --- Detection section (condition cards) --- */
.detection-section {
  margin-top: 10px;
}

.condition-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.condition-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #ffffff;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.condition-row:hover {
  border-color: #9ca3af;
  background: #f9fafb;
}

.condition-icon-chip {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4b5563;
  font-size: 0.66rem;
  font-weight: 700;
  flex-shrink: 0;
}

.condition-main {
  min-width: 0;
  flex: 1;
}

.condition-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #111827;
  line-height: 1.2;
}

.condition-clinical {
  display: block;
  margin-top: 1px;
  font-size: 0.68rem;
  font-style: italic;
  color: #5f6f69;
  line-height: 1.2;
}

.card-clinical {
  margin: -6px 0 8px;
  font-size: 0.76rem;
  font-style: italic;
  color: #5f6f69;
}

.pill-row {
  margin-top: 3px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.domain-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: #f8fafc;
  padding: 1px 6px;
  font-size: 0.62rem;
  font-weight: 700;
  color: #374151;
  white-space: nowrap;
}

.strength-badge {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.strength-primary {
  background: #1a1a2e;
  color: #ffffff;
}

.strength-supporting {
  background: #e5e7eb;
  color: #374151;
}

.strength-context {
  background: #f3f4f6;
  color: #9ca3af;
}

.mini-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fafaf8;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.78rem;
  color: #374151;
}

.certainty-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}

.certainty-group-title {
  margin: 0;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7280;
  font-weight: 700;
}

.consultation-cta {
  margin-top: 8px;
  color: #b91c1c;
  font-weight: 700;
  border: 1px solid #e5a9a9;
  background: #fff3f3;
  border-radius: 8px;
  padding: 8px;
}

.clinical-flag-note {
  margin: 0;
  border: 1px solid #d4a7a2;
  background: #fff1ef;
  color: #7a2720;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.flag-marker {
  width: 10px;
  height: 10px;
  background: #b22e22;
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 0 2px #ffe5e2 inset;
}

.domain-legend {
  display: grid;
  gap: 7px;
}

.domain-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #2e3c36;
}

.domain-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.info-card ul {
  margin: 6px 0 0;
  padding-left: 16px;
  color: #495850;
  font-size: 0.87rem;
}

.meta {
  margin-top: 12px;
  color: #5f6f67;
  font-size: 0.85rem;
  text-align: center;
}

.meta p {
  margin: 2px 0;
}

.meta .disclaimer {
  margin-top: 6px;
  font-size: 0.78rem;
  color: #7a8a82;
  font-style: italic;
}

.meta code {
  color: #445149;
}

/* ── SVG node / link styles ── */

.node rect {
  stroke: #a7bdbe;
  stroke-width: 1;
  transition: fill 0.18s ease, stroke-width 0.18s ease, opacity 0.18s ease;
}

.node text {
  fill: #1f2623;
  font-size: 13px;
  transition: opacity 0.18s ease;
  font-weight: 600;
}

.node.symptom rect {
  fill: #f4f0ea;
}

.node.symptom text {
  font-size: 11px;
}

.expand-row-bg {
  fill: #e8e3da;
  stroke: #c4bdb0;
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.expand-row-label {
  fill: #5a6e60;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.node.expand-row:hover .expand-row-bg {
  fill: #ddd7cc;
  stroke: #9a9385;
}

.node.expand-row:hover .expand-row-label {
  fill: #2d3e33;
}

.node.condition rect {
  fill: #efe9e0;
}

.node.domain rect {
  fill: #f4f0e8;
}

.node.domain rect.domain-cardiovascular {
  fill: color-mix(in srgb, white 72%, var(--domain-cardiovascular));
}

.node.domain rect.domain-metabolic {
  fill: color-mix(in srgb, white 72%, var(--domain-metabolic));
}

.node.domain rect.domain-musculoskeletal {
  fill: color-mix(in srgb, white 72%, var(--domain-musculoskeletal));
}

.node.domain rect.domain-cognitiveneurological {
  fill: color-mix(in srgb, white 72%, var(--domain-cognitiveneurological));
}

.node.domain rect.domain-autoimmuneinflammatory {
  fill: color-mix(in srgb, white 72%, var(--domain-autoimmuneinflammatory));
}

.node.active rect {
  stroke-width: 2.3;
}

.node:focus-visible rect {
  stroke-width: 2.6;
  stroke: #103437;
}

.column-header text {
  fill: #435049;
  font-size: 15px;
  letter-spacing: 0.03em;
  font-weight: 700;
}

.column-header .condition-flag-label {
  fill: #8f2e27;
  font-size: 12px;
  font-weight: 700;
}

.column-header .condition-flag-icon {
  fill: #b32d25;
}

.node.dim rect,
.node.dim text {
  opacity: 0.2;
}

.link {
  fill: none;
  stroke-linecap: round;
  transition: opacity 0.2s ease, stroke-width 0.2s ease;
  mix-blend-mode: normal;
}

.link.dim {
  opacity: 0.03;
}

.link.active {
  opacity: 0.98;
}

.text-map {
  margin: 10px 14px 14px;
  border: 1px solid #d6deda;
  border-radius: 12px;
  background: #fbfcfb;
  padding: 8px 10px;
}

.text-map summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: #2f4746;
}

#text-map-content {
  margin-top: 8px;
  max-height: 280px;
  overflow: auto;
  font-size: 0.78rem;
  color: #233431;
}

.text-map-row {
  border-top: 1px solid #e3e8e3;
  padding-top: 7px;
  margin-top: 7px;
}

.text-map-row h4 {
  margin: 0 0 4px;
  font-size: 0.78rem;
}

.text-map-row ul {
  margin: 0;
  padding-left: 16px;
}

.text-map-row li {
  margin-bottom: 4px;
}

/* ── Responsive breakpoints ── */

/* Tablet / narrow desktop — stack graph + card vertically */
@media (max-width: 1120px) {
  .cards-row {
    grid-template-columns: 1fr;
    position: static;
    max-height: none;
    overflow: visible;
  }

  .stage {
    grid-template-columns: 1fr;
  }

  .hero-details-body {
    grid-template-columns: 1fr;
  }
}

/* Narrow tablet */
@media (max-width: 920px) {
  .app-shell {
    padding: 14px 10px 20px;
  }

  .hero-top {
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
  }

  .hero-title {
    flex: 1 1 0;
    min-width: 0;
  }

  .hero-logo {
    height: 28px;
    margin-left: auto;
    flex-shrink: 0;
  }

  .component-card {
    padding: 10px;
  }
}

/* Small phone */
@media (max-width: 600px) {
  .hero {
    padding-bottom: 6px;
  }

  .hero-top {
    flex-direction: column-reverse;
    gap: 4px;
  }

  .hero-title {
    width: 100%;
  }

  .hero-logo {
    height: 20px;
    margin-left: 0;
    align-self: flex-end;
  }

  .hero h1 {
    font-size: 1.15rem;
    margin: 0 0 2px;
    white-space: nowrap;
  }

  .kicker {
    font-size: 0.55rem;
    margin-bottom: 0;
  }

  .subtitle {
    font-size: 0.7rem;
    line-height: 1.3;
  }

  .subtitle-hint {
    display: none;
  }

  .hero-details summary {
    font-size: 0.72rem;
  }

  .graph-card {
    border-radius: 10px;
  }

  .component-card {
    border-radius: 10px;
    padding: 10px;
  }

  .meta {
    font-size: 0.72rem;
  }

  .focus-content {
    font-size: 0.84rem;
    min-height: 80px;
  }
}

/* ── Horizontal scroll mode for very narrow containers ── */
.graph-card.graph-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.graph-card.graph-scroll #graph {
  min-width: var(--graph-min-width, 800px);
}

/* Portrait orientation prompt for small devices */
.landscape-prompt {
  display: none;
}

@media (max-width: 768px) and (orientation: portrait) {
  .landscape-prompt {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 10px;
    padding: 10px 14px;
    border: 1px solid #d4ddd8;
    border-radius: 10px;
    background: #f4f8f6;
    color: #3a4f47;
    font-size: 0.76rem;
    font-weight: 500;
    line-height: 1.4;
  }

  .landscape-prompt-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 1px;
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .landscape-prompt {
    display: none;
  }

  .hero {
    padding-bottom: 4px;
  }

  .hero-details {
    display: none;
  }

  .graph-card {
    max-height: calc(100dvh - 120px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}
