:root {
  --panel-width: min(390px, 42vw);
  --bg: #0b0d12;
  --bg-panel: #11141b;
  --bg-elev: #181c25;
  --fg: #e6e9ef;
  --fg-dim: #9aa3b2;
  --fg-faint: #6b7280;
  --accent: #f59e0b;
  --border: #232836;

  --c-investor: #ef4444;
  --c-conglomerate: #3b82f6;
  --c-private: #a855f7;
  --c-subsidiary: #8b5cf6;
  --c-brand: #e6e9ef;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  padding: 14px 20px;
  background: linear-gradient(to bottom, rgba(11,13,18,0.95), rgba(11,13,18,0.7) 80%, transparent);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  pointer-events: none;
}

header > * { pointer-events: auto; }

.title h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.title .tagline {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--fg-dim);
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#search {
  width: 320px;
  padding: 8px 12px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 120ms;
}

#search:focus { border-color: var(--accent); }

#risk-sort {
  max-width: 180px;
  padding: 8px 30px 8px 10px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

#risk-sort:focus { border-color: var(--accent); }

#reset,
#risk-index {
  padding: 8px 14px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms;
}

#reset:hover,
#risk-index:hover { background: #232836; }

main {
  position: absolute;
  inset: 0;
}

#graph {
  position: absolute;
  top: 0;
  right: var(--panel-width);
  bottom: 0;
  left: 0;
}

#graph canvas { display: block; }

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  width: var(--panel-width);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 70px 20px 24px;
  overflow-y: auto;
  font-size: 13px;
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.28);
}

.status {
  position: fixed;
  left: 28px;
  bottom: 28px;
  z-index: 12;
  max-width: 420px;
  padding: 10px 12px;
  background: rgba(24, 28, 37, 0.94);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}

.status.hidden {
  display: none;
}

.status.error {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.55);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}

.panel h3 {
  margin: 18px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  font-weight: 600;
}

.panel .p-meta {
  margin: 0 0 12px;
  color: var(--fg-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.panel .p-note {
  margin: 0 0 8px;
  color: var(--fg-dim);
  line-height: 1.5;
}

.owner-label {
  display: inline-flex;
  max-width: 100%;
  margin: 2px 0 12px;
  padding: 6px 8px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.24);
  border-radius: 6px;
  color: var(--fg);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.panel .p-size {
  margin: 0 0 12px;
  color: var(--fg);
  font-size: 12px;
  line-height: 1.4;
}

.panel ul, .panel ol {
  margin: 0;
  padding: 0 0 0 4px;
  list-style: none;
}

.panel ul li, .panel ol li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}

.panel ul li:last-child, .panel ol li:last-child { border-bottom: none; }

.panel ol {
  counter-reset: chain;
  padding-left: 0;
}

.panel ol li {
  counter-increment: chain;
  padding-left: 26px;
  position: relative;
}

.panel ol li::before {
  content: counter(chain);
  position: absolute;
  left: 0;
  top: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--fg-dim);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.node-link {
  background: none;
  border: none;
  color: var(--fg);
  padding: 0;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.node-link:hover { color: var(--accent); }

.starter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.starter-button {
  min-height: 34px;
  padding: 8px 10px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms, background 120ms, transform 120ms;
}

.starter-button:hover,
.starter-button:focus-visible {
  background: #1d2330;
  border-color: rgba(245, 158, 11, 0.65);
  outline: none;
  transform: translateY(-1px);
}

.node-link-with-thumb {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  min-height: 30px;
  vertical-align: middle;
}

.node-link-label {
  overflow-wrap: anywhere;
}

.node-thumb {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(230, 233, 239, 0.14);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--bg-panel);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
}

.node-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  padding: 3px;
}

.node-thumb-fallback {
  background: var(--bg-elev);
  color: var(--fg-dim);
}

.pct {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-left: 8px;
  font-size: 12px;
}

.metric {
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  margin-left: 8px;
  font-size: 12px;
}

.health-list {
  display: grid;
  gap: 8px;
}

.health-card {
  padding: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 6px;
}

.health-card.health-high { border-left-color: #ef4444; }
.health-card.health-watch { border-left-color: #f59e0b; }
.health-card.health-note { border-left-color: #3b82f6; }

.health-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.health-title strong {
  min-width: 0;
  font-size: 12px;
}

.health-badge {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.health-high .health-badge {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

.health-note .health-badge {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
}

.health-card p {
  margin: 0;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.45;
}

.health-source {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent);
  font-size: 11px;
  text-decoration: none;
}

.health-source:hover { text-decoration: underline; }

.risk-row {
  align-items: flex-start;
}

.risk-row-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.risk-row-title {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.risk-owner {
  color: var(--fg-faint);
  font-size: 11px;
  line-height: 1.35;
}

.risk-sources {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.risk-sources a {
  color: var(--accent);
  font-size: 11px;
  text-decoration: none;
}

.risk-sources a:hover { text-decoration: underline; }

.risk-chip {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.risk-chip.high {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

.risk-chip.note {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
}

.health-empty {
  margin: 0;
  color: var(--fg-faint);
  font-size: 12px;
  line-height: 1.45;
}

.health-footnote {
  margin: 8px 0 0;
  color: var(--fg-faint);
  font-size: 11px;
  line-height: 1.45;
}

.legend {
  font-size: 12px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}

.dot-investor { background: var(--c-investor); }
.dot-conglomerate { background: var(--c-conglomerate); }
.dot-private { background: var(--c-private); }
.dot-subsidiary { background: var(--c-subsidiary); }
.dot-brand { background: var(--c-brand); }

.edge {
  width: 22px; height: 2px; flex-shrink: 0;
}

.edge-equity {
  background: repeating-linear-gradient(to right, var(--c-investor) 0 4px, transparent 4px 7px);
}

.edge-subsidiary {
  background: var(--c-subsidiary);
  height: 3px;
}

.edge-brand {
  background: var(--fg-dim);
}

.footnote {
  margin-top: 24px;
  font-size: 11px;
  color: var(--fg-faint);
  line-height: 1.5;
}

.panel-empty h2 { color: var(--fg); }
.panel-empty p {
  color: var(--fg-dim);
  line-height: 1.5;
  margin: 6px 0 0;
}

.search-summary {
  margin: 8px 0 16px;
  color: var(--fg-dim);
  line-height: 1.5;
}

@media (max-width: 900px) {
  :root { --panel-width: 280px; }
  .panel { width: 280px; }
  #search { width: 180px; }
  #risk-sort { display: none; }
}
