/* ===== 数字展签式 3D 器型观察台 ===== */

#modelModal {
  --model-bg: #11110f;
  --model-surface: rgba(24, 23, 20, .88);
  --model-surface-strong: rgba(31, 29, 25, .96);
  --model-text: #f4eee3;
  --model-muted: #c5baa7;
  --model-accent: #c9a86a;
  --model-border: rgba(232, 216, 188, .18);
  --model-focus: #f4c977;
  display: none;
  position: fixed;
  inset: 0;
  z-index: 13000;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 43%, rgba(71, 68, 62, .55) 0%, rgba(31, 30, 27, .62) 31%, transparent 62%),
    linear-gradient(145deg, #171715 0%, var(--model-bg) 58%, #090908 100%);
  color: var(--model-text);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#modelModal.visible {
  display: block;
}

#modelModal::after {
  position: absolute;
  right: 26%;
  bottom: 78px;
  left: 26%;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, .38), transparent 68%);
  content: "";
  pointer-events: none;
}

#modelCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: grab;
  transition: right .22s ease;
}

#modelCanvas:active {
  cursor: grabbing;
}

#modelCanvas canvas {
  position: relative;
  z-index: 2;
  display: block;
}

#modelHeader {
  position: absolute;
  top: max(22px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  z-index: 6;
  max-width: min(520px, calc(100vw - 260px));
  padding-left: 13px;
  border-left: 2px solid var(--model-accent);
  text-shadow: 0 2px 12px rgba(0, 0, 0, .72);
  pointer-events: none;
}

.model-kicker,
.model-card-kicker,
.model-control-label,
.model-desc-kicker {
  display: block;
  color: var(--model-accent);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: .12em;
}

#modelTitle {
  margin-top: 4px;
}

#modelTitle > span:first-child {
  display: block;
  color: var(--model-text);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: clamp(24px, 2vw, 30px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .08em;
}

#modelTitle .sub {
  display: block;
  margin-top: 5px;
  color: var(--model-muted);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: .035em;
}

#modelClose {
  appearance: none;
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  z-index: 8;
  min-width: 64px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--model-border);
  border-radius: 22px;
  background: rgba(255, 255, 255, .08);
  color: var(--model-text);
  font: 500 14px/42px "Microsoft YaHei", sans-serif;
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease;
}

#modelClose:hover {
  border-color: rgba(244, 238, 227, .4);
  background: rgba(255, 255, 255, .16);
}

#modelLoading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  width: 220px;
  transform: translate(-50%, -50%);
  color: rgba(244, 238, 227, .82);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  letter-spacing: .06em;
}

#modelLoading .bar {
  width: 180px;
  height: 3px;
  margin: 11px auto 0;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, .14);
}

#modelLoading .bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--model-accent);
  transition: width .2s ease;
}

/* 左侧数字展签 */
#modelDesc,
#modelObservation {
  position: absolute;
  left: max(24px, env(safe-area-inset-left));
  z-index: 5;
  box-sizing: border-box;
  width: min(320px, calc(100vw - 48px));
  border: 1px solid var(--model-border);
  border-radius: 14px;
  background: var(--model-surface);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .26);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#modelDesc {
  top: 122px;
  max-height: calc(100dvh - 390px);
  overflow: auto;
  padding: 16px 17px 17px;
  color: #ddd3c2;
  font-size: 14px;
  line-height: 1.7;
  letter-spacing: .01em;
  scrollbar-width: thin;
}

#modelDesc[hidden],
#modelObservation[hidden] {
  display: none;
}

.model-desc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 11px;
  border-bottom: 1px solid rgba(232, 216, 188, .12);
}

.model-desc-head strong {
  color: var(--model-text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
}

.model-evidence-tag {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid rgba(201, 168, 106, .32);
  border-radius: 13px;
  background: rgba(201, 168, 106, .12);
  color: #e6c992;
  font-size: 12px;
  line-height: 24px;
  white-space: nowrap;
}

.model-desc-body {
  color: #ddd3c2;
  user-select: text;
}

.model-desc-body > :first-child {
  margin-top: 0;
}

.model-desc-body > :last-child {
  margin-bottom: 0;
}

.model-desc-body strong,
.model-desc-body b {
  color: var(--model-text);
  font-weight: 600;
}

.model-desc-body img {
  max-width: 100%;
  height: auto;
  border-radius: 9px;
}

#modelObservation {
  bottom: 116px;
  padding: 14px 16px 15px;
}

