:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #151210;
  --ink-2: #3a3632;
  --muted: #8a827a;
  --line: #e8e1d7;
  --accent: #151210;
  --accent-contrast: #faf7f2;
  --brand: #b84e2a;
  --danger: #c0392b;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20,15,10,.04), 0 2px 8px rgba(20,15,10,.04);
  --shadow-md: 0 6px 24px rgba(20,15,10,.08);
  --shadow-lg: 0 20px 60px rgba(20,15,10,.14);
  --font-display: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-body: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; }

/* HEADER */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: rgba(250, 247, 242, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.logo-mark {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f3c7a6 0%, #b84e2a 60%, #151210 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}
.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.app-nav { display: flex; gap: 4px; }
.nav-btn {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(20,15,10,.06); color: var(--ink); }
.nav-btn.active { background: var(--ink); color: var(--accent-contrast); }

/* LAYOUT */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px;
}
.screen { display: none; animation: fade 0.25s ease-out; }
.screen.active { display: block; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.hidden { display: none !important; }

.screen-head { margin-bottom: 28px; }
.title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(32px, 4vw, 48px);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  line-height: 1.05;
}
.subtitle { color: var(--muted); font-size: 16px; margin: 0; }
.display {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(32px, 4.8vw, 60px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  margin: 0 0 20px;
}
.lead { font-size: 22px; font-weight: 700; color: var(--ink); line-height: 1.4; max-width: 46ch; margin: 0 0 32px; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  transition: transform .1s, background .15s, opacity .15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { background: #000; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-lg { padding: 14px 26px; font-size: 15px; }
.btn-back {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 20px;
  padding: 6px 0;
}
.btn-back:hover { color: var(--ink); }

/* HERO */
.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: center;
  padding: 40px 0 80px;
}
.hero-cta-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 16px; }
.btn-see-looks { background: #3aa338; color: #fff; border: 0; }
.btn-see-looks:hover { background: #32912f; color: #fff; }
.hero-meta { margin-top: 20px; font-size: 16px; font-weight: 700; color: var(--ink); }
.hero-slideshow {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  justify-self: end;
  width: 100%;
  max-width: 420px;
}
.hero-carousel {
  position: relative;
  width: 100%;
  aspect-ratio: 9/16;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  background: var(--surface);
}
.hero-rerun-btn { font-size: 14px; padding: 8px 16px; }
.hero-carousel-track {
  position: absolute;
  inset: 0;
}
.hero-carousel-track > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  visibility: hidden;
  display: block;
}
.hero-carousel-track > img.active {
  opacity: 1;
  visibility: visible;
}

.features {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  padding: 40px 0 20px;
  border-top: 1px solid var(--line);
}
.feature-num {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
}
.feature h3 { font-size: 16px; margin: 0 0 6px; }
.feature p { color: var(--muted); font-size: 14px; margin: 0; line-height: 1.5; }

/* UPLOAD */
.upload-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 32px;
}
.upload-zone {
  aspect-ratio: 4/5;
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
  overflow: hidden;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--ink);
  background: #fff;
}
.upload-zone.has-photo { border-style: solid; cursor: default; }
.upload-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.upload-empty svg { margin: 0 auto 16px; color: var(--ink-2); }
.upload-empty strong { color: var(--ink); }
.upload-empty .hint { font-size: 13px; margin-top: 8px; }
#photoPreview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.upload-side { display: flex; flex-direction: column; gap: 24px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.field input:focus { outline: none; border-color: var(--ink); }
.photo-tips {
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.photo-tips h4 { margin: 0 0 10px; font-size: 14px; }
.photo-tips ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* CHIPS */
.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-group.scroll-chips {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.chip-group.scroll-chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
  transition: all .15s;
}
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); color: var(--accent-contrast); border-color: var(--ink); }

/* FILTER BAR */
.filter-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}

/* LOOK GRID */
.look-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.look-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  border: 1px solid var(--line);
}
.look-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.look-thumb {
  aspect-ratio: 9/16;
  position: relative;
  overflow: hidden;
}
.look-thumb svg { width: 100%; height: 100%; display: block; }
.look-thumb .look-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}
.look-thumb .look-photo.loaded { opacity: 1; }
.look-meta { padding: 14px 16px 16px; }
.look-meta .tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.look-meta .name {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* DETAIL */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: start;
}
.detail-art {
  aspect-ratio: 9/16;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 100px;
}
.detail-art { position: sticky; top: 100px; }
.detail-art svg { width: 100%; height: 100%; display: block; position: absolute; inset: 0; }
.detail-art .look-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}
.detail-art .look-photo.loaded { opacity: 1; }
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 12px;
}
.garment-list {
  margin: 28px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.garment-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.garment-swatch {
  width: 48px; height: 48px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.garment-info { flex: 1; min-width: 0; }
.garment-name { font-weight: 600; font-size: 14px; }
.garment-sub { font-size: 13px; color: var(--muted); }
.garment-price { font-weight: 600; font-size: 14px; margin-right: 10px; }
.disclosure {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* RESULT */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}
.result-canvas-wrap { display: flex; flex-direction: column; gap: 16px; }
.result-canvas {
  aspect-ratio: 4/5;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: relative;
}
.result-canvas canvas, .result-canvas img { width: 100%; height: 100%; object-fit: cover; display: block; }
.result-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 2;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.result-shop h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 24px;
  margin: 0 0 16px;
}
.shop-list { display: flex; flex-direction: column; gap: 10px; }
.shop-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  transition: border-color .15s;
}
.shop-item:hover { border-color: var(--ink); }
.shop-item .garment-swatch { width: 52px; height: 52px; }
.shop-buy {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--accent-contrast);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

/* CLOSET */
.closet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}
.closet-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .15s;
}
.closet-card:hover { transform: translateY(-2px); }
.closet-thumb {
  aspect-ratio: 4/5;
  background: var(--line);
}
.closet-thumb img, .closet-thumb canvas { width: 100%; height: 100%; object-fit: cover; }
.closet-meta { padding: 10px 14px 14px; }
.closet-meta .name { font-weight: 500; font-size: 14px; }
.closet-meta .date { font-size: 12px; color: var(--muted); }
.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state h3 { font-family: var(--font-display); font-size: 28px; font-weight: 500; color: var(--ink); margin: 0 0 8px; }
.empty-state p { margin: 0 0 20px; }

/* SETTINGS */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 900px;
}
.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.settings-card h3 { font-size: 16px; margin: 0 0 14px; }
.settings-card .hint { color: var(--muted); font-size: 13px; margin: 12px 0; line-height: 1.5; }
.settings-card .btn { margin-right: 10px; margin-top: 8px; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--accent-contrast);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* RESPONSIVE */
@media (max-width: 860px) {
  .app-main { padding: 20px; }
  .hero { grid-template-columns: 1fr; gap: 32px; padding-bottom: 40px; }
  .features { grid-template-columns: repeat(2, 1fr); }
  .upload-grid, .detail-grid, .result-grid, .settings-grid { grid-template-columns: 1fr; }
  .detail-art { position: static; }
  .app-nav { gap: 0; }
  .nav-btn { padding: 8px 10px; font-size: 13px; }
}
