/* ============================================
   3D Preview Sharing — Bambu Studio Dark Theme
   ============================================ */

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

:root {
  --bg-dark: #111317;
  --bg-panel: #181a20;
  --bg-panel-subtle: #20232a;
  --bg-panel-border: rgba(255, 255, 255, 0.08);
  --bambu-green: #00ae42;
  --bambu-green-hover: #00c853;
  --bambu-green-glow: rgba(0, 174, 66, 0.35);
  --accent: #00ae42;
  --accent-hover: #00c853;
  --accent-glow: rgba(0, 174, 66, 0.35);
  --text: #f0f2f5;
  --text-muted: #8c95a3;
  --text-dim: #5a6270;
  --danger: #ef5350;
  --warning: #ff9800;
  --cyan: #00d4ff;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- Utility ---- */
.hidden {
  display: none !important;
}

/* ---- Full-Screen States (Loading / Error / Expired) ---- */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  background: var(--bg-dark);
  text-align: center;
  padding: 24px;
}

/* Loading spinner */
.spinner {
  width: 44px;
  height: 44px;
  border: 3.5px solid var(--bg-panel-subtle);
  border-top-color: var(--bambu-green);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin-bottom: 18px;
  box-shadow: 0 0 16px var(--bambu-green-glow);
}

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

.screen p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 400px;
  line-height: 1.5;
}

/* Error */
.error-icon {
  font-size: 52px;
  margin-bottom: 12px;
}

.screen h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

/* ---- Viewer Container ---- */
#viewer-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: relative;
  background: var(--bg-dark);
}

/* ---- Header (Bambu Slicer Top Bar) ---- */
#header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--bg-panel-border);
  z-index: 20;
  min-height: 46px;
  flex-shrink: 0;
}

.logo {
  height: 24px;
  width: auto;
  pointer-events: none;
}

.model-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

/* View Presets (ISO / TOP / FRONT) in Header */
.view-presets {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  gap: 2px;
}

.view-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.view-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.view-btn.active {
  background: var(--bambu-green);
  color: #ffffff;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* ---- 3D Viewport (Studio Backdrop) ---- */
#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  /* Bambu Studio radial studio vignette */
  background: radial-gradient(ellipse at 50% 40%, #292d37 0%, #1c1f26 55%, #111317 100%);
}

#viewport:active {
  cursor: grabbing;
}

#viewport.measuring {
  cursor: crosshair;
}

#viewport.measuring:active {
  cursor: crosshair;
}

#viewport canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ---- Floating Toolbar (Bambu Slicer Dock) ---- */
#toolbar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(24, 26, 32, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 28px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 30;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}

#toolbar::-webkit-scrollbar {
  display: none;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.16);
}

.tool-btn:active {
  transform: scale(0.96);
}

.tool-btn.active {
  background: var(--bambu-green);
  color: #ffffff;
  border-color: var(--bambu-green);
  font-weight: 600;
  box-shadow: 0 0 12px var(--bambu-green-glow);
}

.tool-btn.active:hover {
  background: var(--bambu-green-hover);
}

.tool-icon {
  font-size: 14px;
  line-height: 1;
}

/* Filament Color Picker */
.filament-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  padding: 0;
  flex-shrink: 0;
}

.color-dot:hover {
  transform: scale(1.22);
}

.color-dot.active {
  border-color: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
  transform: scale(1.18);
}

/* ---- Measurement Label ---- */
.measure-label {
  position: fixed;
  background: rgba(18, 20, 24, 0.94);
  color: #ffffff;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
  border: 1.5px solid var(--cyan);
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.4);
  transform: translate(-50%, -100%);
  letter-spacing: 0.02em;
}

/* ---- Measurement Instructions Toast ---- */
.measure-instructions {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 20, 24, 0.9);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  pointer-events: none;
  z-index: 50;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ---- Responsive (Mobile) ---- */
@media (max-width: 600px) {
  #header {
    padding: 6px 10px;
    gap: 8px;
  }

  .logo {
    height: 20px;
  }

  .model-name {
    font-size: 13px;
  }

  .view-presets {
    gap: 1px;
    padding: 2px;
  }

  .view-btn {
    font-size: 10px;
    padding: 3px 6px;
  }

  #toolbar {
    bottom: 12px;
    padding: 5px 8px;
    gap: 6px;
  }

  .tool-btn {
    padding: 6px 9px;
    font-size: 11.5px;
    gap: 3px;
  }

  .filament-picker {
    padding: 0 5px;
    gap: 4px;
  }

  .color-dot {
    width: 16px;
    height: 16px;
  }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #toolbar {
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
  #header {
    padding-top: calc(8px + env(safe-area-inset-top));
  }
}
