/* 拍照屋 3D 展示
   颜色取自模型本身的材质：粉末喷涂白、深青搪瓷、触控薄荷绿、琥珀色电源线、影棚灰。 */

:root {
  --studio: #dde2df;
  --studio-light: #eaedeb;
  --studio-deep: #ccd3cf;
  --powder: #eef1ed;
  --enamel: #20464a;
  --enamel-ink: #17312f;
  --muted: #4b6668;
  --mint: #70c7b8;
  --amber: #c98a4f;
  --amber-deep: #8f5525;
  --line: rgba(32, 70, 74, 0.18);
  --font-cjk: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB",
    "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC",
    system-ui, sans-serif;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-cjk);
  color: var(--enamel-ink);
  background: radial-gradient(130% 75% at 50% 38%, var(--studio-light) 0%, var(--studio) 55%, var(--studio-deep) 100%);
  background-color: var(--studio);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--amber-deep);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------ 版面
   第一行是 3D 视口（所有浮层叠在这一格里），第二行是操作区。
   操作区不压在模型上，机位构图就是用户真正看到的构图。 */
.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

model-viewer,
.hint,
.sheet,
.loader,
.veil {
  grid-row: 2;
  grid-column: 1;
}

model-viewer {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: transparent;
  --min-hotspot-opacity: 0;
  --progress-bar-height: 0;
  outline: none;
}

/* ------------------------------------------------------------ 标题 */
.masthead {
  grid-row: 1;
  grid-column: 1;
  z-index: 2;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
}

.masthead h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--enamel);
}

/* ------------------------------------------------------------ 热点
   按钮本身是 44 px 的触控区，中心对准模型上的点；标签挂在圆点右侧。 */
.hotspot {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.hotspot-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow:
    0 0 0 2px var(--powder),
    0 0 0 3px rgba(32, 70, 74, 0.55),
    0 2px 8px rgba(15, 40, 42, 0.35);
  transition: transform 0.15s ease;
}

.hotspot-label {
  position: absolute;
  left: 33px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(32, 70, 74, 0.9);
  color: var(--powder);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

/* 整屋视角离得远，几个点挤在一起，只留圆点 */
model-viewer[data-view="overview"] .hotspot-label {
  display: none;
}

.hotspot.is-off {
  visibility: hidden;
  pointer-events: none;
}

.hotspot:not([data-visible]),
.hotspot.is-occluded {
  pointer-events: none;
}

/* 被墙或柜体挡住（见 app.js 的遮挡检测） */
.hotspot.is-occluded {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.hotspot.is-active .hotspot-dot {
  background: var(--amber);
  transform: scale(1.15);
}

.hotspot.is-active .hotspot-label {
  background: var(--amber-deep);
}

/* ------------------------------------------------------------ 热点说明 */
.sheet {
  align-self: end;
  justify-self: center;
  z-index: 4;
  width: calc(100% - 24px);
  max-width: 520px;
  margin: 0 0 12px;
  padding: 14px 8px 16px 16px;
  border-radius: 16px;
  background: var(--powder);
  box-shadow: 0 12px 32px rgba(23, 49, 47, 0.2), 0 0 0 1px var(--line);
}

.sheet[hidden] {
  display: none;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sheet h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--enamel);
}

.sheet-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--amber-deep);
}

.sheet-body {
  margin: 10px 8px 0 0;
  font-size: 14px;
  line-height: 1.7;
  max-width: 34em;
}

.sheet-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -8px 0 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
}

.sheet-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--enamel);
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ------------------------------------------------------------ 操作区 */
.dock {
  grid-row: 3;
  grid-column: 1;
  justify-self: center;
  width: min(100%, 640px);
  z-index: 3;
  display: grid;
  gap: 10px;
  padding: 12px max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--powder);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 28px rgba(23, 49, 47, 0.08), 0 0 0 1px var(--line);
}

.dock-context {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.caption {
  flex: 1;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.reset {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--enamel);
  font-size: 13px;
  cursor: pointer;
}

.reset svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.views {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.view-btn {
  min-height: 48px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--enamel);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.view-btn[aria-pressed="true"] {
  background: var(--enamel);
  border-color: var(--enamel);
  color: var(--powder);
}

.door-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.door-controls[hidden] {
  display: none;
}

.door-btn {
  min-height: 48px;
  border: 1px solid var(--amber-deep);
  border-radius: 12px;
  background: var(--amber-deep);
  color: var(--powder);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.door-btn:disabled {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
  cursor: default;
}

@media (hover: hover) {
  .view-btn:not([aria-pressed="true"]):hover,
  .reset:hover {
    background: rgba(32, 70, 74, 0.07);
  }
  .door-btn:not(:disabled):hover {
    background: #7c4920;
  }
  .hotspot:hover .hotspot-dot {
    transform: scale(1.15);
  }
}

/* 320 px 级别的窄屏：四个视角排成两行 */
@media (max-width: 349px) {
  .views {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .view-btn {
    min-height: 44px;
  }
}

/* 矮屏（如 320 × 568、横屏手机）：收紧操作区，把高度让给模型 */
@media (max-height: 640px) {
  .masthead {
    padding-top: calc(env(safe-area-inset-top) + 8px);
  }
  .dock {
    gap: 8px;
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .caption {
    font-size: 12px;
    line-height: 1.4;
  }
}

/* ------------------------------------------------------------ 提示、加载、转场 */
.hint {
  align-self: end;
  justify-self: center;
  z-index: 2;
  margin: 0 16px 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(32, 70, 74, 0.86);
  color: var(--powder);
  font-size: 13px;
  line-height: 1.3;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

body:not(.ready) .hint,
.hint.gone {
  opacity: 0;
}

.loader {
  place-self: center;
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 16px;
  transition: opacity 0.3s ease;
}

.loader-text {
  margin: 0;
  font-size: 14px;
  color: var(--enamel);
}

.loader-track {
  width: 160px;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.loader-bar {
  height: 100%;
  background: var(--enamel);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.2s ease;
}

body.ready .loader:not(.error) {
  opacity: 0;
  pointer-events: none;
}

.loader.error {
  max-width: 30em;
  margin: 0 16px;
  border-radius: 16px;
  background: var(--powder);
  box-shadow: 0 0 0 1px var(--line);
}

.loader.error .loader-text {
  line-height: 1.7;
}

.loader.error .loader-track {
  display: none;
}

.veil {
  z-index: 3;
  background: var(--studio);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.veil.on {
  opacity: 1;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--powder);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
