/* =========================================================================
   SpectacleHome — Virtual Try-On Styles  (tryon.css)
   Companion to /try-on/index.html. Never edit site.css from here.
   All brand colours via var(--color-*) tokens defined in site.css :root.
   ========================================================================= */

/* ---------------------------------------------------------------------------
   Layout: the two-panel try-on tool
   On desktop: stage left (wider), controls right.
   On mobile:  stage top, controls below.
   ------------------------------------------------------------------------- */
.tryon-tool {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 32px;
  align-items: start;
  margin: 40px 0;
}

@media (max-width: 860px) {
  .tryon-tool {
    /* minmax(0, 1fr) rather than a bare 1fr: a 1fr track keeps an automatic
       min-content floor, which lets a wide child (the stage or the frame
       picker row) blow the column out past the viewport on narrow screens. */
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------------------------------------------------------------------------
   Stage column wrapper
   ------------------------------------------------------------------------- */
.tryon-stage-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------------------------------------------------------------------------
   Stage: the video/photo + canvas wrapper
   CRITICAL: video, photo, and canvas must all occupy the exact same box so
   the frame overlay aligns with the face. All three use position:absolute;
   inset:0; width:100%; height:100%; object-fit:cover inside this wrapper.
   ------------------------------------------------------------------------- */
#tryon-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0d1117;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  /* Never taller than ~60 vh on mobile */
  max-height: 60vh;
  /* Touch dragging for manual adjustment */
  touch-action: none;
  cursor: grab;
}

#tryon-stage:active {
  cursor: grabbing;
}

/* All three media elements occupy the identical box */
#tryon-video,
#tryon-photo,
#tryon-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
}

/* Mirror the live camera feed so it feels like a mirror to the user.
   The engine applies the matching inverse transform when it draws. */
#tryon-video {
  transform: scaleX(-1);
}

/* Photo starts hidden; JS reveals it when user uploads */
#tryon-photo {
  display: none;
}

/* Canvas is the transparent overlay the engine draws frames onto */
#tryon-canvas {
  background: transparent;
  /* pointer-events stay on so the engine can receive drag/touch events */
}

/* ---------------------------------------------------------------------------
   Stage placeholder — shown before camera/photo is active
   ------------------------------------------------------------------------- */
.stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #8ca3b8;
  font-family: var(--font-head);
  font-size: 0.95rem;
  text-align: center;
  padding: 24px;
  pointer-events: none;
  z-index: 1;
}

.stage-placeholder svg {
  width: 56px;
  height: 56px;
  opacity: 0.45;
}

/* JS adds this class to hide the placeholder once camera/photo is active */
.stage-placeholder.is-hidden {
  display: none;
}

/* ---------------------------------------------------------------------------
   Stage preparing overlay
   Shown while the ~1 MB face model downloads in parallel with camera/photo
   startup. Sits above the media but below any later canvas draws.
   ------------------------------------------------------------------------- */
.stage-preparing {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(13, 17, 23, 0.72);
  color: #c9d9e8;
  font-family: var(--font-head);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px;
  z-index: 10;
  border-radius: var(--radius);
}

.stage-preparing.is-visible {
  display: flex;
}

.stage-preparing p {
  margin: 0;
  max-width: 28ch;
  line-height: 1.4;
}

/* Spinner ring */
.preparing-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(201, 217, 232, 0.25);
  border-top-color: var(--color-teal, #17a398);
  border-radius: 50%;
  animation: tryon-spin 0.9s linear infinite;
  flex-shrink: 0;
}

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

@media (prefers-reduced-motion: reduce) {
  .preparing-spinner {
    animation: none;
    border-top-color: var(--color-teal, #17a398);
    opacity: 0.7;
  }
}

/* ---------------------------------------------------------------------------
   Status message — aria-live region below the stage
   ------------------------------------------------------------------------- */
#tryon-status {
  min-height: 1.4em;
  font-size: 0.88rem;
  color: var(--color-slate);
  border-radius: var(--radius-sm);
  padding: 4px 0;
  transition: color 0.2s ease;
}

#tryon-status.is-error {
  color: var(--color-alert, #c0392b);
}

#tryon-status.is-ok {
  color: var(--color-teal, #17a398);
}

/* ---------------------------------------------------------------------------
   Stage action buttons (Re-fit, Follow face, Reset)
   Appear below the stage once it is active.
   ------------------------------------------------------------------------- */
.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-stage-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  border: 2px solid #D1DFE8;
  background: var(--color-white);
  color: var(--color-navy);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn-stage-action:hover:not(:disabled) {
  background: var(--color-cloud);
  border-color: var(--color-navy);
  transform: translateY(-1px);
}

