@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Instrument+Serif:ital@0;1&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* === Color System === */
  --forest: #1a3a2a;
  --forest-mid: #2d5a3f;
  --forest-light: #4a7a5e;
  --bark: #3a2a1a;
  --bark-mid: #5a3e28;
  --bark-light: #7a5a3e;
  --caramel: #c8a87a;
  --cream: #f7f3ec;
  --cream-warm: #f0ebe0;
  --bone: #faf8f4;
  --text-primary: #1a1610;
  --text-secondary: #4a4236;
  --text-tertiary: #8a7e6e;
  --text-inverse: #faf8f4;

  /* === Radii === */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  /* === Shadows === */
  --shadow-sm: 0 2px 8px rgba(26, 22, 16, 0.06);
  --shadow-md: 0 8px 24px rgba(26, 22, 16, 0.08);
  --shadow-lg: 0 16px 48px rgba(26, 22, 16, 0.12);

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

  /* === Safe area (overridden on notched iPhones) === */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bone);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;        /* prevent double-tap zoom */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

em {
  font-family: 'Instrument Serif', serif;
  font-style: italic;
  font-weight: 400;
}

/* ===== GRAIN TEXTURE ===== */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

/* ===== LANDING SCREEN ===== */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  background: var(--forest);
  position: relative;
  overflow: hidden;
  padding-top: var(--sat);
  padding-bottom: var(--sab);
}

.landing::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 80%, rgba(90, 62, 40, 0.4) 0%, transparent 70%),
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(74, 122, 94, 0.3) 0%, transparent 70%);
  z-index: 0;
}

.landing-inner {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1.5rem;
  max-width: 560px;
}

.landing-eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--caramel);
  margin-bottom: 1.25rem;
  opacity: 0;
  animation: fadeUp 0.8s var(--ease-out) 0.2s forwards;
}

.landing-title {
  font-family: 'Instrument Serif', serif;
  font-size: clamp(3rem, 10vw, 6rem);
  color: var(--cream);
  line-height: 0.95;
  margin-bottom: 1.25rem;
  opacity: 0;
  animation: fadeUp 0.8s var(--ease-out) 0.4s forwards;
}

.landing-title em {
  color: var(--caramel);
  font-style: italic;
}

.landing-subtitle {
  font-size: 1.05rem;
  line-height: 1.6;
  color: rgba(250, 248, 244, 0.7);
  margin-bottom: 2rem;
  opacity: 0;
  animation: fadeUp 0.8s var(--ease-out) 0.6s forwards;
}

.btn-start {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--cream);
  color: var(--forest);
  border: none;
  padding: 1rem 2.2rem;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s ease;
  opacity: 0;
  animation: fadeUp 0.8s var(--ease-out) 0.8s forwards;
  -webkit-tap-highlight-color: transparent;
}

.btn-start:active {
  transform: scale(0.96);
}

.landing-hint {
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: rgba(250, 248, 244, 0.35);
  opacity: 0;
  animation: fadeUp 0.8s var(--ease-out) 1s forwards;
}

.landing-hint kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  color: rgba(250, 248, 244, 0.5);
}

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

/* ===== SWIPE SCREEN ===== */
.app {
  display: none;
  flex-direction: column;
  height: 100dvh;
  padding: calc(var(--sat) + 0.5rem) var(--sar) calc(var(--sab) + 0.5rem) var(--sal);
  background: var(--cream-warm);
  overflow: hidden;
}

.app.active { display: flex; }

.app-header {
  flex-shrink: 0;
  padding: 0 1rem;
  margin-bottom: 0.5rem;
}

.app-brand {
  font-family: 'Instrument Serif', serif;
  font-size: 1.1rem;
  color: var(--forest);
  margin-bottom: 0.35rem;
  letter-spacing: -0.01em;
}

.app-brand em {
  color: var(--caramel);
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-track {
  flex: 1;
  height: 4px;
  background: rgba(26, 58, 42, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--forest-mid);
  border-radius: 2px;
  transition: width 0.5s var(--ease-out);
}

.counter {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: 50px;
  text-align: right;
}

/* ===== CARD ===== */
.card-container {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;           /* center on wider screens */
}

.card {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-xl);
  background: white;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  transition: transform 0.15s ease;
  touch-action: none;       /* card captures all touch */
}

.card.swiping { transition: none; }

.card-image {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--cream-warm);
  min-height: 0;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  background: var(--cream-warm);
}

.card-image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 30%;
  background: linear-gradient(to top, rgba(255,255,255,0.95) 0%, transparent 100%);
  pointer-events: none;
}

