:root {
  color-scheme: dark;
  --ink: #f3fbfd;
  --muted: rgba(224, 241, 246, 0.65);
  --panel: rgba(7, 15, 19, 0.72);
  --panel-strong: rgba(7, 15, 19, 0.9);
  --line: rgba(210, 242, 250, 0.14);
  --accent: #8fdfff;
  --gold: #ffd280;
  --danger: #ff8c8c;
}

* { box-sizing: border-box; }
[hidden], .runtime-support { display: none !important; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  position: fixed;
  inset: 0;
  color: var(--ink);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: #0b1114;
}

button, .nav-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(14px);
}

button:hover, button.active, .nav-button:hover {
  border-color: rgba(143, 223, 255, 0.55);
  background: rgba(143, 223, 255, 0.18);
}

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled { opacity: 0.42; cursor: default; }

.stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #0b1114;
}

#model-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#model-canvas:active { cursor: grabbing; }

.spatial-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

.spatial-label {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--ink);
  background: rgba(5, 14, 18, 0.82);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
  white-space: nowrap;
  pointer-events: auto;
}

button.spatial-label { cursor: pointer; }
.room-label { border-radius: 999px; padding: 8px 12px; color: #dff8ff; font-weight: 750; }
.scene-label { min-width: 116px; border-radius: 14px; padding: 9px 12px; text-align: left; }
.scene-label::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(143, 223, 255, 0.14);
}
.scene-label.active { color: #071018; border-color: var(--gold); background: linear-gradient(135deg, var(--accent), var(--gold)); }

.pano-route {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 2px 8px;
  min-width: 110px;
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  font-size: 12px;
}
.pano-route span { grid-column: 2; color: var(--muted); font-size: 10px; }
.ground-route-dot {
  grid-row: 1 / span 2;
  width: 10px;
  height: 10px;
  border: 2px solid #dffaff;
  border-radius: 50%;
  background: #75cde1;
  box-shadow: 0 0 0 7px rgba(117, 205, 225, 0.14);
}

.hud {
  position: fixed;
  z-index: 20;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.eyebrow { margin: 0; color: var(--accent); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; }
.top-left { top: 22px; left: 24px; min-width: 280px; max-width: min(390px, calc(100vw - 550px)); padding: 17px 20px; border-radius: 22px; }
.top-left h1 { margin: 4px 0 8px; overflow: hidden; font-size: clamp(22px, 2.4vw, 30px); text-overflow: ellipsis; white-space: nowrap; }
.top-left p { margin: 0; color: var(--muted); }
.top-right { top: 20px; right: 22px; display: flex; gap: 8px; padding: 6px; border-radius: 999px; }
.top-right .nav-button { display: inline-flex; align-items: center; }
.bottom-left { bottom: 20px; left: 22px; max-width: calc(100vw - 460px); border-radius: 999px; padding: 9px 15px; color: var(--muted); font-size: 11px; }

.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 9px; border-radius: 50%; background: #90a1a7; }
.status-dot.ready { background: #66e0b0; box-shadow: 0 0 0 4px rgba(102, 224, 176, 0.12); }
.status-dot.error { background: #ff7a7a; box-shadow: 0 0 0 4px rgba(255, 122, 122, 0.12); }

.side-panel {
  top: 118px;
  right: 22px;
  bottom: 22px;
  display: flex;
  width: min(310px, calc(100vw - 44px));
  flex-direction: column;
  border-radius: 24px;
  padding: 16px;
  transition: width 220ms ease, bottom 220ms ease;
}
.scene-heading { display: flex; align-items: center; justify-content: space-between; }
.scene-heading > div { display: flex; align-items: baseline; gap: 8px; }
#scene-count { color: var(--accent); font-size: 24px; font-weight: 800; }
#scene-title { font-size: 16px; }
#scene-panel-toggle { min-height: 32px; padding: 6px 11px; font-size: 11px; }
#scene-meta { margin: 8px 0 12px; color: var(--muted); font-size: 12px; }
.scene-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.scene-list { display: grid; align-content: start; gap: 10px; overflow: auto; overscroll-behavior: contain; }
.scene-room-group { display: grid; gap: 6px; border: 1px solid transparent; border-radius: 16px; padding: 7px; background: rgba(255, 255, 255, 0.025); }
.scene-room-group.active { border-color: rgba(255, 210, 128, 0.32); background: rgba(255, 210, 128, 0.045); }
.scene-room-group h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0; padding: 2px 5px; color: #e9f8fb; font-size: 12px; }
.scene-room-group h3 small { color: var(--muted); font-size: 10px; font-weight: 500; }
.scene-room-points { display: grid; gap: 5px; }
.scene-card { display: grid; justify-items: start; border-radius: 14px; padding: 10px 12px; text-align: left; }
.scene-card span { color: var(--muted); font-size: 10px; }
.scene-card.active { border-color: rgba(255, 210, 128, 0.72); background: rgba(255, 210, 128, 0.12); }
.neighbor-chip.doorway-route, .pano-route[data-route-kind='doorway'] { border-color: rgba(255, 210, 128, 0.72); background: rgba(255, 210, 128, 0.14); }
.pano-route[data-route-kind='doorway'] .ground-route-dot { border-color: #fff2cf; background: var(--gold); box-shadow: 0 0 0 7px rgba(255, 210, 128, 0.16); }
body.scene-panel-collapsed .side-panel { top: auto; bottom: 22px; width: 190px; }
body.scene-panel-collapsed #scene-meta,
body.scene-panel-collapsed .scene-actions,
body.scene-panel-collapsed .scene-list { display: none; }

.panorama-toolbar {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  display: grid;
  min-width: 210px;
  justify-items: center;
  gap: 3px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 18px;
  background: var(--panel-strong);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(18px);
}
.panorama-toolbar span { color: var(--muted); font-size: 11px; }

.model-loading {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  background: rgba(5, 10, 13, 0.72);
  transition: opacity 240ms ease, visibility 240ms ease;
}
.model-loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.model-loading-card { display: flex; align-items: center; gap: 18px; width: min(430px, calc(100vw - 40px)); border: 1px solid var(--line); border-radius: 24px; padding: 22px; background: var(--panel-strong); }
.model-loading-card strong, .model-loading-card span { display: block; }
.model-loading-card > div { flex: 1; }
.model-loading-card strong { margin: 5px 0; font-size: 20px; }
.model-loading-card span { color: var(--muted); font-size: 12px; }
.model-loading-orbit { width: 36px; height: 36px; flex: 0 0 auto; border: 2px solid rgba(143, 223, 255, 0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 700ms linear infinite; }
.progress-track { width: 100%; height: 4px; margin-top: 13px; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, 0.12); }
.progress-track i { display: block; width: 4%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #75cde1, var(--gold)); transition: width 180ms ease; }
@keyframes spin { to { transform: rotate(360deg); } }

.view-transition {
  --transition-x: 0px;
  --transition-y: 24px;
  --transition-origin-x: 50%;
  --transition-origin-y: 50%;
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  overflow: hidden;
  align-content: center;
  justify-items: center;
  gap: 9px;
  color: #dff9ff;
  background: rgba(4, 10, 13, 0.4);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 420ms cubic-bezier(0.22, 1, 0.36, 1), visibility 420ms ease;
}
.view-transition::after { content: ''; position: absolute; inset: 0; z-index: 1; background: radial-gradient(circle at center, rgba(28, 70, 79, 0.06), rgba(4, 10, 13, 0.58)); opacity: 0.55; transition: opacity 380ms ease; }
.view-transition.active { opacity: 1; visibility: visible; pointer-events: auto; cursor: wait; }
.view-transition.arriving { opacity: 0; }
.view-transition.arriving::after { opacity: 0; }
#transition-snapshot { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; transform: translate3d(0, 0, 0) scale(1); transform-origin: var(--transition-origin-x) var(--transition-origin-y); filter: blur(0) saturate(1); opacity: 1; will-change: transform, filter, opacity, border-radius; transition: transform 520ms cubic-bezier(0.22, 1, 0.36, 1), filter 420ms ease, opacity 420ms ease, border-radius 420ms ease; }
.view-transition.departing[data-kind='model-to-panorama'] #transition-snapshot { transform: scale(1.2); filter: blur(3px) saturate(0.86); opacity: 0.72; }
.view-transition.departing[data-kind='panorama-to-panorama'] #transition-snapshot { transform: translate3d(var(--transition-x), var(--transition-y), 0) scale(1.1); filter: blur(3px) saturate(0.9); opacity: 0.72; }
.view-transition.departing[data-kind='panorama-to-model'] #transition-snapshot { transform: translate3d(0, 18px, 0) scale(0.82); filter: blur(2px) saturate(0.82); border-radius: 38px; opacity: 0.62; }
.view-transition > span { position: relative; z-index: 2; width: 24px; height: 24px; border: 2px solid rgba(136, 224, 242, 0.2); border-top-color: #8de0f1; border-radius: 50%; animation: spin 700ms linear infinite; }
.view-transition > strong { position: relative; z-index: 2; font-size: 11px; letter-spacing: 0.08em; }

.editor-panel { top: 104px; right: 22px; bottom: 22px; z-index: 45; display: flex; width: min(420px, calc(100vw - 44px)); flex-direction: column; border-radius: 24px; padding: 16px; }
.editor-head, .editor-history-actions, .editor-tabs, .editor-tools, .config-env-head, .config-env-actions { display: flex; align-items: center; gap: 7px; }
.editor-head { justify-content: space-between; }
.editor-head h2 { margin: 3px 0 0; }
.close-editor { color: var(--muted); }
.editor-help { margin: 10px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.editor-switches { display: flex; gap: 14px; margin: 10px 0; color: var(--muted); font-size: 12px; }
.editor-tabs button.active { border-color: var(--accent); }
.editor-list { display: grid; flex: 1; gap: 10px; margin: 10px 0; overflow: auto; }
.edit-card { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 16px; padding: 12px; background: rgba(255, 255, 255, 0.04); }
.edit-card-title { display: flex; justify-content: space-between; gap: 8px; }
.visibility-toggle { color: var(--muted); font-size: 11px; }
.edit-card > label { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.edit-card input, #label-json { min-width: 0; border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; color: var(--ink); background: rgba(0, 0, 0, 0.24); font: inherit; }
.edit-actions { display: flex; gap: 7px; }
.edit-actions button { min-height: 30px; padding: 5px 10px; font-size: 11px; }
.config-env-panel { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.config-env-head { justify-content: space-between; }
.config-env-status { margin: 6px 0; color: var(--muted); font-size: 11px; }
.config-env-status[data-kind='error'] { color: var(--danger); }
.config-env-diff { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.config-env-pill { border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; color: var(--muted); font-size: 10px; }
.config-env-pill.diff { color: var(--gold); }
.config-env-actions { flex-wrap: wrap; }
.config-env-actions button, .editor-tools button { min-height: 32px; padding: 6px 10px; font-size: 11px; }
#label-json { width: 100%; min-height: 76px; margin-top: 9px; resize: vertical; }
body.editing .side-panel { display: none; }
body.editing .top-left { max-width: min(340px, calc(100vw - 490px)); }

@media (max-width: 900px) {
  .top-left { top: 12px; left: 12px; min-width: 0; max-width: calc(100vw - 24px); padding: 11px 14px; }
  .top-left .eyebrow, #project-meta { display: none; }
  .top-left h1 { margin: 0; padding-right: 300px; font-size: 17px; }
  .top-right { top: 8px; right: 8px; gap: 4px; padding: 4px; }
  .top-right button, .top-right .nav-button { min-height: 36px; padding: 7px 10px; font-size: 11px; }
  .side-panel { top: auto; left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 150px; padding: 12px; }
  .scene-list { display: flex; align-items: start; overflow-x: auto; }
  .scene-room-group { min-width: 210px; }
  .scene-card { min-width: 188px; }
  .panorama-toolbar { bottom: 168px; }
  .bottom-left { display: none; }
  .spatial-label { max-width: 44vw; overflow: hidden; font-size: 11px; text-overflow: ellipsis; }
  body.scene-panel-collapsed .side-panel { left: auto; right: 12px; bottom: 12px; width: 180px; }
  .editor-panel { top: 58px; right: 10px; bottom: 10px; width: min(420px, calc(100vw - 20px)); }
  body.editing .top-left { display: none; }
}

@media (max-width: 560px) {
  .top-left h1 { padding-right: 250px; font-size: 14px; }
  .top-right button, .top-right .nav-button { padding-inline: 8px; font-size: 10px; }
  .scene-actions { display: none; }
  .side-panel { max-height: 128px; }
  .panorama-toolbar { bottom: 144px; }
}

/* Mobile drawers: allocate real scroll space instead of shrinking flex children. */
.editor-panel { overflow-y: auto; overscroll-behavior: contain; }
.editor-panel > :not(.editor-list) { flex-shrink: 0; }
.editor-list { min-height: 180px; }
.editor-advanced summary { min-height: 44px; padding: 12px 0; cursor: pointer; }
body.editor-collapsed .editor-panel { top: auto; bottom: max(10px, env(safe-area-inset-bottom)); }
body.editor-collapsed .editor-panel > :not(.editor-head) { display: none; }
.close-editor { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }
.spatial-label, .spatial-label:hover, .spatial-label.active,
.pano-route[data-route-kind='doorway'] { background: transparent; backdrop-filter: none; box-shadow: none; color: var(--ink); border: 1px solid var(--accent); text-shadow: 0 1px 3px #000; }
@media (max-width: 900px) {
  .top-left { top: max(8px, env(safe-area-inset-top)); left: 10px; right: 10px; padding: 10px 12px; max-width: none; }
  .top-left h1 { padding-right: 0; font-size: 17px; }
  .top-right { top: calc(58px + env(safe-area-inset-top)); right: 10px; left: 10px; justify-content: center; }
  .top-right button, .top-right .nav-button, #scene-panel-toggle { min-width: 44px; min-height: 44px; font-size: 13px; }
  .side-panel { max-height: 48dvh; bottom: max(10px, env(safe-area-inset-bottom)); }
  .scene-heading, #scene-meta { flex-shrink: 0; }
  .scene-list { display: grid; min-height: 130px; overflow: auto; }
  .scene-room-group, .scene-card { min-width: 0; }
  body.scene-panel-collapsed .side-panel { width: min(280px, calc(100vw - 24px)); }
  .scene-heading { gap: 10px; }
  .scene-heading > div { min-width: 0; }
  #scene-count, #scene-title, #scene-panel-toggle { white-space: nowrap; }
  #scene-count { font-size: 20px; }
  #scene-title { font-size: 14px; }
  .panorama-toolbar { bottom: calc(48dvh + 20px); min-width: 0; max-width: calc(100vw - 24px); }
  body.scene-panel-collapsed .panorama-toolbar { bottom: 95px; }
  .editor-panel { top: calc(120px + env(safe-area-inset-top)); bottom: max(10px, env(safe-area-inset-bottom)); padding: 12px; width: calc(100vw - 20px); max-height: calc(100dvh - 130px); }
  body.editing .top-right { top: max(8px, env(safe-area-inset-top)); }
  body.editing .editor-panel { top: calc(68px + env(safe-area-inset-top)); max-height: calc(100dvh - 78px); }
  body.editor-collapsed .editor-panel { top: auto; }
  .editor-head h2 { font-size: 17px; }
  .editor-help { display: none; }
  .editor-list { flex: 1 0 190px; min-height: 190px; }
  .editor-panel button, .edit-actions button { min-height: 44px; font-size: 13px; }
  .edit-card > label { grid-template-columns: 72px minmax(0, 1fr); font-size: 13px; }
  .edit-card input, #label-json { min-height: 44px; font-size: 16px; }
  .editor-switches label, .visibility-toggle { min-height: 44px; display: inline-flex; align-items: center; }
  .editor-switches input, .visibility-toggle input { width: 22px; height: 22px; min-height: 22px; }
  .editor-switches { gap: 10px; margin: 4px 0; }
  .editor-tools { flex-wrap: wrap; }
  .spatial-label.scene-label:not(.active) { display: none !important; }
  .room-label { pointer-events: none; padding: 4px 7px; font-size: 10px; }
}

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