:root {
  --aubergine: #1a1016;
  --charcoal: #241722;
  --charcoal-2: #2f1f2c;
  --brass: #c39a5e;
  --brass-deep: #9a7440;
  --bone: #ede6da;
  --bone-dim: #b7aca4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --serif: "Didot", "Playfair Display", Georgia, serif;
  --sans: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--aubergine);
  color: var(--bone);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 24px);
}

/* ---------- Cinematic intro ---------- */
.intro {
  position: fixed;
  inset: 0;
  /* Safari's collapsed bottom bar shrinks inset-based sizing, leaving a black
     band under the film — the large-viewport unit spans the true screen. */
  height: 100vh;
  height: 100lvh;
  z-index: 60;
  background: #000;
  opacity: 1;
  transition: opacity 0.7s ease;
}
.intro video { width: 100%; height: 100%; object-fit: cover; display: block; }
.intro.fade { opacity: 0; }

/* ---------- Landing ---------- */
#home { justify-content: center; gap: 18px; background: var(--aubergine); }
.home-wordmark { width: 52%; max-width: 240px; border-radius: 8px; }
.home-tag { font-family: var(--serif); font-style: italic; color: var(--bone-dim); font-size: 1.03rem; margin-top: -6px; display: flex; align-items: center; gap: 8px; }
.beta-tag {
  font-family: var(--sans);
  font-style: normal;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brass);
  border: 1px solid var(--brass-deep);
  border-radius: 999px;
  padding: 2px 9px;
}
.dest-card {
  width: 100%;
  max-width: 360px;
  min-height: 142px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--charcoal);
  border: 1px solid rgba(195, 154, 94, 0.35);
  border-radius: 16px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  color: var(--bone);
}
.dest-card:active { border-color: var(--brass); }
.dest-card img { width: 84px; height: 114px; flex: none; object-fit: cover; border-radius: 10px; }
.dest-text { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.dest-text strong { font-family: var(--serif); font-size: 1.35rem; font-weight: 500; }
.dest-text span { color: var(--bone-dim); font-size: 0.85rem; line-height: 1.35; }
.dest-card.soon { opacity: 0.75; }
.soon-tag {
  align-self: flex-start;
  font-size: 0.62rem !important;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass) !important;
  border: 1px solid var(--brass-deep);
  border-radius: 999px;
  padding: 3px 10px;
  margin-top: 4px;
}
.page-count { text-align: center; font-size: 0.78rem; color: var(--brass); letter-spacing: 0.08em; }

/* ---------- Steer sheet ---------- */
#steer-body .steer-summary { font-family: var(--serif); font-style: italic; color: var(--bone); text-align: center; font-size: 1.02rem; line-height: 1.5; margin-bottom: 6px; }
.steer-band {
  background: var(--charcoal-2);
  border: 1px solid rgba(195, 154, 94, 0.25);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.steer-band .band-name { font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--brass); }
.steer-band .band-varieties { font-family: var(--serif); font-size: 1.05rem; color: var(--bone); }
.steer-band .band-why { font-size: 0.85rem; color: var(--bone-dim); }

.home-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--brass-deep);
  background: rgba(26, 16, 22, 0.55);
  color: var(--brass);
  font-size: 1.15rem;
  cursor: pointer;
  pointer-events: auto;
}
.cam-header .home-btn { position: absolute; left: 16px; top: calc(var(--safe-top) + 10px); }
.cellar-home { position: absolute; left: 16px; top: calc(var(--safe-top) + 12px); }
.cellar-header { position: relative; width: 100%; }

/* ---------- Camera ---------- */
#camera-screen { padding: 0; }
#viewfinder {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.cam-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 14px) 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: linear-gradient(rgba(26, 16, 22, 0.85), transparent);
  pointer-events: none;
}
.cam-brand {
  font-family: var(--serif);
  letter-spacing: 0.35em;
  font-size: 1.05rem;
  color: var(--brass);
}
.cam-hint { font-size: 0.8rem; color: var(--bone-dim); }
.cam-controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.cam-steer {
  background: rgba(26, 16, 22, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#capture-btn {
  width: 78px; height: 78px;
  border-radius: 50%;
  border: 4px solid var(--brass);
  background: rgba(26, 16, 22, 0.35);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.capture-ring {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--brass);
  transition: transform 0.12s ease;
}
#capture-btn:active .capture-ring { transform: scale(0.85); }

#camera-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px;
  text-align: center;
  background: var(--aubergine);
}
.fallback-wordmark { width: 70%; max-width: 320px; border-radius: 6px; }
#camera-fallback p { color: var(--bone-dim); font-size: 0.95rem; }

