/* CourseStack semantic framework diagrams: HTML first, no canvas/SVG dependency. */
.framework-diagram {
  --fd-accent: var(--accent, var(--pb-accent, #63e68c));
  --fd-accent-soft: color-mix(in srgb, var(--fd-accent) 12%, var(--fd-surface));
  --fd-border: var(--line, var(--pb-line, #232922));
  --fd-surface: var(--paper-raised, var(--pb-paper, #12160f));
  margin: 24px 0 30px;
  padding: 20px;
  border: 1px solid var(--fd-border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--fd-surface) 96%, var(--fd-accent) 4%);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .3);
  overflow: hidden;
}

/* Many older ASCII sketches lived inside a teaching callout. Avoid creating a
   card-inside-card when the richer diagram replaces that sketch. */
.teaching-block > .framework-diagram,
.card > .framework-diagram,
.object-map > .framework-diagram {
  margin: 18px 0 12px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.framework-diagram figcaption { margin-bottom: 18px; }
.framework-diagram-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--fd-accent);
  font: 800 .68rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.framework-diagram-title { display: block; color: var(--ink, var(--pb-ink, #eef2ea)); font: 750 1.05rem/1.35 ui-serif, Georgia, serif; }
.framework-diagram-note { display: block; margin-top: 4px; color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .78rem; line-height: 1.5; }

.fd-flow { display: grid; grid-template-columns: repeat(var(--fd-count), minmax(0, 1fr)); align-items: stretch; gap: 26px; }
.fd-node { position: relative; display: grid; align-content: center; min-width: 0; min-height: 78px; padding: 13px 14px; border: 1px solid var(--fd-border); border-radius: 10px; background: var(--fd-surface); }
.fd-node::after {
  content: '';
  position: absolute;
  top: 50%;
  left: calc(100% + 1px);
  width: 26px;
  border-top: 1.5px solid color-mix(in srgb, var(--fd-accent) 58%, var(--fd-border));
}
.fd-node::before {
  content: '';
  position: absolute;
  z-index: 1;
  top: calc(50% - 4px);
  left: calc(100% + 21px);
  width: 7px;
  height: 7px;
  border-top: 1.5px solid var(--fd-accent);
  border-right: 1.5px solid var(--fd-accent);
  transform: rotate(45deg);
}
.fd-node:last-child::after, .fd-node:last-child::before { display: none; }
.fd-node-kicker { margin: 0 0 5px; color: var(--fd-accent); font: 750 .64rem/1.2 ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; }
.fd-node strong { color: var(--ink, var(--pb-ink, #eef2ea)); font-size: .9rem; line-height: 1.3; }
.fd-node small { display: block; margin-top: 5px; color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .72rem; line-height: 1.42; }
.fd-node[data-tone='accent'] { border-color: color-mix(in srgb, var(--fd-accent) 48%, var(--fd-border)); background: var(--fd-accent-soft); }
.fd-node[data-tone='dark'] { border-color: var(--pb-line, #232922); background: var(--pb-dark, #070907); }
.fd-node[data-tone='dark'] strong, .fd-node[data-tone='dark'] .fd-node-kicker { color: var(--pb-ink, #eef2ea); }
.fd-node[data-tone='dark'] small { color: var(--pb-quiet, #6b766a); }

.fd-lanes { display: grid; gap: 12px; }
.fd-lane { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 14px; align-items: stretch; }
.fd-lane-label { display: grid; align-content: center; padding: 11px 12px; border-left: 3px solid var(--fd-accent); color: var(--ink, var(--pb-ink, #eef2ea)); font-size: .8rem; font-weight: 800; }
.fd-lane .fd-flow { --fd-count: 1; }

.fd-card-grid { display: grid; grid-template-columns: repeat(var(--fd-count), minmax(0, 1fr)); gap: 10px; }
.fd-card { min-width: 0; padding: 15px; border-top: 3px solid var(--fd-accent); border-radius: 9px; background: var(--fd-surface); }
.fd-card strong { display: block; margin-bottom: 7px; font-size: .88rem; }
.fd-card dl { margin: 0; }
.fd-card dt { margin-top: 6px; color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .62rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.fd-card dd { margin: 2px 0 0; font-size: .73rem; line-height: 1.4; }

.fd-stack { display: grid; gap: 6px; max-width: 660px; margin-inline: auto; }
.fd-stack-level { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; align-items: center; width: var(--fd-width, 100%); margin-inline: auto; padding: 11px 14px; border: 1px solid var(--fd-border); border-radius: 8px; background: var(--fd-surface); }
.fd-stack-level strong { font-size: .84rem; }
.fd-stack-level span { color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .72rem; }
.fd-stack-level em { color: var(--fd-accent); font: 750 .65rem/1.2 ui-monospace, monospace; font-style: normal; }

.fd-tree-wrap { overflow-x: auto; padding: 3px 3px 8px; }
.fd-tree, .fd-tree ul { display: flex; justify-content: center; position: relative; margin: 0; padding: 22px 0 0; list-style: none; }
.fd-tree { min-width: 620px; padding-top: 0; }
.fd-tree li { position: relative; padding: 22px 5px 0; text-align: center; }
.fd-tree li::before, .fd-tree li::after { content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 22px; border-top: 1px solid var(--fd-border); }
.fd-tree li::after { right: auto; left: 50%; border-left: 1px solid var(--fd-border); }
.fd-tree li:only-child::before, .fd-tree li:only-child::after { display: none; }
.fd-tree li:first-child::before, .fd-tree li:last-child::after { border: 0; }
.fd-tree li:last-child::before { border-right: 1px solid var(--fd-border); border-radius: 0 7px 0 0; }
.fd-tree li:first-child::after { border-radius: 7px 0 0; }
.fd-tree ul::before { content: ''; position: absolute; top: 0; left: 50%; height: 22px; border-left: 1px solid var(--fd-border); }
.fd-tree-node { display: inline-grid; min-width: 112px; max-width: 180px; min-height: 54px; align-content: center; padding: 9px 11px; border: 1px solid var(--fd-border); border-radius: 9px; background: var(--fd-surface); font-size: .76rem; line-height: 1.3; }
.fd-tree-node strong { font-size: .8rem; }
.fd-tree-node small { margin-top: 3px; color: var(--muted, var(--pb-quiet, #6b766a)); }

.fd-roofline { display: grid; grid-template-columns: 56px minmax(0, 1fr); grid-template-rows: 250px auto; gap: 10px 12px; }
.fd-roofline-y { display: grid; place-items: center; color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .7rem; writing-mode: vertical-rl; transform: rotate(180deg); }
.fd-roofline-plot { position: relative; border-left: 1.5px solid var(--ink, var(--pb-ink, #eef2ea)); border-bottom: 1.5px solid var(--ink, var(--pb-ink, #eef2ea)); background-image: linear-gradient(var(--fd-border) 1px, transparent 1px), linear-gradient(90deg, var(--fd-border) 1px, transparent 1px); background-size: 25% 25%; }
.fd-roofline-bandwidth { position: absolute; left: 8%; bottom: 7%; width: 50%; height: 3px; background: var(--fd-accent); transform: rotate(-26deg); transform-origin: left center; }
.fd-roofline-compute { position: absolute; top: 25%; left: 52%; right: 4%; height: 3px; background: var(--fd-accent); }
.fd-roofline-ridge { position: absolute; top: 25%; left: 52%; bottom: 0; border-left: 1px dashed color-mix(in srgb, var(--fd-accent) 60%, transparent); }
.fd-roofline-label { position: absolute; padding: 5px 7px; border-radius: 6px; background: color-mix(in srgb, var(--fd-surface) 92%, transparent); font-size: .68rem; font-weight: 700; }
.fd-roofline-label--bandwidth { left: 12%; bottom: 42%; }
.fd-roofline-label--compute { top: 12%; right: 6%; }
.fd-roofline-label--ridge { left: 53%; bottom: 5%; color: var(--fd-accent); }
.fd-roofline-x { grid-column: 2; text-align: center; color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .7rem; }

.fd-callout { margin: 14px 0 0; padding: 10px 12px; border-left: 3px solid var(--fd-accent); background: var(--fd-accent-soft); color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .76rem; line-height: 1.5; }
.fd-source { margin-top: 14px; border-top: 1px solid var(--fd-border); padding-top: 10px; }
.fd-source > summary { cursor: pointer; color: var(--muted, var(--pb-quiet, #6b766a)); font-size: .72rem; font-weight: 700; }
.fd-source pre { margin: 10px 0 0; box-shadow: none; }

@media (max-width: 760px) {
  .framework-diagram { padding: 16px; }
  .fd-flow { grid-template-columns: 1fr; gap: 18px; }
  .fd-node { min-height: 0; }
  .fd-node::after { top: 100%; left: 22px; width: 1px; height: 18px; border-top: 0; border-left: 1.5px solid color-mix(in srgb, var(--fd-accent) 58%, var(--fd-border)); }
  .fd-node::before { top: calc(100% + 11px); left: 18.5px; transform: rotate(135deg); }
  .fd-lane { grid-template-columns: 1fr; gap: 7px; }
  .fd-lane-label { border-left: 0; border-bottom: 2px solid var(--fd-accent); }
  .fd-card-grid { grid-template-columns: 1fr; }
  .fd-stack-level { grid-template-columns: 88px 1fr; width: 100% !important; }
  .fd-stack-level em { grid-column: 2; }
  .fd-roofline { grid-template-rows: 210px auto; }
}

@media print {
  .framework-diagram { break-inside: avoid; box-shadow: none; }
  .fd-source { display: none; }
}
