:root {
  --bg: #e9ddc6;
  --ink: #21180f;
  --muted: #75664f;
  --panel: #f5ead5;
  --panel-strong: #fff4df;
  --line: rgba(33, 24, 15, 0.14);
  --stage: #07101c;
  --stage-2: #0c1d32;
  --accent: #bd7b38;
  --accent-deep: #79331f;
  --shadow: 0 18px 54px rgba(32, 24, 16, 0.16);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 16%, rgba(189, 123, 56, 0.2), transparent 24rem),
    radial-gradient(circle at 90% 0%, rgba(7, 16, 28, 0.14), transparent 22rem),
    linear-gradient(135deg, #f6ecd8 0%, var(--bg) 100%);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select { font: inherit; }

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
  background: var(--panel-strong);
  font-weight: 800;
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), background 180ms ease, color 180ms ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(0.99); }

button[aria-pressed="true"],
.model-item.is-active {
  color: #fff7e9;
  background: var(--accent-deep);
  border-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(10px, 1.6dvh, 18px);
  width: min(1500px, calc(100% - 28px));
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: clamp(10px, 1.8dvh, 24px) 0;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  gap: 16px;
  align-items: end;
  min-height: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-deep);
  font-size: clamp(0.64rem, 1.2vw, 0.76rem);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: clamp(1.9rem, 5.2vw, 5rem);
  line-height: 0.96;
  letter-spacing: -0.065em;
}

.status-card,
.model-panel,
.control-panel {
  border: 1px solid var(--line);
  background: rgba(245, 234, 213, 0.88);
  box-shadow: var(--shadow);
}

.status-card {
  display: grid;
  gap: 6px;
  padding: clamp(12px, 1.6vw, 18px);
  min-width: 0;
}

.status-card strong {
  overflow: hidden;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: clamp(1.08rem, 1.8vw, 1.75rem);
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-card small,
.panel-head small {
  color: var(--muted);
  line-height: 1.45;
}

.stage-layout {
  display: grid;
  grid-template-columns: clamp(210px, 18vw, 280px) minmax(0, 1fr) clamp(240px, 19vw, 300px);
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.model-panel,
.control-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 14px;
  padding: clamp(12px, 1.4vw, 18px);
  overflow: hidden;
}

.panel-head {
  display: grid;
  flex: 0 0 auto;
  gap: 4px;
}

.panel-head span {
  color: var(--accent-deep);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.model-select { display: none; }

.model-list,
.control-scroll {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.model-list {
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 4px;
}

.model-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 50px;
  padding: 9px 11px;
  border-radius: 15px;
  text-align: left;
  background: rgba(255, 244, 223, 0.72);
}

.model-item span {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-item small {
  color: currentColor;
  opacity: 0.62;
  font-size: 0.74rem;
}

.empty-models {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.viewer-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(circle at 50% 44%, rgba(64, 105, 146, 0.24), transparent 18rem),
    radial-gradient(circle at 30% 18%, rgba(189, 123, 56, 0.14), transparent 18rem),
    linear-gradient(145deg, var(--stage), var(--stage-2) 58%, #02060b 100%);
  box-shadow: 0 24px 70px rgba(7, 16, 28, 0.34);
  overflow: hidden;
}

.viewer-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.13) 1px, transparent 1px);
  background-size: 48px 48px;
}

#sceneCanvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.viewer-help {
  position: absolute;
  z-index: 2;
  left: 14px;
  bottom: 14px;
  max-width: calc(100% - 28px);
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 247, 233, 0.78);
  background: rgba(2, 6, 11, 0.58);
  font-size: 0.82rem;
  pointer-events: none;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 18px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.loading-overlay.is-visible {
  opacity: 1;
}

.loading-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2, 6, 11, 0.18), rgba(2, 6, 11, 0.56));
}

.loading-panel {
  position: relative;
  display: grid;
  width: min(430px, 100%);
  gap: 10px;
  padding: 18px;
  border: 1px solid rgba(255, 247, 233, 0.22);
  border-radius: 18px;
  color: #fff7e9;
  background: rgba(9, 12, 15, 0.82);
  box-shadow: 0 20px 60px rgba(2, 6, 11, 0.34);
}

.loading-panel span {
  color: rgba(255, 247, 233, 0.76);
  font-size: 0.86rem;
  font-weight: 800;
}

.loading-panel strong {
  font-size: clamp(1.75rem, 5vw, 3.2rem);
  line-height: 0.95;
}

.loading-panel small {
  color: rgba(255, 247, 233, 0.7);
  line-height: 1.4;
}

.loading-track {
  overflow: hidden;
  height: 12px;
  border: 1px solid rgba(255, 247, 233, 0.18);
  border-radius: 999px;
  background: rgba(255, 247, 233, 0.16);
}

.loading-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #d09148, #ffe2a8);
  transition: width 180ms ease;
}

.loading-overlay.is-indeterminate .loading-track i {
  width: 42%;
  animation: loading-scan 1.05s ease-in-out infinite;
}

@keyframes loading-scan {
  0% { transform: translateX(-105%); }
  100% { transform: translateX(245%); }
}

.control-scroll {
  display: grid;
  align-content: start;
  gap: 13px;
  padding-right: 2px;
}

.field,
.view-block {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.field span,
.view-block > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.field b { color: var(--ink); }

input[type="color"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-strong);
  padding: 5px;
}

