:root {
  --bg: #0b1a31;
  --panel: #0e2039;
  --line: #1d3150;
  --line2: #2a4268;
  --ink: #eef3fb;
  --muted: #a9b9d0;
  --faint: #7084a6;
  --accent: #4ea1f3;
  --on: #1d3a63;
  --k-id: #ffd166;
  --k-version: #4fd1e8;
  --k-sheet: #ff7eb6;
  --sans: "Poppins", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--sans); }
body { overflow: hidden; }

.wrap {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 18px 24px 16px;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.htext { flex: 1 1 auto; min-width: 0; }
.kicker { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
h1 { margin: 4px 0 0; font-weight: 600; font-size: clamp(22px, 2.6vw, 34px); letter-spacing: -0.01em; line-height: 1.1; }
.sub { color: var(--muted); margin-top: 6px; font-size: 13.5px; }
.sub b { color: var(--ink); font-weight: 600; margin-right: 8px; }
.blurb { color: var(--faint); font-size: 13px; margin-top: 3px; max-width: 860px; line-height: 1.5; }
.blurb b { color: var(--muted); font-weight: 600; }

.hright { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; flex: none; max-width: 100%; }
.tabs { display: flex; gap: 6px; align-items: center; flex: none; }
.tabs button, .seg button, .optbtn {
  font: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}
.tabs button.on, .seg button.on, .optbtn.on { background: var(--on); color: var(--ink); border-color: #3c63a0; font-weight: 600; }
.tabs button:hover, .seg button:hover, .optbtn:hover { color: var(--ink); }
.tabs .info { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--line2); font: italic 700 15px Georgia, serif; margin-left: 2px; }
.optbtn { border-color: var(--line2); }
.classbtn {
  font: inherit; font-size: 14px; font-weight: 600; color: #1b1206; background: #F7962B; border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
}
.classbtn:hover { background: #ffaa4d; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { position: relative; min-width: 0; min-height: 0; overflow: hidden; border-radius: 12px; }
.scroll { position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; }
.scroll.panning { cursor: grabbing; }
#cv { display: block; }
#cv, aside, header { user-select: none; -webkit-user-select: none; }

/* nodes: tree and radial labels get their size from the group, so they stay readable at any zoom */
.n { cursor: pointer; }
.n rect.box { stroke: rgba(11, 26, 49, 0.9); stroke-width: 1; }
.n.sel rect.box { stroke: #fff; stroke-width: 2; }
.n .more { fill: none; stroke: var(--muted); stroke-dasharray: 2 2; }
.nodes { font-size: 13px; stroke-width: 3px; }
.n text { font-family: var(--sans); font-weight: 500; fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-linejoin: round; pointer-events: none; }
.n text .b { fill: var(--muted); font-weight: 400; }
.n.dim { opacity: 0.15; }
.n.ic text { stroke: none; fill: #0b1a31; font-weight: 600; font-size: 12.5px; }
.n.ic text .b { fill: rgba(11, 26, 49, 0.66); font-weight: 500; }
.link { fill: none; stroke: #3a5684; stroke-width: 1.1; vector-effect: non-scaling-stroke; }
.link.dim { opacity: 0.15; }
.n rect.box, .n .more, .mlink, .pframe { vector-effect: non-scaling-stroke; }
.link.hot { stroke: #9fb0c9; stroke-width: 1.8; }
.mlink { fill: none; stroke-width: 1.6; stroke-dasharray: 5 4; pointer-events: none; }
.ptitle { font-family: var(--sans); font-size: 12.5px; font-weight: 600; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.pframe { fill: rgba(255, 255, 255, 0.015); stroke: var(--line); }

/* the Workbook tab opens on the data-app parts; this flips to all of them */
.focus {
  position: absolute; left: 12px; top: 12px; z-index: 2;
  font: inherit; font-size: 12.5px; color: var(--muted); background: rgba(14, 32, 57, 0.92);
  border: 1px solid var(--line2); border-radius: 18px; padding: 5px 12px; cursor: pointer;
}
.focus b { color: var(--ink); font-weight: 600; margin-left: 2px; }
.focus:hover { border-color: #3c63a0; }

/* zoom controls */
.zoom {
  position: absolute; right: 12px; bottom: 12px; z-index: 2;
  display: flex; align-items: center; gap: 2px; padding: 3px;
  background: rgba(14, 32, 57, 0.92); border: 1px solid var(--line2); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.zoom button {
  font: inherit; font-size: 14px; color: var(--muted); background: transparent; border: 0; border-radius: 7px;
  min-width: 32px; height: 30px; padding: 0 8px; cursor: pointer;
}
.zoom button:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
#zoomV { font-size: 12.5px; min-width: 52px; font-variant-numeric: tabular-nums; }

/* detail card: docked right, so it never sits on the root or the part that was clicked */
.card {
  position: absolute;
  right: 12px;
  top: 12px;
  max-height: calc(100% - 74px);
  overflow-y: auto;
  width: min(380px, calc(100% - 24px));
  background: rgba(14, 32, 57, 0.97);
  border: 1px solid var(--line2);
  border-radius: 12px;
  padding: 14px 16px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  z-index: 3;
}
.card.bottom { top: auto; bottom: 60px; left: 12px; right: 12px; width: auto; max-height: 46%; }
.card .x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.card .crumbs { font-size: 11.5px; color: var(--faint); margin-right: 22px; }
.card .crumbs button { font: inherit; color: var(--faint); background: none; border: 0; padding: 0; cursor: pointer; }
.card .crumbs button:hover { color: var(--ink); }
.card h4 { margin: 4px 0 2px; font-size: 15.5px; color: var(--ink); font-weight: 600; font-family: var(--mono); word-break: break-word; }
.card .facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 8px; font-size: 12.5px; }
.card .facts b { color: var(--ink); font-weight: 600; }
.card .role { display: inline-flex; align-items: center; gap: 6px; }
.card .role i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.card p { margin: 0 0 8px; color: #c4d0e2; }
.card .mk { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.card .mk .t { font-weight: 600; font-size: 12px; letter-spacing: 0.04em; }
.card .mk .why { font-size: 12px; color: var(--faint); margin: 2px 0 4px; }
.card .places { display: flex; flex-wrap: wrap; gap: 4px; }
.card .places button {
  font: inherit; font-size: 11.5px; color: var(--muted); background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line2); border-radius: 14px; padding: 2px 9px; cursor: pointer;
}
.card .places button:hover { color: var(--ink); border-color: #3c63a0; }
.card .places button.me { color: var(--ink); border-color: currentColor; cursor: default; }

/* options: a popover under the Options button, closed until asked for */
aside {
  position: fixed; z-index: 8; width: min(300px, calc(100vw - 16px)); max-height: calc(100vh - 110px);
  overflow-x: hidden; overflow-y: auto; font-size: 14px;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; padding: 14px 14px 4px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  display: none;
}
aside.open { display: block; }
.sec { margin-bottom: 16px; }
.sec h3 { display: flex; justify-content: space-between; margin: 0 0 10px; font-size: 12px; letter-spacing: 0.16em; color: var(--muted); font-weight: 700; cursor: pointer; }
.sec.closed .body { display: none; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 9px; background: rgba(255, 255, 255, 0.015); }
.seg button { flex: 1; padding: 8px 4px; font-size: 13.5px; }
.seg button:disabled { opacity: 0.28; cursor: default; color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: center; margin: 11px 0; }
.lab { color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; margin: 12px 0 6px; }
.lab b { color: var(--ink); }
.tog { position: relative; width: 44px; height: 24px; border-radius: 12px; background: #2a3a55; border: 0; cursor: pointer; flex: none; }
.tog::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #0b1a31; transition: left 0.15s; }
.tog.on { background: var(--accent); }
.tog.on::after { left: 23px; }
.tog:disabled { opacity: 0.3; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font: inherit; font-size: 12.5px; color: var(--muted); background: transparent; border: 1px solid var(--line2); border-radius: 20px; padding: 3px 10px 3px 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chips button i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; opacity: 0.35; }
.chips button.on { color: var(--ink); background: var(--on); border-color: #3c63a0; }
.chips button.on i { opacity: 1; }
.keys { display: grid; gap: 4px; margin: -4px 0 6px; font-size: 12.5px; color: var(--muted); }
.keys div { display: flex; align-items: center; gap: 8px; }
.keys i { width: 18px; border-top: 2px dashed; display: inline-block; }
.keys span { color: var(--faint); margin-left: auto; }
.note, .hint { color: var(--faint); font-size: 12px; line-height: 1.45; margin-top: 6px; }

/* tooltip + about */
#tip { position: fixed; pointer-events: none; background: rgba(8, 18, 35, 0.96); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; line-height: 1.45; max-width: 320px; display: none; z-index: 9; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); }
#tip b { font-family: var(--mono); font-size: 12.5px; }
#tip .m { color: var(--muted); }
#about { position: fixed; inset: 0; background: rgba(4, 10, 22, 0.72); display: none; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
#about .acard { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; max-width: 580px; padding: 22px 26px; line-height: 1.6; color: var(--muted); font-size: 14px; }
#about h2 { color: var(--ink); margin: 0 0 8px; font-weight: 600; }
#about b { color: var(--ink); }
#about code { font-family: var(--mono); color: var(--ink); font-size: 13px; }
#about .k-id { color: var(--k-id); }
#about .k-version { color: var(--k-version); }
#about .k-sheet { color: var(--k-sheet); }
#about .src { color: var(--faint); font-size: 12.5px; }
.solo { font: inherit; font-size: 13.5px; color: var(--ink); background: var(--on); border: 1px solid #3c63a0; border-radius: 8px; padding: 7px 16px; cursor: pointer; }

.error { padding: 40px; color: #ff8a65; }

/* narrow: header stacks, blurb folds away */
@media (max-width: 860px) {
  .wrap { padding: 12px 12px 10px; gap: 10px; }
  header { flex-direction: column; gap: 10px; }
  .hright { justify-content: flex-start; }
  .blurb { display: none; }
}
@media (max-width: 520px) {
  .tabs button { padding: 7px 10px; font-size: 13.5px; }
  .optbtn, .classbtn { padding: 7px 11px; font-size: 13.5px; }
  .sub b { display: block; margin-bottom: 2px; }
}
@media (max-height: 520px) {
  .blurb { display: none; }
  h1 { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .tog::after { transition: none; }
}

/* plate mode: the same diagram printed on the class's roll-down chart */
main.plate-mode { border-radius: 0; }
main.plate-mode .scroll { cursor: default; pointer-events: none; }
main.plate-mode .zoom, main.plate-mode .card, main.plate-mode .focus { display: none !important; }
main.plate-mode .n { cursor: default; }
main.plate-mode .n rect.box { stroke: #5A4632; stroke-width: 1.2; }
main.plate-mode .n text { font-family: var(--serif, Georgia, serif); font-weight: 600; fill: #3d2f20; stroke: #F3EBDD; }
main.plate-mode .n text .b { fill: #7a6450; }
main.plate-mode .n .more { stroke: #8a7358; }
main.plate-mode .link { stroke: #8a7358; stroke-width: 1.2; }
main.plate-mode .ptitle { font-family: var(--serif, Georgia, serif); fill: #5A4632; stroke: #F3EBDD; font-variant: small-caps; letter-spacing: 0.04em; }
main.plate-mode .pframe { fill: none; stroke: rgba(90, 70, 50, 0.35); stroke-dasharray: 3 3; }
.pins .leader { stroke: #5A4632; stroke-width: 1.1; }
.pins .pin { fill: #F3EBDD; stroke: #5A4632; stroke-width: 1.4; }
.pins .pinn { font-family: var(--serif, Georgia, serif); font-size: 12px; font-weight: 700; fill: #5A4632; }