/* ---------- Buttons ---------- */
.btn-brass {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--aubergine);
  background: var(--brass);
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
}
.btn-quiet {
  font-size: 0.95rem;
  color: var(--brass);
  background: transparent;
  border: 1px solid var(--brass-deep);
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
}
.btn-quiet.subtle { border: none; color: var(--bone-dim); }

/* ---------- Scanning overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 16, 22, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  z-index: 40;
}
#scan-copy { font-family: var(--serif); font-size: 1.15rem; color: var(--bone); font-style: italic; }
.candle { position: relative; width: 40px; height: 110px; }
.wax {
  position: absolute; bottom: 0; left: 8px;
  width: 24px; height: 62px;
  background: var(--bone);
  border-radius: 5px 5px 3px 3px;
}
.wick { position: absolute; bottom: 60px; left: 19px; width: 2px; height: 8px; background: #4a3428; }
.flame {
  position: absolute; bottom: 66px; left: 12px;
  width: 16px; height: 26px;
  background: radial-gradient(ellipse at 50% 75%, #f6d67c 0%, var(--brass) 55%, transparent 75%);
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  transform-origin: 50% 100%;
  animation: flicker 0.9s infinite alternate ease-in-out;
}
@keyframes flicker {
  0% { transform: scale(1) rotate(-2deg); opacity: 0.92; }
  50% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(0.94) rotate(-1deg); opacity: 0.88; }
}
@media (prefers-reduced-motion: reduce) { .flame { animation: none; } }

/* ---------- Sheets ---------- */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--charcoal);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
  z-index: 30;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-grab { width: 44px; height: 4px; border-radius: 2px; background: var(--brass-deep); margin: 4px auto 2px; }
.sheet-title { font-family: var(--serif); font-size: 1.5rem; text-align: center; color: var(--bone); }

.pick-card {
  background: var(--charcoal-2);
  border: 1px solid rgba(195, 154, 94, 0.25);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}
.pick-card + .pick-card { margin-top: 10px; }
.pick-role { font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--brass); }
.pick-name { font-family: var(--serif); font-size: 1.15rem; color: var(--bone); }
.pick-reason { font-size: 0.88rem; color: var(--bone-dim); }
.pick-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--brass); }

#detail-body h3 { font-family: var(--serif); font-size: 1.4rem; margin-bottom: 4px; }
#detail-body .pick-role { display: block; margin-bottom: 8px; }
#detail-body p { font-size: 0.95rem; color: var(--bone-dim); margin: 8px 0; line-height: 1.5; }
#detail-body .price-line { color: var(--brass); font-weight: 600; }
#detail-body .palate-line { color: var(--bone); font-style: italic; }
.detail-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Pair stub ---------- */
#pair-stub { justify-content: center; text-align: center; gap: 16px; background: var(--aubergine); z-index: 35; }
.stub-hero { width: 55%; max-width: 240px; border-radius: 10px; }
#pair-stub h2 { font-family: var(--serif); font-size: 1.5rem; }
#pair-stub p { color: var(--bone-dim); max-width: 300px; font-size: 0.92rem; line-height: 1.5; }

