.fri3d-diagram {
  --fd-border: color-mix(in srgb, currentColor 17%, transparent);
  --fd-surface: var(--md-default-bg-color, #fff);
  --fd-subtle: color-mix(in srgb, currentColor 5%, transparent);
  --fd-accent: var(--md-accent-fg-color, #526cfe);
  --fri3d-sidebar-width: 280px;
  width: 100%;
  max-width: none;
  margin: 1rem 0 1.5rem;
}

.fri3d-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.fri3d-diagram__loading,
.fri3d-diagram__error {
  padding: 1rem;
  border: 1px solid var(--fd-border);
  border-radius: .7rem;
}

.fri3d-diagram__shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6px var(--fri3d-sidebar-width);
  width: 100%;
  min-height: 440px;
  height: clamp(460px, 52vw, 700px);
  overflow: hidden;
  border: 1px solid var(--fd-border);
  border-radius: .75rem;
  background: var(--fd-surface);
  isolation: isolate;
}

.fri3d-diagram__stage {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: var(--fd-surface);
}

.fri3d-diagram__stage.is-panning {
  cursor: grabbing;
}

.fri3d-diagram__stage:focus-visible {
  outline: 2px solid var(--fd-accent);
  outline-offset: -2px;
}

.fri3d-diagram__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.fri3d-toolbar {
  position: absolute;
  z-index: 10;
  top: .7rem;
  left: .7rem;
  display: flex;
  gap: 1px;
  padding: 3px;
  border: 1px solid var(--fd-border);
  border-radius: .55rem;
  background: color-mix(in srgb, var(--fd-surface) 94%, transparent);
  box-shadow: 0 3px 14px rgb(0 0 0 / .12);
  backdrop-filter: blur(10px);
}

.fri3d-toolbar button {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: .38rem;
  background: transparent;
  color: inherit;
  font: 700 1rem/1 system-ui, sans-serif;
  cursor: pointer;
}

.fri3d-toolbar button:hover,
.fri3d-toolbar button:focus-visible {
  background: color-mix(in srgb, currentColor 9%, transparent);
  outline: none;
}

.fri3d-tooltip {
  position: absolute;
  z-index: 11;
  max-width: min(360px, calc(100% - 20px));
  padding: .68rem .75rem;
  border-radius: .55rem;
  background: #111;
  color: #fff;
  box-shadow: 0 8px 24px rgb(0 0 0 / .2);
  pointer-events: none;
  font-size: .75rem;
  line-height: 1.42;
}

.fri3d-tooltip strong,
.fri3d-tooltip span {
  display: block;
}

.fri3d-tooltip strong {
  margin-bottom: .25rem;
  font-size: .82rem;
}

.fri3d-tooltip span {
  opacity: .82;
}

.fri3d-real-node,
.fri3d-real-edge {
  transition: opacity .12s ease, filter .12s ease;
}

.fri3d-real-node {
  cursor: pointer;
}

.fri3d-real-node.is-fri3d-muted {
  opacity: .48;
}

.fri3d-real-node.is-fri3d-related,
.fri3d-real-node.is-fri3d-selected {
  opacity: 1;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--fd-accent) 75%, transparent));
}

.fri3d-real-edge.is-fri3d-muted {
  opacity: .30;
}

.fri3d-real-edge.is-fri3d-active {
  opacity: 1;
  filter: drop-shadow(0 0 2px color-mix(in srgb, var(--fd-accent) 65%, transparent));
}

.fri3d-real-edge.is-fri3d-active path,
.fri3d-real-edge.is-fri3d-active polyline,
.fri3d-real-edge.is-fri3d-active line {
  stroke: var(--fd-accent) !important;
  stroke-width: 2.5px !important;
  vector-effect: non-scaling-stroke;
}

.fri3d-resizer {
  position: relative;
  z-index: 7;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  touch-action: none;
}

.fri3d-resizer::before {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: var(--fd-border);
  transition: background .12s ease;
}

.fri3d-resizer:hover::before,
.fri3d-resizer:focus-visible::before,
.fri3d-resizer.is-resizing::before {
  background: var(--fd-accent);
}

.fri3d-resizer:focus-visible {
  outline: none;
}

html.fri3d-resizing,
html.fri3d-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.fri3d-index {
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr) auto;
  overflow: hidden;
  background: color-mix(in srgb, var(--fd-surface) 98%, currentColor 2%);
}

