:root {
  --bg: #0c0c0e;
  --panel: #161719;
  --panel-2: #202225;
  --line: #34363b;
  --text: #f3f4f6;
  --muted: #9aa0a8;
  --accent: #e9eaec;       /* near-white: primary buttons / key UI */
  --accent-2: #ffffff;     /* white: brand, stars, highlights */
  --danger: #9c4d46;       /* restrained brick red for destructive actions */
  --good: #cfd2d6;         /* light gray pill */
  --radius: 14px;
  --tabbar-h: 64px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

#appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: linear-gradient(180deg, #161719, #0c0c0e);
  border-bottom: 1px solid var(--line);
}
#brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--accent);
  background: #000;
  flex-shrink: 0;
}
#appbar h1 {
  margin: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
#appbar h1 .kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
#appbar h1 .dk {
  font-size: 20px;
  letter-spacing: 0.5px;
  font-weight: 800;
  color: var(--accent-2);
}
.badge {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 3px 10px;
  border-radius: 999px;
}

main#view {
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
}

#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: #0c0c0e;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 1px;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 9px;
  cursor: pointer;
}
.tab .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab .ico { font-size: 19px; line-height: 1; display: flex; }
.tab.active { color: var(--accent-2); }

/* Cards & panels */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 42px; margin-bottom: 8px; }

/* Buttons */
button.btn {
  background: var(--accent);
  color: var(--on-accent, #101012);
  border: none;
  border-radius: 10px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
button.btn:active { transform: scale(0.99); }
button.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.btn.danger { background: var(--danger); color: #fff; }
button.btn.ghost { background: none; color: var(--accent-2); }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field .lab { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  font-family: inherit;
}
textarea { min-height: 72px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Photo capture */
.photo-drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
}
.photo-preview { width: 100%; border-radius: var(--radius); display: block; }
.photo-wrap { position: relative; }
.photo-wrap .retake {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.6); color: #fff; border: none;
  border-radius: 999px; padding: 8px 12px; font-size: 13px;
}

/* Bottle list item */
.bottle {
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
}
.bottle .thumb {
  width: 56px; height: 72px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-2);
  flex-shrink: 0;
}
.bottle .thumb.placeholder { display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--line); }
.bottle .meta { flex: 1; min-width: 0; }
.row-ai {
  flex: 0 0 auto; align-self: center;
  width: 36px; height: 36px; padding: 0;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font-size: 16px; line-height: 1; cursor: pointer;
}
.row-ai:disabled { opacity: 0.5; }
.bottle .nm { font-weight: 600; }
.bottle .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; color: var(--muted); }

/* Stars */
.stars { display: inline-flex; gap: 2px; font-size: 22px; color: var(--line); }
.stars .s.on { color: var(--accent-2); }
.stars.small { font-size: 15px; }
.stars button { background: none; border: none; padding: 0 1px; color: inherit; font-size: inherit; cursor: pointer; }

/* Catalog epigraph */
.catalog-quote {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 16px;
  line-height: 1.5;
  text-align: center;
  color: var(--muted);
  margin: 2px 0 16px;
  padding: 0 12px 14px;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.2px;
}
.catalog-quote .mark { color: var(--line); font-size: 20px; }

/* Search bar */
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 6px; }
.chip { white-space: nowrap; font-size: 13px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; }
.chip.active { background: var(--accent); color: var(--on-accent, #101012); border-color: var(--accent); font-weight: 600; }

/* Modal / sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 30; display: flex; align-items: flex-end; }
.sheet {
  background: var(--bg);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--line);
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
}
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 999px; margin: 4px auto 14px; }
/* Sticky top bar so a Close control is always reachable without scrolling. */
.sheet-top {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -16px 8px;
  padding: 6px 16px 8px;
  background: var(--bg);
}
.sheet-top .sheet-handle { margin-top: 0; margin-bottom: 0; }
.sheet-close {
  position: absolute;
  top: 8px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

/* Spinner */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.25); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 12px 0; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #000;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* Detail rows */
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-weight: 500; }

.hero { width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--radius); background: var(--panel); margin-bottom: 14px; }

.note-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 14px; line-height: 1.5; color: var(--text); }

