/* The whole window: overlays never resize the stream (net.js tells the server what they cover). */
.sv-stage {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: var(--sv-viewport-bg);
}

.sv-viewport {
  position: absolute;
  inset: 0;
}

.sv-viewport video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ?client=webcodecs (webcodecs.js): decoded frames over the empty video, which keeps the input. */
.sv-viewport .sv-wc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* The server's hover pick: what a click there would select. */
.sv-viewport video.is-hot {
  cursor: pointer;
}

/* Edit mode: the selection's body (a press slides it). */
.sv-viewport video.is-move {
  cursor: move;
}

.sv-viewport video:active {
  cursor: grabbing;
}

/* The ring is drawn over the viewport, so the warp canvas and WebCodecs frames don't cover it;
   white either side of the accent keeps it visible over dark frames. */
.sv-viewport video:focus-visible {
  outline: none;
}

.sv-viewport.is-kbd-focus:has(> video:focus)::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--sv-accent), inset 0 0 0 6px #fff;
  pointer-events: none;
}

/* input.js 2D warp: the frame on screen, shifted/scaled over the video while pan or wheel zoom is
   ahead of it; what it uncovers shows the stage background (the render's clear colour). */
.sv-warp {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--sv-viewport-bg);
  pointer-events: none;
}

.sv-warp canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  will-change: transform;
}

/* input.js box select (edit mode): the rectangle being drawn, in stage px. */
.sv-band {
  position: absolute;
  z-index: 2;
  border: 1px solid #2f6bff;
  background: rgb(47 107 255 / 0.1);
  pointer-events: none;
}

.sv-pivot-marker {
  position: absolute;
  z-index: 2;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--sv-accent);
  border-radius: 50%;
  background: rgb(255 255 255 / 0.6);
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.8);
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 160ms ease-out;
  pointer-events: none;
}

.sv-pivot-marker.is-active {
  opacity: 1;
}

/* Hover tooltip: what is under the mouse and what a click does. input.js moves it with
   transform only, flipping it at the stage's right and bottom edges. */
.sv-tip {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  max-width: 240px;
  padding: 6px 10px;
  border: 1px solid var(--sv-border);
  border-radius: 8px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  will-change: transform;
}

.sv-tip__name {
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sv-tip__hint {
  color: var(--sv-faint);
  font-size: 11px;
}

/* Hidden / isolated parts: a pill with the way back, under the top band, centred in the part of
   the stage the drawer and card leave (--sv-l / --sv-r: net.js's insets). */
.sv-visibility {
  position: absolute;
  z-index: 3;
  top: 56px;
  left: calc(var(--sv-l, 0px) + (100% - var(--sv-l, 0px) - var(--sv-r, 0px)) / 2);
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content; /* else left: 50% halves the room it shrinks to fit */
  max-width: calc(100% - var(--sv-l, 0px) - var(--sv-r, 0px) - 32px);
  padding: 3px 3px 3px 12px;
  border: 1px solid var(--sv-border);
  border-radius: 999px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
  font-size: 12px;
  transform: translateX(-50%);
}

.sv-visibility__text {
  min-width: 0;
  overflow: hidden;
  color: var(--sv-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#viewer .sv-visibility__action {
  flex: none;
  min-height: 26px;
  padding: 0 10px;
  border-color: transparent;
  border-radius: 999px;
  color: var(--sv-accent);
  background: var(--sv-accent-soft);
}

#viewer .sv-visibility__action:hover:not(:disabled) {
  background: #dce3fb;
}

@media (pointer: coarse) {
  #viewer .sv-visibility__action {
    min-height: 44px;
  }
}

/* Notices from the server (`notice` on 'ctl'): a pill like the one above, 12 px below it when both show. */
.sv-toast {
  position: absolute;
  z-index: 3;
  top: 56px;
  left: calc(var(--sv-l, 0px) + (100% - var(--sv-l, 0px) - var(--sv-r, 0px)) / 2);
  max-width: calc(100% - var(--sv-l, 0px) - var(--sv-r, 0px) - 32px);
  padding: 6px 14px;
  border: 1px solid var(--sv-border);
  border-radius: 999px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
  color: var(--sv-muted);
  font-size: 12px;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  animation: sv-toast-in 160ms ease-out;
}

.sv-visibility:not([hidden]) + .sv-toast {
  top: calc(56px + 34px + 12px); /* pill: 26px button, 3px padding, 1px border each side */
}

@keyframes sv-toast-in {
  from {
    opacity: 0;
  }
}

