/* ==========================================================================
   Hypershell v15_rev3 Mobile-First 3D Viewer
   Leica / Apple Industrial Design Aesthetic
   Strict Gates:
     - Every interactive control >= 44 x 44 px
     - Every text element >= 12 px
     - Zero external CDN dependencies
   ========================================================================== */

:root {
  --bg-top: #f2f5f8;
  --bg-mid: #e6ebf1;
  --bg-bot: #d8dfe8;

  --surface-glass: rgba(255, 255, 255, 0.80);
  --surface-strong: rgba(255, 255, 255, 0.92);
  --surface-subtle: rgba(15, 23, 36, 0.05);
  --border-glass: rgba(20, 30, 46, 0.10);
  --border-strong: rgba(20, 30, 46, 0.16);

  --ink-primary: #141923;
  --ink-secondary: #4a5568;
  --ink-muted: #5d697b;

  --accent-vermilion: #d93829;
  --accent-active-bg: #18202c;
  --accent-active-fg: #ffffff;
  --accent-fine-bg: #e6f4ee;
  --accent-fine-fg: #136844;
  --accent-lite-bg: #edf1f6;
  --accent-lite-fg: #3b4759;

  --shadow-soft: 0 8px 28px rgba(15, 23, 36, 0.10), 0 1px 3px rgba(15, 23, 36, 0.06);
  --shadow-dock: 0 10px 32px rgba(15, 23, 36, 0.14), 0 2px 6px rgba(15, 23, 36, 0.08);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-primary);
  background: radial-gradient(ellipse at 50% 38%, var(--bg-top) 0%, var(--bg-mid) 56%, var(--bg-bot) 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

button,
input {
  font-family: inherit;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Full-bleed WebGL Canvas Stage */
.stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.stage:active {
  cursor: grabbing;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* ==========================================================================
   Top Floating Header
   ========================================================================== */
.top-bar {
  position: fixed;
  top: max(12px, var(--safe-top));
  left: max(12px, var(--safe-left));
  right: max(12px, var(--safe-right));
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.brand-card {
  pointer-events: auto;
  flex: 0 1 auto;
  min-width: 0;
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 9px 14px;
  box-shadow: var(--shadow-soft);
  max-width: calc(100% - 68px);
}

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

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-vermilion);
  box-shadow: 0 0 0 2px rgba(217, 56, 41, 0.18);
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Quick View Presets */
.view-preset-wrap {
  pointer-events: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.glass-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  color: var(--ink-primary);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
}

.glass-btn:hover {
  background: var(--surface-strong);
}

.glass-btn[aria-expanded="true"] {
  background: var(--accent-active-bg);
  color: var(--accent-active-fg);
  border-color: var(--accent-active-bg);
}

.view-preset-bar {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: var(--surface-strong);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: var(--shadow-soft);
  white-space: nowrap;
}

.view-preset-bar.is-open {
  display: flex;
}

.preset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.preset-btn:hover {
  background: var(--surface-subtle);
}

.preset-btn.is-active {
  background: var(--accent-active-bg);
  color: var(--accent-active-fg);
}

/* ==========================================================================
   Toast & Gesture Hint
   ========================================================================== */
.toast {
  position: fixed;
  top: calc(max(12px, var(--safe-top)) + 64px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: rgba(20, 25, 35, 0.88);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(15, 23, 36, 0.20);
  pointer-events: none;
}

.toast[hidden] {
  display: none;
}

.toast-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #ffffff;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

.toast.is-done .toast-spinner {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.gesture-hint {
  position: fixed;
  bottom: calc(max(12px, var(--safe-bottom)) + 68px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--border-glass);
  color: var(--ink-secondary);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.gesture-hint.is-hidden {
  opacity: 0;
}

/* ==========================================================================
   Shared Buttons (strictly >= 44 x 44 px)
   ========================================================================== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: #ffffff;
  border-color: var(--border-strong);
}

.icon-text-btn,
.subtle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-text-btn:hover,
.subtle-btn:hover {
  background: #ffffff;
  border-color: var(--border-strong);
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  background: var(--accent-active-bg);
  color: var(--accent-active-fg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.12s ease;
}

.primary-btn:hover {
  opacity: 0.92;
}

.primary-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ==========================================================================
   Bottom Always-Visible Floating Dock
   ========================================================================== */
.bottom-dock {
  position: fixed;
  left: 50%;
  bottom: max(12px, var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: min(calc(100vw - 24px), 440px);
  padding: 5px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
  background: var(--surface-strong);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow: var(--shadow-dock);
}

.dock-btn {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 44px;
  padding: 0 8px;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--ink-primary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.1s ease;
}

.dock-btn:hover {
  background: var(--surface-subtle);
}

.dock-btn:active {
  transform: scale(0.97);
}

.dock-btn.is-active {
  background: var(--accent-active-bg);
  color: var(--accent-active-fg);
}

.dock-label {
  font-size: 13px;
  line-height: 1.2;
}

/* ==========================================================================
   Explosion Slider Bar
   ========================================================================== */
.explode-bar {
  position: fixed;
  left: 50%;
  bottom: calc(max(12px, var(--safe-bottom)) + 64px);
  transform: translateX(-50%);
  z-index: 24;
  width: min(calc(100vw - 24px), 440px);
  padding: 10px 12px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: var(--surface-strong);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  box-shadow: var(--shadow-soft);
}

.explode-bar[hidden] {
  display: none;
}

.explode-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  padding: 0 2px;
}

.explode-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-primary);
}

.explode-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-vermilion);
  font-variant-numeric: tabular-nums;
}

.explode-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Range input strictly >= 44px tall for touch accuracy */
.explode-slider {
  flex: 1 1 auto;
  min-width: 120px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  touch-action: pan-x;
}

.explode-slider::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--accent-active-bg) 0%,
    var(--accent-active-bg) var(--pct, 0%),
    rgba(20, 30, 46, 0.16) var(--pct, 0%),
    rgba(20, 30, 46, 0.16) 100%
  );
}