.shelf-board { display: flex; flex-direction: column; gap: 14px; }
.shelf {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.shelf h3 { margin: 0 0 4px; font-size: 15px; color: var(--accent-2); }
.shelf .cnt { font-size: 12px; color: var(--muted); }
.shelf ul { margin: 8px 0 0; padding-left: 18px; }
.shelf li { padding: 2px 0; font-size: 14px; }

.help { font-size: 13px; color: var(--muted); line-height: 1.5; }
a { color: var(--accent-2); }
.score-pill { font-size: 12px; background: var(--good); color: #101012; border-radius: 999px; padding: 2px 8px; font-weight: 600; }

/* ---- Gigi's Rochambeau (spinner) ---- */
.spin-wrap { text-align: center; }
.spin-title { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: 2px; }
.spin-sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.wheel-stage { position: relative; width: 100%; max-width: 360px; margin: 0 auto 6px; aspect-ratio: 1 / 1; }
.wheel-stage canvas { width: 100%; height: 100%; touch-action: manipulation; cursor: pointer; display: block; }
.wheel-pointer {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; z-index: 3;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 26px solid var(--accent-2);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
}
.wheel-hub {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 64px; height: 64px; border-radius: 50%;
  background: #000; border: 3px solid var(--accent-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; z-index: 2; box-shadow: 0 0 0 4px rgba(0,0,0,0.4);
}
.wheel-hub img { width: 100%; height: 100%; object-fit: cover; }
.wheel-hub .glyph { font-size: 26px; }
.spin-hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }

/* Tasting / social card */
.tasting-card {
  background: linear-gradient(180deg, #1b1c1f, #0c0c0e);
  border: 1px solid var(--accent);
  border-radius: 18px;
  padding: 18px;
  margin-top: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.tc-head { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.tc-head img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #000; border: 1px solid var(--accent); }
.tc-head .tc-brand { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--accent-2); font-weight: 700; line-height: 1.2; }
.tc-pick { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); }
.tasting-card h2 { margin: 2px 0 8px; font-size: 24px; color: var(--text); }
.tc-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tc-notes { font-size: 14px; line-height: 1.5; color: var(--muted); margin-bottom: 10px; }
.tc-rate { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.tc-foot { font-size: 11px; color: var(--muted); text-align: right; letter-spacing: 1px; }

/* ---- Recommendations (For You) ---- */
.rec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.wish-add {
  flex: none; background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.wish-add .star { font-size: 14px; line-height: 1; }
.wish-add.added { border-color: var(--accent-2); color: var(--accent-2); }
.wish-add.flag { border-style: dashed; border-color: var(--danger); color: var(--good); }

/* ---- Wishlist ---- */
.wl-actions { display: flex; gap: 10px; margin-bottom: 14px; }
.wl-actions .btn { flex: 1; }
.owned-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  border-radius: 999px; padding: 3px 9px; margin-top: 4px;
}
.owned-badge.have { background: var(--danger); color: #fff; }
.owned-badge.new { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.dup-warn {
  background: rgba(156,77,70,0.16); border: 1px solid var(--danger);
  border-radius: 10px; padding: 12px; font-size: 14px; line-height: 1.5; color: var(--text);
  margin-bottom: 12px;
}
.dup-warn b { color: var(--accent-2); }
.wl-avail { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

/* ---- First-run onboarding ---- */
.onboard-bg {
  position: fixed; inset: 0; z-index: 100; padding: 24px;
  background: radial-gradient(120% 80% at 50% 0%, #1a1b1e 0%, var(--bg) 70%);
  display: flex; align-items: center; justify-content: center;
}
.onboard { max-width: 360px; width: 100%; text-align: center; position: relative; }
.onboard-skip {
  position: absolute; top: -6px; right: 0; background: none; border: 0;
  color: var(--muted); font-size: 14px; padding: 6px 4px; cursor: pointer;
}
.onboard-icon { font-size: 60px; line-height: 1; margin-bottom: 10px; }
.onboard h2 { margin: 6px 0 10px; }
.onboard p { color: var(--muted); line-height: 1.55; min-height: 84px; margin: 0 4px; }
.onboard-dots { display: flex; gap: 6px; justify-content: center; margin: 18px 0; }
.onboard-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); transition: background .2s; }
.onboard-dots span.on { background: var(--accent-2); }
.onboard .btn-row { justify-content: center; }

/* ---- BYOK help disclosure ---- */
details.byok-help { margin: 4px 0 10px; }
details.byok-help summary { cursor: pointer; color: var(--accent-2); font-size: 14px; padding: 4px 0; }
details.byok-advanced > summary { cursor: pointer; color: var(--accent-2); font-weight: 600; padding: 2px 0; }
details.byok-help ol { margin: 8px 0; padding-left: 20px; }
details.byok-help li { margin: 5px 0; }

/* ---- Credit balance pill (Settings → Account) ---- */
.balance-pill {
  display: inline-block; margin: 8px 0 4px; padding: 6px 14px;
  border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); font-size: 15px; font-weight: 600;
}

/* Sign in with Apple button (native iOS app). Follows Apple's HIG: black pill,
   white logo + text, full width to match the Google sign-in button. */
.apple-signin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  background: #000;
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
}
.apple-signin-btn:disabled { opacity: 0.6; }
.apple-signin-btn svg { display: block; }

/* ---- Phase 2: status segmented control, pills, dictation ---- */
.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1; padding: 9px 6px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); border-radius: 10px; font-size: 14px; cursor: pointer;
}
.seg-btn.on { background: var(--accent); color: var(--on-accent, #111); border-color: var(--accent); font-weight: 600; }

/* ---- Appearance / theme picker ---- */
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 6px; cursor: pointer; color: var(--text); width: 100%;
}
.theme-swatch.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.theme-dot {
  width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.theme-dot > span { width: 15px; height: 15px; border-radius: 999px; display: block; }
.theme-name { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.2; }
input[type="color"] { width: 100%; border-radius: 10px; cursor: pointer; }

/* ---- "What people say" consensus block ---- */
.cons-head { display: flex; align-items: center; gap: 8px; }
.cons-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.cons-score { margin-left: auto; font-size: 13px; color: var(--muted); }
.cons-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; font-size: 14px; line-height: 1.5; }
.cons-ic { flex: 0 0 auto; }
.cons-inrec { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/* ---- search-by-name chooser ---- */
.cbn-list { display: flex; flex-direction: column; gap: 8px; }
.cbn-item {
  display: block; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; cursor: pointer; color: var(--text);
}
.cbn-item:active { transform: scale(0.995); }
.cbn-item .nm { font-weight: 600; }
.cbn-item .sub { font-size: 13px; margin-top: 2px; }

/* ---- interactive coachmark tour ---- */
.coach-bg { position: fixed; inset: 0; z-index: 60; }
.coach-hole {
  position: fixed; z-index: 60; pointer-events: none;
  border-radius: 12px; border: 2px solid var(--accent-2);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72);
  transition: left .2s, top .2s, width .2s, height .2s;
}
.coach-tip {
  position: fixed; z-index: 61; max-width: 300px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px;
}
.coach-tip h3 { margin: 0 0 6px; font-size: 16px; }
.coach-tip p { margin: 0 0 12px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.coach-actions { display: flex; align-items: center; gap: 12px; }
.coach-step { font-size: 12px; color: var(--muted); margin-right: auto; }
.coach-skip { background: none; border: none; color: var(--muted); font-size: 13px; cursor: pointer; }

.status-pill {
  display: inline-block; font-size: 11px; font-weight: 600; line-height: 1;
  padding: 3px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
  border: 1px solid var(--line); color: var(--muted);
}
.status-pill.open { color: #e8b85a; border-color: #e8b85a66; background: #e8b85a18; }
.status-pill.empty { color: #b9777f; border-color: #b9777f55; background: #b9777f14; }
.status-pill.qty { color: var(--text); }

.tag.tap { cursor: pointer; }

.mic {
  border: 0; background: none; cursor: pointer; font-size: 14px; padding: 0 4px;
  line-height: 1; opacity: 0.8;
}
.mic.listening { color: var(--danger); animation: micpulse 1s infinite; }
@keyframes micpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---- Phase 3: collector value & ROI ---- */
.roi.pos { color: #6fcf97; font-weight: 600; }
.roi.neg { color: #d98a8a; font-weight: 600; }
.roi-readout { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-size: 15px; }
.collection-summary .cs-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.collection-summary .cs-num { font-size: 18px; font-weight: 700; color: var(--text); }
.collection-summary .cs-lab { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* PDF export now renders into an isolated iframe (see exportCollectionPdf). */
