/* ==========================================================================
   LipiTry AI — design tokens
   Palette: warm ivory stage, deep wine/plum accent, rose-gold secondary.
   Type: Playfair Display for the wordmark & headings, Inter for UI.
   ========================================================================== */

:root {
  --ivory: #FBF6F1;
  --ivory-deep: #F3E8E2;
  --plum: #2B1E24;
  --plum-soft: #5B4550;
  --wine: #7A2048;
  --wine-dark: #5E1836;
  --rose-gold: #C89B8C;
  --blush: #F3D9DD;
  --line: #E7D9D2;
  --success: #4C7A5A;
  --error: #B1122A;

  --font-display: 'Playfair Display', 'Georgia', serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-lg: 28px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-stage: 0 24px 60px -24px rgba(43, 30, 36, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--plum);
  background:
    radial-gradient(circle at 15% 0%, var(--blush) 0%, transparent 45%),
    radial-gradient(circle at 100% 100%, var(--ivory-deep) 0%, transparent 55%),
    var(--ivory);
  min-height: 100vh;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.5rem) clamp(1rem, 4vw, 2rem) 3rem;
}

/* ---------- Header ---------- */
.app-header {
  text-align: center;
  margin-bottom: clamp(1.25rem, 4vw, 2.25rem);
}

.wordmark {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 5vw, 3.1rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--plum);
  margin: 0;
  line-height: 1.05;
}

.wordmark em {
  font-style: normal;
  color: var(--wine);
}

.tagline {
  font-size: 0.98rem;
  color: var(--plum-soft);
  margin-top: 0.35rem;
  letter-spacing: 0.02em;
}

/* ---------- Layout: stage + panel ---------- */
.experience {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: clamp(1rem, 3vw, 2rem);
  align-items: start;
}

@media (max-width: 900px) {
  .experience {
    grid-template-columns: 1fr;
  }
}

/* ---------- Camera stage ---------- */
.stage-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: clamp(0.75rem, 2vw, 1.25rem);
  box-shadow: var(--shadow-stage);
  border: 1px solid var(--line);
}

#camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: linear-gradient(160deg, #1F1720, #33202B 60%, #1F1720);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Viewfinder-style corner accents, purely decorative */
#camera-stage::before,
#camera-stage::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(230, 210, 217, 0.55);
  z-index: 2;
  pointer-events: none;
}
#camera-stage::before { top: 14px; left: 14px; border-right: none; border-bottom: none; border-radius: 6px 0 0 0; }
#camera-stage::after  { bottom: 14px; right: 14px; border-left: none; border-top: none; border-radius: 0 0 6px 0; }

@media (min-width: 700px) {
  #camera-stage { aspect-ratio: 4 / 3; }
}

#camera-feed, #lip-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror for a natural "looking in a mirror" feel */
}

.camera-placeholder {
  color: #EFE1E7;
  text-align: center;
  padding: 1.5rem;
}

.camera-placeholder .cam-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.9rem;
  opacity: 0.85;
}

.camera-placeholder .cam-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  letter-spacing: 0.02em;
}

.camera-placeholder .cam-sub {
  font-size: 0.85rem;
  color: #CBB3BC;
  margin-top: 0.25rem;
}

.camera-watermark {
  position: absolute;
  right: 16px;
  bottom: 14px;
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  z-index: 2;
  pointer-events: none;
  user-select: none;
}

.status-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(43, 30, 36, 0.72);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  z-index: 3;
  backdrop-filter: blur(4px);
  transition: opacity 0.15s ease;
}

.status-badge[data-tone="info"] {
  background: rgba(122, 32, 72, 0.82);
}

#status-message {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--ivory-deep);
  color: var(--plum-soft);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#status-message[data-tone="error"] {
  background: #FBE7E9;
  color: var(--error);
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--rose-gold);
  border-top-color: var(--wine);
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
}

/* ---------- Controls ---------- */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.btn-lipitry {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 999px;
  padding: 0.65rem 1.3rem;
  border: 1px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, background 0.15s ease;
  cursor: pointer;
}

.btn-lipitry:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-lipitry:active:not(:disabled) {
  transform: translateY(0);
}

.btn-lipitry:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.btn-primary-wine {
  background: var(--wine);
  color: #fff;
}
.btn-primary-wine:hover:not(:disabled) { background: var(--wine-dark); }

.btn-outline-plum {
  background: #fff;
  color: var(--plum);
  border-color: var(--line);
}
.btn-outline-plum:hover:not(:disabled) { border-color: var(--wine); color: var(--wine); }

.btn-ghost {
  background: transparent;
  color: var(--plum-soft);
  border-color: var(--line);
}
.btn-ghost:hover:not(:disabled) { color: var(--plum); }

/* ---------- Shade panel ---------- */
.panel-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: clamp(1rem, 2.5vw, 1.5rem);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-stage);
}

