/* Both the owner and share player use the same viewport geometry. */
body.viewer-open {
  overflow: hidden;
}

#viewerDialog,
#publicViewer {
  max-width: none;
  max-height: none;
  overflow: hidden;
}

#viewerShell,
#publicViewerShell {
  min-width: 0;
  min-height: 0;
}

#viewerStage,
#publicViewerStage {
  min-width: 0;
  min-height: 0;
}

#viewerStage .panorama-canvas,
#publicViewerStage .panorama-canvas {
  width: 100%;
}

#viewerShell:fullscreen,
#publicViewerShell:fullscreen {
  display: block;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
}

#viewerShell:fullscreen .viewer-stage,
#publicViewerShell:fullscreen .viewer-stage,
#viewerShell:fullscreen .panorama-canvas,
#publicViewerShell:fullscreen .panorama-canvas {
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-height: none;
}

#viewerDialog.native-fullscreen,
#publicViewer.native-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
}

#viewerDialog.native-fullscreen .viewer-head,
#publicViewer.native-fullscreen .viewer-head {
  display: none;
}

#viewerDialog.native-fullscreen .viewer-shell,
#publicViewer.native-fullscreen .viewer-shell,
#viewerDialog.native-fullscreen .viewer-stage,
#publicViewer.native-fullscreen .viewer-stage,
#viewerDialog.native-fullscreen .panorama-canvas,
#publicViewer.native-fullscreen .panorama-canvas {
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  max-height: none;
}

@media (max-width: 760px) {
  #viewerDialog,
  #publicViewer {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
  }

  #viewerDialog:not([open]),
  #publicViewer:not([open]) {
    display: none;
  }

  #viewerDialog .viewer-head,
  #publicViewer .viewer-head {
    flex: 0 0 auto;
  }

  #viewerShell,
  #publicViewerShell {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
  }

  #viewerStage,
  #publicViewerStage,
  #viewerStage .panorama-canvas,
  #publicViewerStage .panorama-canvas {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  #viewerShell:fullscreen,
  #publicViewerShell:fullscreen,
  #viewerShell:fullscreen .viewer-stage,
  #publicViewerShell:fullscreen .viewer-stage,
  #viewerShell:fullscreen .panorama-canvas,
  #publicViewerShell:fullscreen .panorama-canvas {
    height: 100dvh;
    min-height: 100dvh;
  }

  #viewerDialog.native-fullscreen .viewer-shell,
  #publicViewer.native-fullscreen .viewer-shell,
  #viewerDialog.native-fullscreen .viewer-stage,
  #publicViewer.native-fullscreen .viewer-stage,
  #viewerDialog.native-fullscreen .panorama-canvas,
  #publicViewer.native-fullscreen .panorama-canvas {
    height: 100dvh;
    min-height: 100dvh;
  }

  #publicViewer .public-options {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
  }

  #publicViewer .public-options label {
    display: block;
    min-width: 0;
    font-size: 0;
  }

  #publicViewer .public-options label:first-child {
    grid-column: 1 / -1;
  }

  #publicViewer .public-options label select {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: .9rem;
  }

  #publicViewer .public-options .edge-option,
  #viewerDialog .viewer-options label:nth-of-type(3) {
    display: none;
  }

  #publicViewer .public-options #publicFullscreen {
    min-width: 70px;
  }

  #viewerDialog .viewer-options {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
  }

  #viewerDialog .viewer-options label {
    display: block;
    min-width: 0;
    font-size: 0;
  }

  #viewerDialog .viewer-options label:first-child {
    grid-column: 1 / -1;
  }

  #viewerDialog .viewer-options label select {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: .9rem;
  }
}