#modelObservation strong {
  display: block;
  margin-top: 5px;
  color: var(--model-text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
}

#modelObservation p {
  margin: 6px 0 0;
  color: var(--model-muted);
  font-size: 13px;
  line-height: 1.55;
}

/* 统一控制区 */
#modelControlDock {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 7;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px 14px;
  box-sizing: border-box;
  max-width: min(760px, calc(100vw - 400px));
  padding: 8px 10px;
  border: 1px solid var(--model-border);
  border-radius: 16px;
  background: rgba(20, 19, 17, .9);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .34);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: left .22s ease, opacity .18s ease;
}

.model-view-controls,
.model-material-controls,
#modelMaterials {
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-material-controls {
  min-width: 0;
}

.model-control-label {
  flex: 0 0 auto;
  margin: 0 3px 0 1px;
  color: var(--model-muted);
  letter-spacing: .06em;
  white-space: nowrap;
}

#modelControlDock button,
#modelInfoToggle {
  appearance: none;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(232, 216, 188, .18);
  border-radius: 10px;
  background: rgba(255, 255, 255, .055);
  color: #d8cebd;
  font: 500 13px/1 "Microsoft YaHei", sans-serif;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: color .18s ease, background-color .18s ease, border-color .18s ease;
}

#modelControlDock button:hover,
#modelInfoToggle:hover {
  border-color: rgba(232, 216, 188, .36);
  background: rgba(255, 255, 255, .11);
  color: var(--model-text);
}

#modelControlDock button.on,
#modelControlDock button[aria-pressed="true"] {
  border-color: var(--model-accent);
  background: var(--model-accent);
  color: #211c14;
}

#modelMaterials {
  min-width: 0;
}

#modelMaterials button {
  border-radius: 22px;
}

#modelMaterialNote {
  grid-column: 1 / -1;
  margin: -1px 4px 0;
  color: #a99e8d;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}

#modelHint {
  position: absolute;
  bottom: 104px;
  left: 50%;
  z-index: 5;
  transform: translateX(-50%);
  color: rgba(244, 238, 227, .52);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  letter-spacing: .04em;
  pointer-events: none;
  transition: opacity .35s ease;
}

#modelInfoToggle {
  display: none;
  position: absolute;
  z-index: 9;
}

#modelClose:focus-visible,
#modelControlDock button:focus-visible,
#modelInfoToggle:focus-visible {
  outline: 3px solid var(--model-focus);
  outline-offset: 2px;
}

/* 热点弹窗与展厅中的 3D 入口 */
.model-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 10px;
  padding: 0 16px;
  border: 0;
  border-radius: 22px;
  background: linear-gradient(180deg, #d8ba82 0%, #c49d59 100%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .28);
  color: #241f16 !important;
  font: 600 13px/1 "Microsoft YaHei", sans-serif;
  letter-spacing: .04em;
  cursor: pointer;
  transition: filter .18s ease;
}

.model-btn:hover {
  filter: brightness(1.08);
}

#modelEntry {
  position: absolute;
  bottom: 18px;
  left: 18px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px 0 14px;
  border: 1px solid rgba(201, 168, 106, .42);
  border-radius: 22px;
  background: rgba(20, 19, 18, .76);
  color: #e8dcc4;
  font: 500 13px/44px "Microsoft YaHei", sans-serif;
  letter-spacing: .06em;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: color .2s ease, background-color .2s ease, border-color .2s ease;
}

#modelEntry:hover {
  border-color: var(--model-accent);
  background: rgba(201, 168, 106, .94);
  color: #1b1a18;
}

#modelEntry .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c9a86a;
  box-shadow: 0 0 0 0 rgba(201, 168, 106, .7);
  animation: modelPulse 2.2s infinite;
}

/* H01完整三维器型库 */
.h01-model-library {
  position: fixed;
  inset: 0;
  z-index: 12950;
  display: grid;
  box-sizing: border-box;
  padding: clamp(14px, 3vw, 38px);
  overflow: auto;
  place-items: center;
  background: rgba(13, 13, 12, .76);
  color: #2d2923;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.h01-model-library[hidden] {
  display: none;
}

