:root {
  color-scheme: dark;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color: #fff;
  background: #141414;
  --top: max(16px, env(safe-area-inset-top));
  --left: max(16px, env(safe-area-inset-left));
  --right: max(16px, env(safe-area-inset-right));
  --bar-bottom: max(clamp(16px, 4.54vh, 49px), calc(env(safe-area-inset-bottom) + 12px));
  --bar-height: 80px;
  --panel: rgba(28, 28, 28, 0.95);
  --accent: #ffd188;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
img { display: block; }
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 2px #141414;
}

#tour, #viewer-ui, #panorama { position: absolute; inset: 0; }
#tour { overflow: hidden; background: #141414; }
#panorama:focus-visible { outline-offset: -4px; }
#panorama :is(.pnlm-load-box, .pnlm-load-button, .pnlm-about-msg, .pnlm-error-msg) { display: none !important; }
#panorama.view-superseded :is(canvas, .tour-hotspot) { visibility: hidden !important; }

.icon-button {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.icon-button img { width: 37.5px; height: 37.5px; object-fit: contain; pointer-events: none; }
.icon-button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); }
.icon-button:disabled img { opacity: 0.36; }

.control-bar {
  position: absolute;
  z-index: 2;
  bottom: var(--bar-bottom);
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(614px, calc(100% - var(--left) - var(--right)));
  height: var(--bar-height);
  padding-inline: clamp(8px, 7.75vw - 13px, 49px);
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: 999px;
  background: rgba(36, 36, 36, 0.42);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.13), inset 0 0 20px rgba(255, 255, 255, 0.11);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}
.control-group { display: flex; gap: clamp(0px, 2.1vw - 4px, 11px); }

.scene-indicator, .scene-loading {
  position: absolute;
  z-index: 2;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(20, 20, 20, 0.82);
  font-variant-numeric: tabular-nums;
}
.scene-indicator {
  top: max(34px, calc(var(--top) + 4px));
  right: max(40px, var(--right));
  max-width: calc(100% - 32px);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.85rem;
  text-align: right;
}
.scene-loading {
  bottom: calc(var(--bar-bottom) + var(--bar-height) + 12px);
  left: 50%;
  width: min(270px, calc(100% - 32px));
  padding: 10px 14px;
  transform: translateX(-50%);
  border-radius: 10px;
  font-size: 0.85rem;
}
.scene-loading .progress-row { margin-top: 5px; }
.scene-loading .retry-button { margin-top: 8px; }

.minimap {
  position: absolute;
  z-index: 2;
  top: max(40px, var(--top));
  left: max(46px, var(--left));
  width: min(418px, 39vw);
}
.map-surface { position: relative; }
.map-image {
  width: 100%;
  height: auto;
  opacity: 0.8;
  /* The supplied map has a painted chevron in its bottom 12 pixels. */
  clip-path: inset(0 0 8% 0);
}
#map-points { position: absolute; inset: 0; pointer-events: none; }
.map-point {
  position: absolute;
  width: 28px;
  height: 28px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
}
.map-point:hover { background: rgba(255, 255, 255, 0.27); }
#map-position {
  position: absolute;
  width: 9.09%;
  transform: translate(-87%, -50%);
  pointer-events: none;
}
#map-position img { width: 100%; height: auto; transform-origin: 87% 50%; }
.map-collapse {
  position: relative;
  display: grid;
  margin: -26px auto 0;
}
.map-collapse img { width: 21px; height: auto; }
.map-expand {
  display: grid;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
}
.map-expand img { width: 100%; height: auto; }
.map-expand:hover { background: rgba(255, 255, 255, 0.14); }

