/* Shared by every OSPF demo page. These pages are opened full screen or in an
   iframe, which cannot see the site's own light/dim switch, so they follow
   the reader's system preference. */

:root {
  --bg: #ffffff;
  --card: #ffffff;
  --border: #dfe3e8;
  --text: #22272e;
  --dim: #5f6b78;
  --accent: #0077b8;
  --btn: #f4f5f7;
  --panel: #0d2436;
  --panel-text: #eaf1f6;
  --wire: #9aa8b4;
  --full: #2e9e4f;
  --router: #fff3e0;
  --router-stroke: #d9822b;
  --abr: #e8f0fe;
  --abr-stroke: #3b6fd8;
  --switch: #e8f5e9;
  --switch-stroke: #4c9a5f;
  --area0: rgba(59, 111, 216, 0.07);
  --area0-stroke: rgba(59, 111, 216, 0.45);
  --area1: rgba(217, 130, 43, 0.07);
  --area1-stroke: rgba(217, 130, 43, 0.45);
  --area2: rgba(46, 158, 79, 0.07);
  --area2-stroke: rgba(46, 158, 79, 0.45);
  --area3: rgba(156, 75, 196, 0.07);
  --area3-stroke: rgba(156, 75, 196, 0.45);
  --hello: #e0531f;
  --exchange: #8e44ad;
  --st-down: #9aa3ad;
  --st-init: #d99a00;
  --st-2way: #2f7fd8;
  --st-exch: #8e44ad;
  --st-full: #2e9e4f;
  --flash: rgba(255, 196, 0, 0.35);
  --tip: #0d2436;
  --tip-text: #eaf1f6;
  --drop: #d23b3b;
  --flood: #00897b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1d2b;
    --card: #112b40;
    --border: #234862;
    --text: #eaf1f6;
    --dim: #9fb2c2;
    --accent: #4fb3ff;
    --btn: #16374f;
    --panel: #081b29;
    --panel-text: #eaf1f6;
    --wire: #5b7382;
    --full: #43b866;
    --router: #4a3318;
    --router-stroke: #d9914b;
    --abr: #18335e;
    --abr-stroke: #6f9bf0;
    --switch: #163f2a;
    --switch-stroke: #4fae6f;
    --area0: rgba(111, 155, 240, 0.09);
    --area0-stroke: rgba(111, 155, 240, 0.5);
    --area1: rgba(217, 145, 75, 0.09);
    --area1-stroke: rgba(217, 145, 75, 0.5);
    --area2: rgba(79, 174, 111, 0.09);
    --area2-stroke: rgba(79, 174, 111, 0.5);
    --area3: rgba(186, 120, 222, 0.09);
    --area3-stroke: rgba(186, 120, 222, 0.5);
    --hello: #ff7a45;
    --exchange: #b36ad6;
    --st-down: #5d6e7c;
    --st-init: #c79200;
    --st-2way: #3d8fe6;
    --st-exch: #9b59c0;
    --st-full: #38a95a;
    --flash: rgba(255, 196, 0, 0.3);
    --tip: #eaf1f6;
    --tip-text: #0d2436;
    --drop: #ff6464;
    --flood: #26a69a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.ospf-app { padding: 0.75rem 16px 1.5rem; max-width: 1700px; margin: 0 auto; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

/* --- controls */
.ospf-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.ospf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.9rem; margin: 0.1rem 0 0.6rem; }
.ospf-head h1 { font-size: 1.45rem; margin: 0; letter-spacing: -0.01em; }
.ospf-head p { margin: 0; color: var(--dim); font-size: 0.92rem; }
.ospf-series { margin-left: auto; font-size: 0.82rem; color: var(--dim); }
.ospf-series a { color: var(--accent); text-decoration: none; }
.ospf-series a:hover { text-decoration: underline; }
.ospf-series b { color: var(--text); font-weight: 600; }
.ospf-btn, .ospf-speed button {
  background: var(--btn); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.35rem 0.9rem; font-size: 0.88rem; cursor: pointer;
}
.ospf-btn:hover, .ospf-speed button:hover { border-color: var(--accent); }
.ospf-btn.play { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 6rem; font-weight: 600; }
.ospf-speed { display: inline-flex; }
.ospf-speed button { border-radius: 0; margin-left: -1px; padding: 0.35rem 0.6rem; }
.ospf-speed button:first-child { border-radius: 8px 0 0 8px; }
.ospf-speed button:last-child { border-radius: 0 8px 8px 0; }
.ospf-speed button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ospf-clock { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9rem; color: var(--dim); min-width: 7.5rem; }
.ospf-legend { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-left: auto; font-size: 0.75rem; }

