/* ===========================================================================
   Basic Mathematics — 3D scene stages (.s3d-*), built by assets/scenes3d.js
   Loaded after site.css. A stage stacks three layers in one 660 × 420 frame:
   the SVG picture (first paint and fallback), the canvas the WebGL painter
   copies into, and the overlay SVG for labels and handles. Colours come only
   from the tokens in src/styles/tokens.css.
   =========================================================================== */

.scene3d .s3d-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 660 / 420;
  max-height: min(70vh, 520px);
  background: var(--plot-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  touch-action: pan-y;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.scene3d .s3d-stage[data-drag] { cursor: grabbing; }
.scene3d .s3d-stage:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); }

/* site.css gives figure svgs height:auto and touch-action:none; a stage needs both layers
   to fill it, and vertical swipes over it to scroll the page */
.scene3d .s3d-stage > svg,
.scene3d .s3d-stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y;
}
.scene3d .s3d-canvas { display: none; }
.scene3d[data-painter="gl"] .s3d-canvas { display: block; }
.scene3d[data-painter="gl"] .s3d-pic { visibility: hidden; }
.scene3d .s3d-over { pointer-events: none; overflow: visible; }

.s3d-label {
  font-family: var(--sans);
  font-size: var(--s3d-fs, 13px);
  paint-order: stroke;
  stroke: var(--plot-bg);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.s3d-selring, .s3d-rail-key { display: none; }
.s3d-stage:focus-visible .s3d-selring, .s3d-stage:focus-visible .s3d-rail-key { display: inline; }

.s3d-tools {
  position: absolute;
  top: .5rem;
  right: .5rem;
  display: flex;
  gap: .3rem;
  z-index: 2;
}
.s3d-tools .icon-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
}
.s3d-status {
  position: absolute;
  left: .6rem;
  bottom: .45rem;
  right: 3rem;
  margin: 0;
  font-family: var(--sans);
  font-size: .72rem;
  line-height: 1.35;
  color: var(--muted);
  pointer-events: none;
}
.s3d-status > span { background: var(--plot-bg); }

/* control groups: a muted label in front of chips or the matrix */
.scene3d .s3d-group, .scene3d .s3d-matrix-ctrl { flex-wrap: wrap; }
.s3d-group-label { color: var(--muted); white-space: nowrap; }
.scene3d .s3d-views { flex-basis: 100%; }
.scene3d .s3d-btn:disabled { opacity: .45; cursor: default; }

/* a 3 × 3 grid of number inputs drawn as a determinant, with a colour key per row */
.s3d-matrix {
  display: inline-grid;
  grid-template-columns: .35rem repeat(3, 3.3rem);
  gap: .3rem .35rem;
  align-items: center;
  padding: .2rem .55rem;
  border-left: 2px solid var(--text);
  border-right: 2px solid var(--text);
}
.s3d-row-key { width: .35rem; height: 1.5rem; border-radius: 2px; background: var(--border-strong); }
.s3d-matrix input {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-family: var(--mono);
  font-size: .9rem;
  text-align: center;
  padding: .25rem .1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
}
.s3d-matrix input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.s3d-matrix input[readonly] { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

@media (max-width: 480px) {
  .widget.scene3d { padding: .55rem; }
  .scene3d .s3d-stage { aspect-ratio: 4 / 3; }
}

@media print {
  .scene3d .s3d-canvas { display: none !important; }
  .scene3d .s3d-pic { visibility: visible !important; }
  .s3d-tools, .s3d-status { display: none !important; }
}