.loading-screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #141414;
  opacity: 1;
  transition: opacity 500ms ease;
}
.loading-screen.leaving { opacity: 0; }
.loading-content { width: min(100%, 440px); text-align: center; }
.loading-content h1 { margin: 0; font-size: clamp(1.5rem, 5vw, 2.65rem); line-height: 1.15; }
#tour-subtitle { margin: 10px 0 40px; color: #e2e2e2; font-size: clamp(1rem, 3vw, 1.25rem); }
.loading-message { margin: 0 0 10px; color: #ddd; font-size: 0.95rem; }
.loading-content .retry-button { margin: 14px auto 0; }
.progress-row { display: flex; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; }
.progress-row span { width: 4ch; text-align: right; font-size: 0.85rem; }
progress {
  flex: 1;
  width: 100%;
  height: 3px;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  appearance: none;
  background: #545454;
  color: var(--accent);
}
progress::-webkit-progress-bar { background: #545454; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.retry-button {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid #b7b7b7;
  border-radius: 6px;
  background: #373737;
}
.retry-button:hover { background: #4a4a4a; }

.dialog-panel {
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.78);
  background: var(--panel);
}
.dialog-panel::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog-panel h2 { margin: 0; font-size: 1.35rem; }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.dialog-close img { width: 38px; height: 38px; }

.tutorial {
  width: min(1332px, calc(100% - 48px));
  max-width: none;
  max-height: calc(100% - var(--top) - max(16px, env(safe-area-inset-bottom)));
  padding: clamp(24px, 4.63vh, 50px) 0 clamp(16px, 3.65vh, 39px);
  text-align: center;
  border-width: 2px;
  border-radius: 3px;
}
.tutorial h2 { font-size: clamp(1.45rem, 2.3vw, 1.9rem); }
.tutorial-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-block: clamp(20px, 6vh, 65px) clamp(16px, 5vh, 54px); }
.tutorial-step { display: grid; grid-template-rows: auto 1fr; justify-items: center; }
.tutorial-art {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vw, 30px);
  width: 100%;
  min-height: clamp(100px, 15.3vh, 165px);
}
.tutorial-step + .tutorial-step .tutorial-art { border-inline-start: 3px dotted rgba(255, 255, 255, 0.82); }
.tutorial-step p {
  max-width: 22ch;
  margin: clamp(14px, 5vh, 54px) 10px 0;
  font-size: clamp(0.95rem, 1.5vw, 1.25rem);
  line-height: 1.45;
  word-break: keep-all;
}
.mouse-pair { gap: clamp(16px, 3vw, 60px); font-size: clamp(0.85rem, 1.5vw, 1.3rem); }
.mouse {
  position: relative;
  display: block;
  width: clamp(50px, 7vw, 91px);
  aspect-ratio: 91 / 132;
  margin: 0 auto 8px;
  overflow: hidden;
  border: 2px solid #ddd;
  border-radius: 999px;
}
.mouse::after { position: absolute; content: ""; top: 0; height: 35%; background: #f5a623; }
.mouse.move::after { left: 0; width: 50%; border-right: 4px solid #ddd; }
.mouse.zoom::after { left: calc(50% - 3px); width: 6px; }
.navigation-icons img:first-child { width: clamp(36px, 6vw, 49px); height: auto; }
.navigation-icons img:last-child { width: clamp(36px, 6vw, 54px); height: auto; }
.info-icons img { width: clamp(35px, 5vw, 50px); height: auto; }

.scene-drawer {
  inset: var(--top) var(--right) max(16px, env(safe-area-inset-bottom)) auto;
  width: min(360px, calc(100% - 32px));
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
}
.scene-drawer[open] { display: flex; flex-direction: column; }
.scene-drawer .dialog-header, .info-dialog .dialog-header { padding: 10px 14px; }
.scene-list {
  min-height: 0;
  margin: 0;
  padding: 4px 12px 16px;
  overflow-y: auto;
  scroll-padding-block: 4px;
  list-style: none;
}
.scene-list li + li { margin-top: 4px; }
.scene-button {
  display: grid;
  grid-template-columns: 80px 2.5ch minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  text-align: left;
}
.scene-button img { width: 100%; height: auto; aspect-ratio: 2; border-radius: 4px; object-fit: cover; }
.scene-button:hover { background: rgba(255, 255, 255, 0.12); }
.scene-button[aria-current] { background: rgba(255, 209, 136, 0.18); border-color: var(--accent); }
.scene-meta { color: #ddd; font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.info-dialog { width: min(820px, calc(100% - 32px)); max-height: 90%; border-radius: 12px; padding: 0; }
.info-dialog[open] { display: flex; flex-direction: column; }
.info-content { min-height: 0; overflow: auto; padding: 0 18px 18px; }
.info-content :is(img, video) { display: block; width: 100%; max-height: 65vh; object-fit: contain; }
.info-content p { margin: 4px 0; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.dialog-focus-return { position: absolute; width: 1px; height: 1px; opacity: 0; }

.tour-hotspot { width: 50px; height: 50px; }
.hotspot-button { width: 100%; height: 100%; }
.hotspot-button .hotspot-icon { width: 50px; height: 50px; }
.hotspot-button .hotspot-icon.pin { width: auto; height: 62px; margin-top: -12px; }
.hotspot-button .monitor-label {
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  width: clamp(126px, 21vw, 224px);
  height: auto;
  transform: translateY(-50%);
  pointer-events: none;
}

.edit-panel {
  position: absolute;
  z-index: 3;
  right: var(--right);
  bottom: calc(var(--bar-bottom) + var(--bar-height) + 12px);
  width: min(240px, calc(100% - 32px));
  padding: 10px;
  border: 1px solid #a0a0a0;
  border-radius: 8px;
  background: var(--panel);
  font: 0.8rem ui-monospace, monospace;
}
.edit-panel p { margin: 0 0 8px; }
.edit-panel textarea { width: 100%; margin-top: 4px; resize: vertical; }

@media (max-width: 600px) {
  :root {
    --bar-height: 56px;
    --bar-bottom: calc(env(safe-area-inset-bottom) + 16px);
  }
  .control-bar { padding-inline: clamp(0px, 7vw - 24px, 18px); }
  .control-bar .icon-button { width: 40px; height: 44px; }
  .control-bar img { width: 28px; height: 28px; }
  .control-group { gap: 0; }
  .minimap { top: var(--top); left: var(--left); width: min(190px, 42vw); }
  .map-collapse { margin-top: -19px; }
  .scene-indicator { top: calc(var(--top) + 44px); right: var(--right); }
  .tutorial { width: calc(100% - 32px); padding: 16px 14px; }
  .tutorial-grid { grid-template-columns: minmax(0, 1fr); margin: 10px 0; }
  .tutorial-step { padding-block: 8px 10px; }
  .tutorial-step + .tutorial-step { border-top: 2px dotted rgba(255, 255, 255, 0.58); }
  .tutorial-step + .tutorial-step .tutorial-art { border-inline-start: 0; }
  .tutorial-art { min-height: 48px; }
  .tutorial-step p { max-width: 30ch; margin: 6px 0 0; }
  .mouse { width: 34px; margin-bottom: 3px; }
  .navigation-icons img:last-child { height: 47px; width: auto; }
  .scene-drawer {
    inset: auto 0 0;
    width: 100%;
    max-height: 70vh;
    max-height: 70dvh;
    padding: 0 var(--right) env(safe-area-inset-bottom) var(--left);
    border-radius: 14px 14px 0 0;
  }
}

@media (max-width: 354px) {
  .control-bar .control-group { flex: 1; flex-wrap: wrap; justify-content: center; }
  :root { --bar-height: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; scroll-behavior: auto !important; }
}