/* --- timeline */
.ospf-track {
  position: relative; height: 34px; margin: 0.6rem 0 0.2rem; cursor: pointer;
}
.ospf-track::before {
  content: ''; position: absolute; left: 0; right: 0; top: 6px; height: 6px;
  border-radius: 3px; background: var(--btn); border: 1px solid var(--border);
}
.ospf-progress { position: absolute; left: 0; top: 7px; height: 6px; border-radius: 3px; background: var(--accent); width: 0; }
.ospf-mark {
  position: absolute; top: 0; transform: translateX(-2px); padding: 18px 0 0 4px;
  background: none; border: 0; border-left: 2px solid var(--dim); color: var(--dim);
  font-size: 0.72rem; white-space: nowrap; cursor: pointer; height: 34px;
}
.ospf-mark:hover { color: var(--accent); border-color: var(--accent); }

/* --- caption */
.ospf-caption {
  display: flex; gap: 0.8rem; align-items: baseline;
  background: var(--panel); color: var(--panel-text); border-radius: 8px;
  padding: 0.55rem 0.9rem; font-size: 0.92rem; line-height: 1.45;
  /* A fixed height: the box sits above the buttons, and a step's text must
     not push Step out from under the pointer. Longer text scrolls. */
  height: 8.2em; overflow-y: auto;
  margin-bottom: 0.6rem;
}
.ospf-caption .t { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; opacity: 0.7; white-space: nowrap; }

/* --- stage: drawing beside the panels on a wide screen, above them otherwise */
.ospf-stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.75rem; margin-top: 0.4rem; }
@media (min-width: 1600px) {
  .ospf-stage { grid-template-columns: minmax(0, 1fr) 400px; }
}
.ospf-svg-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
#ospf-svg { display: block; width: 100%; min-width: 900px; height: auto; font-family: inherit; user-select: none; }
.ospf-side { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.ospf-box { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 0.7rem 0.85rem; font-size: 0.82rem; }
.ospf-box h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--dim); margin: 0 0 0.4rem; display: flex; align-items: center; }
.ospf-box h2 label { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; cursor: pointer; }
#ospf-detail h3 { font-size: 1rem; margin: 0 0 0.4rem; }
#ospf-detail h3 span { font-size: 0.78rem; font-weight: 400; color: var(--dim); margin-left: 0.3rem; }
#ospf-detail table { width: 100%; border-collapse: collapse; margin-bottom: 0.5rem; }
#ospf-detail th { text-align: left; font-weight: 600; color: var(--dim); font-size: 0.74rem; border-bottom: 1px solid var(--border); padding: 0.2rem 0.3rem; }
#ospf-detail td { padding: 0.22rem 0.3rem; border-bottom: 1px solid var(--border); vertical-align: top; }
#ospf-log { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; font-size: 0.78rem; }
#ospf-log li { padding: 0.18rem 0 0.18rem 0.5rem; border-left: 3px solid transparent; line-height: 1.35; }
#ospf-log li .t { display: inline-block; min-width: 3.2rem; color: var(--dim); font-family: ui-monospace, Menlo, monospace; }
#ospf-log li b { margin-right: 0.2rem; }
#ospf-log li.st-init { border-color: var(--st-init); }
#ospf-log li.st-2way { border-color: var(--st-2way); }
#ospf-log li.st-exstart, #ospf-log li.st-exchange, #ospf-log li.st-loading { border-color: var(--st-exch); }
#ospf-log li.st-full { border-color: var(--st-full); }
#ospf-log li.st-down, #ospf-log li.power { border-color: var(--drop); }
#ospf-log li.election { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