.btn-stage-action:focus-visible {
  outline: 3px solid var(--color-coral);
  outline-offset: 3px;
}

.btn-stage-action:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

/* Track button: active (following) state */
#tryon-track[aria-pressed="true"] {
  border-color: var(--color-teal, #17a398);
  color: var(--color-teal, #17a398);
  background: #eaf5f4;
}

/* ---------------------------------------------------------------------------
   Controls panel (right column / bottom on mobile)
   ------------------------------------------------------------------------- */
.tryon-controls {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ---------------------------------------------------------------------------
   Step headings
   ------------------------------------------------------------------------- */
.step-heading {
  font-size: 1.05rem;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-navy);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-white);
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Secondary step (fine-tune) is visually quieter */
.step-heading--secondary {
  color: var(--color-slate);
  font-size: 0.97rem;
}

.step-num--secondary {
  background: var(--color-cloud);
  color: var(--color-slate);
  border: 1px solid #D1DFE8;
}

.optional-tag {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-slate);
  background: var(--color-cloud);
  border: 1px solid #D1DFE8;
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------------------------------------------------------------------------
   Source group: "Get started" section
   ------------------------------------------------------------------------- */
.tryon-source-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-note {
  font-size: 0.83rem;
  color: var(--color-slate);
  background: var(--color-cloud);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  line-height: 1.5;
}

.source-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.source-tip {
  font-size: 0.8rem;
  color: var(--color-slate);
  margin: 0;
}

/* Camera button */
#tryon-start-cam {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 12px 22px;
  border-radius: 999px;
  cursor: pointer;
  border: 2px solid var(--color-primary);
  background: var(--color-primary);
  color: var(--color-white);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

#tryon-start-cam:hover {
  background: var(--color-navy);
  border-color: var(--color-navy);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

#tryon-start-cam:focus-visible {
  outline: 3px solid var(--color-coral);
  outline-offset: 3px;
}

/* The file input is visually hidden; the styled label is the clickable target */
#tryon-upload {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 12px 22px;
  border-radius: 999px;
  cursor: pointer;
  border: 2px solid var(--color-primary);
  background: var(--color-white);
  color: var(--color-primary);
  transition: background 0.15s ease, transform 0.15s ease;
}

.upload-label:hover {
  background: var(--color-cloud);
  transform: translateY(-1px);
}

.upload-label:focus-within {
  outline: 3px solid var(--color-coral);
  outline-offset: 3px;
  border-radius: 999px;
}

/* ---------------------------------------------------------------------------
   Privacy notice — prominent trust feature, not fine print
   ------------------------------------------------------------------------- */
.privacy-notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #EAF5F4;
  border: 1px solid rgba(23, 163, 152, 0.3);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.9rem;
  color: #0e6058;
  margin-bottom: 4px;
}

.privacy-notice svg {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--color-teal, #17a398);
}

.privacy-notice strong {
  display: block;
  margin-bottom: 2px;
  color: #0a4f49;
  font-family: var(--font-head);
}

/* ---------------------------------------------------------------------------
   Frame picker (#tryon-frame-list)
   Horizontal scroll row on narrow viewports; 2-col grid on desktop.
   JS populates this; the empty-state message is replaced on load.
   ------------------------------------------------------------------------- */
.frame-picker-section {
  display: flex;
  flex-direction: column;
}

#tryon-frame-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (max-width: 860px) {
  #tryon-frame-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    gap: 10px;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    /* Give a subtle hint that the row scrolls */
    mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
  }
}

/* Each frame button — JS creates these with class "frame-btn" */
.frame-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 8px;
  border: 2px solid #E7ECF3;
  border-radius: var(--radius-sm);
  background: var(--color-white);
  cursor: pointer;
  font-family: var(--font-head);
  font-size: 0.78rem;
  color: var(--color-ink);
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  scroll-snap-align: start;
  flex-shrink: 0;
  position: relative;
}

@media (max-width: 860px) {
  .frame-btn {
    width: 120px;
  }
}

.frame-btn img,
.frame-btn svg {
  width: 80px;
  height: auto;
  max-height: 40px;
  object-fit: contain;
}

.frame-btn span {
  line-height: 1.2;
}

.frame-btn:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
  background: #f0f6fd;
}

.frame-btn:focus-visible {
  outline: 3px solid var(--color-coral);
  outline-offset: 2px;
}

/* Selected state — border + checkmark badge, never colour-only */
.frame-btn[aria-pressed="true"],
.frame-btn.is-selected {
  border-color: var(--color-primary);
  background: #e8f2fb;
  box-shadow: 0 0 0 2px var(--color-primary);
}

