/* ================================================================
   VRCards AR Photo/Video — Design System
   Premium dark UI with gold accents, glassmorphism, micro-animations
   ================================================================ */

/* ----------------------------------------------------------------
   1. DESIGN TOKENS
   ---------------------------------------------------------------- */
:root {
  /* Palette */
  --bg-base:          #060609;
  --bg-elevated:      #0c0c14;
  --bg-surface:       rgba(255, 255, 255, 0.035);
  --bg-surface-hover: rgba(255, 255, 255, 0.07);
  --bg-glass:         rgba(12, 12, 20, 0.72);

  --border-subtle:    rgba(255, 255, 255, 0.06);
  --border-mid:       rgba(255, 255, 255, 0.10);
  --border-accent:    rgba(198, 167, 94, 0.30);

  --accent:           #C6A75E;
  --accent-soft:      rgba(198, 167, 94, 0.15);
  --accent-hover:     #D4B96A;

  --text-primary:     #ece8e0;
  --text-secondary:   rgba(255, 255, 255, 0.50);
  --text-tertiary:    rgba(255, 255, 255, 0.22);

  --danger:           #ef4444;
  --danger-soft:      rgba(239, 68, 68, 0.18);
  --success:          #4ade80;

  /* Spacing */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;
  --sp-2xl: 48px;
  --sp-3xl: 64px;

  /* Radii */
  --r-sm:   8px;
  --r-md:   14px;
  --r-lg:   22px;
  --r-xl:   28px;
  --r-full: 9999px;

  /* Easing */
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);

  /* Safe areas */
  --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);
}


/* ----------------------------------------------------------------
   2. RESET & BASE
   ---------------------------------------------------------------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
  outline: none;
}

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

img, video {
  display: block;
  max-width: 100%;
}


/* ----------------------------------------------------------------
   3. SCREEN SYSTEM (transition between views)
   ---------------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s var(--ease-out), visibility 0s 0.45s;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.45s var(--ease-out), visibility 0s 0s;
  z-index: 10;
}


/* ----------------------------------------------------------------
   4. TOPBAR (shared across screens)
   ---------------------------------------------------------------- */
.selector-topbar,
.viewer-topbar,
.result-topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: calc(var(--sp-md) + var(--safe-top)) var(--sp-md) var(--sp-md);
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-align: center;
}

.topbar-spacer {
  width: 36px; /* mirrors back button for centering */
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  color: var(--text-secondary);
  transition: color 0.2s, background 0.2s;
}

.btn-icon:active {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}


/* ----------------------------------------------------------------
   5. WELCOME SCREEN
   ---------------------------------------------------------------- */
#screen-welcome {
  background: var(--bg-base);
  align-items: center;
  justify-content: center;
}

/* Ambient orbs */
.welcome-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.welcome-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.4;
  animation: orbFloat 12s ease-in-out infinite alternate;
}

.welcome-orb--1 {
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, rgba(198, 167, 94, 0.35), transparent 70%);
  top: 10%;
  right: -10%;
  animation-delay: 0s;
}

.welcome-orb--2 {
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(100, 80, 180, 0.25), transparent 70%);
  bottom: 15%;
  left: -8%;
  animation-delay: -4s;
}

@keyframes orbFloat {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(20px, -30px) scale(1.15); }
}

.welcome-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-lg);
  padding: var(--sp-xl);
  animation: fadeSlideUp 0.9s var(--ease-out) both;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  color: var(--accent);
  opacity: 0.85;
  animation: fadeSlideUp 0.7s var(--ease-out) 0.1s both;
}

.welcome-icon svg {
  width: 100%;
  height: 100%;
}

.welcome-title {
  font-size: clamp(28px, 7vw, 42px);
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: fadeSlideUp 0.8s var(--ease-out) 0.2s both;
}

.welcome-subtitle {
  font-size: clamp(14px, 3.5vw, 17px);
  color: var(--text-secondary);
  font-weight: 300;
  letter-spacing: 0.5px;
  max-width: 280px;
  animation: fadeSlideUp 0.8s var(--ease-out) 0.35s both;
}