.explode-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9.5px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--accent-active-bg);
  box-shadow: 0 2px 8px rgba(15, 23, 36, 0.22);
}

.explode-slider::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(20, 30, 46, 0.16);
}

.explode-slider::-moz-range-progress {
  height: 5px;
  border-radius: 999px;
  background: var(--accent-active-bg);
}

.explode-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--accent-active-bg);
  box-shadow: 0 2px 8px rgba(15, 23, 36, 0.22);
}

/* ==========================================================================
   Part Inspector Card (Compact slide-up on mobile, left card on desktop)
   ========================================================================== */
.inspector-card {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(max(12px, var(--safe-bottom)) + 64px);
  z-index: 23;
  max-height: 36vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
  background: var(--surface-strong);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow: var(--shadow-dock);
  touch-action: pan-y;
}

.inspector-card[hidden] {
  display: none;
}

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

.inspector-title-group {
  min-width: 0;
  flex: 1;
}

.inspector-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.inspector-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-primary);
  line-height: 1.3;
}

.inspector-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspector-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.quality-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  flex-shrink: 0;
}

.quality-badge.is-fine {
  background: var(--accent-fine-bg);
  color: var(--accent-fine-fg);
}

.quality-badge.is-lite {
  background: var(--accent-lite-bg);
  color: var(--accent-lite-fg);
}

.quality-badge.is-loading {
  background: #fef3e6;
  color: #a35200;
}

.spec-grid {
  margin: 10px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border-glass);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.spec-item {
  min-width: 0;
}

.spec-item-wide {
  grid-column: 1 / -1;
}

.spec-item dt {
  margin: 0;
  font-size: 12px;
  color: var(--ink-muted);
}

.spec-item dd {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.inspector-note {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  font-size: 13px;
  color: var(--ink-secondary);
  line-height: 1.45;
}

/* ==========================================================================
   Module Drawer (Compact sheet on mobile, right drawer on desktop)
   ========================================================================== */
.module-drawer {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(max(12px, var(--safe-bottom)) + 64px);
  z-index: 24;
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
  background: var(--surface-strong);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow: var(--shadow-dock);
  touch-action: pan-y;
}

.module-drawer[hidden] {
  display: none;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.drawer-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-primary);
}

.drawer-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-secondary);
}

.drawer-toolbar {
  margin-bottom: 10px;
}

.module-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.module-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.module-main-btn {
  flex: 1 1 auto;
  min-width: 44px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-glass);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink-primary);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.module-main-btn:hover {
  background: #ffffff;
  border-color: var(--border-strong);
}

.module-main-btn.is-selected {
  border-color: var(--accent-active-bg);
  background: #ffffff;
  box-shadow: 0 0 0 1px var(--accent-active-bg);
}

.module-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.module-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(20, 30, 46, 0.22);
  flex-shrink: 0;
}

.module-info {
  min-width: 0;
}

.module-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.module-size {
  font-size: 12px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.module-vis-btn {
  min-width: 44px;
  min-height: 44px;
  width: 48px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-glass);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.module-vis-btn:hover {
  background: #ffffff;
}

.module-vis-btn.is-hidden-mod {
  background: var(--surface-subtle);
  color: var(--ink-muted);
  text-decoration: line-through;
}

/* ==========================================================================
   First-Screen Loading Overlay
   ========================================================================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 42%, rgba(242, 245, 248, 0.94) 0%, rgba(216, 223, 232, 0.96) 100%);
  transition: opacity 0.28s ease;
}

.loading-overlay.is-fading {
  opacity: 0;
  pointer-events: none;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-card {
  width: min(100%, 340px);
  padding: 22px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-dock);
}

.loading-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.loading-brand-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-secondary);
}

.loading-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-primary);
  margin-bottom: 12px;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(20, 30, 46, 0.10);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #18202c 0%, #3d4d63 100%);
  transition: width 0.16s ease-out;
}

.loading-detail {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Desktop Responsive Refinement (>= 768px)
   ========================================================================== */
@media (min-width: 768px) {
  .top-bar {
    top: 18px;
    left: 20px;
    right: 20px;
  }

  .brand-card {
    padding: 11px 16px;
    max-width: 420px;
  }

  .brand-title {
    font-size: 16px;
  }

  .view-menu-trigger {
    display: none;
  }

  .view-preset-bar {
    position: static;
    display: flex;
  }

  .inspector-card {
    left: 20px;
    right: auto;
    bottom: 24px;
    width: 320px;
    max-height: calc(100vh - 140px);
  }

  .module-drawer {
    left: auto;
    right: 20px;
    top: 84px;
    bottom: auto;
    width: 332px;
    max-height: calc(100vh - 180px);
  }

  .bottom-dock {
    bottom: 22px;
    width: 440px;
  }

  .explode-bar {
    bottom: 84px;
    width: 440px;
  }

  .gesture-hint {
    bottom: 86px;
  }
}