.panel-heading {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin: 0 0 0.15rem;
}

#selected-shade-name {
  color: var(--wine);
  font-weight: 600;
}

.inline-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--swatch-color, transparent);
  border: 2px solid #fff;
  outline: 1px solid var(--line);
  vertical-align: middle;
  margin: 0 0.15rem 0 0.4rem;
}

.category-tabs,
.finish-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1rem 0 0;
}

.finish-tabs {
  margin-bottom: 0.9rem;
}

.cat-pill,
.finish-pill {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--ivory);
  color: var(--plum-soft);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.cat-pill.active {
  background: var(--plum);
  color: #fff;
  border-color: var(--plum);
}

.finish-pill.active {
  background: var(--wine);
  color: #fff;
  border-color: var(--wine);
}

.empty-shades {
  font-size: 0.85rem;
  color: var(--plum-soft);
  padding: 0.5rem 0;
}

.swatch-delete {
  position: absolute;
  bottom: -3px;
  left: -3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--plum);
  color: #fff;
  font-size: 0.72rem;
  line-height: 16px;
  text-align: center;
  border: 2px solid #fff;
}

.swatch-delete:hover {
  background: var(--error);
}

/* ---------- Add a color ---------- */
.add-shade-block {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.add-shade-btn {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.add-shade-count {
  font-size: 0.75rem;
  color: var(--plum-soft);
  margin-left: 0.6rem;
}

.add-shade-form {
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.add-shade-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.add-shade-row input[type="color"] {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  flex: 0 0 auto;
}

.add-shade-row input[type="text"],
.add-shade-row select {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--ivory);
  color: var(--plum);
}

.add-shade-row input[type="text"]:focus,
.add-shade-row select:focus {
  outline: 2px solid var(--rose-gold);
  outline-offset: 1px;
}

.add-shade-actions {
  display: flex;
  gap: 0.5rem;
}

/* Shade grid: wraps on desktop, horizontally scrolls on mobile */
.shade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 0.6rem;
}

@media (max-width: 900px) {
  .shade-grid {
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: repeat(2, 46px);
    overflow-x: auto;
    padding-bottom: 0.4rem;
    scroll-snap-type: x proximity;
  }
  .swatch { scroll-snap-align: start; }
}

.swatch {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #fff;
  outline: 1px solid var(--line);
  background: var(--swatch-color);
  cursor: pointer;
  transition: transform 0.12s ease, outline-color 0.12s ease;
  flex: 0 0 auto;
}

.swatch:hover { transform: translateY(-2px); }

.swatch.active {
  outline: 2px solid var(--wine);
  outline-offset: 2px;
  transform: translateY(-2px);
}

.fav-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rose-gold);
  border: 2px solid #fff;
}

.panel-hint {
  font-size: 0.78rem;
  color: var(--plum-soft);
  margin-top: 0.9rem;
  opacity: 0.85;
}

/* ---------- Capture modal ---------- */
.capture-modal {
  position: fixed;
  inset: 0;
  background: rgba(43, 30, 36, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.capture-modal.d-none { display: none; }

.capture-card {
  position: relative;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: pop-in 0.18s ease;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.capture-close-x {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--ivory);
  color: var(--plum-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.capture-close-x:hover {
  background: var(--blush);
  color: var(--wine);
}

.capture-shade-label {
  margin-top: -0.2rem;
}

.capture-card img {
  width: 100%;
  border-radius: var(--radius-md);
  margin: 0.75rem 0 1rem;
  transform: scaleX(1);
}

.d-none { display: none !important; }

/* ==========================================================================
   Mobile: behave like a native camera app — fixed full-height shell,
   camera fills the top, controls sit as a bottom toolbar, shades live in
   a bottom sheet. No page-level scrolling; only the shade sheet scrolls.
   ========================================================================== */
@media (max-width: 700px) {
  html, body { height: 100%; }
  body {
    overflow: hidden;
    background: var(--ivory);
  }

  .app-shell {
    height: 100dvh;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .app-header {
    flex: 0 0 auto;
    padding: 0.55rem 1rem 0.35rem;
    margin-bottom: 0;
  }

  .wordmark { font-size: 1.35rem; }
  .tagline { display: none; }

  .experience {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .stage-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  #camera-stage {
    flex: 1;
    min-height: 0;
    width: 100%;
    aspect-ratio: auto;
    border-radius: 0;
  }

  #status-message {
    margin: 0.5rem 0.9rem 0;
  }

  .controls-row {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0;
    padding: 0.55rem 0.8rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }

  .btn-lipitry {
    flex: 0 0 auto;
    padding: 0.55rem 0.85rem;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .panel-card {
    flex: 0 0 auto;
    max-height: 34vh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    border: none;
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 24px -18px rgba(43, 30, 36, 0.35);
    padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }

  .panel-heading { font-size: 1.05rem; }

  .add-shade-block {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
  }
}