.fri3d-index__header {
  padding: .75rem;
  border-bottom: 1px solid var(--fd-border);
}

.fri3d-index__header > div {
  margin-bottom: .55rem;
}

.fri3d-index__header strong {
  display: block;
  font-size: .88rem;
}

.fri3d-index__header span {
  display: block;
  margin-top: .15rem;
  font-size: .65rem;
  opacity: .62;
}

.fri3d-search input {
  box-sizing: border-box;
  width: 100%;
  height: 2rem;
  padding: .3rem .55rem;
  border: 1px solid var(--fd-border);
  border-radius: .45rem;
  background: var(--fd-surface);
  color: inherit;
  font: inherit;
  font-size: .72rem;
}

.fri3d-search input:focus {
  border-color: var(--fd-accent);
  outline: 1px solid var(--fd-accent);
}

.fri3d-index__list {
  min-height: 120px;
  overflow-y: auto;
  padding: .3rem;
}

.fri3d-index__group + .fri3d-index__group {
  margin-top: .3rem;
}

.fri3d-index__group > h4 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: .42rem .45rem .25rem;
  background: color-mix(in srgb, var(--fd-surface) 96%, transparent);
  color: inherit;
  font-size: .61rem;
  font-weight: 750;
  letter-spacing: .05em;
  text-transform: uppercase;
  opacity: .62;
}

.fri3d-index__item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .45rem;
  margin: 0;
  padding: .48rem .52rem;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.fri3d-index__item:hover,
.fri3d-index__item:focus-visible,
.fri3d-index__item.is-active {
  background: color-mix(in srgb, var(--fd-accent) 11%, transparent);
  outline: none;
}

.fri3d-index__item.is-selected {
  background: color-mix(in srgb, var(--fd-accent) 16%, transparent);
  box-shadow: inset 3px 0 0 var(--fd-accent);
}

.fri3d-index__name {
  min-width: 0;
  font-size: .73rem;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.fri3d-index__kind {
  max-width: 6rem;
  padding: .12rem .3rem;
  border: 1px solid var(--fd-border);
  border-radius: 999px;
  font-size: .52rem;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: .035em;
  opacity: .58;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fri3d-index__empty,
.fri3d-empty {
  margin: .7rem;
  font-size: .7rem;
  opacity: .6;
}

.fri3d-index__detail {
  max-height: 48%;
  overflow-y: auto;
  padding: .78rem;
  border-top: 1px solid var(--fd-border);
  background: var(--fd-surface);
}

.fri3d-index__detail[hidden] {
  display: none;
}

.fri3d-index__detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.fri3d-chip {
  display: inline-block;
  padding: .18rem .42rem;
  border: 1px solid var(--fd-border);
  border-radius: 999px;
  font-size: .58rem;
  font-weight: 700;
}

.fri3d-index__detail h3 {
  margin: .48rem 0 .5rem;
  font-size: .98rem;
  line-height: 1.25;
  white-space: pre-line;
}

.fri3d-index__detail h4 {
  margin: .9rem 0 .35rem;
  font-size: .72rem;
}

.fri3d-index__detail p {
  margin: .35rem 0;
  font-size: .72rem;
  line-height: 1.48;
}

.fri3d-index__unpin {
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: 999px;
  background: var(--fd-subtle);
  color: inherit;
  cursor: pointer;
  font: 700 1rem/1 system-ui, sans-serif;
}

.fri3d-index__unpin:hover,
.fri3d-index__unpin:focus-visible {
  background: color-mix(in srgb, currentColor 12%, transparent);
  outline: none;
}

.fri3d-node-meta {
  display: grid;
  gap: .25rem;
  margin: .65rem 0;
  padding: .5rem .58rem;
  border: 1px solid var(--fd-border);
  border-radius: .45rem;
  background: var(--fd-subtle);
  font-size: .68rem;
}

.fri3d-node-meta div {
  display: flex;
  justify-content: space-between;
  gap: .8rem;
}

.fri3d-node-meta dt {
  font-weight: 700;
}

.fri3d-node-meta dd {
  margin: 0;
}

.fri3d-connection-group + .fri3d-connection-group {
  margin-top: .55rem;
}

.fri3d-connection-group h5 {
  margin: 0 0 .2rem;
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .045em;
  opacity: .58;
}

.fri3d-connection-group ul {
  margin: 0;
  padding-left: 1rem;
  font-size: .68rem;
  line-height: 1.4;
}

.fri3d-connection-group li + li {
  margin-top: .25rem;
}

.fri3d-connection-group li span {
  display: block;
  opacity: .62;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .61rem;
}

.fri3d-more {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-weight: 700;
  text-decoration: none;
}

.fri3d-diagram__shell:fullscreen,
.fri3d-diagram__shell.is-pseudo-fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--fd-surface);
}