.card-body {
  padding: 0.85rem 1.15rem;
  flex-shrink: 0;
  background: white;
}

.card-name {
  font-family: 'Instrument Serif', serif;
  font-size: 1.15rem;
  line-height: 1.2;
  margin-bottom: 0.3rem;
  color: var(--text-primary);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tag-style {
  background: rgba(45, 90, 63, 0.08);
  color: var(--forest-mid);
}

.tag-color {
  color: white;
  font-weight: 700;
}

/* Swipe overlay indicators */
.swipe-indicator {
  position: absolute;
  top: 1.5rem;
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 1.3rem;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 10;
  pointer-events: none;
  letter-spacing: 0.05em;
}

.swipe-indicator.like {
  right: 1.25rem;
  border: 3px solid var(--forest-mid);
  color: var(--forest-mid);
  transform: rotate(12deg);
}

.swipe-indicator.nope {
  left: 1.25rem;
  border: 3px solid #c4453a;
  color: #c4453a;
  transform: rotate(-12deg);
}

/* ===== SWIPE BUTTONS ===== */
.swipe-actions {
  flex-shrink: 0;
  display: flex;
  gap: 1.75rem;
  padding: 1rem 0 0.25rem;
  align-items: center;
  justify-content: center;
}

.btn-swipe {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
  box-shadow: var(--shadow-md);
  -webkit-tap-highlight-color: transparent;
}

.btn-swipe:active {
  transform: scale(0.88);
}

.btn-nope {
  color: #c4453a;
}

.btn-like {
  color: var(--forest-mid);
}

.btn-undo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: white;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}

.btn-undo:active {
  transform: scale(0.88);
}

.key-hint {
  display: none;           /* hidden on mobile by default */
  font-size: 0.72rem;
  color: var(--text-tertiary);
  padding: 0.25rem 0 0.5rem;
  text-align: center;
}

.key-hint kbd {
  background: white;
  border: 1px solid rgba(26, 22, 16, 0.12);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.68rem;
}

.swipe-hint-mobile {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  padding: 0.25rem 0 0.5rem;
  text-align: center;
}

/* ===== RESULTS SCREEN ===== */
.results {
  display: none;
  flex-direction: column;
  align-items: center;
  height: 100dvh;
  padding: calc(var(--sat) + 1rem) calc(var(--sar) + 1rem) calc(var(--sab) + 1rem) calc(var(--sal) + 1rem);
  max-width: 720px;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.results.active { display: flex; }

.results-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.results-eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--caramel);
  margin-bottom: 0.35rem;
}

.results-title {
  font-family: 'Instrument Serif', serif;
  font-size: clamp(2.2rem, 7vw, 3.5rem);
  color: var(--forest);
  line-height: 1;
  margin-bottom: 0.75rem;
}

.results-sub {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 480px;
}

/* Insight Cards */
.insight-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(26, 22, 16, 0.04);
  width: 100%;
}

.insight-card h3 {
  font-family: 'Instrument Serif', serif;
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--forest);
}

.insight-bar-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}

.insight-bar-label {
  width: 95px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.insight-bar-track {
  flex: 1;
  height: 22px;
  background: var(--cream-warm);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.insight-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.8s var(--ease-out);
  min-width: 0;
}

.insight-bar-value {
  width: 36px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}

/* Liked sofas grid */
.liked-sofas {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.liked-sofa-item {
  background: var(--cream-warm);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.liked-sofa-item .mini-img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.liked-sofa-item .mini-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin: 0.5rem auto 0.3rem;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.liked-sofa-item .info {
  padding: 0 0.5rem 0.5rem;
  text-align: center;
}

.liked-sofa-item .name {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 0.1rem;
  color: var(--text-primary);
}

.liked-sofa-item .meta {
  font-size: 0.65rem;
  color: var(--text-tertiary);
}

/* Summary card */
.insight-card.summary-card {
  background: var(--forest);
  color: var(--text-inverse);
  border: none;
}

.insight-card.summary-card h3 {
  color: var(--caramel);
}

.insight-card.summary-card p {
  color: rgba(250, 248, 244, 0.85);
}

.insight-card.summary-card strong {
  color: var(--cream);
}

/* Results actions */
.results-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.btn-more, .btn-restart, .btn-explore {
  padding: 0.9rem 2rem;
  border-radius: var(--radius-full);
  font-size: 1rem;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-more:active, .btn-restart:active, .btn-explore:active {
  transform: scale(0.96);
}

.btn-more {
  background: var(--forest);
  color: var(--cream);
  border: none;
}

.btn-explore {
  background: white;
  color: var(--forest);
  border: 2px solid var(--forest);
}

.btn-restart {
  background: white;
  color: var(--text-secondary);
  border: 2px solid rgba(26, 22, 16, 0.1);
}

/* Color helpers */
.bg-green { background: var(--forest-mid); }
.bg-brown { background: var(--bark-mid); }
.fill-green { background: linear-gradient(90deg, var(--forest), var(--forest-light)); }
.fill-brown { background: linear-gradient(90deg, var(--bark), var(--bark-light)); }

/* ===== ALL SOFAS SCREEN ===== */
.all-sofas {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--sat) + 0.5rem) var(--sar) calc(var(--sab) + 0.5rem) var(--sal);
  background: var(--cream-warm);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 50;
}

.all-sofas.active { display: flex; }

.all-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem 1rem;
  border-bottom: 1px solid rgba(26, 22, 16, 0.08);
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  background: white;
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}

.btn-back:active { transform: scale(0.96); }

.btn-back svg { stroke: var(--text-secondary); }

.all-title {
  font-family: 'Instrument Serif', serif;
  font-size: 1.5rem;
  color: var(--forest);
  flex: 1;
}

.all-count {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--caramel);
  background: var(--forest);
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-full);
}

