/* WebAR - Mobile-first, Safari-friendly */
:root {
  --bg: #0f0f12;
  --surface: #1a1a1f;
  --border: #2d2d35;
  --text: #f0f0f2;
  --text-muted: #8a8a94;
  --accent: #6c5ce7;
  --accent-hover: #5b4cdb;
  --success: #00c853;
  --error: #ff5252;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  min-height: 100vh;
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: var(--safe-top) 0 var(--safe-bottom);
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
  min-height: 100vh;
}

/* Pages */
.page {
  display: none;
  min-height: 100dvh;
  min-height: 100vh;
  padding: 1rem 1.25rem;
  padding-top: max(1rem, var(--safe-top));
  padding-bottom: max(1rem, var(--safe-bottom));
}

.page.active {
  display: block;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header.compact {
  text-align: left;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.back-btn:active {
  opacity: 0.8;
}

/* Upload */
.upload-section {
  margin: 2rem 0;
}

#photo-input {
  position: absolute;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 2rem;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-label:hover,
.upload-label:focus-within {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.06);
}

.upload-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.9;
}

.upload-text {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.upload-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tip {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin: 1rem 0 0;
}

/* Result */
.result-section {
  margin-bottom: 1.5rem;
}

.result-canvas-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  position: relative;
}

#result-canvas {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
}

.actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.btn {
  padding: 0.875rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: transform 0.15s, background 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  color: white;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

/* AR section */
.ar-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.ar-section.hidden {
  display: none;
}

.ar-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.model-viewer-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.ar-button {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(108, 92, 231, 0.4);
}

.ar-fallback-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.75rem 0 0;
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 18, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
}

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

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

#loading-text {
  margin: 1rem 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: max(1rem, var(--safe-bottom));
  left: 1rem;
  right: 1rem;
  padding: 0.875rem 1rem;
  background: var(--error);
  color: white;
  border-radius: var(--radius);
  font-size: 0.9rem;
  text-align: center;
  z-index: 1001;
  box-shadow: 0 4px 20px rgba(255, 82, 82, 0.3);
}

.toast.hidden {
  display: none;
}

/* model-viewer fullscreen on mobile */
model-viewer {
  --poster-color: transparent;
}

model-viewer::part(default-progress-bar) {
  display: none;
}