.fri3d-diagram__shell.is-pseudo-fullscreen {
  position: fixed;
  z-index: 10000;
  inset: 0;
}

html.fri3d-no-scroll {
  overflow: hidden;
}

@media (max-width: 760px) {
  .fri3d-diagram__shell,
  .fri3d-diagram__shell:fullscreen,
  .fri3d-diagram__shell.is-pseudo-fullscreen {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 1fr) minmax(210px, 38%);
    height: min(84vh, 760px);
  }

  .fri3d-resizer {
    display: none;
  }

  .fri3d-index {
    border-top: 1px solid var(--fd-border);
  }

  .fri3d-index__detail {
    max-height: 46%;
  }
}


/* v20 — deliberately simple, stable sidebar UX */
.fri3d-index {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: var(--fd-surface);
}

.fri3d-index__header {
  flex: 0 0 auto;
  padding: .75rem .8rem;
  border-bottom: 1px solid var(--fd-border);
}

.fri3d-index__header strong {
  display: block;
  font-size: .85rem;
}

.fri3d-index__header span {
  margin-top: .12rem;
  font-size: .64rem;
  opacity: .55;
}

.fri3d-index__list {
  flex: 1 1 auto;
  min-height: 100px;
  padding: .35rem;
  overflow-y: auto;
}

.fri3d-index__item {
  display: block;
  width: 100%;
  padding: .5rem .55rem;
  border: 0;
  border-radius: .35rem;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.fri3d-index__item:hover,
.fri3d-index__item:focus-visible {
  background: color-mix(in srgb, currentColor 6%, transparent);
  outline: none;
}

.fri3d-index__item.is-active {
  background: color-mix(in srgb, var(--fd-accent) 8%, transparent);
}

.fri3d-index__item.is-selected {
  background: color-mix(in srgb, var(--fd-accent) 13%, transparent);
  box-shadow: inset 3px 0 0 var(--fd-accent);
}

.fri3d-index__name {
  display: block;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: pre-line;
}

.fri3d-index__detail {
  flex: 0 0 auto;
  max-height: 52%;
  padding: .8rem;
  overflow-y: auto;
  border-top: 1px solid var(--fd-border);
  background: var(--fd-surface);
}

.fri3d-index__detail-head {
  align-items: flex-start;
}

.fri3d-index__detail-head h3 {
  margin: .35rem 0 0;
}

.fri3d-node-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .8rem;
  padding: .45rem .55rem;
}

.fri3d-node-meta span {
  font-size: .66rem;
}

.fri3d-connections {
  margin: .3rem 0 .75rem;
  padding: 0;
  list-style: none;
}

.fri3d-connections li {
  padding: .35rem 0;
  border-bottom: 1px solid color-mix(in srgb, currentColor 8%, transparent);
  font-size: .68rem;
}

.fri3d-connections li:last-child {
  border-bottom: 0;
}

.fri3d-connections li strong,
.fri3d-connections li span {
  display: block;
}

.fri3d-connections li span {
  margin-top: .08rem;
  opacity: .58;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .61rem;
}

/* Old grouped/search UI is intentionally gone in v20. */
.fri3d-search,
.fri3d-index__group,
.fri3d-index__kind,
.fri3d-connection-group {
  display: none !important;
}


/* v22 — one sidebar, one state */
.fri3d-index {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--fd-surface);
}

.fri3d-index__header {
  flex: 0 0 auto;
}

.fri3d-index__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.fri3d-index__list,
.fri3d-index__detail {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain; /* wheel past the list end must not scroll the page */
  box-sizing: border-box;
}

.fri3d-index__list {
  padding: .35rem;
}

.fri3d-index__detail {
  max-height: none;
  padding: .8rem;
  border-top: 0;
}