/* On phones, controls sit below the picture. Fullscreen uses an auto-hiding overlay. */
@media (max-width: 760px), (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #viewerDialog, #publicViewer { background: #050b09; }

  #viewerDialog, #publicViewer {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
  }
  #viewerDialog:not([open]), #publicViewer:not([open]) { display: none; }
  #viewerDialog .viewer-head, #publicViewer .viewer-head { flex: 0 0 auto; }

  #viewerShell, #publicViewerShell {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }
  #viewerStage, #publicViewerStage {
    flex: 1 1 auto;
    order: 0;
    height: auto;
    min-height: 0;
  }
  #viewerDialog .panorama-canvas, #publicViewer .panorama-canvas {
    height: 100%;
    min-height: 0;
  }
  #viewerDialog .viewer-hud:not(.hidden),
  #publicViewer .viewer-hud:not(.hidden) {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    flex: 0 0 auto;
    order: 2;
    width: 100%;
    max-height: min(42dvh, 300px);
    overflow-y: auto;
    padding: 8px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: var(--panel);
  }
  #viewerDialog .viewer-status,
  #publicViewer .viewer-status {
    position: static;
    order: 1;
    flex: 0 0 auto;
    padding: 5px 12px;
    background: #13231e;
    text-shadow: none;
  }
  #viewerDialog .viewer-status:empty,
  #publicViewer .viewer-status:empty { display: none; }

  #viewerDialog .timeline-row,
  #publicViewer .timeline-row {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    min-width: 0;
    gap: 8px;
  }
  #viewerDialog .timeline,
  #publicViewer .timeline { min-width: 0; width: 100%; min-height: 44px; }
  #viewerDialog .viewer-options,
  #publicViewer .public-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 7px;
    align-items: end;
  }
  #viewerDialog .viewer-options label,
  #publicViewer .public-options label,
  #viewerDialog .viewer-options label:nth-of-type(3) {
    display: grid;
    grid-column: auto;
    gap: 3px;
    min-width: 0;
    font-size: .75rem;
  }
  #viewerDialog .viewer-options label:first-child,
  #publicViewer .public-options label:first-child { grid-column: auto; }
  #viewerDialog .viewer-options label:last-of-type,
  #publicViewer .public-options .edge-option { display: none; }
  #viewerDialog .viewer-options select,
  #publicViewer .public-options select { min-width: 0; min-height: 44px; width: 100%; font-size: .875rem; }
  #gyroButton, #publicGyro, #fullscreenButton, #publicFullscreen {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 44px;
  }
  #publicViewer .public-options .download-link {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  #viewerShell:fullscreen .viewer-hud:not(.hidden),
  #publicViewerShell:fullscreen .viewer-hud:not(.hidden),
  #viewerDialog.native-fullscreen .viewer-hud:not(.hidden),
  #publicViewer.native-fullscreen .viewer-hud:not(.hidden) {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 50dvh;
    border: 0;
    background: linear-gradient(transparent, #000e 30%, #000e);
  }
  #viewerShell:fullscreen .viewer-status,
  #publicViewerShell:fullscreen .viewer-status,
  #viewerDialog.native-fullscreen .viewer-status,
  #publicViewer.native-fullscreen .viewer-status {
    position: absolute;
    top: max(8px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    padding: 4px 8px;
    background: #0009;
  }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #viewerDialog .viewer-head,
  #publicViewer .viewer-head { min-height: 44px; padding: 4px 12px; }
  #viewerDialog .viewer-head p,
  #publicViewer .viewer-head p { display: none; }
  #viewerDialog .viewer-head h2,
  #publicViewer .viewer-head h2 { max-width: 75vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; }
  #viewerDialog .icon-button,
  #publicViewer .icon-button { min-height: 40px; }

  #viewerDialog .viewer-hud:not(.hidden),
  #publicViewer .viewer-hud:not(.hidden) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    max-height: min(52dvh, 200px);
    padding: 5px max(8px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  #viewerDialog .viewer-options,
  #publicViewer .public-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 0;
  }
  #viewerDialog .viewer-options label,
  #publicViewer .public-options label { gap: 0; font-size: 0; }
  #fullscreenButton, #publicFullscreen { grid-column: auto; }
}

#viewerDialog .playback-line-button,
#publicViewer .playback-line-button {
  flex: 0 0 auto;
  white-space: nowrap;
}

@media (max-width: 760px) {
  #viewerDialog .playback-line-button,
  #publicViewer .playback-line-button {
    min-height: 44px;
    justify-self: stretch;
  }
}

/* Keep fullscreen media out of the grid's intrinsic track sizing. */
:is(#viewerShell:fullscreen, #publicViewerShell:fullscreen,
    #viewerDialog.native-fullscreen, #publicViewer.native-fullscreen) .viewer-stage {
  position: relative;
  flex: 0 0 auto;
  height: 100dvh;
  min-height: 0;
}

:is(#viewerShell:fullscreen, #publicViewerShell:fullscreen,
    #viewerDialog.native-fullscreen, #publicViewer.native-fullscreen)
    .viewer-stage > :is(video, img):not(.panorama-source) {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  object-fit: contain;
}

@media (max-width: 760px) {
  #viewerPlaybackLine, #publicPlaybackLine {
    min-width: 52px;
    min-height: 44px;
    padding: 6px 8px;
    white-space: nowrap;
  }
  #publicDownloadButton { min-width: 52px; min-height: 44px; padding: 6px 9px; white-space: nowrap; }
}

