:root {
  color-scheme: dark;
  --background: #111913;
  --glass: #202a22;
  --glass-border: rgb(170 181 169 / 17%);
  --primary: #78896c;
  --primary-hover: #879879;
  --surface: #18221b;
  --text: #fff;
  --muted: #aab5a9;
  --line: #354136;
  --focus: #d2dfc8;
  --loading: #c8a85a;
  --error: #e79191;
  font: 12px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { padding: 0; border: 0; background: transparent; }
button:enabled { cursor: pointer; }
button:disabled { opacity: .48; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.viewer {
  --inset: 20px;
  --footer-height: 34px;
  --iframe-overscan: 88px;
  --identity-height: 52px;
  --panel-top: 92px;
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}
.viewport {
  position: absolute;
  inset: 0 0 var(--footer-height);
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
}
.viewport iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  /* Match the embedded document's color scheme so its transparent splash shows the black background. */
  color-scheme: light;
}
.viewport[data-asset-ready="true"] iframe {
  /* Clip the native top-right controls above the compass and the bottom watermark. */
  bottom: auto;
  height: calc(100% + var(--iframe-overscan));
  clip-path: polygon(0 0, calc(100% - 230px) 0, calc(100% - 230px) 52px, 100% 52px, 100% 100%, 0 100%);
}
.viewer:has(#compass-control:not([hidden])) .viewport[data-asset-ready="true"] iframe {
  /* Only omit the native compass while the header dial controls the camera. */
  clip-path: polygon(0 0, calc(100% - 230px) 0, calc(100% - 230px) 52px, calc(100% - 64px) 52px,
    calc(100% - 64px) 112px, 100% 112px, 100% 100%, 0 100%);
}
.viewport:not([data-asset-ready="true"]) ~ .toolbar,
.viewport:not([data-asset-ready="true"], [data-asset-picker]) ~ :is(.topbar, .navigation, .panel) {
  display: none;
}
.camera-navigation {
  position: absolute;
  z-index: 1;
  inset: 0 0 var(--footer-height);
  /* Nira centers the pause dialog in the taller iframe. Leave its action row
     open to real pointer events; a parent page cannot relay a trusted click. */
  --actions-left: max(0px, calc(50% - 140px));
  --actions-right: min(100%, calc(50% + 140px));
  --frame-center: calc(50% + var(--iframe-overscan) / 2);
  --actions-top: calc(var(--frame-center) - 14px);
  --actions-bottom: calc(var(--frame-center) + 76px);
  clip-path: polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0,
    var(--actions-left) var(--actions-top), var(--actions-right) var(--actions-top),
    var(--actions-right) var(--actions-bottom), var(--actions-left) var(--actions-bottom),
    var(--actions-left) var(--actions-top), 0 0);
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.camera-navigation[data-tool="Zoom"] { cursor: ns-resize; }
.camera-navigation[data-dragging="true"] { cursor: grabbing; }
.camera-navigation:focus-visible { outline-offset: -3px; }
.compass-control {
  display: block;
  flex: none;
  width: var(--identity-height);
  height: var(--identity-height);
  border-radius: 50%;
  background: #111a13;
  box-shadow: 0 5px 18px #0003;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.compass-control:hover { outline: 1px solid #c2cdb5; outline-offset: 2px; }
.compass-control:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.compass-control:active { cursor: grabbing; }
.compass-control svg { display: block; width: 100%; height: 100%; pointer-events: none; }
#compass-rotor { transform-box: view-box; transform-origin: 50% 50%; transition: transform 80ms linear; }
.empty { color: var(--muted); text-align: center; padding: 20px; }
.glass {
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  background: var(--glass);
  box-shadow: 0 8px 28px rgb(0 0 0 / 22%);
}
.topbar {
  position: absolute;
  z-index: 4;
  top: var(--inset);
  left: var(--inset);
  right: var(--inset);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.identity, .viewer-actions, #back-to-studio { pointer-events: auto; }
.identity-group { display: flex; align-items: center; gap: 12px; min-width: 0; }
.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: var(--identity-height);
  padding: 6px 14px 6px 6px;
}
.identity img { flex: 0 0 auto; object-fit: contain; }
.identity .return-gallery { width: 36px; height: 36px; }
.identity-text { display: grid; min-width: 0; gap: 2px; line-height: 1.35; }
.identity-text h1, .identity-text span {
  margin: 0;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.identity-text h1 { font-weight: 600; }
.identity-text span { max-width: min(30vw, 280px); color: var(--muted); }
.viewer-actions { display: flex; gap: 8px; }
.action {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 12px;
  border-radius: 10px;
}
.action:hover { background: var(--line); }
.action svg { width: 17px; height: 17px; }
.navigation {
  position: absolute;
  z-index: 5;
  top: var(--panel-top);
  left: var(--inset);
  display: grid;
  gap: 6px;
  padding: 6px;
}
.icon-button {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  transition: background-color 120ms;
}
.icon-button svg { width: 21px; height: 21px; }
.icon-button:not(:disabled):hover { background: rgb(255 255 255 / 7%); }
.icon-button[aria-pressed="true"], .icon-button[aria-expanded="true"],
.icon-button[aria-pressed="true"]:hover, .icon-button[aria-expanded="true"]:hover {
  color: var(--background);
  background: var(--primary);
}
.tooltip {
  position: absolute;
  top: 50%;
  left: calc(100% + 14px);
  z-index: 8;
  width: max-content;
  padding: 6px 9px;
  transform: translateY(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--background);
  visibility: hidden;
  pointer-events: none;
}
.icon-button:hover .tooltip, .icon-button:focus-visible .tooltip { visibility: visible; }
.panel {
  position: absolute;
  z-index: 4;
  top: var(--panel-top);
  left: 90px;
  display: flex;
  flex-direction: column;
  width: 340px;
  max-height: calc(100% - var(--panel-top) - 156px - var(--footer-height));
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px 7px 20px;
  border-bottom: 1px solid var(--line);
}
.panel-header h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-header svg { width: 18px; height: 18px; }
.panel-body { padding: 16px 20px 20px; overflow: auto; overscroll-behavior: contain; }
.panel-body h3 { margin: 0 0 12px; font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.panel-section { margin-top: 20px; }
.panel-section h3 { font-size: 12px; }
.data { margin: 0; }
.data div { display: grid; grid-template-columns: 95px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.data dt, .muted { color: var(--muted); }
.data dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
form { display: grid; gap: 8px; }
input { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; background: var(--surface); }
input::placeholder { color: var(--muted); }
.button {
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.button:enabled:hover { border-color: var(--primary-hover); }
.primary, .button[aria-pressed="true"] { color: var(--background); background: var(--primary); font-weight: 600; }
.error { margin: 0; color: var(--error); }
.alternatives { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.background-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
#background-color { width: 48px; padding: 4px; cursor: pointer; }
.panel-link { display: inline-flex; align-items: center; }
.asset-settings { margin-top: 10px; }
#asset-form { margin-top: 16px; }
.callout-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.callout-list li { display: flex; gap: 6px; }
.callout-list .legend-delete { width: 40px; flex: none; justify-content: center; color: var(--muted); }
.callout-list .legend-delete:enabled:hover { color: var(--error); border-color: currentColor; }
#legend-delete-status:empty { margin: 0; }
.callout-list .button[data-uuid] { flex: 1; min-width: 0; text-align: left; }
.legend-tools { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.legend-tools label { display: inline-flex; align-items: center; gap: 8px; }
.legend-tools input { width: 16px; min-height: 16px; margin: 0; accent-color: var(--primary-hover); }
.callout-list button { display: flex; align-items: center; gap: 10px; overflow-wrap: anywhere; }
.callout-list svg { width: 18px; height: 18px; flex: none; }
.callout-list small { display: block; font-size: 11px; }
.legend-detail { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.legend-detail h3 { margin-bottom: 8px; font-size: 15px; }
.legend-vertices { display: grid; gap: 8px; list-style: none; margin: 10px 0; padding: 0; font-variant-numeric: tabular-nums; }
.legend-vertices span { display: block; color: var(--muted); overflow-wrap: anywhere; }
.legend-description { white-space: pre-wrap; overflow-wrap: anywhere; }
.legend-media :is(video,iframe) { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 8px; background: #000; }
#legend-form { margin-top: 12px; }
#legend-form summary { cursor: pointer; }
#legend-form label { display: block; margin-top: 10px; }
#legend-form textarea { width: 100%; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--text); font: inherit; }
#legend-save { margin-top: 8px; }
.altimeter {
  position: absolute;
  z-index: 2;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 106px;
  text-align: right;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px #0005);
}
.altimeter-title { margin-bottom: 6px; font-weight: 500; text-shadow: 0 1px 3px #000; }
.altimeter-tape {
  position: relative;
  height: 224px;
  overflow: hidden;
  border-right: 2px solid #d2dfc8;
  background: linear-gradient(90deg, transparent, #18221b99);
}
#altimeter-ticks { position: absolute; top: 50%; right: 0; }
.altimeter-tick {
  position: absolute;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateY(-50%);
  font: 11px/1 monospace;
}
.altimeter-tick::after { content: ""; width: 12px; border-top: 1px solid #d2dfc8; }
.altimeter-readout {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  min-width: 84px;
  padding: 7px 9px;
  border: 1px solid #aab5a9;
  border-radius: 8px 0 0 8px;
  background: #18221b;
  font: 600 17px/1.3 monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.altimeter-readout small { color: #c1cbc0; font: 11px/1 sans-serif; }
.altimeter-caption { position: absolute; right: 0; top: 100%; margin-top: 7px; font-size: 11px; text-shadow: 0 1px 3px #000; }

.toolbar {
  position: absolute;
  z-index: 3;
  bottom: calc(var(--footer-height) + var(--inset));
  left: 50%;
  display: flex;
  gap: 6px;
  padding: 7px;
  transform: translateX(-50%);
}
.toolbar .icon-button { width: 46px; height: 46px; }
.toolbar .tooltip { top: auto; bottom: calc(100% + 13px); left: 50%; transform: translateX(-50%); }
.tool-divider { margin: 8px 2px; border-left: 1px solid var(--line); }
.minimap {
  position: absolute;
  z-index: 2;
  bottom: calc(var(--footer-height) + 20px);
  left: 20px;
  width: 152px;
  overflow: hidden;
  border: 1px solid #495749;
  border-radius: 12px;
  background: #18221bf2;
  box-shadow: 0 8px 24px #0003;
}
.minimap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 500;
}
.minimap-header span { color: #aab5a9; font-variant-numeric: tabular-nums; }
.minimap-header:hover { background: #ffffff10; }
.minimap button:focus-visible { outline-offset: -3px; }
#map-target, #map-target svg { display: block; width: 100%; }
#map-target { cursor: crosshair; }
.minimap-label { padding: 0 10px 8px; font-size: 10px; color: #c1cbc0; }
.footer {
  position: absolute;
  z-index: 4;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 var(--inset);
  border-top: 1px solid var(--line);
  background: var(--background);
  color: var(--muted);
  font-size: 11px;
}
.status { display: inline-flex; align-items: center; min-width: 0; gap: 7px; }
.status i { flex: 0 0 6px; height: 6px; border-radius: 50%; background: var(--loading); }
.status i[data-state="ready"] { background: var(--primary); }
.status i[data-state="error"] { background: var(--error); }
#share-status { flex-shrink: 0; }
#share-status:empty { display: none; }
.viewer[data-immersive="true"] :is(.identity,.viewer-actions,.navigation,.panel,.toolbar,.minimap,.altimeter,.footer) { display: none; }
.viewer[data-immersive="true"] :is(.viewport, .camera-navigation) { bottom: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 1023px) { .panel { width: 310px; } }
@media (max-width: 600px) {
  .viewer { --inset: 12px; --panel-top: 80px; }
  .topbar { gap: 6px; }
  .identity-group { gap: 8px; }
  .identity { gap: 5px; padding-right: 8px; }
  .identity .return-gallery { width: 28px; }
  .identity-text span { max-width: 110px; }
  .viewer-actions { gap: 4px; }
  .viewer-actions .action { width: 38px; min-height: 44px; padding: 0; }
  .viewer-actions .action span { display: none; }
  .panel { left: 76px; width: calc(100% - 88px); }
  .panel-header, .panel-body { padding-left: 13px; }
  .panel-body { padding-right: 13px; }
  .toolbar { gap: 3px; padding: 5px; }
  .toolbar .icon-button { width: clamp(40px, 12vw, 44px); height: 44px; }
}
@media (max-width: 700px) {
  .minimap { left: 12px; bottom: 124px; width: 112px; border-radius: 10px; }
  .minimap-header { padding: 8px 8px 0; }
  .minimap-header span, .altimeter-caption { font-size: 10px; }
  .minimap-label { padding: 0 8px 8px; }
  .altimeter { right: 12px; width: 84px; }
  .altimeter-title { font-size: 11px; }
  .altimeter-tape { height: 184px; }
  .altimeter-readout { min-width: 74px; padding-inline: 5px; font-size: 15px; }
}
@media (max-height: 520px) {
  .minimap { left: 90px; bottom: calc(var(--footer-height) + 12px); width: 96px; }
  .minimap-label { display: none; }
  .minimap-header { font-size: 10px; padding-inline: 8px; }
  .altimeter-tape { height: 124px; }
}
@media (max-height: 520px) and (max-width: 740px) {
  .minimap { bottom: calc(var(--footer-height) + 90px); }
}
@media (orientation: landscape) and (max-height: 380px) {
  /* Keep the tools below the iframe, clear of its dialog buttons. */
  .viewer { --footer-height: 64px; }
  .toolbar { left: auto; right: var(--inset); bottom: 1px; transform: none; }
  .footer { right: min(65%, 368px); flex-wrap: wrap; align-content: center; gap: 4px; }
  .minimap { bottom: calc(var(--footer-height) + 12px); }
}
@media (max-width: 370px) {
  .topbar { flex-wrap: wrap; }
  .viewer-actions { margin-left: auto; }
  .viewer { --panel-top: 124px; }
}
@media (prefers-reduced-motion: reduce) { .icon-button, #compass-rotor { transition: none; } }