.fri3d-index__detail[hidden],
.fri3d-index__list[hidden] {
  display: none !important;
}

.fri3d-index__back {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  margin: 0 0 .75rem;
  padding: .3rem .4rem;
  border: 0;
  border-radius: .35rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: .7rem;
  font-weight: 600;
  opacity: .72;
}

.fri3d-index__back:hover,
.fri3d-index__back:focus-visible {
  background: color-mix(in srgb, currentColor 7%, transparent);
  opacity: 1;
  outline: none;
}

/* The old split-pane detail behavior is intentionally disabled. */
.fri3d-index__unpin {
  display: none !important;
}


/* v23 — connections are plain interactive rows, no bullets/dots */
.fri3d-connections {
  display: block;
  margin: .25rem 0 .75rem;
  padding: 0;
}

.fri3d-connection-row {
  display: block;
  width: 100%;
  padding: .48rem .5rem;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, currentColor 8%, transparent);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.fri3d-connection-row:last-child {
  border-bottom: 0;
}

.fri3d-connection-row:hover,
.fri3d-connection-row:focus-visible {
  background: color-mix(in srgb, var(--fd-accent) 9%, transparent);
  outline: none;
}

.fri3d-connection-row strong,
.fri3d-connection-row span {
  display: block;
}

.fri3d-connection-row strong {
  font-size: .7rem;
  font-weight: 650;
  line-height: 1.3;
}

.fri3d-connection-row span {
  margin-top: .08rem;
  opacity: .6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .61rem;
  line-height: 1.35;
}

/* Disable obsolete list styling from earlier versions. */
.fri3d-connections li {
  display: none !important;
}


/* v24 — physical board inside the shell: sidebar spans the full component
   height and sticks while scrolling; front/back switch floats over the board. */
.fri3d-diagram__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* With a board below the diagram the shell grows with its content. The page
   scrolls past it while the sidebar sticks — sticky needs a non-clipping
   shell, so overflow:hidden goes and the corner rounding moves to children. */
.fri3d-diagram--has-physical .fri3d-diagram__shell {
  height: auto;
  overflow: visible;
}

.fri3d-diagram--has-physical .fri3d-diagram__stage {
  flex: 0 0 auto;
  height: auto;
  aspect-ratio: var(--fri3d-stage-aspect, 3 / 2);
  min-height: 320px;
  max-height: min(76vh, 700px);
  border-radius: .75rem 0 0 0;
}

/* The sidebar layout wrapper. In the sticky layout this is the element that
   sticks and gets the viewport cap, so the grid item itself can stay
   size-contained. */
.fri3d-index__inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* No percentage heights below the wrapper — they don't resolve under its
   auto height + max-height clamp (the list then grows to full content and
   the bottom items get clipped). Flex hands out the real space instead. */
.fri3d-index__body {
  display: flex;
  flex-direction: column;
}

.fri3d-index__list,
.fri3d-index__detail {
  height: auto;
  flex: 1 1 auto;
  min-height: 0;
}

/* The sidebar must contribute ZERO height to the grid row — otherwise a long
   component list (or a zoomed-out page) stretches the row and leaves an empty
   band under the board. contain:size lets the diagram+board column alone set
   the row height; the inner wrapper does the sticking. */
.fri3d-diagram--has-physical .fri3d-index {
  contain: size;
  display: block;
  height: auto;
  overflow: visible;
}

.fri3d-diagram--has-physical .fri3d-index__inner {
  position: sticky;
  top: 2.9rem; /* just below the sticky Material header */
  height: auto;
  /* Cap by the viewport AND by the component column (as a measured length —
     a % can't resolve against the size-contained cell): keeps the list
     scrollable within the viewport and stops it hanging out of the component
     bottom over the page text below. */
  max-height: min(var(--fri3d-column-h, 100vh), calc(100vh - 3.5rem));
  background: var(--fd-surface);
  border-radius: 0 .75rem .75rem 0;
}

.fri3d-physical {
  border-top: 1px solid var(--fd-border);
  background: var(--fd-surface);
  border-radius: 0 0 0 .75rem;
}

/* (Pseudo) fullscreen keeps the whole component — diagram, board, sidebar.
   The left column scrolls when diagram + board exceed the screen height. */
