*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --overlay-bg: rgba(28, 32, 38, 0.72);
  --overlay-border: rgba(255, 255, 255, 0.08);
  --text: #f4f6f8;
  --text-muted: rgba(244, 246, 248, 0.75);
  --accent: #4db8e8;
  --accent-glow: rgba(77, 184, 232, 0.45);
  --scrollbar-thumb: rgba(255, 255, 255, 0.22);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.38);
  --scrollbar-track: rgba(255, 255, 255, 0.06);
  --control-size: 52px;
  --font: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: #0e1014;
  color: var(--text);
}

.viewer {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

@supports (height: 100svh) {
  .viewer {
    height: 100svh;
  }
}

.viewer__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.viewer__canvas--hidden {
  visibility: hidden;
  pointer-events: none;
  z-index: 0;
}

#panorama:not(.viewer__canvas--hidden) {
  z-index: 1;
}

#flat-image:not(.viewer__canvas--hidden) {
  z-index: 1;
  background-color: #111;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

/* 平铺水印层 */
.viewer__watermark {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background-repeat: repeat;
}

.viewer__watermark--image {
  background-position: center, 0 0;
  background-repeat: no-repeat, repeat;
  background-size: auto 18%, 260px 180px;
}

#panorama .pnlm-container {
  background: #111;
}

/* 隐藏 Pannellum 自带缩放、全屏按钮 */
#panorama .pnlm-zoom-controls,
#panorama .pnlm-fullscreen-toggle,
#panorama .pnlm-orientation-button,
#panorama .pnlm-compass {
  display: none !important;
}

/* 隐藏右键 Pannellum 版权菜单 */
#panorama .pnlm-about-msg {
  display: none !important;
  visibility: hidden !important;
}

/* 叠加层 */
.overlay {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}

.overlay > * {
  pointer-events: auto;
}

/* 左上信息：设计稿 195 × 556 */
.overlay--info {
  top: 20px;
  left: 20px;
  width: 195px;
  height: 556px;
  box-sizing: border-box;
  padding: 14px 12px;
  background: var(--overlay-bg);
  border: 1px solid var(--overlay-border);
  border-radius: 4px;
  backdrop-filter: blur(8px);
  line-height: 1.55;
  font-size: 12px;
  /* 面板本身是 .overlay，需开启指针事件才能拖动滚动条、选中文字 */
  pointer-events: auto;
  -webkit-user-select: text;
  user-select: text;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.overlay--info::-webkit-scrollbar {
  width: 4px;
}

.overlay--info::-webkit-scrollbar-track {
  margin: 6px 0;
  background: var(--scrollbar-track);
  border-radius: 4px;
}

.overlay--info::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
  min-height: 32px;
}

.overlay--info::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.overlay--info::-webkit-scrollbar-button,
.overlay--info::-webkit-scrollbar-corner {
  display: none;
  width: 0;
  height: 0;
}

.overlay--info:hover {
  scrollbar-color: var(--scrollbar-thumb-hover) var(--scrollbar-track);
}

.info__row {
  margin-bottom: 8px;
}

.info__row:last-child {
  margin-bottom: 0;
}

.info__label {
  color: var(--text-muted);
  white-space: nowrap;
}

.info__row--desc .info__label {
  display: block;
  margin-bottom: 4px;
}

#description {
  color: var(--text);
  display: block;
  word-break: break-word;
}

/* 右侧控制 */
.overlay--controls {
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.control-btn {
  position: relative;
  width: var(--control-size);
  height: var(--control-size);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.2s;
}

.control-btn__icon {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.control-btn:hover {
  opacity: 0.9;
  transform: scale(1.04);
}

.control-btn--active {
  opacity: 1;
}

.control-btn--hidden {
  display: none !important;
}

/* 左下：隐藏场景栏 */
.overlay--toggle-bar {
  left: 20px;
  bottom: 24px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 11;
}

.toggle-bar__icon {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.overlay--toggle-bar:hover {
  opacity: 0.9;
  transform: scale(1.04);
}

/* 底部场景栏 */
.overlay--scenes {
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--overlay-bg);
  border: 1px solid var(--overlay-border);
  border-radius: 6px;
  backdrop-filter: blur(10px);
  transition: opacity 0.25s, transform 0.25s, visibility 0.25s;
  max-width: calc(100vw - 100px);
}

.overlay--scenes--hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(12px);
  pointer-events: none;
}

.scenes {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.scenes::-webkit-scrollbar {
  height: 4px;
}

.scenes::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 2px;
}

.scenes::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.scene-thumb {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--text);
}

