:root {
  --bg: #0b0f17;
  --surface: rgba(15, 23, 42, 0.76);
  --surface-strong: rgba(15, 23, 42, 0.92);
  --surface-hover: rgba(30, 41, 59, 0.88);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #34d399;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Fullscreen panorama stage */
.pano-stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 35%, #172033 0%, #0b0f17 70%);
}

#pano-canvas {
  width: 100%;
  height: 100%;
}

/* Override Pannellum default container borders/fonts cleanly */
.pnlm-container {
  background: transparent !important;
  font-family: var(--font) !important;
}

.pnlm-controls-container {
  top: 72px !important;
  left: 16px !important;
}

body.is-embed .pnlm-controls-container {
  top: 12px !important;
  left: 12px !important;
}

/* Floating glass topbar */
.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.title-input {
  width: 220px;
  max-width: 32vw;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.title-input:focus {
  border-color: var(--accent);
}

.viewer-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55vw;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  min-height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-strong);
  border-color: rgba(56, 189, 248, 0.5);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #0369a1;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.16);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.28);
}

.btn-active {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--accent);
  color: #e0f2fe;
}

.btn-sm {
  padding: 5px 10px;
  min-height: 30px;
  font-size: 12px;
}

/* Initial upload dropzone */
.upload-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
}

.upload-card {
  pointer-events: auto;
  width: 100%;
  max-width: 460px;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1.5px dashed var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}

.upload-card.drag-over {
  border-color: var(--accent);
  transform: scale(1.01);
}

.upload-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
}

.upload-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.upload-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* Mode hint pill */
.mode-hint {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  padding: 6px 14px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  pointer-events: none;
  white-space: nowrap;
}

/* Hotspot list drawer */
.drawer {
  position: fixed;
  top: 72px;
  right: 12px;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  width: 300px;
  max-width: calc(100vw - 24px);
  z-index: 28;
  display: flex;
  flex-direction: column;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  outline: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hotspot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.hotspot-item:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--border);
}

.hotspot-item-main {
  min-width: 0;
  flex: 1;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.hotspot-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hotspot-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.hotspot-item-actions {
  display: flex;
  gap: 4px;
}

.empty-tip {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

/* Custom Pannellum voice hotspot (must preserve Pannellum's position: absolute) */
.pv-hotspot {
  cursor: pointer;
  user-select: none;
}

.pv-hotspot-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px 6px 8px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
  background: rgba(15, 23, 42, 0.84);
  color: #fff;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}

.pv-hotspot-btn:hover {
  transform: scale(1.05);
  background: rgba(2, 132, 199, 0.92);
  border-color: #fff;
}

.pv-hotspot-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #0b0f17;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.pv-hotspot-label {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pv-hotspot.is-playing .pv-hotspot-btn {
  background: var(--accent-strong);
  border-color: #bae6fd;
}

.pv-hotspot.is-playing .pv-hotspot-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  animation: pv-pulse 1.5s ease-out infinite;
  pointer-events: none;
}

@keyframes pv-pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.25);
    opacity: 0;
  }
}

/* Bottom floating audio player bar */
.audio-bar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 32;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 8px 14px;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.audio-bar.is-error {
  border-color: rgba(248, 113, 113, 0.65);
}

.audio-seek {
  width: clamp(72px, 16vw, 150px);
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}

.audio-bar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.audio-bar.is-playing .audio-bar-dot {
  animation: pv-blink 1s ease-in-out infinite;
}

@keyframes pv-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.audio-bar-title {
  font-size: 13px;
  font-weight: 500;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-bar-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Embed floating controls (top-right in embed mode so bottom audio-bar never overlaps) */
.embed-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 30;
  display: flex;
  gap: 8px;
}

.embed-controls .btn {
  background: rgba(15, 23, 42, 0.9);
  border-color: rgba(255, 255, 255, 0.32);
  color: #f8fafc;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.embed-controls .btn:hover:not(:disabled) {
  background: rgba(2, 132, 199, 0.92);
  border-color: rgba(255, 255, 255, 0.55);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: #111827;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.input,
.textarea {
  width: 100%;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
}

.input:focus,
.textarea:focus {
  border-color: var(--accent);
}

.textarea {
  min-height: 86px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.coords-badge {
  display: inline-block;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge-warning {
  color: var(--warning);
  border: 1px solid rgba(251, 191, 36, 0.35);
}

/* Recorder box inside hotspot modal */
.recorder-box {
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.recorder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.recorder-timer {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.recorder-timer.is-warning {
  color: var(--warning);
  font-weight: 600;
}

.meter {
  width: 100%;
  height: 6px;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.08s linear;
}

.audio-preview {
  width: 100%;
  margin-top: 10px;
  height: 36px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-footer-split {
  justify-content: space-between;
}

.copy-row {
  display: flex;
  gap: 6px;
}

.copy-row .input {
  flex: 1;
}

/* Toast banner */
.toast {
  position: fixed;
  top: 112px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.toast.is-error {
  border-color: rgba(248, 113, 113, 0.65);
  background: rgba(69, 10, 10, 0.92);
  color: #fecaca;
}

.toast.is-success {
  border-color: rgba(52, 211, 153, 0.65);
  background: rgba(6, 78, 59, 0.92);
  color: #d1fae5;
}

/* Viewer error state */
.error-card {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.error-box {
  max-width: 400px;
  width: 100%;
  padding: 28px 22px;
  text-align: center;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.error-box h1 {
  margin: 0 0 8px;
  font-size: 18px;
}

.error-box p {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.scene-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 26;
  padding: 10px 18px;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

body.is-immersive #viewer-topbar {
  opacity: 0.28;
  transition: opacity 0.2s;
}

body.is-immersive #viewer-topbar:hover {
  opacity: 1;
}

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

/* Responsive adjustments for mobile (390x844 etc.) */
@media (max-width: 640px) {
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .brand-text {
    display: none;
  }

  .title-input {
    width: 130px;
    max-width: 40vw;
    font-size: 12px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 36px;
  }

  .mode-hint {
    top: auto;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    font-size: 11px;
  }

  .drawer {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 45vh;
    max-height: 45dvh;
  }

  .audio-bar {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 8px 12px;
    gap: 6px;
    width: calc(100vw - 16px);
    border-radius: var(--radius);
    flex-wrap: wrap;
    justify-content: center;
  }

  .audio-seek {
    flex: 1 1 88px;
  }

  .audio-bar-title {
    max-width: 120px;
    font-size: 12px;
  }

  .toast {
    top: 76px;
  }

  /* Compact circular voice badges on mobile to prevent edge clipping and neighbor overlap */
  .pv-hotspot-btn {
    padding: 7px;
    min-width: 40px;
    min-height: 40px;
    justify-content: center;
    gap: 0;
  }

  .pv-hotspot-icon {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }

  .pv-hotspot-label {
    display: none;
  }

  .pv-hotspot.is-playing .pv-hotspot-btn {
    padding: 6px 10px 6px 6px;
    gap: 6px;
  }

  .pv-hotspot.is-playing .pv-hotspot-label {
    display: inline-block;
    max-width: 36vw;
  }
}
