/* ==========================================================
   Room setup diagrams (js/setup-diagrams.js): homepage, support page,
   team Events tab. Each diagram is two boxes, Host and Listeners, with
   a numbered chain of pictured steps in each. Tokens from style.css.
   ========================================================== */
.sd { --sd-pic: 132px; text-align: center; }
.sd-flow, .sd-panel { text-align: initial; }

.sd-tabs {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; margin: 0 auto 20px;
  border-radius: var(--radius-full);
  background: var(--bg-hover); border: 1px solid var(--border);
  max-width: 100%;
}
.sd-tab {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 18px;
  border: 0; border-radius: var(--radius-full);
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1.2;
  cursor: pointer;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.sd-tab svg { width: 17px; height: 17px; flex-shrink: 0; }
.sd-tab:hover { color: var(--text); }
.sd-tab:focus-visible { outline: none; box-shadow: var(--ring); }
.sd-tab.active { background: var(--bg-card); color: var(--text); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border); }
.sd-tab.active svg { color: var(--primary); }

.sd-panel { outline: none; }
.sd-panel:focus-visible { box-shadow: var(--ring); border-radius: var(--radius); }
.sd-lead { max-width: 62ch; margin: 0 auto 22px; text-align: center; color: var(--text-muted); font-size: var(--fs-lg); line-height: 1.55; }

/* Two parts, always: Host on top, Listeners below, joined by the "over the internet" link.
   Each part is a titled box with its own numbered chain of steps. */
.sd { container-type: inline-size; }
.sd-part {
  --part: var(--primary); --part-rgb: var(--primary-rgb); --part-bg: var(--primary-bg);
  max-width: 1040px; margin: 0 auto; padding: 0 20px 22px;
  border-radius: var(--radius-xl);
  background: var(--bg-card); border: 1px solid var(--border);
  border-top: 4px solid var(--part);
  box-shadow: var(--shadow-sm);
}
.sd-part.is-listener { --part: var(--accent); --part-rgb: var(--accent-rgb); --part-bg: var(--accent-bg); }
.sd-part-head { display: flex; align-items: center; gap: 14px; padding: 16px 0 18px; text-align: left; }
.sd-part-ico { width: 44px; height: 44px; flex-shrink: 0; border-radius: 14px; display: grid; place-items: center; background: var(--part-bg); color: var(--part); }
.sd-part-ico svg { width: 22px; height: 22px; }
.sd-part-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sd-part-text strong { font-family: var(--font-heading); font-size: var(--fs-xl); letter-spacing: -0.01em; color: var(--text); }
.sd-part-text span { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.4; }
/* The link between the two parts */
.sd-link { display: flex; justify-content: center; position: relative; height: 64px; }
.sd-link::before { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 0; border-left: 2px dashed var(--border-strong); }
.sd-link span {
  position: relative; align-self: center;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: var(--radius-full);
  background: var(--bg-card); border: 1px solid var(--border-strong);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
}
.sd-link svg { width: 15px; height: 15px; color: var(--primary); }

/* A part's chain: a centred grid, read left to right. Each step is numbered and an arrow
   (or a "+" before an optional add-on) joins it to the next one in its row. Columns follow
   the diagram's own width (container queries), so it also works in a narrow column. */
