/* Shared styling for the interactive demos (demos/src/). Colours are variables on
   .qb-demo, so a dark theme only needs to override these. */
.qb-demo {
  --qb-fg: #222; --qb-muted: #777; --qb-grid: #e3e3e3; --qb-axis: #444;
  --qb-bg: #fff; --qb-panel: #f6f7f9; --qb-accent: #1f77b4;
  --qb-c1: #1f77b4; --qb-c2: #d62728; --qb-c3: #2ca02c; --qb-c4: #ff7f0e; --qb-c5: #9467bd;
  display: flex; flex-wrap: wrap; gap: 1.2em; align-items: flex-start;
  color: var(--qb-fg); font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px; line-height: 1.35; margin: 1em 0;
}
.qb-demo svg { display: block; user-select: none; -webkit-user-select: none; }
.qb-demo svg text { fill: var(--qb-fg); font-family: inherit; }
.qb-demo .qb-plot { flex: 1 1 320px; min-width: 0; max-width: 560px; }
.qb-demo .qb-panel { flex: 0 1 300px; display: flex; flex-direction: column; gap: .55em; }
.qb-demo .grid { stroke: var(--qb-grid); }
.qb-demo .axis { stroke: var(--qb-axis); }
.qb-demo .handle { fill: #fff; stroke-width: 3; cursor: grab; }

.qb-demo .qb-slider { display: grid; grid-template-columns: auto 1fr 3.6em; gap: .5em; align-items: center; }
.qb-demo .qb-slider-name { white-space: nowrap; }
.qb-demo .qb-slider input[type=range] { width: 100%; min-width: 6em; accent-color: var(--qb-accent); }
.qb-demo .qb-slider output { font-family: ui-monospace, monospace; text-align: right; }
.qb-demo .qb-check { display: flex; align-items: center; gap: .3em; cursor: pointer; }
.qb-demo .qb-presets { display: flex; flex-wrap: wrap; gap: .35em; }
.qb-demo .qb-btn {
  font: inherit; font-size: .85em; padding: .25em .7em; border-radius: 6px; cursor: pointer;
  border: 1px solid #bbb; background: var(--qb-bg); color: var(--qb-fg);
}
.qb-demo .qb-btn:hover { border-color: var(--qb-accent); }
.qb-demo .qb-btn.active { background: var(--qb-accent); border-color: var(--qb-accent); color: #fff; }
.qb-demo .qb-readout {
  font-family: ui-monospace, monospace; font-size: .9em; white-space: pre-wrap;
  background: var(--qb-panel); border-radius: 6px; padding: .45em .6em;
}
.qb-demo .qb-note { font-size: .85em; color: var(--qb-muted); }
.qb-demo .qb-big { font-size: 1.25em; font-weight: 600; }

/* Inside a reveal.js slide: larger text, no outer margin, fit the content area. */
.reveal .qb-demo { font-size: 22px; margin: .2em 0; text-align: left; }
.reveal .qb-demo .qb-plot { max-width: none; }
.reveal .qb-demo .qb-btn { font-size: .8em; }

@media (max-width: 640px) {
  .qb-demo { flex-direction: column; }
  .qb-demo .qb-panel { flex-basis: auto; width: 100%; }
}

/* ---- Shared components of demos/src/lib (plot.ts, gridui.ts, paint.ts, playground.ts,
   shapecanvas.ts, gl3d.ts). Colours only through the variables above. ---- */
.qb-demo .qb-figure { margin: 0; }
.qb-demo .qb-figure figcaption, .qb-demo .qb-paint figcaption { font-size: 17px; text-align: center; margin: 0 0 .2em; }
.qb-demo .qb-plot-svg { display: block; overflow: visible; }
.qb-demo svg text.qb-halo, .qb-demo svg .qb-halo text {
  paint-order: stroke; stroke: var(--qb-bg); stroke-width: 4px; stroke-linejoin: round;
}
/* grid step-through */
.qb-demo .qb-gridstep { display: flex; flex-wrap: wrap; gap: 1em; align-items: flex-start; width: 100%; }
.qb-demo .qb-gridstep-grids { display: flex; flex-wrap: wrap; gap: 1em; flex: 1 1 420px; min-width: 0; }
.qb-demo .qb-gridstep-cell { flex: 1 1 200px; min-width: 0; }
.qb-demo .qb-grid-svg { display: block; touch-action: none; }
.qb-demo .qb-gridstep-panel { flex: 0 1 320px; }
.qb-demo .qb-gridstep-ctl .qb-btn:disabled { opacity: .45; cursor: default; }
.qb-demo .qb-gridstep-log { font-size: 14px; max-height: 9.5em; overflow-y: auto; white-space: normal; }
.qb-demo .qb-gridstep-log .qb-gridstep-cur { font-weight: 700; color: var(--qb-accent); }
/* label painting, point playground, shape canvas */
.qb-demo .qb-paint { margin: 0; flex: 0 1 360px; min-width: 0; }
.qb-demo .qb-paint-canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 3px;
  image-rendering: pixelated; touch-action: none; cursor: crosshair; }
.qb-demo .qb-btn.qb-paint-label { border-color: var(--qb-label, #bbb); box-shadow: inset 4px 0 0 var(--qb-label, #bbb); }
.qb-demo .qb-btn.qb-paint-label.active { background: var(--qb-label, var(--qb-accent)); border-color: var(--qb-label, var(--qb-accent)); color: #fff; box-shadow: none; }
.qb-demo .qb-playground svg, .qb-demo .qb-shapecanvas svg { touch-action: none; cursor: crosshair; }
/* WebGL view */
.qb-demo .qb-gl { position: relative; width: 100%; min-width: 0; border-radius: 4px; overflow: hidden;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.qb-demo .qb-gl-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.qb-demo .qb-gl-label { position: absolute; font-size: 18px; padding: 0 .35em; border-radius: 4px;
  background: var(--qb-bg); color: var(--qb-fg); opacity: .85; pointer-events: none; }
.qb-demo .qb-gl-msg { padding: 1em; background: var(--qb-panel); border: 2px solid var(--qb-c2);
  border-radius: 6px; font-size: 18px; cursor: default; }

/* ---- Fitting the screen (demos/README.md, "Fitting the screen"; checked by make check-fit).
   A demo must fit in the window (height <= 100vh - 60px) with its controls beside the figure. ---- */
/* Pages: autoMount (lib/ui.ts) moves a demo into Quarto's wide grid column (.qb-wide =
   .column-screen-inset-right: from the text column to the window's right edge; Quarto folds
   the table of contents into an "On this page" button while it is on screen). */
.qb-demo.qb-wide { background: var(--qb-bg); }
/* Figures never taller than the window minus room for a caption and a button row. SVGs keep
   their aspect ratio through the viewBox; canvases through object-fit. */
.qb-demo svg, .qb-demo canvas { max-height: calc(100vh - 200px); }
.qb-demo canvas { object-fit: contain; }
/* The control panel stays a column beside the figure; when it is taller than the window it
   scrolls rather than pushing the demo off the screen. (min-width: a scrolling flex item
   would otherwise shrink below its content and cut it off.) */
@media (min-width: 641px) {
  .qb-demo .qb-panel { max-height: calc(100vh - 100px); overflow-y: auto; overflow-x: hidden;
    min-width: min-content; scrollbar-width: thin; overscroll-behavior: contain; }
}
/* Slides: reveal.js scales a 1280x720 slide, so limits are in slide pixels (content area
   about 1150x560), not in vh. */
.reveal .qb-demo svg, .reveal .qb-demo canvas { max-height: 560px; }
.reveal .qb-demo .qb-panel { max-height: 600px; }