/* ---------- Cellar ---------- */
#cellar-screen { background: var(--aubergine); overflow-y: auto; gap: 16px; }
.cellar-header { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.cellar-wordmark { width: 46%; max-width: 210px; border-radius: 6px; }
.cellar-header h2 { font-family: var(--serif); font-size: 1.3rem; }
.cellar-sub { font-family: var(--serif); font-style: italic; color: var(--bone-dim); font-size: 1.0rem; line-height: 1.45; text-align: center; padding: 0 22px; margin-top: -4px; }
#cellar-empty { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
#cellar-empty img { width: 62%; max-width: 260px; border-radius: 10px; }
#cellar-empty p { color: var(--bone-dim); font-size: 0.92rem; max-width: 300px; line-height: 1.5; }
#cellar-list { list-style: none; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.bottle {
  background: var(--charcoal);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bottle-name { font-family: var(--serif); font-size: 1.05rem; }
.bottle-meta { font-size: 0.8rem; color: var(--bone-dim); }
.window-tag { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--brass); }
.readiness { height: 5px; border-radius: 3px; background: var(--charcoal-2); overflow: hidden; margin-top: 4px; }
.readiness > div { height: 100%; background: linear-gradient(90deg, var(--brass-deep), var(--brass)); }

/* ---------- Onboarding ---------- */
#onboarding { background: var(--aubergine); z-index: 50; justify-content: flex-start; gap: 14px; padding-top: calc(var(--safe-top) + 20px); padding-bottom: calc(var(--safe-bottom) + 22px); }
.onboard-track { display: flex; overflow: hidden; width: 100%; flex: 1; min-height: 0; align-items: center; }
.onboard-slide {
  min-width: 100%;
  transition: transform 0.35s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  text-align: center;
  transition: transform 0.35s ease;
}
.onboard-slide img, .onboard-slide video { max-height: 46vh; width: auto; max-width: 78%; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); }
.onboard-slide h2 { font-family: var(--serif); font-size: clamp(1.25rem, 5.2vw, 1.7rem); line-height: 1.3; }
.onboard-slide h2 em { color: var(--brass); }
.slide-sub { font-family: var(--serif); font-style: italic; color: var(--bone-dim); font-size: clamp(0.98rem, 4.1vw, 1.13rem); line-height: 1.45; margin-top: -6px; padding: 0 10px; }
.onboard-dots { display: flex; gap: 8px; margin-top: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--charcoal-2); }
.dot.active { background: var(--brass); }

/* ---------- Chips (food styles & dishes) ---------- */
.sheet-sub { text-align: center; color: var(--bone-dim); font-size: 0.85rem; margin-top: -6px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font-size: 0.85rem;
  color: var(--bone);
  background: var(--charcoal-2);
  border: 1px solid rgba(195, 154, 94, 0.3);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.chip.on { background: var(--brass); color: var(--aubergine); border-color: var(--brass); font-weight: 600; }

/* ---------- Bottle confirmation ---------- */
#bottle-body h3 { font-family: var(--serif); font-size: 1.3rem; margin-bottom: 2px; }
#bottle-body .bottle-fields { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 0.9rem; margin-top: 10px; }
#bottle-body .bottle-fields dt { color: var(--brass); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; align-self: center; }
#bottle-body .bottle-fields dd { color: var(--bone); margin: 0; }
#bottle-body .bottle-note { color: var(--bone-dim); font-size: 0.98rem; margin-top: 10px; font-style: italic; }

/* ---------- Quantity stepper & take ---------- */
.qty-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; color: var(--bone-dim); }
.qty-ctl { display: flex; align-items: center; gap: 14px; }
.qty-ctl button {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--brass-deep);
  background: transparent;
  color: var(--brass);
  font-size: 1.2rem;
  cursor: pointer;
}
.qty-ctl strong { font-family: var(--serif); font-size: 1.2rem; color: var(--bone); min-width: 20px; text-align: center; }
.take-btn {
  align-self: flex-end;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--bone-dim);
  background: transparent;
  border: 1px solid var(--charcoal-2);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  margin-top: 2px;
}
.take-btn:active { color: var(--brass); border-color: var(--brass-deep); }
.qty-badge { color: var(--brass); font-family: var(--sans); font-size: 0.85rem; }
#toast .toast-action {
  margin-left: 12px;
  color: var(--brass);
  background: transparent;
  border: none;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- Cellar management ---------- */