.all-filters {
  display: flex;
  gap: 0.6rem;
  padding: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid rgba(26, 22, 16, 0.08);
}

.all-filters select {
  padding: 0.7rem 1rem;
  background: white;
  border: 1px solid rgba(26, 22, 16, 0.1);
  border-radius: var(--radius-md);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  min-width: 130px;
  flex-shrink: 0;
}

.all-filters select:focus {
  outline: none;
  border-color: var(--forest-mid);
}

.all-sofas-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 1rem;
}

@media (min-width: 480px) {
  .all-sofas-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 768px) {
  .all-sofas-grid { grid-template-columns: repeat(4, 1fr); max-width: 1200px; margin: 0 auto; }
}

.all-sofa-card {
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(26, 22, 16, 0.06);
  cursor: pointer;
  transition: transform 0.3s var(--ease-out), box-shadow 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.all-sofa-card:active { transform: scale(0.98); }

.all-sofa-card.liked { box-shadow: 0 0 0 2px var(--forest-mid), var(--shadow-md); }

.all-sofa-image {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--cream-warm);
  overflow: hidden;
}

.all-sofa-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.all-sofa-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--cream), var(--cream-warm));
}

.all-sofa-fallback .emoji { font-size: 3rem; filter: saturate(0.7); }

.all-sofa-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 28px;
  height: 28px;
  background: var(--forest);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.all-sofa-badge svg {
  width: 16px;
  height: 16px;
  stroke: white;
  stroke-width: 2.5;
  fill: white;
}

.all-sofa-info { padding: 0.75rem; }

.all-sofa-name {
  font-family: 'Instrument Serif', serif;
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.all-sofa-brand {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-bottom: 0.4rem;
}

.all-sofa-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}

.all-sofa-tag {
  font-size: 0.68rem;
  padding: 0.2rem 0.5rem;
  background: var(--cream-warm);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-weight: 600;
}

.all-sofa-price {
  font-family: 'Instrument Serif', serif;
  font-size: 1.1rem;
  color: var(--forest-mid);
}

@media (hover: hover) and (pointer: fine) {
  .btn-explore:hover {
    background: var(--forest);
    color: var(--cream);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }

  .btn-back:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  .all-sofa-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
  }
}

/* ===== DESKTOP ENHANCEMENTS ===== */
@media (hover: hover) and (pointer: fine) {
  .key-hint { display: block; }
  .swipe-hint-mobile { display: none; }
  .landing-hint { display: block; }

  .card-container {
    max-width: 400px;
    margin: 0 auto;
  }

  .btn-start:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  }

  .btn-start:hover svg {
    transform: translateX(4px);
  }

  .btn-swipe:hover {
    transform: scale(1.12);
    box-shadow: var(--shadow-lg);
  }

  .btn-undo:hover {
    transform: scale(1.1);
    color: var(--text-secondary);
    box-shadow: var(--shadow-md);
  }

  .card:hover .card-image img {
    transform: scale(1.03);
    transition: transform 0.6s var(--ease-out);
  }

  .liked-sofa-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  .btn-more:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }

  .btn-restart:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  .insight-card:hover {
    box-shadow: var(--shadow-md);
  }
}

/* Hide landing hint on touch devices */
@media (hover: none) {
  .landing-hint { display: none; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .grain { display: none; }
}