.scene-thumb__preview {
  width: 88px;
  height: 56px;
  border-radius: 3px;
  border: 2px solid transparent;
  background-color: #222;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  transition: border-color 0.2s, box-shadow 0.2s;
  display: block;
  -webkit-user-drag: none;
  user-drag: none;
}

.scene-thumb__label {
  font-size: 12px;
  color: var(--text-muted);
  transition: color 0.2s;
}

.scene-thumb:hover .scene-thumb__preview {
  border-color: rgba(255, 255, 255, 0.35);
}

.scene-thumb--active .scene-thumb__preview {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.scene-thumb--active .scene-thumb__label {
  color: var(--accent);
}

/* 移动端顶部标题（桌面端隐藏） */
.overlay--mobile-header {
  display: none;
}

@media (max-width: 640px) {
  :root {
    --control-size: 44px;
    --mobile-thumb-h: 58px;
    --mobile-label-h: 26px;
    --mobile-bar-height: calc(var(--mobile-thumb-h) + 6px + var(--mobile-label-h));
    --mobile-safe-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    --mobile-toggle-gap: 12px;
    --mobile-section-gap: 14px;
  }

  .overlay--mobile-header,
  .overlay--controls,
  .overlay--toggle-bar,
  .overlay--scenes {
    position: fixed;
  }

  /* 隐藏桌面信息面板，改用顶部标题 */
  .overlay--info {
    display: none;
  }

  .overlay--mobile-header {
    display: block;
    top: max(12px, env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 48px);
    max-width: 320px;
    text-align: center;
    pointer-events: none;
  }

  .mobile-header__title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.45;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.65);
    word-break: break-word;
  }

  .mobile-header__designer {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.88);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  }

  .info__row--desc {
    display: none;
  }

  /* 右侧模式按钮：在图片列表上方 */
  .overlay--controls {
    top: auto;
    right: 16px;
    bottom: calc(
      var(--mobile-safe-bottom) + var(--control-size) + var(--mobile-toggle-gap) +
        var(--mobile-bar-height) + var(--mobile-section-gap)
    );
    transform: none;
    gap: 14px;
  }

  .control-btn {
    border: none;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .control-btn__icon {
    width: 100%;
    height: 100%;
  }

  .control-btn--active {
    filter: none;
    box-shadow: none;
  }

  .control-btn:hover {
    transform: none;
  }

  /* rm 按钮：最底部左下角 */
  .overlay--toggle-bar {
    left: 16px;
    bottom: var(--mobile-safe-bottom);
    width: var(--control-size);
    height: var(--control-size);
    border: none;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .toggle-bar__icon {
    width: 100%;
    height: 100%;
  }

  .overlay--toggle-bar:hover {
    transform: none;
  }

  /* 图片列表：在 rm 按钮上方，居中横向滚动 */
  .overlay--scenes {
    left: 50%;
    right: auto;
    bottom: calc(var(--mobile-safe-bottom) + var(--control-size) + var(--mobile-toggle-gap));
    width: calc(100% - 24px);
    transform: translateX(-50%);
    max-width: none;
    padding: 0;
    overflow: visible;
    background: transparent;
    border: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .overlay--scenes--hidden {
    transform: translateX(-50%) translateY(16px);
  }

  .scenes {
    display: flex;
    width: 100%;
    gap: 12px;
    align-items: flex-end;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 8px 4px;
    scroll-padding-inline: 8px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }

  .scenes.scenes--fit {
    justify-content: center;
    overflow-x: hidden;
    touch-action: auto;
  }

  .scenes::-webkit-scrollbar {
    display: none;
  }

  .scene-thumb {
    flex: 0 0 auto;
    width: 92px;
    gap: 6px;
    scroll-snap-align: center;
  }

  .scene-thumb__preview {
    width: 100%;
    height: var(--mobile-thumb-h);
    border-radius: 4px;
    border-width: 2px;
  }

  .scene-thumb__label {
    position: static;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    min-height: var(--mobile-label-h);
    padding: 4px 10px;
    font-size: 11px;
    line-height: 1.35;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: rgba(52, 55, 60, 0.82);
    border-radius: 999px;
    pointer-events: none;
    box-sizing: border-box;
  }

  .scene-thumb--active .scene-thumb__label {
    color: #fff;
  }

  .scene-thumb--active .scene-thumb__preview {
    border-color: var(--accent);
    box-shadow: none;
  }

  /* 普通图移动端铺满屏幕 */
  #flat-image:not(.viewer__canvas--hidden) {
    background-size: cover;
  }
}