.h01-model-library-panel {
  width: min(1120px, 100%);
  max-height: calc(100dvh - clamp(28px, 6vw, 76px));
  overflow: auto;
  border: 1px solid rgba(160, 126, 74, .38);
  border-radius: 20px;
  outline: 0;
  background: #f4f0e7;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .42);
}

.h01-model-library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 26px 20px;
  border-bottom: 1px solid rgba(122, 93, 52, .2);
  background: linear-gradient(125deg, #312a22 0%, #44382c 72%, #5a4632 100%);
  color: #f7f0e2;
}

.h01-model-library-kicker {
  display: block;
  margin-bottom: 7px;
  color: #d8b579;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
}

.h01-model-library-header h2 {
  margin: 0;
  font-size: clamp(22px, 2.3vw, 30px);
  font-weight: 600;
  letter-spacing: .04em;
}

.h01-model-library-header p {
  max-width: 720px;
  margin: 9px 0 0;
  color: rgba(247, 240, 226, .72);
  font-size: 13px;
  line-height: 1.65;
}

#h01ModelLibraryClose {
  flex: 0 0 auto;
  min-width: 64px;
  height: 42px;
  border: 1px solid rgba(247, 240, 226, .28);
  border-radius: 21px;
  background: rgba(255, 255, 255, .07);
  color: #f7f0e2;
  font: 500 13px/40px "Microsoft YaHei", sans-serif;
  cursor: pointer;
}

.h01-model-library-boundary {
  margin: 0;
  padding: 12px 26px;
  border-bottom: 1px solid rgba(122, 93, 52, .15);
  background: #e9dfcf;
  color: #66543d;
  font-size: 12px;
  line-height: 1.65;
}

.h01-model-library-groups {
  display: grid;
  gap: 22px;
  padding: 22px 26px 28px;
}

.h01-model-library-group h3 {
  margin: 0;
  color: #40362a;
  font-size: 18px;
  font-weight: 600;
}

.h01-model-library-group > p {
  margin: 5px 0 13px;
  color: #786b5b;
  font-size: 12px;
  line-height: 1.55;
}