.fri3d-diagram--has-physical .fri3d-diagram__shell:fullscreen,
.fri3d-diagram--has-physical .fri3d-diagram__shell.is-pseudo-fullscreen {
  height: 100vh;
  overflow: hidden;
}

.fri3d-diagram__shell:fullscreen .fri3d-diagram__main,
.fri3d-diagram__shell.is-pseudo-fullscreen .fri3d-diagram__main {
  min-height: 0;
  overflow-y: auto;
}

.fri3d-diagram--has-physical .fri3d-diagram__shell:fullscreen .fri3d-diagram__stage,
.fri3d-diagram--has-physical .fri3d-diagram__shell.is-pseudo-fullscreen .fri3d-diagram__stage {
  max-height: 80vh;
  border-radius: 0;
}

/* Diagrams without a board keep the stage filling the screen. */
.fri3d-diagram:not(.fri3d-diagram--has-physical) .fri3d-diagram__shell:fullscreen .fri3d-diagram__stage,
.fri3d-diagram:not(.fri3d-diagram--has-physical) .fri3d-diagram__shell.is-pseudo-fullscreen .fri3d-diagram__stage {
  flex: 1 1 auto;
  height: 100%;
  border-radius: 0;
}

.fri3d-diagram__shell:fullscreen .fri3d-index,
.fri3d-diagram__shell.is-pseudo-fullscreen .fri3d-index {
  contain: none;
  display: flex;
  overflow: hidden;
  position: static;
  height: 100%;
  max-height: none;
}

.fri3d-diagram__shell:fullscreen .fri3d-index__inner,
.fri3d-diagram__shell.is-pseudo-fullscreen .fri3d-index__inner {
  position: static;
  max-height: none;
}

.fri3d-physical__toggle {
  position: absolute;
  z-index: 6;
  top: .7rem;
  left: .7rem;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--fd-border);
  border-radius: .55rem;
  background: color-mix(in srgb, var(--fd-surface) 94%, transparent);
  box-shadow: 0 3px 14px rgb(0 0 0 / .12);
  backdrop-filter: blur(10px);
}

.fri3d-physical__toggle button {
  padding: .34rem .85rem;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: .68rem;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
}

.fri3d-physical__toggle button:hover,
.fri3d-physical__toggle button:focus-visible {
  background: color-mix(in srgb, currentColor 9%, transparent);
  outline: none;
}

.fri3d-physical__toggle button.is-active {
  background: color-mix(in srgb, var(--fd-accent) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--fd-accent) 45%, transparent);
}

.fri3d-physical__stage {
  position: relative;
  display: flex;
  justify-content: center;
  padding: .9rem;
}

.fri3d-physical__board {
  position: relative;
  max-width: 100%;
  margin: 0;
}

.fri3d-physical__board[hidden] {
  display: none;
}

.fri3d-physical__board img {
  display: block;
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.fri3d-physical__overlay {
  position: absolute;
  inset: 0;
}

.fri3d-physical__hotspot {
  position: absolute;
  box-sizing: border-box;
  padding: 0;
  border: 2px solid transparent;
  border-radius: .45rem;
  background: transparent;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease;
}

.fri3d-physical__hotspot > span {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(100% + 5px);
  width: max-content;
  max-width: 180px;
  padding: .28rem .4rem;
  border-radius: .35rem;
  background: #111;
  color: #fff;
  font: 650 .62rem/1.25 system-ui, sans-serif;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 3px);
  transition: opacity .1s ease, transform .1s ease;
}

/* Highlights sit on top of a photo, so contrast comes from a white inner
   ring against the accent ring, plus a pulsing glow. */
.fri3d-physical__hotspot:hover,
.fri3d-physical__hotspot:focus-visible,
.fri3d-physical__hotspot.is-active {
  border-color: #fff;
  background: color-mix(in srgb, var(--fd-accent) 30%, transparent);
  animation: fri3d-hotspot-pulse 1.2s ease-in-out infinite;
  outline: none;
}

.fri3d-physical__hotspot.is-selected {
  border-color: #fff;
  background: color-mix(in srgb, var(--fd-accent) 42%, transparent);
  animation: fri3d-hotspot-pulse-selected 1.2s ease-in-out infinite;
}