@media (pointer: coarse) {
  .sv-visibility:not([hidden]) + .sv-toast {
    top: calc(56px + 52px + 12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sv-toast {
    animation: none;
  }
}

.sv-model-help {
  position: absolute;
  z-index: 1;
  /* above the toolbar, centred in what the drawer and card leave (wraps if that is narrow) */
  bottom: var(--sv-above-dock);
  left: calc(var(--sv-l, 0px) + (100% - var(--sv-l, 0px) - var(--sv-r, 0px)) / 2);
  width: max-content;
  max-width: calc(100% - var(--sv-l, 0px) - var(--sv-r, 0px) - 32px);
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
  text-align: center;
  color: var(--sv-muted);
  font-size: 12px;
  transition: opacity 300ms;
  pointer-events: none;
}

/* Faded once the viewport has been used (main.js), and under an open toolbar menu. */
.sv-model-help.is-done,
.sv-stage:has(.sv-dock__toggle[aria-expanded="true"]) .sv-model-help {
  opacity: 0;
}

.sv-help-touch {
  display: none;
}

@media (pointer: coarse) {
  .sv-help-pointer {
    display: none;
  }

  .sv-help-touch {
    display: inline;
  }
}

/* Status card: connecting, uploading, errors. */
.sv-model-state {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100% - 48px));
  padding: 20px 24px;
  border: 1px solid var(--sv-border);
  border-radius: 12px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
  transform: translate(-50%, -50%);
}

.sv-model-state h3,
.sv-drop__card h2 {
  margin: 0 0 6px;
  color: var(--sv-ink);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.3;
}

.sv-model-state p {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--sv-muted);
}

#viewer .sv-model-state button {
  margin-top: 14px;
}

/* Drop zone: the empty state, and the overlay while a file is dragged over the window. */
.sv-drop {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(236 235 232 / 0.85);
}

/* Same card as the status card and the panel's surfaces; while a file is dragged over the window
   a dashed accent ring marks the target. */
.sv-drop__card {
  width: min(440px, 100%);
  padding: 32px 24px;
  border: 1px solid var(--sv-border);
  border-radius: 12px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
  text-align: center;
  outline: 2px dashed transparent;
  outline-offset: -10px;
  transition: outline-color 120ms, background-color 120ms;
}

.sv-drop.is-dragging .sv-drop__card {
  outline-color: var(--sv-accent);
  background: var(--sv-accent-soft);
}

.sv-drop__card p {
  margin: 0;
  color: var(--sv-muted);
}

#viewer .sv-drop [data-action="open"] {
  margin-top: 18px;
  border-color: var(--sv-accent);
  color: #fff;
  background: var(--sv-accent);
}

#viewer .sv-drop [data-action="open"]:hover:not(:disabled) {
  background: #1f39ad;
}

#viewer .sv-drop__error {
  margin: 16px 0 0;
  overflow-wrap: anywhere;
  color: var(--sv-danger);
}

.sv-drop__card .sv-url {
  justify-content: center;
  margin-top: 14px;
}

#viewer .sv-drop__card .sv-url input {
  flex: 1;
}

.sv-demos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.sv-demos__title {
  margin: 18px 0 8px;
  color: var(--sv-muted);
  font-size: 12px;
  font-weight: 500;
}

#viewer .sv-demos .sv-chip {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 14px;
  font-size: 12px;
}

@media (pointer: coarse) {
  #viewer .sv-demos .sv-chip {
    min-height: 40px;
  }
}

/* Phones (portrait, or landscape with a short height). */
@media (max-width: 760px), (max-width: 1023px) and (max-height: 520px) and (min-aspect-ratio: 301/200) {
  .sv-model-help {
    white-space: nowrap;
  }

  .sv-model-state {
    width: min(420px, calc(100% - 32px));
    padding: 16px 18px;
  }

  .sv-visibility {
    /* under the pill and the stats line */
    top: calc(max(10px, env(safe-area-inset-top)) + 76px);
  }

  .sv-toast {
    top: calc(max(10px, env(safe-area-inset-top)) + 76px);
  }

  .sv-visibility:not([hidden]) + .sv-toast {
    top: calc(max(10px, env(safe-area-inset-top)) + 76px + 46px);
  }

  @media (pointer: coarse) {
    .sv-visibility:not([hidden]) + .sv-toast {
      top: calc(max(10px, env(safe-area-inset-top)) + 76px + 64px);
    }
  }

  .sv-drop__card {
    padding: 28px 18px;
  }
}