.frame-btn[aria-pressed="true"]::after,
.frame-btn.is-selected::after {
  content: '';
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2 6l3 3 5-5' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat;
}

/* Loading/empty state inside #tryon-frame-list */
.frame-loading {
  grid-column: 1 / -1;
  color: var(--color-slate);
  font-size: 0.88rem;
  padding: 12px 0;
}

/* ---------------------------------------------------------------------------
   Adjustments section: all three sliders (width, tilt, vertical)
   ------------------------------------------------------------------------- */
.tryon-adjustments {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.adjust-intro {
  font-size: 0.83rem;
  color: var(--color-slate);
  margin: 0 0 12px;
  line-height: 1.5;
}

/* Each slider row: label + range + value readout */
.slider-row {
  display: grid;
  grid-template-columns: 60px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.slider-label {
  font-family: var(--font-head);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-navy);
}

.slider-value {
  font-family: var(--font-head);
  font-size: 0.8rem;
  color: var(--color-slate);
  text-align: right;
  white-space: nowrap;
  /* <output> is inline by default; reset so it aligns */
  display: block;
}

/* Shared range input styling applied to all three sliders */
input[type="range"]#tryon-size,
input[type="range"]#tryon-rotate,
input[type="range"]#tryon-vertical {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #D1DFE8;
  cursor: pointer;
  outline: none;
}

input[type="range"]#tryon-size::-webkit-slider-thumb,
input[type="range"]#tryon-rotate::-webkit-slider-thumb,
input[type="range"]#tryon-vertical::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-white);
  box-shadow: 0 2px 6px rgba(11, 60, 97, 0.25);
  cursor: pointer;
}

input[type="range"]#tryon-size::-moz-range-thumb,
input[type="range"]#tryon-rotate::-moz-range-thumb,
input[type="range"]#tryon-vertical::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-white);
  box-shadow: 0 2px 6px rgba(11, 60, 97, 0.25);
  cursor: pointer;
}

input[type="range"]#tryon-size:focus-visible,
input[type="range"]#tryon-rotate:focus-visible,
input[type="range"]#tryon-vertical:focus-visible {
  outline: 3px solid var(--color-coral);
  outline-offset: 3px;
  border-radius: 3px;
}

/* ---------------------------------------------------------------------------
   Snapshot button
   ------------------------------------------------------------------------- */
#tryon-snapshot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 11px 20px;
  border-radius: 999px;
  cursor: pointer;
  border: 2px solid #D1DFE8;
  background: var(--color-white);
  color: var(--color-navy);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  width: 100%;
  justify-content: center;
}

#tryon-snapshot:hover:not(:disabled) {
  background: var(--color-cloud);
  border-color: var(--color-navy);
  transform: translateY(-1px);
}

#tryon-snapshot:focus-visible {
  outline: 3px solid var(--color-coral);
  outline-offset: 3px;
}

#tryon-snapshot:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ---------------------------------------------------------------------------
   Limitation / disclaimer callout (below the tool)
   ------------------------------------------------------------------------- */
.tryon-disclaimer {
  background: var(--color-cloud);
  border-left: 4px solid var(--color-coral);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 0.85rem;
  color: var(--color-slate);
  margin: 0;
}

.tryon-disclaimer strong {
  color: var(--color-navy);
}

/* ---------------------------------------------------------------------------
   CTA strip below the tool
   ------------------------------------------------------------------------- */
.tryon-cta {
  text-align: center;
  padding: 48px 0 16px;
}

.tryon-cta h2 {
  margin-bottom: 0.3em;
}

.tryon-cta p {
  color: var(--color-slate);
  max-width: 52ch;
  margin: 0 auto 22px;
}

.tryon-cta .cta-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}

/* ---------------------------------------------------------------------------
   Noscript banner
   ------------------------------------------------------------------------- */
.noscript-banner {
  background: #FFF7ED;
  border: 1px solid rgba(255, 107, 74, 0.35);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  text-align: center;
  color: var(--color-ink);
  margin: 32px 0;
}

.noscript-banner p {
  margin-bottom: 12px;
}

/* ---------------------------------------------------------------------------
   Reduced motion: disable non-essential transitions and animations
   ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #tryon-start-cam,
  .upload-label,
  .frame-btn,
  #tryon-snapshot,
  .btn-stage-action,
  .btn {
    transition: none;
  }
  #tryon-status {
    transition: none;
  }
  .preparing-spinner {
    animation: none;
  }
}
