/* ============================================================
   SVG Animation Player — Controls for SMIL-animated SVGs
   Used by: Quarto site (inline SVGs) + svg-viewer.html
   ============================================================ */

/* Container — positioned parent for absolute controls */
.svg-player {
  position: relative;
}
.svg-player > svg,
.svg-player > a > svg,
.svg-player > .svg-toggle-view > svg,
.svg-player > .svg-toggle-view > a > svg {
  display: block;
  text-rendering: geometricPrecision;
  padding-top: 12px;
  padding-bottom: 20px; /* space above player controls */
}
/* Prevent page CSS from affecting inline SVG rendering (scoped to main SVG, not button icons) */
.svg-player > svg text,
.svg-player > svg tspan,
.svg-player > a > svg text,
.svg-player > a > svg tspan {
  line-height: normal !important;
  letter-spacing: normal !important;
  word-spacing: normal !important;
}
.svg-player > a {
  display: block;
  line-height: 0;
}

/* ── Control bar ── */
.svgp-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  background: transparent;
  z-index: 10;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.25s ease;
}

/* Desktop: hide until hover */
@media (hover: hover) and (pointer: fine) {
  .svgp-controls { opacity: 0; }
  .svg-player:hover .svgp-controls { opacity: 1; }
}

/* Touch devices: always visible, slightly dimmed */
@media (hover: none) {
  .svgp-controls { opacity: 0.75; }
}

/* Viewer (standalone page): always visible, dimmed until hover */
[data-viewer] .svgp-controls { opacity: 0.6; }
[data-viewer]:hover .svgp-controls { opacity: 1; }

/* Viewer on mobile: fix controls to viewport bottom */
@media (hover: none) {
  [data-viewer] .svgp-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    opacity: 0.85;
  }
}

/* ── Buttons ── */
.svgp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  color: #444;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.svgp-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #111;
}
.svgp-btn:active {
  transform: scale(0.92);
}
.svgp-btn svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
  display: block;
}

/* Dark buttons */
body.quarto-dark .svgp-btn,
body.dark .svgp-btn {
  color: rgba(224, 228, 240, 0.8);
}
body.quarto-dark .svgp-btn:hover,
body.dark .svgp-btn:hover {
  background: rgba(0, 217, 255, 0.12);
  color: #00d9ff;
}

/* ── Step buttons (right of scrub bar) ── */
.svgp-step-prev,
.svgp-step-next {
  opacity: 0.7;
}
.svgp-step-prev:hover,
.svgp-step-next:hover {
  opacity: 1;
}
.svgp-step-label {
  font: 11px/1 "Jost", system-ui, sans-serif;
  color: rgba(0,0,0,0.5);
  min-width: 70px;
  text-align: center;
  white-space: nowrap;
}
body.quarto-dark .svgp-step-label,
body.dark .svgp-step-label {
  color: rgba(255,255,255,0.5);
}

/* ── Scrub bar ── */
.svgp-scrub {
  flex: 1;
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
.svgp-track {
  width: 100%;
  height: 2px;
  border-radius: 1px;
  background: rgba(0, 0, 0, 0.15);
  overflow: hidden;
  position: relative;
}
.svgp-fill {
  height: 100%;
  width: 100%;
  background: #555;
  border-radius: 1px;
  transform-origin: left center;
  transform: scaleX(0);
  will-change: transform;
}

/* Dark scrub */
body.quarto-dark .svgp-track,
body.dark .svgp-track {
  background: rgba(255, 255, 255, 0.1);
}
body.quarto-dark .svgp-fill,
body.dark .svgp-fill {
  background: linear-gradient(90deg, #00d9ff, #c084fc);
}

/* Thumb */
.svgp-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  will-change: transform;
}
.svgp-scrub:hover .svgp-thumb,
.svgp-scrub.svgp-active .svgp-thumb {
  opacity: 1;
}

/* Dark thumb */
body.quarto-dark .svgp-thumb,
body.dark .svgp-thumb {
  background: #00d9ff;
  box-shadow: 0 0 4px rgba(0, 217, 255, 0.5);
}

/* ── Segmented progress bar (LaTeX step-through) ── */
.svgp-segments {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}
.svgp-seg {
  flex: 1;
  height: 3px;
  border-radius: 1.5px;
  background: rgba(0, 0, 0, 0.12);
  transition: background 0.25s ease;
}
.svgp-seg-filled {
  background: #555;
}

/* Dark segmented bar */
body.quarto-dark .svgp-seg,
body.dark .svgp-seg {
  background: rgba(255, 255, 255, 0.1);
}
body.quarto-dark .svgp-seg-filled,
body.dark .svgp-seg-filled {
  background: linear-gradient(90deg, #00d9ff, #c084fc);
}

/* ============================================================
   SVG Toggle — Static/Animated view switcher
   ============================================================ */

.svg-toggle {
  position: relative;
}
.svg-toggle svg {
  text-rendering: geometricPrecision;
}
.svg-toggle-view svg *,
.svg-toggle svg * {
  transition: none !important;
}
.svg-toggle svg text,
.svg-toggle svg tspan {
  line-height: normal !important;
  letter-spacing: normal !important;
  word-spacing: normal !important;
  text-indent: 0 !important;
  text-transform: none !important;
}
.svg-toggle-view svg {
  display: block;
}

/* Fixed height mode (default): grid overlay, height = max of both views */
.svg-toggle:not(.svg-toggle-flex) {
  display: grid;
  align-items: start;
}
.svg-toggle:not(.svg-toggle-flex) > .svg-toggle-view {
  grid-area: 1 / 1;
}
.svg-toggle:not(.svg-toggle-flex) > .svg-toggle-view:not(.svg-toggle-active) {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Flex mode: hide inactive, animate height */
.svg-toggle-flex > .svg-toggle-view:not(.svg-toggle-active) {
  display: none;
}
.svg-toggle-flex {
  overflow: hidden;
  transition: height 0.3s ease;
}

/* Toggle button */
.svg-toggle-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #444;
  z-index: 11;
  opacity: 0.5;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
}
.svg-toggle-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.95);
  color: #111;
}
.svg-toggle-btn:active {
  transform: scale(0.92);
}
/* Enlarge touch target on coarse-pointer (mobile) devices — 44×44px minimum */
@media (pointer: coarse) {
  .svg-toggle-btn {
    /* Shift visual inward so the invisible hit area doesn't overflow container */
    top: 6px;
    right: 6px;
  }
  .svg-toggle-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
  }
}
.svg-toggle-btn svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
  display: block;
}

/* Dark toggle button */
body.quarto-dark .svg-toggle-btn,
body.dark .svg-toggle-btn {
  background: rgba(30, 30, 40, 0.7);
  color: rgba(224, 228, 240, 0.8);
}
body.quarto-dark .svg-toggle-btn:hover,
body.dark .svg-toggle-btn:hover {
  background: rgba(30, 30, 40, 0.9);
  color: #00d9ff;
}