.h01-model-library-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.h01-model-card {
  display: grid;
  grid-template-rows: 126px auto;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(104, 82, 52, .2);
  border-radius: 12px;
  background: #fffdf8;
  color: #332b22;
  text-align: left;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.h01-model-card:hover,
.h01-model-card:focus-visible {
  border-color: #aa7d43;
  outline: 0;
  box-shadow: 0 10px 24px rgba(79, 57, 30, .14);
  transform: translateY(-2px);
}

.h01-model-card-media {
  display: grid;
  overflow: hidden;
  place-items: center;
  background: radial-gradient(circle at 50% 42%, #f8f5ed 0%, #e9e2d4 72%, #ddd2c1 100%);
}

.h01-model-card-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.h01-model-card-copy {
  display: block;
  min-width: 0;
  padding: 11px 12px 12px;
}

.h01-model-card-copy strong,
.h01-model-card-copy small,
.h01-model-card-copy em {
  display: block;
}

.h01-model-card-copy strong {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.h01-model-card-copy small {
  margin-top: 4px;
  color: #877866;
  font-size: 11px;
  line-height: 1.45;
}

.h01-model-card-copy em {
  margin-top: 7px;
  color: #9a633c;
  font-size: 10px;
  font-style: normal;
  font-weight: 600;
  letter-spacing: .04em;
}

@media (max-width: 900px) {
  .h01-model-library-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .h01-model-library { padding: 0; place-items: stretch; }
  .h01-model-library-panel { width: 100%; max-height: 100dvh; border: 0; border-radius: 0; }
  .h01-model-library-header { padding: 18px 16px 16px; }
  .h01-model-library-header p { font-size: 12px; }
  .h01-model-library-boundary { padding: 10px 16px; }
  .h01-model-library-groups { gap: 20px; padding: 18px 16px 24px; }
  .h01-model-library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .h01-model-card { grid-template-rows: 108px auto; }
}

@keyframes modelPulse {
  0% { box-shadow: 0 0 0 0 rgba(201, 168, 106, .6); }
  70% { box-shadow: 0 0 0 9px rgba(201, 168, 106, 0); }
  100% { box-shadow: 0 0 0 0 rgba(201, 168, 106, 0); }
}

/* IP 讲解抽屉打开后，把模型和控制区移入剩余视区 */
@media (min-width: 761px) and (min-height: 621px) {
  body.model-guide-open #modelCanvas {
    right: min(390px, 34vw);
  }

  body.model-guide-open #modelControlDock {
    left: calc(50% - min(195px, 17vw));
  }
}

/* 手机竖屏：模型优先，展签按需展开为底部面板 */
@media (max-width: 760px) {
  #modelModal::after {
    right: 14%;
    bottom: 132px;
    left: 14%;
  }

  #modelHeader {
    top: max(12px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    max-width: calc(100vw - 96px - env(safe-area-inset-left) - env(safe-area-inset-right));
    padding-left: 10px;
  }

  .model-kicker {
    font-size: 10px;
  }

  #modelTitle > span:first-child {
    font-size: 20px;
  }

  #modelTitle .sub {
    overflow: hidden;
    max-width: 100%;
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  #modelClose {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    min-width: 58px;
    height: 44px;
    padding: 0 12px;
    line-height: 42px;
  }

  #modelDesc,
  #modelObservation {
    display: none;
  }

  #modelInfoToggle {
    display: block;
    bottom: calc(158px + env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    min-height: 44px;
    border-color: rgba(201, 168, 106, .42);
    background: rgba(20, 19, 17, .9);
    color: #ead9b9;
  }

  #modelModal.info-open #modelDesc {
    top: 24dvh;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    display: block;
    width: 100%;
    max-height: none;
    padding: 18px 18px calc(154px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 20px 20px 0 0;
    background: rgba(25, 23, 20, .98);
    box-shadow: 0 -18px 52px rgba(0, 0, 0, .46);
  }

  #modelModal.info-open #modelObservation {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 14px;
    z-index: 11;
    display: block;
    width: auto;
    background: #28241e;
  }

  #modelModal.info-open #modelInfoToggle {
    top: calc(24dvh + 12px);
    right: 12px;
    bottom: auto;
    left: auto;
    z-index: 12;
  }

  #modelModal.info-open #modelControlDock,
  #modelModal.info-open #modelHint {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  #modelControlDock {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    grid-template-columns: 1fr;
    gap: 6px;
    max-width: none;
    padding: 7px;
    transform: none;
  }

  .model-view-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .model-view-controls button {
    min-width: 0;
    padding: 0 6px !important;
  }

  .model-material-controls {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  #modelMaterials {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #modelMaterials button {
    min-width: 0;
    padding: 0 5px;
    font-size: 12px;
  }

  #modelMaterialNote {
    display: none;
  }

  #modelHint {
    bottom: calc(142px + env(safe-area-inset-bottom));
    width: calc(100vw - 150px);
    font-size: 11px;
    text-align: right;
  }

}

/* 矮屏与手机横屏：控制区压缩为单排，避免遮住器型 */
@media (max-height: 620px) {
  #modelHeader {
    top: max(10px, env(safe-area-inset-top));
  }

  #modelDesc,
  #modelObservation {
    display: none;
  }

  #modelInfoToggle {
    display: block;
    top: max(68px, calc(58px + env(safe-area-inset-top)));
    bottom: auto;
    left: max(12px, env(safe-area-inset-left));
    min-height: 44px;
    border-color: rgba(201, 168, 106, .42);
    background: rgba(20, 19, 17, .9);
    color: #ead9b9;
  }

  #modelControlDock {
    right: max(78px, calc(68px + env(safe-area-inset-right)));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    display: flex;
    max-width: none;
    padding: 6px;
    transform: none;
  }

  .model-control-label,
  #modelMaterialNote {
    display: none;
  }

  #modelControlDock button {
    min-height: 42px;
    padding: 0 10px;
  }

  #modelHint {
    bottom: 66px;
  }

}

@media (prefers-reduced-motion: reduce) {
  #modelCanvas,
  #modelControlDock,
  #modelClose,
  #modelControlDock button,
  #modelInfoToggle,
  #modelEntry {
    animation: none !important;
    transition-duration: .01ms !important;
  }

  #modelEntry .dot {
    animation: none;
  }
}

/* Use the spare observation-control slot for the phone digital label. */
@media (max-width: 760px) and (min-height: 621px) {
  #modelModal:not(.info-open) #modelInfoToggle {
    bottom: calc(68px + env(safe-area-inset-bottom));
    right: max(18px, env(safe-area-inset-right));
    left: auto;
  }
}
