/* ---------- "Bifurcation stenting, step by step" ----------
   The stepper built by public/js/widgets/bifurcation.js, and the two blocks of that post that need more than
   the article's own styles: the rules grid and the tables that scroll sideways.
   The frame uses the page's tokens. The drawing brings its own colours, because they mean something: blue is
   the main vessel stent, orange the side branch stent, teal a balloon, ochre plaque. */

.bif {
  --bif-lumen:   #F8E3DC;
  --bif-wall:    #B4473F;
  --bif-plaque:  #D2A84E;
  --bif-mv:      #1F55A8;
  --bif-sb:      #BD5B0A;
  --bif-balloon: #2A8FA8;
  --bif-mark:    #7A2BB0;
}
.dark-theme .bif {
  --bif-lumen:   #3A2022;
  --bif-wall:    #DC6A62;
  --bif-plaque:  #A98A3D;
  --bif-mv:      #8AB6FF;
  --bif-sb:      #FFB04D;
  --bif-balloon: #7FD0E6;
  --bif-mark:    #D8A3FF;
}
@media (prefers-color-scheme: dark) {
  :root:not(.light-theme) .bif {
    --bif-lumen:   #3A2022;
    --bif-wall:    #DC6A62;
    --bif-plaque:  #A98A3D;
    --bif-mv:      #8AB6FF;
    --bif-sb:      #FFB04D;
    --bif-balloon: #7FD0E6;
    --bif-mark:    #D8A3FF;
  }
}

/* Without the script the post shows one line in the drawing's place. The theme snippet in head.ejs puts a
   class on <html> whenever scripts run, so that line never flashes before the stepper is built. */
.bif .bif-fallback { margin-bottom: var(--space-lg); font-style: italic; color: var(--color-text-muted); }
.dark-theme .bif-fallback, .light-theme .bif-fallback { display: none; }

/* The stepper and the trials table are wider than the text column where the screen has the room. The
   stepper lays itself out by its own width (the queries at the end), not the window's. */
.bif.is-live, .e-content > .bif-scroll {
  --bif-w: max(100%, min(1040px, 100vw - 88px));
  width: var(--bif-w);
  margin: var(--space-xl) calc((100% - var(--bif-w)) / 2) var(--space-2xl);
}
.e-content > .bif-scroll { margin-block: var(--space-lg); }
.bif.is-live {
  container: bif / inline-size;
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-family: var(--font-sans);
  font-size: 0.94rem;
  line-height: 1.55;
}
/* the article's spacing for headings, paragraphs and lists stops at the stepper's edge */
.bif :is(h2, h3) { margin: 0; }
.bif :is(p, ul, ol, li) { margin: 0; padding: 0; list-style: none; }
.bif :is(.bif-tabs, .bif-ctl, .bif-steps) button { font: inherit; color: inherit; cursor: pointer; }
.bif button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.bif .seg { align-self: flex-start; }

.bif-view { display: flex; flex-direction: column; gap: 18px; }
.bif-view[hidden] { display: none; }
.bif-view > h3, .bif-pearls h3 { font-size: 1.05rem; }

/* which technique */
.bif-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.bif .bif-tabs button {
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-white);
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.bif .bif-tabs button:hover { color: var(--color-ink); }
.bif .bif-tabs button[aria-selected="true"] { background: var(--color-ink); border-color: var(--color-ink); color: var(--color-bg); }

.bif-head { display: flex; flex-direction: column; gap: 8px; }
.bif-head h2 { font-size: 1.45rem; }
.bif-head p { max-width: 68ch; font-family: var(--font-body); font-size: 1.02rem; color: var(--color-text-muted); }
.bif-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bif-chips li { border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-white); padding: 2px 8px; font-size: 0.8rem; }
.bif-chips b { margin-right: 5px; font-weight: 600; color: var(--color-text-muted); }

/* the drawing, with the step it shows; the list of steps beside it */
.bif-work { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: start; }
.bif-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.bif-stage { border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-white); padding: 6px; overflow: hidden; }
.bif-stage svg { display: block; width: 100%; height: auto; }

.bif-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.78rem; color: var(--color-text-muted); }
.bif-legend li { display: flex; align-items: center; gap: 6px; }
.bif-legend i { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--bif-mv); }
.bif-legend .l-sb { border-color: var(--bif-sb); }
.bif-legend .l-w { border-top: 2px solid var(--color-ink); }
.bif-legend .l-ws { border-top: 2px dashed var(--color-ink); }
.bif-legend .l-b { height: 9px; border: 1px solid var(--bif-balloon); border-radius: 5px; background: color-mix(in srgb, var(--bif-balloon) 38%, transparent); }
.bif-legend .l-p { height: 8px; border: 0; border-radius: 4px; background: var(--bif-plaque); }

/* tall enough for the longest step, so what follows keeps its place while the steps go by */
.bif-now { display: flex; flex-direction: column; gap: 4px; min-height: 8.4em; }
.bif-now .k { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-highlight); font-variant-numeric: tabular-nums; }
.bif-now h3 { font-family: var(--font-sans); font-size: 1.08rem; letter-spacing: 0; }
.bif-now p:last-child { font-family: var(--font-body); font-size: 1rem; }