@keyframes fri3d-hotspot-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 2px var(--fd-accent),
      0 0 0 4px rgb(255 255 255 / .55),
      0 0 10px 2px color-mix(in srgb, var(--fd-accent) 85%, transparent);
  }
  50% {
    box-shadow:
      0 0 0 3px var(--fd-accent),
      0 0 0 6px rgb(255 255 255 / .28),
      0 0 26px 9px color-mix(in srgb, var(--fd-accent) 95%, transparent);
  }
}

@keyframes fri3d-hotspot-pulse-selected {
  0%, 100% {
    box-shadow:
      0 0 0 3px var(--fd-accent),
      0 0 0 5px rgb(255 255 255 / .7),
      0 0 14px 4px var(--fd-accent);
  }
  50% {
    box-shadow:
      0 0 0 4px var(--fd-accent),
      0 0 0 8px rgb(255 255 255 / .35),
      0 0 34px 12px var(--fd-accent);
  }
}

/* Hotspot editor (?fri3d-edit) */
.fri3d-editor-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .8rem;
  padding: .55rem .8rem;
  border-bottom: 1px solid var(--fd-border);
  background: color-mix(in srgb, var(--fd-accent) 7%, var(--fd-surface));
  font-size: .7rem;
}

.fri3d-editor-bar strong {
  font-size: .78rem;
}

.fri3d-editor-bar span {
  flex: 1 1 16rem;
  opacity: .65;
  line-height: 1.35;
}

.fri3d-editor-bar button {
  padding: .35rem .7rem;
  border: 1px solid var(--fd-border);
  border-radius: .4rem;
  background: var(--fd-surface);
  color: inherit;
  font: inherit;
  font-size: .68rem;
  font-weight: 650;
  cursor: pointer;
}

.fri3d-editor-bar button:hover,
.fri3d-editor-bar button:focus-visible {
  border-color: var(--fd-accent);
  outline: none;
}

.fri3d-editor-output {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: .7rem .8rem;
  border: 0;
  border-top: 1px solid var(--fd-border);
  background: var(--fd-surface);
  color: inherit;
  font: .66rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.fri3d-physical.is-editing .fri3d-physical__hotspot {
  border: 1.5px dashed color-mix(in srgb, var(--fd-accent) 75%, transparent);
  background: color-mix(in srgb, var(--fd-accent) 10%, transparent);
  animation: none !important;
  cursor: move;
}

.fri3d-physical.is-editing .fri3d-physical__hotspot.is-unmatched {
  border-color: #e5484d;
  background: rgb(229 72 77 / .14);
}

.fri3d-physical.is-editing .fri3d-physical__hotspot.is-editor-selected {
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--fd-accent), 0 0 14px color-mix(in srgb, var(--fd-accent) 70%, transparent);
}

.fri3d-physical__handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 3px;
  background: var(--fd-accent);
  cursor: nwse-resize;
}

@media (prefers-reduced-motion: reduce) {
  .fri3d-physical__hotspot:hover,
  .fri3d-physical__hotspot:focus-visible,
  .fri3d-physical__hotspot.is-active,
  .fri3d-physical__hotspot.is-selected {
    animation: none;
    box-shadow:
      0 0 0 3px var(--fd-accent),
      0 0 0 5px rgb(255 255 255 / .6),
      0 0 18px 5px color-mix(in srgb, var(--fd-accent) 90%, transparent);
  }
}

.fri3d-physical__hotspot:hover > span,
.fri3d-physical__hotspot:focus-visible > span {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .fri3d-diagram--has-physical .fri3d-diagram__shell {
    grid-template-rows: auto auto;
    height: auto;
  }

  .fri3d-diagram--has-physical .fri3d-diagram__stage {
    height: auto;
    min-height: 240px;
    max-height: min(64vh, 520px);
    border-radius: .75rem .75rem 0 0;
  }

  .fri3d-diagram--has-physical .fri3d-index {
    contain: none;
    display: flex;
    overflow: hidden;
    align-self: stretch;
    height: auto;
    max-height: 45vh;
    border-radius: 0 0 .75rem .75rem;
  }

  .fri3d-diagram--has-physical .fri3d-index__inner {
    position: static;
    max-height: none;
    border-radius: 0;
  }

  .fri3d-physical {
    border-radius: 0;
  }

  .fri3d-physical__stage {
    padding: .6rem;
  }
}