.welcome-footer {
  position: absolute;
  bottom: calc(var(--sp-xl) + var(--safe-bottom));
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 1px;
  text-transform: uppercase;
  animation: fadeSlideUp 0.8s var(--ease-out) 0.6s both;
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


/* ----------------------------------------------------------------
   6. BUTTONS
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  padding: 14px 32px;
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.5px;
  transition: all 0.25s var(--ease-out);
  position: relative;
  overflow: hidden;
}

.btn--primary {
  background: var(--accent);
  color: #0a0a0a;
  box-shadow: 0 0 0 1px rgba(198, 167, 94, 0.3),
              0 4px 24px rgba(198, 167, 94, 0.18);
}

.btn--primary:active {
  transform: scale(0.97);
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-mid);
  backdrop-filter: blur(10px);
}

.btn--secondary:active {
  background: var(--bg-surface-hover);
  transform: scale(0.97);
}

.btn--ghost {
  color: var(--text-secondary);
  padding: 12px 24px;
}

.btn--ghost:active {
  color: var(--text-primary);
}

.btn--sm {
  padding: 10px 20px;
  font-size: 13px;
}


/* ----------------------------------------------------------------
   7. MODE SELECTOR
   ---------------------------------------------------------------- */
#screen-selector {
  background: var(--bg-base);
}

.selector-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-lg);
}

.selector-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-md);
  width: 100%;
  max-width: 400px;
}

@media (min-width: 480px) {
  .selector-cards {
    grid-template-columns: 1fr 1fr;
    max-width: 560px;
  }
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-xl) var(--sp-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  text-align: center;
  transition: all 0.3s var(--ease-out);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mode-card:active {
  transform: scale(0.97);
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent),
              0 8px 32px rgba(198, 167, 94, 0.12);
}

.mode-card__icon {
  width: 56px;
  height: 56px;
  color: var(--accent);
}

.mode-card__icon svg {
  width: 100%;
  height: 100%;
}

.mode-card__title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.mode-card__desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 200px;
}

.mode-card__badge {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: var(--r-full);
  font-weight: 500;
  letter-spacing: 0.5px;
}


/* ----------------------------------------------------------------
   8. VIEWER SCREEN
   ---------------------------------------------------------------- */
#screen-viewer {
  background: var(--bg-base);
}

model-viewer {
  flex: 1;
  width: 100%;
  background: radial-gradient(ellipse at 50% 40%, #12121e 0%, var(--bg-base) 70%);
  --poster-color: transparent;
  outline: none;
  touch-action: pan-y;
}

/* Hide model-viewer's default AR button completely */
.mv-ar-btn-hidden {
  display: none !important;
}

/* Model-viewer loading overlay */
.mv-loading {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-md);
  background: var(--bg-base);
  color: var(--text-secondary);
  font-size: 13px;
}

.mv-loading__spinner {
  width: 36px;
  height: 36px;
  border: 2.5px solid var(--border-mid);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Mode badge */
.mode-badge {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 14px;
  border-radius: var(--r-full);
  border: 1px solid rgba(198, 167, 94, 0.15);
}


/* ----------------------------------------------------------------
   9. VIEWER CONTROLS (camera-style bottom bar)
   ---------------------------------------------------------------- */
.viewer-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2xl);
  padding: var(--sp-lg) var(--sp-xl) calc(var(--sp-xl) + var(--safe-bottom));
  background: linear-gradient(to top, rgba(6, 6, 9, 0.92) 0%, rgba(6, 6, 9, 0.6) 60%, transparent 100%);
}

/* Small control buttons (music, AR) */
.ctrl-btn {
  width: 48px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: var(--r-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  transition: all 0.2s var(--ease-out);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.ctrl-btn svg {
  width: 22px;
  height: 22px;
}

.ctrl-btn:active {
  transform: scale(0.92);
  background: var(--bg-surface-hover);
}

.ctrl-btn .ctrl-label {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.5px;
  opacity: 0.7;
  margin-top: -2px;
}

/* Music muted state */
.ctrl-btn.muted {
  opacity: 0.45;
}

/* Capture button (large circle) */
.capture-btn {
  position: relative;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease-spring);
}

.capture-btn:active {
  transform: scale(0.92);
}

.capture-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  transition: border-color 0.3s;
}