.bif-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bif .bif-ctl button {
  min-width: 76px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-white);
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-ink);
}
.bif .bif-ctl button.pri { background: var(--color-ink); border-color: var(--color-ink); font-weight: 600; color: var(--color-bg); }
.bif .bif-ctl button:disabled { opacity: 0.45; cursor: default; }
.bif-ctl span { margin-left: 4px; font-family: var(--font-mono); font-size: 0.72rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
@media (pointer: coarse) { .bif .bif-ctl button { padding-block: 11px; } }

.bif-steps { display: flex; flex-direction: column; gap: 2px; }
.bif .bif-steps button {
  display: grid;
  grid-template-columns: 3.8em minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 7px 10px;
  text-align: left;
}
.bif-steps button span { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.bif .bif-steps button:hover { background: color-mix(in srgb, var(--color-bg-alt) 55%, transparent); }
.bif .bif-steps button[aria-current="step"] { background: var(--color-bg-alt); font-weight: 600; color: var(--color-ink); }
.bif-steps button[aria-current="step"] span { color: var(--color-highlight); }

.bif-pearls { display: flex; flex-direction: column; gap: 8px; }
.bif-dots { display: flex; flex-direction: column; gap: 6px; max-width: 74ch; font-family: var(--font-body); font-size: 1rem; }
.bif-dots li { position: relative; padding-left: 18px; }
.bif-dots li::before { content: ""; position: absolute; left: 2px; top: 0.7em; width: 6px; height: 6px; border-radius: 50%; background: var(--color-accent); }

/* side by side */
.bif-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.bif-mini { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bif-mini h3 { font-family: var(--font-sans); font-size: 0.95rem; letter-spacing: 0; }
.bif-mini p { min-height: 2.6em; font-size: 0.82rem; color: var(--color-text-muted); }
.bif-mini p b { font-weight: 600; color: var(--color-highlight); font-variant-numeric: tabular-nums; }

/* a table wider than a phone scrolls inside its own frame (the comparison here, the trials in the post);
   its first column stays put, so a row keeps its name while the rest passes under it */
.bif-scroll { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-white); }
.bif-scroll table { min-width: 680px; margin: 0; border-collapse: separate; border-spacing: 0; font-family: var(--font-sans); font-size: 0.86rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
.bif-scroll :is(th, td) { padding: 8px 10px; }
.bif-scroll :is(th, td):first-child { position: sticky; left: 0; background: var(--color-white); box-shadow: 1px 0 0 var(--color-border); }
@media (max-width: 640px) { .bif-scroll table { min-width: 780px; } }   /* it scrolls there anyway: give the columns room */
.bif-scroll thead th { white-space: nowrap; }
.bif-scroll tbody tr:last-child :is(th, td) { border-bottom: 0; }
.bif-scroll tbody th, .bif-scroll tbody td:first-child { font-family: var(--font-sans); font-size: inherit; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--color-ink); white-space: nowrap; }
.bif-scroll .na { display: block; font-size: 0.78rem; font-weight: 400; color: var(--color-text-muted); }

/* the rules: short entries, two across */
.bif-rules { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 28px; margin: var(--space-lg) 0 var(--space-xl); }
.bif-rules article { min-width: 0; border-top: 2px solid var(--color-border); padding-top: 10px; }
.bif-rules h3 { margin: 0 0 6px; font-size: 1.02rem; }
.bif-rules p { margin: 0; font-size: 0.98rem; line-height: 1.55; }
@media (max-width: 640px) { .bif-rules { grid-template-columns: minmax(0, 1fr); } }

/* the drawing */
.bif-lumen { fill: var(--bif-lumen); stroke: var(--bif-wall); stroke-width: 3; stroke-linejoin: round; }
.bif-plq { fill: var(--bif-plaque); }
.bif-st { fill: none; stroke-width: 1.25; stroke-linejoin: round; stroke-linecap: round; }
.bif-st.m { stroke: var(--bif-mv); }
.bif-st.s { stroke: var(--bif-sb); }
.bif-fill.m { fill: var(--bif-mv); fill-opacity: 0.1; }
.bif-fill.s { fill: var(--bif-sb); fill-opacity: 0.12; }
.bif-wire { fill: none; stroke: var(--color-ink); stroke-width: 1.4; stroke-linecap: round; }
.bif-wire.d { stroke-dasharray: 5 3; }
.bif-bal { fill: var(--bif-balloon); fill-opacity: 0.36; stroke: var(--bif-balloon); stroke-width: 1; }
.bif-balp { fill: none; stroke: var(--bif-balloon); stroke-opacity: 0.42; stroke-linecap: round; stroke-linejoin: round; }
.bif-mk { fill: none; stroke: var(--bif-mark); stroke-width: 1.6; stroke-dasharray: 3 2.2; }
.bif-mkt { fill: var(--bif-mark); font: 600 9.5px var(--font-sans); paint-order: stroke; stroke: var(--color-white); stroke-width: 3px; stroke-linejoin: round; }
.bif-lbl { fill: var(--color-text-muted); font: 500 8.5px var(--font-sans); }

/* by the stepper's own width: the steps drop under the drawing, then everything goes to one column */
@container bif (max-width: 780px) {
  .bif-work { grid-template-columns: minmax(0, 1fr); }
  .bif-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bif-now { min-height: 0; }
}
@container bif (max-width: 520px) {
  .bif-grid { grid-template-columns: minmax(0, 1fr); }
  .bif .bif-ctl button { min-width: 0; flex: 1; }
  .bif-ctl span { flex-basis: 100%; margin-left: 0; }
}
