:root {
  --carbon: #090b0c;
  --carbon-soft: #111518;
  --zinc: #c7d1d4;
  --zinc-muted: #89969a;
  --brass: #d9a93a;
  --copper: #c76a3a;
  --glass: rgba(13, 17, 18, 0.76);
  --hairline: rgba(224, 230, 230, 0.22);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-left: max(18px, env(safe-area-inset-left));
  --safe-right: max(18px, env(safe-area-inset-right));
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  color: var(--zinc);
  background: var(--carbon);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--carbon);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.stage,
.viewer {
  position: absolute;
  inset: 0;
}

.stage {
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, #20282a 0, var(--carbon) 68%);
}

.viewer {
  z-index: 0;
  background: transparent;
}

.viewer .openseadragon-canvas:focus {
  outline: none;
}

.stage::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0.28), transparent 14%),
    linear-gradient(to top, rgba(0, 0, 0, 0.4), transparent 25%);
  opacity: 0.8;
}

.back-button {
  position: absolute;
  z-index: 10;
  top: var(--safe-top);
  left: var(--safe-left);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 15px 0 11px;
  color: #f2f5f5;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: rgba(7, 9, 10, 0.67);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
  text-decoration: none;
  font-size: 14px;
  font-weight: 590;
  letter-spacing: 0.02em;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.back-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-button:hover {
  border-color: rgba(217, 169, 58, 0.62);
  background: rgba(7, 9, 10, 0.84);
  transform: translateX(-2px);
}

.back-button:focus-visible,
.play-button:focus-visible,
.map-control:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

.loading-panel {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: rgba(235, 239, 239, 0.88);
  background: var(--carbon);
  font-size: 13px;
  letter-spacing: 0.1em;
  transition:
    opacity 500ms ease,
    visibility 500ms ease;
}

.loading-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.loading-orbit {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(199, 209, 212, 0.24);
  border-top-color: var(--brass);
  border-right-color: var(--copper);
  border-radius: 50%;
  animation: loading-spin 1.2s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(1turn);
  }
}

.navigator-shell {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: var(--safe-bottom);
  width: clamp(250px, 29vw, 370px);
  margin: 0;
  transform: translateX(-50%);
  user-select: none;
  -webkit-user-select: none;
}

.map-control {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(215, 222, 223, 0.3);
  border-radius: 50%;
  background: transparent;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.42),
    0 2px 10px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(217, 169, 58, 0.1);
  cursor: crosshair;
  touch-action: none;
}

.map-control::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  background: transparent;
}

.preview-image,
.trajectory {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.map-control {
  --ring-mask: radial-gradient(
    circle at center,
    transparent 0 52%,
    #000 52% 85%,
    transparent 85%
  );
}

.preview-image {
  object-fit: contain;
  filter: saturate(0.74) contrast(1.05) brightness(0.74);
  -webkit-mask-image: var(--ring-mask);
  mask-image: var(--ring-mask);
  transition: filter 180ms ease;
}

.map-control:hover .preview-image,
.map-control.is-dragging .preview-image {
  filter: saturate(0.9) contrast(1.04) brightness(0.85);
}

.trajectory {
  overflow: visible;
  pointer-events: none;
  -webkit-mask-image: var(--ring-mask);
  mask-image: var(--ring-mask);
}

.trajectory-halo,
.trajectory-line,
.radial-line,
.position-handle {
  vector-effect: non-scaling-stroke;
}

.trajectory-halo {
  fill: none;
  stroke: rgba(0, 0, 0, 0.74);
  stroke-width: 5px;
}

.trajectory-line {
  fill: none;
  stroke: rgba(238, 195, 85, 0.92);
  stroke-width: 1.7px;
  stroke-dasharray: 3 5;
}

.radial-line {
  stroke: rgba(238, 195, 85, 0.54);
  stroke-width: 1px;
  stroke-dasharray: 2 4;
}

.position-handle {
  fill: rgba(235, 183, 55, 0.58);
  stroke: rgba(255, 229, 154, 0.88);
  stroke-width: 1.8px;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.82));
}

.sample-mark,
.angle-readout {
  position: absolute;
  z-index: 2;
  left: 50%;
  pointer-events: none;
  color: var(--brass);
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  text-shadow: 0 1px 7px rgba(0, 0, 0, 0.95);
  transform: translate(-50%, -50%);
}

.sample-mark {
  top: 45%;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
}

.sample-mark span:first-child {
  font-size: clamp(20px, 2.1vw, 27px);
  font-weight: 650;
  letter-spacing: 0.03em;
}

.sample-mark span:last-child {
  margin-top: 6px;
  color: rgba(217, 169, 58, 0.76);
  font-size: clamp(7px, 0.72vw, 10px);
  font-weight: 480;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.angle-readout {
  top: 64%;
  color: rgba(244, 203, 101, 0.92);
  font-size: clamp(14px, 1.35vw, 18px);
  font-variant-numeric: tabular-nums;
  font-weight: 520;
  letter-spacing: 0.08em;
}

.play-button {
  position: absolute;
  z-index: 10;
  top: var(--safe-top);
  right: var(--safe-right);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #f2f5f5;
  border: 1px solid rgba(234, 238, 238, 0.32);
  border-radius: 50%;
  background: rgba(7, 9, 10, 0.69);
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition:
    background-color 160ms ease,
    transform 160ms ease;
}

.play-button:hover {
  background: rgba(7, 9, 10, 0.88);
  transform: scale(1.06);
}

.play-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.play-button .play-icon {
  display: none;
  fill: currentColor;
  stroke: none;
}

.play-button.is-paused .pause-icon {
  display: none;
}

.play-button.is-paused .play-icon {
  display: block;
}

.error-panel {
  position: absolute;
  z-index: 12;
  top: 50%;
  left: 50%;
  width: min(88vw, 420px);
  padding: 22px 24px;
  color: #eef2f2;
  border: 1px solid rgba(199, 106, 58, 0.5);
  border-radius: 12px;
  background: rgba(18, 14, 12, 0.93);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  text-align: center;
}

.error-panel strong,
.error-panel span {
  display: block;
}

.error-panel strong {
  margin-bottom: 8px;
  color: #f0bc9f;
  font-size: 15px;
}

.error-panel span {
  color: rgba(238, 242, 242, 0.72);
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 680px) {
  .navigator-shell {
    width: min(72vw, 300px);
  }

  .back-button {
    min-height: 40px;
  }

}

@media (max-height: 560px) and (orientation: landscape) {
  .navigator-shell {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: auto;
    width: min(31vw, 245px);
    transform: none;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