.sd-flow {
  --sd-gap: 32px;
  list-style: none; margin: 0; padding: 0; counter-reset: sd;
  display: grid; justify-content: center;
  grid-template-columns: repeat(var(--sd-n, 4), minmax(0, 210px));
  gap: 26px var(--sd-gap);
}
.sd-flow[data-n="2"] { --sd-n: 2; }
.sd-flow[data-n="3"] { --sd-n: 3; }
.sd-flow[data-n="4"] { --sd-n: 4; }
.sd-flow[data-n="5"] { --sd-n: 5; --sd-gap: 26px; }
.sd-node {
  position: relative; counter-increment: sd; min-width: 0;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 16px 12px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-subtle); border: 1px solid var(--border);
}
.sd-node.is-optional { border-style: dashed; border-color: var(--border-strong); background: transparent; }
.sd-node::before {
  content: counter(sd); position: absolute; top: 10px; left: 10px; z-index: 1;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--part); color: #fff;
  font-family: var(--font-heading); font-size: 0.78rem; font-weight: 700;
}
/* Arrow to the next step in the row */
.sd-node:not(:last-child)::after {
  content: ''; position: absolute; left: 100%; top: calc(16px + var(--sd-pic) / 2);
  width: var(--sd-gap); height: 14px; margin-top: -7px;
  background:
    linear-gradient(var(--part), var(--part)) 4px center / calc(100% - 16px) 2px no-repeat,
    conic-gradient(from 240deg at 100% 50%, var(--part) 60deg, transparent 0) calc(100% - 4px) center / 10px 14px no-repeat;
  opacity: 0.8;
}
/* "+" instead of an arrow before an optional add-on */
.sd-node.is-plus-next:not(:last-child)::after {
  content: '+'; background: none; opacity: 1;
  height: 24px; margin-top: -12px;
  display: grid; place-items: center;
  font-family: var(--font-heading); font-size: 1.25rem; font-weight: 700; line-height: 1; color: var(--text-light);
}
@container (max-width: 900px) {
  .sd-flow[data-n="4"], .sd-flow[data-n="5"] { --sd-n: 3; --sd-gap: 28px; }
  .sd-flow[data-n="4"] .sd-node:nth-child(3n)::after, .sd-flow[data-n="5"] .sd-node:nth-child(3n)::after { display: none; }
}
@container (max-width: 620px) {
  .sd-flow[data-n="3"], .sd-flow[data-n="4"], .sd-flow[data-n="5"] { --sd-n: 2; --sd-gap: 24px; }
  .sd-flow[data-n="4"] .sd-node:nth-child(3n)::after, .sd-flow[data-n="5"] .sd-node:nth-child(3n)::after { display: grid; }
  .sd-flow .sd-node:nth-child(2n)::after { display: none !important; }
}
.sd-tag {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  padding: 2px 10px; border-radius: var(--radius-full);
  background: var(--bg-card); border: 1px solid var(--border-strong);
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-light);
  white-space: nowrap;
}
.sd-pic {
  display: block; width: var(--sd-pic); height: var(--sd-pic); flex-shrink: 0;
  border-radius: var(--radius); overflow: hidden;
  background: #f1f1f0;              /* the illustrations' own paper colour */
}
.sd-pic img { display: block; width: 100%; height: 100%; object-fit: cover; mix-blend-mode: multiply; transition: transform var(--dur) var(--ease-out); }
a.sd-pic:hover img { transform: scale(1.06); }
a.sd-pic:focus-visible { outline: none; box-shadow: var(--ring); }
.sd-title { font-family: var(--font-heading); font-size: var(--fs-base); line-height: 1.25; color: var(--text); margin-top: 4px; }
.sd-desc { font-size: var(--fs-sm); line-height: 1.45; color: var(--text-muted); }
.sd-buy {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: auto; padding: 6px 12px; min-height: 36px;
  border-radius: var(--radius-full);
  background: var(--primary-bg); border: 1px solid var(--primary-border); color: var(--primary-dark);
  font-size: var(--fs-xs); font-weight: 700; text-decoration: none;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.sd-node .sd-desc + .sd-buy { margin-top: 8px; }
.sd-buy:hover { background: var(--primary); border-color: var(--primary); color: var(--text-on-primary); }
.sd-buy:focus-visible { outline: none; box-shadow: var(--ring); }
.sd-buy svg { width: 13px; height: 13px; }

.sd-note { display: flex; gap: 10px; align-items: flex-start; justify-content: center; max-width: 70ch; margin: 22px auto 0; font-size: var(--fs-sm); line-height: 1.5; color: var(--text-secondary); }
.sd-note svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; color: var(--primary); }
.sd-disclosure { max-width: 70ch; margin: 12px auto 0; text-align: center; font-size: var(--fs-xs); line-height: 1.5; color: var(--text-light); }

/* Compact variant (team Events tab): smaller pictures */
.sd.is-compact { --sd-pic: 104px; }
.sd.is-compact .sd-lead { font-size: var(--fs-base); }
.sd.is-compact .sd-part { box-shadow: none; }
.sd.is-compact .sd-part-text strong { font-size: var(--fs-lg); }

/* Narrow (phones): one column, each step a row (picture left, words right), connectors point down */
@container (max-width: 460px) {
  .sd-part { padding: 0 12px 14px; border-radius: var(--radius-lg); }
  .sd-flow, .sd-flow[data-n] { grid-template-columns: minmax(0, 1fr); gap: 26px; }
  .sd-node {
    display: grid; grid-template-columns: 84px minmax(0, 1fr); column-gap: 14px; row-gap: 2px;
    align-items: start; text-align: left; padding: 12px;
  }
  .sd-pic { grid-row: 1 / span 3; width: 84px; height: 84px; }
  .sd-title { margin-top: 2px; }
  .sd-buy { justify-self: start; margin-top: 6px; min-height: 40px; }
  .sd-node::before { top: 6px; left: 6px; }
  .sd-flow .sd-node:not(:last-child)::after {
    display: block !important; left: 54px; top: 100%;
    width: 14px; height: 26px; margin: 0 0 0 -7px;
    background:
      linear-gradient(var(--part), var(--part)) center 3px / 2px calc(100% - 14px) no-repeat,
      conic-gradient(from 330deg at 50% 100%, var(--part) 60deg, transparent 0) center calc(100% - 3px) / 14px 10px no-repeat;
  }
  .sd-flow .sd-node.is-plus-next:not(:last-child)::after { display: grid !important; background: none; width: 24px; margin-left: -12px; }
  .sd-tag { left: auto; right: 12px; transform: none; }
  .sd-link { height: 56px; }
}
@media (max-width: 640px) {
  .sd-tabs { display: grid; grid-auto-flow: row; width: 100%; border-radius: var(--radius); }
  .sd-tab { border-radius: var(--radius-sm); justify-content: flex-start; }
  .sd-lead { font-size: var(--fs-base); text-align: left; }
  .sd-note { justify-content: flex-start; }
  .sd-disclosure { text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  .sd-pic img { transition: none; }
  a.sd-pic:hover img { transform: none; }
}

/* Five steps in a row: the Amazon button must stay on one line */
.sd-buy span { white-space: nowrap; }
.sd-flow[data-n="5"] .sd-buy { padding: 6px 10px; gap: 5px; }
.sd-flow[data-n="5"] .sd-buy svg:first-child { display: none; }