.ospf-chip { display: inline-block; border-radius: 9px; padding: 0 0.5rem; color: #fff; font-size: 0.74rem; line-height: 1.5; background: var(--st-down); }
.ospf-chip.st-init { background: var(--st-init); }
.ospf-chip.st-2way { background: var(--st-2way); }
.ospf-chip.st-exstart, .ospf-chip.st-exchange, .ospf-chip.st-loading { background: var(--st-exch); }
.ospf-chip.st-full { background: var(--st-full); }

/* --- the drawing */
.ospf-area { stroke-width: 1.5; stroke-dasharray: 6 4; }
.ospf-area-0 { fill: var(--area0); stroke: var(--area0-stroke); }
.ospf-area-1 { fill: var(--area1); stroke: var(--area1-stroke); }
.ospf-area-2 { fill: var(--area2); stroke: var(--area2-stroke); }
.ospf-area-3 { fill: var(--area3); stroke: var(--area3-stroke); }
.ospf-area-name { font-size: 16px; font-weight: 700; fill: var(--dim); }
.ospf-wire { stroke: var(--wire); stroke-width: 3; stroke-linecap: round; transition: stroke 0.3s; }
.ospf-wire.is-full { stroke: var(--full); }
.ospf-net-label { font-size: 12.5px; fill: var(--dim); font-family: ui-monospace, Menlo, Consolas, monospace; paint-order: stroke; stroke: var(--card); stroke-width: 4px; }
.ospf-switch rect { fill: var(--switch); stroke: var(--switch-stroke); stroke-width: 2; }
.ospf-switch-port { fill: var(--text); opacity: 0.8; }
.ospf-switch-led { fill: var(--full); }
.ospf-lan-bar { stroke: var(--wire); stroke-width: 5; stroke-linecap: round; }
.ospf-lan-drop { stroke: var(--wire); stroke-width: 1.5; }
.ospf-host { fill: var(--card); stroke: var(--wire); stroke-width: 1.5; }
.ospf-router { cursor: pointer; }
.ospf-router-body { fill: var(--router); stroke: var(--router-stroke); stroke-width: 2.5; transition: fill 0.3s; }
.ospf-router-abr .ospf-router-body { fill: var(--abr); stroke: var(--abr-stroke); }
.ospf-router.is-selected .ospf-router-body { stroke-width: 4.5; }
.ospf-router.is-down .ospf-router-body { fill: var(--card); stroke: var(--st-down); stroke-dasharray: 4 3; }
.ospf-router-name { font-size: 14.5px; font-weight: 700; fill: var(--text); paint-order: stroke; stroke: var(--card); stroke-width: 4px; }
.ospf-iface { fill: var(--text); stroke: var(--card); stroke-width: 1.5; }
.ospf-iface.is-down { fill: var(--st-down); }
.ospf-iface:hover { r: 7; fill: var(--accent); }
.ospf-hoverable { cursor: pointer; }

.ospf-card { cursor: pointer; }
.ospf-card-bg { fill: var(--card); stroke: var(--border); stroke-width: 1.2; }
.ospf-card.is-selected .ospf-card-bg { stroke: var(--accent); stroke-width: 2; }
.ospf-card.is-down { opacity: 0.55; }
.ospf-card-head { font-size: 13px; font-weight: 700; fill: var(--text); }
.ospf-card-rid, .ospf-card-off { font-size: 11px; fill: var(--dim); font-family: ui-monospace, Menlo, Consolas, monospace; }
.ospf-card-off { font-style: italic; font-family: inherit; font-size: 11px; }
.ospf-card-rule { stroke: var(--border); }
.ospf-row-name { font-size: 12.5px; fill: var(--text); }
.ospf-row-state { font-size: 11px; font-weight: 600; fill: #fff; }
.ospf-row-flash { fill: transparent; transition: fill 0.4s; }
.ospf-row-flash.on { fill: var(--flash); }
.ospf-pill { fill: var(--st-down); }
.ospf-pill.st-off { fill: transparent; }
.ospf-pill.st-init { fill: var(--st-init); }
.ospf-pill.st-2way { fill: var(--st-2way); }
.ospf-pill.st-exstart, .ospf-pill.st-exchange, .ospf-pill.st-loading { fill: var(--st-exch); }
.ospf-pill.st-full { fill: var(--st-full); }

.ospf-badge rect { fill: var(--card); stroke: var(--dim); stroke-width: 1.3; }
.ospf-badge text { font-size: 12px; font-weight: 700; fill: var(--dim); }
.ospf-badge.role-dr rect { fill: var(--accent); stroke: var(--accent); }
.ospf-badge.role-bdr rect { fill: color-mix(in srgb, var(--accent) 22%, var(--card)); stroke: var(--accent); }
.ospf-badge.role-dr text { fill: #fff; }
.ospf-badge.role-bdr text { fill: var(--text); }
.ospf-badge.role-wait rect { stroke-dasharray: 3 2; }
.ospf-badge.role-down { opacity: 0.4; }

.ospf-pkt circle { stroke: var(--card); stroke-width: 1.5; }
.ospf-pkt text { font-size: 10px; font-weight: 800; fill: #fff; pointer-events: none; }
.ospf-pkt-hello circle { fill: var(--hello); }
.ospf-pkt-dbd circle, .ospf-pkt-lsr circle, .ospf-pkt-lsu circle { fill: var(--exchange); }
.ospf-pkt:hover circle { r: 11; }
.ospf-drop path { stroke: var(--drop); stroke-width: 3; stroke-linecap: round; }

.ospf-tip { pointer-events: none; }
.ospf-tip rect { fill: var(--tip); opacity: 0.96; }
.ospf-tip text { font-size: 13px; fill: var(--tip-text); }
.ospf-tip .ospf-tip-head { font-weight: 700; }

/* --- step mode and the election panel */
.ospf-caption-body { display: flex; flex-direction: column; gap: 0.3rem; }
.ospf-step-text { font-size: 0.84rem; padding-top: 0.3rem; border-top: 1px solid rgba(234, 241, 246, 0.2); opacity: 0.92; }
.ospf-election p { margin: 0 0 0.45rem; line-height: 1.45; }
.ospf-election ol { margin: 0.3rem 0 0.5rem; padding-left: 1.2rem; line-height: 1.45; }
.ospf-election li { margin-bottom: 0.3rem; }
.ospf-election table { width: 100%; border-collapse: collapse; margin: 0.2rem 0 0.3rem; }
.ospf-election th { text-align: left; font-weight: 600; color: var(--dim); font-size: 0.74rem; border-bottom: 1px solid var(--border); padding: 0.2rem 0.3rem; }
.ospf-election td { padding: 0.2rem 0.3rem; border-bottom: 1px solid var(--border); }
.ospf-election tr.self td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.ospf-el-when, .ospf-el-note { color: var(--dim); font-size: 0.78rem; }
.ospf-el-result { border-left: 3px solid var(--accent); padding-left: 0.5rem; }

.ospf-pkt-key { display: inline-flex; align-items: center; gap: 0.2rem; color: var(--dim); margin-left: 0.3rem; }
.ospf-pkt-key i { display: inline-grid; place-items: center; width: 1.25em; height: 1.25em; border-radius: 50%; color: #fff; font-style: normal; font-weight: 800; font-size: 0.68rem; }
.ospf-pkt-key i.h { background: var(--hello); }
.ospf-pkt-key i.x { background: var(--exchange); }

/* --- database exchange */
.ospf-pkt-key i.f { background: var(--flood); }
.ospf-pkt-lsack circle { fill: var(--exchange); }
.ospf-pkt.flood circle { fill: var(--flood); }
#ospf-detail h4 { font-size: 0.78rem; margin: 0.6rem 0 0.2rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.03em; }
#ospf-detail tr.fresh td { background: var(--flash); transition: background 0.4s; }
.ospf-ladder-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.ospf-ladder-table th { text-align: center; color: var(--dim); font-size: 0.74rem; border-bottom: 1px solid var(--border); padding: 0.2rem; }
.ospf-ladder-table td { padding: 0.18rem 0.3rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ospf-ladder-table td.t { color: var(--dim); font-family: ui-monospace, Menlo, monospace; width: 2.8rem; }
.ospf-ladder-table td:nth-child(2), .ospf-ladder-table td:nth-child(4) { width: 3.6rem; text-align: center; }
.ospf-ladder-table td.arrow { position: relative; }
.ospf-ladder-table td.arrow.right::after { content: ' →'; color: var(--exchange); font-weight: 700; }
.ospf-ladder-table td.arrow.left::before { content: '← '; color: var(--exchange); font-weight: 700; }
.ospf-ladder-table .k { display: inline-block; min-width: 2.7rem; text-align: center; border-radius: 8px; color: #fff; background: var(--exchange); font-size: 0.7rem; font-weight: 700; padding: 0 0.3rem; }

/* --- shortest path first */
.spf-svg { aspect-ratio: 1300 / 800; overflow: hidden; }
.spf-world { transform-origin: 0 0; transition: transform 0.8s ease-in-out; }
.spf-svg .ospf-areas, .spf-svg .ospf-wires, .spf-svg .ospf-nets, .spf-svg .ospf-nodes, .spf-graph,
.spf-svg [data-area] { transition: opacity 0.5s; }
.spf-graph { opacity: 0; pointer-events: none; }
/* Area 1 in focus: everything outside it fades. */
.spf-svg:not([data-phase="net"]) [data-area]:not([data-area~="1"]) { opacity: 0.08; }
.spf-svg:not([data-phase="net"]) .ospf-area-name-0 { opacity: 0; }
/* The bare graph: only area 1's background stays under it. */
.spf-svg[data-phase="graph"] :is(.ospf-wires, .ospf-nets, .ospf-nodes),
.spf-svg[data-phase="marks"] :is(.ospf-wires, .ospf-nets, .ospf-nodes),
.spf-svg[data-phase="spf"] :is(.ospf-wires, .ospf-nets, .ospf-nodes),
.spf-svg[data-phase="tree"] :is(.ospf-wires, .ospf-nets, .ospf-nodes) { opacity: 0; pointer-events: none; }
.spf-svg:is([data-phase="graph"], [data-phase="marks"], [data-phase="spf"], [data-phase="tree"]) .spf-graph { opacity: 1; pointer-events: auto; }
/* Back on the network: the tree's edges over the real links, nothing else of the graph. */
.spf-svg[data-phase="map"] .spf-graph { opacity: 1; }
.spf-svg[data-phase="map"] .spf-node, .spf-svg[data-phase="map"] .spf-edge-label,
.spf-svg[data-phase="map"] .spf-edge:not(.tree) { opacity: 0; }
.spf-svg[data-phase="map"] .spf-edge.tree line { stroke-width: 7; opacity: 0.55; }

.spf-edge line { stroke: var(--wire); stroke-width: 3.5; stroke-linecap: round; transition: stroke 0.3s, opacity 0.3s; }
.spf-edge.candidate line { stroke: var(--st-init); stroke-dasharray: 7 5; }
.spf-edge.tree line { stroke: var(--full); stroke-width: 5.5; }
.spf-edge.out line { opacity: 0.35; stroke-dasharray: 3 6; }
.spf-edge.out .spf-edge-label { opacity: 0.45; }
.spf-edge.focus line { stroke: var(--accent); stroke-width: 6; opacity: 1; stroke-dasharray: none; }
.spf-edge-label rect { fill: var(--card); stroke: var(--border); }
.spf-edge-label text { font-size: 11px; font-weight: 700; fill: var(--text); font-family: ui-monospace, Menlo, Consolas, monospace; }
.spf-edge.focus .spf-edge-label rect { stroke: var(--accent); stroke-width: 2; }
.spf-node { cursor: pointer; }
.spf-node circle { fill: var(--card); stroke: var(--st-down); stroke-width: 2.5; transition: fill 0.3s, stroke 0.3s; }
.spf-letter { font-size: 16px; font-weight: 800; fill: var(--text); pointer-events: none; }
.spf-node.candidate circle { fill: color-mix(in srgb, var(--st-init) 25%, var(--card)); stroke: var(--st-init); }
.spf-node.final circle { fill: var(--full); stroke: var(--full); }
.spf-node.final .spf-letter { fill: #fff; }
.spf-node.root circle { stroke: var(--accent); stroke-width: 4; }
.spf-node.focus circle { stroke: var(--accent); stroke-width: 5; }
.spf-cost rect { fill: var(--card); stroke: var(--border); }
.spf-cost text { font-size: 11px; font-weight: 700; fill: var(--text); }
.spf-node.plain .spf-cost { opacity: 0; }
.spf-node.candidate .spf-cost rect { stroke: var(--st-init); }
.spf-node.final .spf-cost rect { stroke: var(--full); }

.spf-root { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.85rem; color: var(--dim); margin-left: 0.4rem; }
.spf-root button { width: 1.9rem; height: 1.9rem; border-radius: 50%; border: 1.5px solid var(--border); background: var(--btn); color: var(--text); font-weight: 700; cursor: pointer; }
.spf-root button.on { border-color: var(--accent); background: var(--accent); color: #fff; }
.ospf-btn:disabled { opacity: 0.45; cursor: default; }
.ospf-chip.spf-k-final { background: var(--full); }
.ospf-chip.spf-k-cand { background: var(--st-init); }
.spf-k-edge { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--dim); margin-left: 0.4rem; }
.spf-k-edge::before { content: ''; width: 1.6rem; border-top: 4px solid var(--full); }
.spf-k-edge.out::before { border-top: 3px dotted var(--wire); }
.spf-table table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.spf-table th { text-align: left; color: var(--dim); font-size: 0.74rem; border-bottom: 1px solid var(--border); padding: 0.2rem 0.3rem; }
.spf-table td { padding: 0.22rem 0.3rem; border-bottom: 1px solid var(--border); }
.spf-table tr.final td:first-child { border-left: 3px solid var(--full); }
.spf-table tr.candidate td:first-child { border-left: 3px solid var(--st-init); }
.spf-table tr.unseen { color: var(--dim); }
.spf-table tr.focus td { background: var(--flash); }
.spf-table .dim { color: var(--dim); font-size: 0.76rem; }
.spf-table p { margin: 0; color: var(--dim); font-size: 0.84rem; }

/* The step's text, left of the graph, level with what the step is about. */
.spf-wrap { position: relative; }
.spf-say {
  position: absolute; left: 12px; top: 40%; width: calc(25% - 18px); min-width: 210px; z-index: 2;
  background: color-mix(in srgb, var(--card) 92%, transparent); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 0.7rem 0.9rem; transition: top 0.5s ease-in-out;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.spf-say .n { font-size: 0.74rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.3rem; }
.spf-say .main { font-size: 1.3rem; line-height: 1.3; font-weight: 600; margin: 0 0 0.5rem; }
.spf-say .more { font-size: 0.98rem; line-height: 1.45; margin: 0; color: var(--text); }
.spf-say .num { color: var(--accent); font-size: 1.12em; font-variant-numeric: tabular-nums; }
/* The step on the edge marks picks the costs out. */
.spf-edge-cost { transition: font-size 0.3s; }
.spf-svg[data-phase="marks"] .spf-edge-cost { fill: var(--accent); font-size: 15px; }
.spf-svg[data-phase="marks"] .spf-edge-label rect { stroke: var(--accent); }

/* The note on loops: opened from the text beside the graph, closed with ×. */
.spf-why-open { margin-top: 0.6rem; background: none; border: 1px solid var(--accent); color: var(--accent); border-radius: 14px; padding: 0.25rem 0.75rem; font-size: 0.88rem; cursor: pointer; }
.spf-why-open:hover { background: var(--accent); color: #fff; }
.spf-why {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, 90%); z-index: 5;
  background: var(--card); border: 1px solid var(--border); border-top: 4px solid var(--accent);
  border-radius: 10px; padding: 0.8rem 1rem; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12); font-size: 0.95rem; line-height: 1.45;
}
.spf-why[hidden] { display: none; }
.spf-why h3 { margin: 0 1.6rem 0.4rem 0; font-size: 1.1rem; }
.spf-why p { margin: 0 0 0.4rem; }
.spf-why ul { margin: 0 0 0.6rem; padding-left: 1.1rem; }
.spf-why li { margin-bottom: 0.35rem; }
.spf-why .num { color: var(--accent); }
.spf-why a { color: var(--accent); font-weight: 600; text-decoration: none; }
.spf-why a:hover { text-decoration: underline; }
.spf-why-close { position: absolute; right: 0.5rem; top: 0.35rem; background: none; border: 0; font-size: 1.4rem; line-height: 1; color: var(--dim); cursor: pointer; }
.spf-why-close:hover { color: var(--text); }

.spf-shade { position: absolute; inset: 0; z-index: 4; background: rgba(8, 20, 32, 0.45); border-radius: 12px; }
.spf-shade[hidden] { display: none; }
.spf-why { font-size: 1.02rem; padding: 1rem 1.2rem; }
.spf-why h3 { font-size: 1.25rem; }
/* Graph-like phases: the Dijkstra step shows the graph too. */
.spf-svg[data-phase="dijkstra"] :is(.ospf-wires, .ospf-nets, .ospf-nodes) { opacity: 0; pointer-events: none; }
.spf-svg[data-phase="dijkstra"] .spf-graph { opacity: 1; }
.spf-fig { margin: 0.7rem 0 0; }
.spf-fig img { display: block; width: 150px; height: auto; border-radius: 6px; }
.spf-fig figcaption { font-size: 0.72rem; color: var(--dim); margin-top: 0.3rem; line-height: 1.35; }
.spf-say a, .spf-fig a { color: var(--accent); }
.spf-root button:disabled { opacity: 0.45; cursor: default; }

/* --- inter-area routing */
.ia-svg { aspect-ratio: 1300 / 650; overflow: hidden; }
.ia-path.thin { stroke-width: 4; opacity: 0.9; }
.ia-svg [data-area] { transition: opacity 0.5s; }
.ia-svg .ia-faded { opacity: 0.22; }
.ia-svg.ia-abrs .ospf-router-abr .ospf-router-body { stroke-width: 5; filter: drop-shadow(0 0 6px var(--abr-stroke)); }
.ia-path { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: 0.6; }
.ia-path.pa { stroke: var(--accent); }
.ia-path.pd { stroke: var(--hello); }
.ia-path.p2 { stroke: var(--full); }
.ia-path.ghost { stroke: var(--wire); stroke-dasharray: 2 12; opacity: 0.9; stroke-width: 6; }
.ia-tag rect { fill: var(--card); stroke: var(--dim); stroke-width: 1.5; }
.ia-tag text { font-size: 14px; font-weight: 700; fill: var(--text); font-family: ui-monospace, Menlo, Consolas, monospace; }
.ia-tag.pa rect { stroke: var(--accent); }
.ia-tag.pd rect { stroke: var(--hello); }
.ia-tag.p2 rect { stroke: var(--full); }
.ia-tag.p0 rect { stroke: var(--flood); }
.ia-tag.ask text { font-size: 18px; }
.ia-lsa circle { fill: var(--flood); stroke: var(--card); stroke-width: 1.5; }
.ia-lsa text { font-size: 11px; font-weight: 800; fill: #fff; }
.ia-k { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--dim); margin-left: 0.4rem; }
.ia-k::before { content: ''; width: 1.6rem; border-top: 6px solid; border-radius: 3px; opacity: 0.7; }
.ia-k.pa::before { border-color: var(--accent); }
.ia-k.pd::before { border-color: var(--hello); }
.ia-k.p2::before { border-color: var(--full); }
.spf-table tr.ia td:first-child { border-left: 3px solid var(--flood); }


/* --- previous/next in the series, at the right end of the controls row */
/* It takes whatever the row leaves and holds its links at the right-hand
   end, also when it wraps onto a line of its own. */
.ospf-pager { display: flex; flex: 1 0 auto; justify-content: flex-end; gap: 0.5rem; }
.ospf-pager[hidden] { display: none; }
.ospf-pager a, .ospf-next-demo {
  border: 1.5px solid var(--accent); border-radius: 14px; padding: 0.15rem 0.75rem;
  color: var(--accent); font-size: 0.85rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.ospf-pager a.prev { border-color: var(--border); color: var(--dim); font-weight: 400; }
.ospf-pager a:hover, .ospf-next-demo:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.ospf-next-demo { display: inline-block; margin-top: 0.7rem; font-size: 0.95rem; padding: 0.3rem 0.9rem; }
.ospf-next-demo[hidden] { display: none; }
/* The area databases: a card per area, one chip per LSA, by type. */
.ia-db-bg { fill: var(--card); stroke: var(--border); stroke-width: 1.3; }
.ia-db-title { font-size: 14.5px; font-weight: 700; fill: var(--dim); }
.ia-chip rect { fill: var(--card); stroke: var(--border); stroke-width: 1.2; }
.ia-chip text { font-size: 13.5px; fill: var(--text); font-family: ui-monospace, Menlo, Consolas, monospace; }
.ia-chip text.n { font-size: 10.5px; font-weight: 800; fill: #fff; font-family: inherit; }
.ia-chip.t1 circle { fill: var(--router-stroke); }
.ia-chip.t2 circle { fill: var(--abr-stroke); }
.ia-chip.t3 circle { fill: var(--flood); }
.ia-chip.lit rect { fill: var(--flash); stroke: var(--accent); stroke-width: 1.8; }
.ospf-pkt-key i.t1 { background: var(--router-stroke); }
.ospf-pkt-key i.t2 { background: var(--abr-stroke); }
.ospf-box[hidden] { display: none; }
.ia-db-h { font-size: 0.8rem; margin: 0.5rem 0 0.2rem; color: var(--dim); }
.ia-db.shown .ia-db-bg { stroke: var(--accent); stroke-width: 2.2; }
.spf-table tr.lit td { background: color-mix(in srgb, var(--flash) 55%, transparent); }
.spf-table td .ospf-pkt-key { margin-left: 0; }
.spf-table td code { white-space: nowrap; }
.spf-table td:nth-child(2) { white-space: nowrap; }

/* --- flooding */
.ospf-pkt.data circle { fill: var(--text); r: 4.5; }
.ospf-pkt.data:hover circle { r: 8; }
.ospf-pkt-key i.d { background: var(--text); width: 0.7em; height: 0.7em; }
.ospf-wire.is-cut { stroke: var(--drop); stroke-dasharray: 6 6; opacity: 0.7; }
.fl-cut { stroke: var(--drop); stroke-width: 4; stroke-linecap: round; }
.fl-path { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; opacity: 0.28; transition: stroke 0.3s; }
.fl-path.loop, .fl-path.dead { stroke: var(--drop); opacity: 0.35; }
.fl-k { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--dim); margin-left: 0.4rem; }
.fl-k::before { content: ''; width: 1.6rem; border-top: 8px solid var(--accent); border-radius: 4px; opacity: 0.4; }
.fl-table table + table { margin-top: 0.6rem; }
#ospf-detail tr.fresh-row td { background: color-mix(in srgb, var(--flash) 60%, transparent); }
#ospf-detail tr.gone td { color: var(--dim); text-decoration: line-through; }