input[type="range"] {
  width: 100%;
  min-height: 34px;
  accent-color: var(--accent);
}

.view-grid,
.button-stack {
  display: grid;
  gap: 8px;
}

.view-grid {
  grid-template-columns: 1fr 1fr;
}

.button-stack button,
.view-grid button {
  min-height: 40px;
  padding: 0 10px;
}

.model-select {
  width: 100%;
  min-height: 46px;
  padding: 0 42px 0 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--ink);
  background: var(--panel-strong);
  font-weight: 800;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent-deep) 50%),
    linear-gradient(135deg, var(--accent-deep) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) 19px,
    calc(100% - 15px) 19px;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
}

@media (max-width: 1180px) {
  .stage-layout {
    grid-template-columns: clamp(190px, 24vw, 240px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .viewer-card { grid-column: 2; }

  .control-panel {
    grid-column: 1 / -1;
    max-height: clamp(150px, 25dvh, 230px);
  }

  .control-scroll {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
  }

  .view-block,
  .button-stack {
    grid-column: span 2;
  }

  .info-block,
  .clip-block {
    grid-column: span 2;
    min-height: auto;
  }

  .button-stack {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 14px, 1500px);
    gap: 9px;
    padding: 8px 0;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
  }

  h1 {
    font-size: clamp(1.65rem, 8.8vw, 2.5rem);
    line-height: 1;
  }

  .status-card {
    gap: 4px;
    padding: 10px 12px;
    box-shadow: 0 10px 30px rgba(32, 24, 16, 0.1);
  }

  .status-card strong {
    font-size: 1.02rem;
  }

  .status-card small {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    font-size: 0.82rem;
  }

  .stage-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(190px, 34dvh);
    gap: 9px;
  }

  .model-panel,
  .control-panel {
    padding: 10px;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(32, 24, 16, 0.1);
  }

  .model-panel {
    gap: 0;
  }

  .model-select {
    display: block;
  }

  .model-list {
    display: none;
  }

  .viewer-card {
    grid-column: auto;
    border-radius: 20px;
  }

  .viewer-card:fullscreen {
    border-radius: 0;
  }

  .viewer-help {
    display: none;
  }

  .control-panel {
    max-height: none;
  }

  .panel-head {
    display: none;
  }

  .control-scroll {
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    overflow: auto;
  }

  .view-block,
  .button-stack,
  .clip-block,
  .info-block {
    grid-column: 1 / -1;
  }

  .button-stack {
    grid-template-columns: 1fr 1fr;
  }

  .button-stack button,
  .view-grid button {
    min-height: 42px;
    font-size: 0.86rem;
  }

  .field {
    gap: 6px;
    font-size: 0.84rem;
    min-width: 0;
  }

  .field span {
    align-items: baseline;
    min-width: 0;
  }

  .field span b {
    flex: 0 0 auto;
  }

  input[type="color"] {
    height: 40px;
  }

  .clip-block {
    grid-template-columns: minmax(112px, 0.8fr) minmax(0, 1.2fr);
    align-items: end;
  }

  .clip-head {
    grid-column: 1 / -1;
  }

  .clip-block .compact-field {
    min-width: 0;
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: calc(100% - 10px);
  }

  .stage-layout {
    grid-template-rows: auto minmax(0, 1fr) minmax(118px, 30dvh);
  }

  .control-scroll {
    grid-template-columns: 1fr;
  }

  .button-stack {
    grid-template-columns: 1fr;
  }

  .clip-block {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 700px) and (min-width: 761px) {
  .app-shell {
    padding: 8px 0;
    gap: 8px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: clamp(1.6rem, 3.2vw, 3rem);
  }

  .status-card {
    padding: 10px 12px;
  }

  .model-item {
    min-height: 44px;
  }

  .control-scroll {
    gap: 9px;
  }
}

.control-select {
  width: 100%;
  min-height: 40px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: var(--panel-strong);
  font-weight: 800;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent-deep) 50%),
    linear-gradient(135deg, var(--accent-deep) 50%, transparent 50%);
  background-position:
    calc(100% - 19px) 17px,
    calc(100% - 13px) 17px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.info-block,
.clip-block {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(33, 24, 15, 0.1);
  border-radius: 16px;
  background: rgba(255, 244, 223, 0.54);
  color: var(--muted);
  font-size: 0.88rem;
}

.info-block > span,
.clip-head span {
  color: var(--accent-deep);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.info-block strong {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.35;
}

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

.clip-head button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.8rem;
}

.compact-field {
  gap: 5px;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.hotspot-layer.is-visible {
  opacity: 1;
}

.hotspot {
  position: absolute;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid rgba(255, 247, 233, 0.26);
  border-radius: 999px;
  color: #fff7e9;
  background: rgba(121, 51, 31, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 12px 28px rgba(2, 6, 11, 0.26);
  font-size: 0.72rem;
  pointer-events: auto;
  white-space: nowrap;
  will-change: transform;
}

.hotspot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff7e9;
  transform: translate(-50%, calc(-50% - 21px));
}

@media (max-width: 1180px) {
  .info-block,
  .clip-block {
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .control-select {
    min-height: 40px;
  }

  .info-block,
  .clip-block {
    padding: 9px;
    font-size: 0.82rem;
  }

  .hotspot {
    min-height: 26px;
    padding: 0 8px;
    font-size: 0.68rem;
  }
}