#cellar-stats { display: flex; gap: 10px; width: 100%; }
.stat {
  flex: 1;
  background: var(--charcoal);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
}
.stat.active { border-color: var(--brass); }
.stat strong { font-family: var(--serif); font-size: 1.4rem; color: var(--brass); }
.stat span { font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--bone-dim); }
#cellar-search {
  width: 100%;
  background: var(--charcoal);
  border: 1px solid rgba(195, 154, 94, 0.25);
  border-radius: 10px;
  color: var(--bone);
  font-size: 0.95rem;
  padding: 11px 14px;
  -webkit-appearance: none;
}
#cellar-search::placeholder { color: var(--bone-dim); }
#cellar-insights {
  width: 100%;
  background: var(--charcoal);
  border: 1px solid var(--brass-deep);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#cellar-insights .ins-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
#cellar-insights .ins-title { font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--brass); }
#cellar-insights .ins-chevron { color: var(--brass); font-size: 0.8rem; transition: transform 0.15s ease; }
#cellar-insights.collapsed .ins-chevron { transform: rotate(-90deg); }
.ins-chevron.spin { animation: inspin 1.1s linear infinite; }
@keyframes inspin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ins-chevron.spin { animation: none; } }
.ins-thinking { font-style: italic; }
#cellar-insights.collapsed .ins-body { display: none; }
#cellar-insights .ins-body { display: flex; flex-direction: column; gap: 8px; }
#cellar-insights p { color: var(--bone-dim); line-height: 1.45; }
#cellar-insights p strong { color: var(--bone); font-weight: 600; }
#cellar-groups { width: 100%; display: flex; flex-direction: column; gap: 8px; }
#cellar-groups details {
  background: var(--charcoal);
  border-radius: 12px;
  overflow: hidden;
}
#cellar-groups summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--bone);
}
#cellar-groups summary::-webkit-details-marker { display: none; }
#cellar-groups summary .count { font-family: var(--sans); font-size: 0.75rem; color: var(--brass); letter-spacing: 0.1em; }
#cellar-groups ul { list-style: none; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- Install sheet ---------- */
.install-icon { width: 76px; height: 76px; border-radius: 18px; align-self: center; box-shadow: 0 6px 22px rgba(0,0,0,0.45); }
.install-steps { list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.install-steps li { counter-increment: step; display: flex; align-items: center; gap: 12px; color: var(--bone-dim); font-size: 0.95rem; }
.install-steps li::before {
  content: counter(step);
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  border: 1px solid var(--brass-deep);
  color: var(--brass);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 0.9rem;
}
.install-steps strong { color: var(--bone); }
.install-alt { text-align: center; color: var(--bone-dim); font-size: 0.78rem; }
#install-sheet .btn-brass { align-self: center; }
.install-link { color: var(--brass); }

/* ---------- Why Garde ---------- */
.home-links { display: flex; gap: 22px; margin-top: 4px; }
.why-body { display: flex; flex-direction: column; gap: 12px; padding: 0 6px; }
.why-body p { color: var(--bone-dim); font-size: 0.95rem; line-height: 1.6; }
.why-body em { color: var(--bone); font-family: var(--serif); }
.why-flourish { text-align: center; color: var(--brass) !important; font-family: var(--serif); font-style: italic; }
#why-sheet .btn-brass { align-self: center; }

/* ---------- Feedback ---------- */
.feedback-link {
  background: none;
  border: none;
  color: var(--bone-dim);
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  margin-top: 4px;
}
#feedback-text {
  width: 100%;
  background: var(--charcoal-2);
  border: 1px solid rgba(195, 154, 94, 0.25);
  border-radius: 10px;
  color: var(--bone);
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 12px;
  resize: vertical;
}
#feedback-text::placeholder { color: var(--bone-dim); }

/* ---------- Group-by toggle ---------- */
.group-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bone-dim);
}
.group-toggle button {
  background: transparent;
  border: 1px solid var(--charcoal-2);
  border-radius: 999px;
  color: var(--bone-dim);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 12px;
  cursor: pointer;
}
.group-toggle button.on { color: var(--brass); border-color: var(--brass-deep); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 60px);
  transform: translateX(-50%);
  background: var(--charcoal-2);
  color: var(--bone);
  border: 1px solid var(--brass-deep);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.88rem;
  max-width: 84vw;
  text-align: center;
  z-index: 60;
}
