/* figure3d.css — the "View in 3D" button, the 3D stage and the stage stepper.
 * Loaded on pages with a data-scene figure, beside assets/js/figure3d.js.
 * docs/3D-FIGURES-PLAN.md §5–§6: sized from the container (never a fixed
 * width), 44 px touch targets, colours from the site's tokens, and the 2D
 * figure is what prints.
 */

/* ── The bar under the 2D figure ─────────────────────────────────────────── */
.fig3d-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 0;
  cursor: default;
}

.fig3d-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-md, 10px);
  background: var(--primary-surface, transparent);
  color: var(--primary);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.fig3d-btn:hover:not(:disabled) { background: var(--primary); color: var(--card-bg); }
.fig3d-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.fig3d-btn:disabled { opacity: 0.7; cursor: progress; }
.fig3d-btn[hidden] { display: none; }
.fig3d-btn--quiet { border-color: var(--divider-light, var(--border)); color: var(--text-secondary); background: transparent; }

.fig3d-msg { font-size: 0.8rem; color: var(--text-secondary); }
.fig3d-msg:empty { display: none; }

/* ── The stage ──────────────────────────────────────────────────────────── */
/* While 3D is open the 2D view is hidden by class, not inline style, so print
   can bring it back. (An SVG element has no .hidden property.) */
.svg-frame.fig3d-open { cursor: default; }
.svg-frame.fig3d-open > svg,
.svg-frame.fig3d-open > img,
.svg-frame.fig3d-open > picture { display: none; }

.fig3d-stage {
  padding: 8px 12px 4px;
  cursor: default;
}

.fig3d-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 75vh;
  max-height: 75svh;           /* fits on one screen (docs/3D-FIGURES-PLAN.md §6 rule 11) */
  border-radius: var(--radius-md, 10px);
  overflow: hidden;
  /* A faint well, so the figure reads as an object, not a hole in the card. */
  background: radial-gradient(ellipse at 50% 40%, var(--primary-surface, rgba(37, 99, 235, 0.06)), transparent 70%);
  touch-action: none;
}
.fig3d-viewport:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.fig3d-viewport > canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
.fig3d-viewport > canvas:active { cursor: grabbing; }

.fig3d-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.fig3d-label {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  background: color-mix(in srgb, var(--card-bg) 82%, transparent);
  border-radius: 6px;
  padding: 1px 5px;
  white-space: nowrap;
  pointer-events: none;
}
.fig3d-label--accent { color: var(--clr-warning); }
.fig3d-label--muted { color: var(--text-secondary); font-weight: 500; }
.fig3d-label--atom { background: transparent; padding: 0; font-size: 0.8rem; }
/* The sign of ψ on an orbital lobe (scenes/orbital.js). */
.fig3d-label--sign { font-size: 0.95rem; padding: 0 6px; }

/* ── Legend card ────────────────────────────────────────────────────────── */
.fig3d-legend {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--card-bg);
  border: 1px solid var(--divider-light, var(--border));
  border-radius: 12px;
  font-size: 0.8rem;
  line-height: 1.45;
}
.fig3d-legend[hidden] { display: none; }
.fig3d-legend__title { font-weight: 700; color: var(--text); margin-bottom: 2px; }
.fig3d-legend__row { display: flex; flex-wrap: wrap; gap: 0 8px; justify-content: space-between; }
.fig3d-legend__key { color: var(--text-secondary); }
.fig3d-legend__val { color: var(--text); font-weight: 600; text-align: right; }
.fig3d-legend__note { margin-top: 4px; color: var(--text-secondary); font-size: 0.75rem; }

/* Beside the figure when the stage is wide enough, below it otherwise, so the
   legend never covers the model or its labels. */
.fig3d-stage { container-type: inline-size; }
@container (min-width: 620px) {
  .fig3d-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 230px;
    gap: 12px;
    align-items: start;
  }
  .fig3d-body .fig3d-legend { margin-top: 0; }
}
@media (max-width: 599px) {
  .fig3d-viewport { aspect-ratio: 1 / 1; }
}

/* ── Controls row and stepper ───────────────────────────────────────────── */
.fig3d-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.fig3d-controls__spacer { flex: 1 1 0; min-width: 0; }

.stepper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.stepper__btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  font-weight: 600;
  border: 1px solid var(--divider-light, var(--border));
  border-radius: var(--radius-md, 10px);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}
.stepper__btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.stepper__btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stepper__btn:disabled { opacity: 0.4; cursor: default; }
.stepper__btn[hidden] { display: none; }
.stepper__status {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0 4px;
  overflow-wrap: anywhere;
}

.fig3d-hint {
  margin: 6px 0 4px;
  font-size: 0.72rem;
  color: var(--text-muted, var(--text-secondary));
}

/* ── Posters: a scene's rendered 2D view, one per theme ─────────────────── */
/* <div class="fig3d-poster-wrap"><img class="fig3d-poster fig3d-poster--light">
   <img class="fig3d-poster fig3d-poster--dark"></div> — scripts/render_scene_posters.js */
.fig3d-poster { display: block; width: 100%; height: auto; max-height: 75vh; max-height: 75svh; object-fit: contain; }
.fig3d-poster--dark { display: none; }
[data-theme="dark"] .fig3d-poster--light { display: none; }
[data-theme="dark"] .fig3d-poster--dark { display: block; }
.svg-frame.fig3d-open > .fig3d-poster-wrap { display: none; }

/* ── Print: the 2D figure, never the 3D controls ────────────────────────── */
@media print {
  .fig3d-bar, .fig3d-stage { display: none !important; }
  .svg-frame.fig3d-open > svg,
  .svg-frame.fig3d-open > img,
  .svg-frame.fig3d-open > picture,
  .svg-frame.fig3d-open > .fig3d-poster-wrap { display: block !important; }
  .fig3d-poster--light { display: block !important; }
  .fig3d-poster--dark { display: none !important; }
}