.capture-inner {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  transition: all 0.3s var(--ease-out);
}

/* Video mode → red capture button */
.capture-btn.video-mode .capture-ring {
  border-color: var(--danger);
}

.capture-btn.video-mode .capture-inner {
  background: var(--danger);
  width: 54px;
  height: 54px;
}

/* Recording state → square stop button */
.capture-btn.recording .capture-inner {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--danger);
}

.capture-btn.recording .capture-ring {
  border-color: var(--danger);
  animation: ringPulse 1.2s ease-in-out infinite;
}

@keyframes ringPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}


/* ----------------------------------------------------------------
   10. RECORDING INDICATOR
   ---------------------------------------------------------------- */
.recording-indicator {
  position: absolute;
  top: calc(60px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 6px 16px;
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--danger);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fadeSlideUp 0.3s var(--ease-out) both;
}

.recording-indicator[hidden] {
  display: none;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: recBlink 1s step-start infinite;
}

@keyframes recBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}


/* ----------------------------------------------------------------
   11. FLASH OVERLAY (photo capture)
   ---------------------------------------------------------------- */
.flash-overlay {
  position: fixed;
  inset: 0;
  background: white;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
}

.flash-overlay.flash {
  animation: flashAnim 0.35s var(--ease-out) both;
}

@keyframes flashAnim {
  0%   { opacity: 0.85; }
  100% { opacity: 0; }
}


/* ----------------------------------------------------------------
   12. VIEWER ERROR STATE
   ---------------------------------------------------------------- */
.viewer-error {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 9, 0.92);
  padding: var(--sp-xl);
}

.viewer-error[hidden] {
  display: none;
}

.viewer-error__content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-md);
}

.viewer-error__icon {
  font-size: 48px;
}

.viewer-error__content p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 260px;
}


/* ----------------------------------------------------------------
   13. RESULT SCREEN
   ---------------------------------------------------------------- */
#screen-result {
  background: var(--bg-base);
}

.result-preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-lg);
  overflow: hidden;
}

.result-preview img,
.result-preview video {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r-md);
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.result-preview img[hidden],
.result-preview video[hidden] {
  display: none;
}

.result-placeholder {
  color: var(--text-tertiary);
  font-size: 14px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-lg) var(--sp-xl) calc(var(--sp-xl) + var(--safe-bottom));
}

.result-actions .btn {
  width: 100%;
  max-width: 320px;
}


/* ----------------------------------------------------------------
   14. UTILITY CLASSES
   ---------------------------------------------------------------- */
.hidden { display: none !important; }

[hidden] { display: none !important; }


/* ----------------------------------------------------------------
   15. MEDIA QUERIES
   ---------------------------------------------------------------- */
@media (min-height: 700px) {
  .selector-cards {
    gap: var(--sp-lg);
  }
  .mode-card {
    padding: var(--sp-2xl) var(--sp-xl);
  }
}

/* Desktop hover (no hover on touch devices) */
@media (hover: hover) and (pointer: fine) {
  .mode-card:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 1px var(--accent),
                0 8px 32px rgba(198, 167, 94, 0.10);
    transform: translateY(-2px);
  }

  .btn--primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 0 1px rgba(198, 167, 94, 0.4),
                0 8px 32px rgba(198, 167, 94, 0.24);
    transform: translateY(-1px);
  }

  .btn--secondary:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-mid);
  }

  .btn--ghost:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
  }

  .btn-icon:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
  }

  .ctrl-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-mid);
  }
}


/* ----------------------------------------------------------------
   16. SCROLL OVERRIDE (for screens that might scroll)
   ---------------------------------------------------------------- */
.selector-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}


/* ----------------------------------------------------------------
   17. MODEL VIEWER CUSTOM PROGRESS BAR
   ---------------------------------------------------------------- */
model-viewer .progress-bar {
  display: block;
  width: 33%;
  height: 2px;
  max-height: 2px;
  position: absolute;
  left: 50%;
  bottom: 40%;
  transform: translateX(-50%);
  border-radius: var(--r-full);
  overflow: hidden;
  background: var(--border-subtle);
}

model-viewer .update-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}
