/* Shared interactive-result controls used by the docs landing page and mdBook. */
.result-viewer {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #22242b;
}

/* Reserve the plot's framing before JavaScript wraps a guide figure in a viewer. */
[data-result-figure] > img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #22242b;
}

.result-viewer-fallback {
  display: block;
  width: 100%;
  height: auto;
  transition: opacity 180ms ease;
}

.result-viewer .result-viewer-fallback {
  position: absolute;
  inset: 0;
  height: 100%;
  object-fit: contain;
}

.result-viewer canvas {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: grab;
  touch-action: none;
  transition: opacity 180ms ease;
}

.result-viewer canvas:active {
  cursor: grabbing;
}

.result-viewer.is-ready .result-viewer-fallback {
  opacity: 0;
}

.result-viewer.is-ready canvas {
  opacity: 1;
}

/* Only the loading message and orientation axes overlay the canvas. */
.result-viewer .viewer-status {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 5px;
  background: rgb(20 22 27 / 82%);
  color: #e9eaf0;
  font-size: 12px;
  transform: translate(-50%, -50%);
}

.result-viewer.is-ready .viewer-status {
  overflow: hidden;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.result-viewer.is-pan-mode canvas {
  cursor: move;
}

.result-viewer .viewer-axes {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: none;
  width: 96px;
  height: 96px;
  overflow: hidden;
  pointer-events: none;
}

.result-viewer.is-ready .viewer-axes {
  display: block;
}

.result-viewer[data-presentation-only] .viewer-axes {
  display: none;
}

.viewer-shell {
  --result-viewer-accent: var(--vanellus-accent, #00d4a0);
  min-width: 0;
  color: #e9eaf0;
  color-scheme: dark;
  background: #22242b;
}

.viewer-shell [hidden] {
  display: none !important;
}

.viewer-footer {
  padding: 12px;
  border-top: 1px solid rgb(255 255 255 / 12%);
  background: #292c34;
}

.viewer-legend {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 12px;
  padding-bottom: 12px;
  color: #e9eaf0;
  text-align: left;
}

.viewer-legend > span {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 12px;
  font-weight: 600;
}

.viewer-legend-gradient {
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, #3880fa, #ededed, #d11f1f);
}

.viewer-legend[data-viewer-palette="viridis"] .viewer-legend-gradient {
  background: linear-gradient(90deg, #440154, #31688e, #35b779, #fde725);
}

.viewer-legend-labels {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  line-height: 1.3;
}

.viewer-actions,
.viewer-view-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.viewer-actions {
  flex-wrap: wrap;
}

.viewer-view-actions {
  margin-left: auto;
}

.viewer-shell .viewer-actions :is(button, select) {
  min-height: 44px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid #626775;
  border-radius: 5px;
  color: #e9eaf0;
  background: #202229;
  font: inherit;
  font-size: 12px;
  line-height: 1.3;
  text-shadow: none;
  cursor: pointer;
}

/* Hover is neutral; only a persistent mode or open panel gets the green state. */
@media (hover: hover) {
  .viewer-shell .viewer-actions :is(button, select):hover,
  .viewer-variant-choices button:hover {
    border-color: #9299a8;
    background: #30343e;
    color: #fff;
  }
}

.viewer-shell .viewer-actions button:active {
  border-color: #c4c6d1;
  background: #3b404c;
}

.viewer-shell .viewer-actions button:is([aria-pressed="true"], [aria-expanded="true"]) {
  border-color: var(--result-viewer-accent);
  background: #23453f;
  color: #fff;
}

.viewer-shell :is(button, select, input):focus-visible {
  outline: 2px solid var(--result-viewer-accent);
  outline-offset: 2px;
}

.viewer-shell .viewer-view-actions button {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 10px;
}

.viewer-view-actions svg {
  display: block;
  width: 22px;
  height: 22px;
}

.viewer-field {
  flex: 1 1 130px;
  min-width: 0;
  max-width: 220px;
}

.viewer-shell .viewer-actions .viewer-display-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
}

.viewer-display-button svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.viewer-display-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgb(255 255 255 / 12%);
}

.viewer-display-title {
  margin-bottom: 4px;
  color: #c4c6d1;
  font-size: 12px;
  font-weight: 600;
}

.viewer-display-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 4px 12px;
}

.viewer-display-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: #e9eaf0;
  font-size: 12px;
  cursor: pointer;
}

.viewer-display-options input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--result-viewer-accent);
  cursor: pointer;
}

/* Captions keep their space beneath the complete viewer, including its toolbar. */
figure .viewer-shell + figcaption {
  padding: 12px 16px;
  font-size: 14.4px;
  line-height: 21.6px;
  text-align: center;
}

/* Comparison controls sit outside the canvas so choosing a setting never obscures the mesh. */
.viewer-variants {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid rgb(255 255 255 / 12%);
  background: #292c34;
  color: #e9eaf0;
}

.viewer-variant-title {
  font-size: 13px;
  font-weight: 600;
}

.viewer-variant-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.viewer-variant-choices button {
  padding: 9px 14px;
  border: 1px solid #626775;
  border-radius: 5px;
  background: #202229;
  color: #e9eaf0;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.viewer-variant-choices button[aria-pressed="true"] {
  border-color: #72dbc7;
  background: #23453f;
  color: #fff;
}

.viewer-variant-choices button:focus-visible {
  outline: 2px solid #72dbc7;
  outline-offset: 3px;
}

.viewer-variants .viewer-variant-summary {
  margin: 0;
  color: #c4c6d1;
  font-size: 12px;
  line-height: 1.5;
}

/* Keep controls visible while the plot uses the rest of the expanded viewport. */
.viewer-fullscreen-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #22242b;
}

html:has(.viewer-fullscreen-dialog[open]) {
  overflow: hidden;
}

.viewer-shell:fullscreen,
.viewer-fullscreen-dialog .viewer-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

:is(.viewer-shell:fullscreen, .viewer-fullscreen-dialog .viewer-shell) > .result-viewer {
  flex: 1;
  min-height: 0;
  aspect-ratio: auto;
}

:is(.viewer-shell:fullscreen, .viewer-fullscreen-dialog .viewer-shell) > .viewer-footer {
  flex-shrink: 0;
  max-height: 45dvh;
  overflow-y: auto;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

:is(.viewer-shell:fullscreen, .viewer-fullscreen-dialog .viewer-shell) > .viewer-variants {
  flex-shrink: 0;
  max-height: 25dvh;
  overflow-y: auto;
}

@media (max-width: 700px) {
  .tutorial-result-viewer,
  [data-result-figure] > img {
    aspect-ratio: 4 / 3;
  }

  .result-viewer .viewer-axes {
    top: 8px;
    left: 8px;
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 480px) {
  .viewer-field {
    flex-basis: 100%;
    max-width: none;
  }
}