/* Compact player: one primary row, advanced controls only on demand. */
#viewerDialog .viewer-hud:not(.hidden),
#publicViewer .viewer-hud:not(.hidden) {
  overflow: visible !important;
  max-height: none !important;
  padding: 24px 18px 12px;
}
#viewerDialog .timeline-row,
#publicViewer .timeline-row {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
#viewerDialog .timeline-row .viewer-button,
#publicViewer .timeline-row .viewer-button {
  min-height: 38px;
  padding: 6px 10px;
  white-space: nowrap;
}
#viewerDialog .settings-button,
#publicViewer .settings-button {
  min-width: 52px;
}
#viewerDialog .viewer-settings-panel,
#publicViewer .viewer-settings-panel {
  position: absolute;
  right: 18px;
  bottom: calc(100% + 10px);
  z-index: 12;
  width: min(430px, calc(100vw - 32px));
  max-height: min(62dvh, 520px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0f1e19f7;
  box-shadow: 0 18px 50px #000b;
  backdrop-filter: blur(14px);
}
#viewerDialog .settings-head,
#publicViewer .settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
#viewerDialog .settings-head strong,
#publicViewer .settings-head strong {
  font-size: .86rem;
}
#viewerDialog .settings-close,
#publicViewer .settings-close {
  padding: 0;
  width: 34px;
  min-height: 34px;
  font-size: 1.5rem;
  line-height: 1;
}
#viewerDialog .settings-grid,
#publicViewer .settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  align-items: end;
}
#viewerDialog .settings-grid label,
#publicViewer .settings-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: .72rem;
}
#viewerDialog .settings-grid select,
#publicViewer .settings-grid select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 9px;
  font-size: .82rem;
}
#viewerDialog .settings-grid input[type="range"],
#publicViewer .settings-grid input[type="range"] {
  width: 100%;
  min-height: 38px;
  padding: 0;
}
#viewerDialog .settings-grid .viewer-button,
#publicViewer .settings-grid .viewer-button {
  width: 100%;
  min-height: 38px;
  padding: 7px 9px;
  font-size: .8rem;
}
#viewerDialog #viewerPlaybackLine,
#publicViewer #publicPlaybackLine {
  grid-column: 1 / -1;
}
#viewerDialog .settings-downloads,
#publicViewer .settings-downloads {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}
#viewerDialog .settings-downloads a,
#publicViewer .settings-downloads a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #182824;
  color: var(--text);
  font-size: .78rem;
  text-decoration: none;
}
#viewerDialog .settings-downloads a:hover,
#publicViewer .settings-downloads a:hover {
  border-color: var(--accent);
  color: var(--accent);
}
@media (max-width: 760px) {
  #viewerDialog .viewer-hud:not(.hidden),
  #publicViewer .viewer-hud:not(.hidden) {
    padding: 8px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  #viewerDialog .timeline-row,
  #publicViewer .timeline-row {
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    gap: 6px;
  }
  #viewerDialog #durationTime,
  #viewerDialog #bufferStatus,
  #publicViewer #publicDuration,
  #publicViewer #publicBuffer {
    display: none;
  }
  #viewerDialog .viewer-settings-panel,
  #publicViewer .viewer-settings-panel {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: calc(100% + 8px);
    max-height: 56dvh;
    padding: 10px;
  }
}
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #viewerDialog .viewer-hud:not(.hidden),
  #publicViewer .viewer-hud:not(.hidden) {
    padding: 5px max(8px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  #viewerDialog .timeline-row,
  #publicViewer .timeline-row {
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    gap: 6px;
  }
  #viewerDialog .viewer-settings-panel,
  #publicViewer .viewer-settings-panel {
    max-height: 62dvh;
  }
}

#viewerDialog #fullscreenButton,
#publicViewer #publicFullscreen {
  grid-column: auto;
  width: auto;
}
@media (max-width: 760px) {
  #viewerDialog .timeline-row .viewer-button,
  #publicViewer .timeline-row .viewer-button {
    min-height: 44px;
  }
}

#viewerDialog .viewer-hud.photo-mode .timeline-row,
#publicViewer .viewer-hud.photo-mode .timeline-row {
  display: flex;
  justify-content: flex-end;
}
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #viewerDialog .viewer-hud:not(.hidden),
  #publicViewer .viewer-hud:not(.hidden) {
    display: block;
  }
}
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #viewerDialog #durationTime,
  #viewerDialog #bufferStatus,
  #publicViewer #publicDuration,
  #publicViewer #publicBuffer {
    display: none;
  }
}
