/* Cava v4 — phone first, big targets, light + dark. */
:root {
  --paper: #f5eee2; --card: #fffaf1; --ink: #23170f; --muted: #7b6b5d; --line: #e5dac8;
  --wine: #6b1d24; --wine-ink: #fff7ef; --gold: #a9853a; --soft: #efe5d4;
  --go: #2f6b4f; --warn: #a65e1b; --stop: #9b2c2c; --cool: #3d6286;
  --t1: #8b8279; --t2: #b19366; --t3: #c0605f; --t4: #7a1f2a; --t5: #b08a2e;
  --display: 'Cormorant Garamond', Georgia, serif;
  --ui: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 16px; --tabs: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15100e; --card: #211916; --ink: #f2e8da; --muted: #a8988a; --line: #3a2d28;
    --wine: #c4515d; --wine-ink: #1a0f0d; --gold: #d0a95a; --soft: #2a201c;
    --go: #6fbf95; --warn: #e0a05a; --stop: #e07a7a; --cool: #8fb2d6;
    --t1: #9a918a; --t2: #c8ab7d; --t3: #d97b79; --t4: #c4515d; --t5: #d6b25a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #15100e; --card: #211916; --ink: #f2e8da; --muted: #a8988a; --line: #3a2d28;
  --wine: #c4515d; --wine-ink: #1a0f0d; --gold: #d0a95a; --soft: #2a201c;
  --go: #6fbf95; --warn: #e0a05a; --stop: #e07a7a; --cool: #8fb2d6;
  --t1: #9a918a; --t2: #c8ab7d; --t3: #d97b79; --t4: #c4515d; --t5: #d6b25a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--ui); font-size: 16px; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
a { color: var(--wine); }

main { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabs) + env(safe-area-inset-bottom) + 24px); }
.screen > section, .screen > .card { margin-top: 18px; }
.boot, .center { display: grid; place-items: center; min-height: 40vh; }
.center-row { display: flex; justify-content: center; margin-top: 12px; }
h1 { font-family: var(--display); font-weight: 600; font-size: 40px; line-height: 1; margin: 0; letter-spacing: -0.01em; }
h2, h3 { margin: 0 0 8px; }
h3 { font-size: 15px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 700; display: flex; gap: 6px; align-items: center; }
.section-title { font-family: var(--display); font-size: 24px; font-weight: 600; display: flex; gap: 8px; align-items: center; margin: 24px 0 8px; }
.eyebrow { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); } .small { font-size: 14px; } .tiny { font-size: 12px; } .cap { text-transform: capitalize; }
.error { color: var(--stop); }
.note { font-size: 14px; color: var(--warn); margin: 6px 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card p { margin: 6px 0; line-height: 1.45; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 16px; font-weight: 700; display: inline-flex; gap: 8px; align-items: center; justify-content: center; min-height: 48px; }
.btn.primary { background: var(--wine); color: var(--wine-ink); border-color: var(--wine); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: 12px; } .btn.big { min-height: 58px; font-size: 18px; }
.btn.grow { flex: 1; }
.btn:disabled { opacity: 0.5; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--wine); font-weight: 700; display: inline-flex; gap: 6px; align-items: center; }
.icon-btn { background: none; border: 0; padding: 8px; color: var(--muted); }
.row { display: flex; gap: 10px; margin-top: 14px; }

/* home */
.home-head { display: flex; justify-content: space-between; align-items: flex-end; margin: 8px 0 16px; }
.screen-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.screen-head h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The Casa M room switcher (casam.me/rooms.js) in Cava's own tokens, light and dark. */
casam-rooms { flex: none; --casam-rooms-ink: var(--ink); --casam-rooms-bg: var(--card); --casam-rooms-line: var(--line);
  --casam-rooms-gold: var(--wine); --casam-rooms-mark-bg: var(--card); --casam-rooms-serif: var(--display); --casam-rooms-sans: var(--ui); }
.home-head casam-rooms { align-self: center; }
.home-head h1 { font-size: 52px; color: var(--wine); }
.scan-cta { width: 100%; display: flex; gap: 16px; align-items: center; text-align: left; background: var(--wine); color: var(--wine-ink); border: 0; border-radius: 20px; padding: 20px; box-shadow: 0 10px 30px -14px rgba(80, 10, 20, 0.6); }
.scan-cta b { display: block; font-size: 20px; }
.scan-cta small { opacity: 0.85; font-size: 14px; }
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; margin-top: 16px; }
.counts > * { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center; }
.counts b { display: block; font-family: var(--display); font-size: 30px; line-height: 1; }
.counts small { color: var(--muted); font-size: 13px; }

.row-card { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-top: 8px; }
.row-card.current { border-color: var(--wine); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 14px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.row-tiers { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 4px; font-size: 14px; }
.who-tier { display: inline-flex; gap: 4px; align-items: center; }

.tile { border-radius: 8px; object-fit: cover; flex: none; background: var(--soft); }
.tile-blank { background: linear-gradient(160deg, var(--soft), var(--line)); }
.tile-blank.style-red { background: linear-gradient(160deg, #6b1d24, #3d0f14); }
.tile-blank.style-white { background: linear-gradient(160deg, #efe0a8, #d6c27a); }
.tile-blank.style-rose { background: linear-gradient(160deg, #f2b8b0, #d9837a); }
.tile-blank.style-sparkling { background: linear-gradient(160deg, #f4e9c2, #d9c58a); }
.tile-blank.style-dessert, .tile-blank.style-fortified { background: linear-gradient(160deg, #c08a3a, #7a4a12); }
.tile-blank.style-orange { background: linear-gradient(160deg, #e7a25a, #b8692a); }

.tier-badge { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--t3); white-space: nowrap; }
.tier-badge.small { font-size: 12px; padding: 1px 7px; }
.tier-badge.t1 { background: var(--t1); } .tier-badge.t2 { background: var(--t2); } .tier-badge.t3 { background: var(--t3); }
.tier-badge.t4 { background: var(--t4); } .tier-badge.t5 { background: linear-gradient(90deg, var(--t5), #e6c56e); color: #2b1d05; }

.ready { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; }
.ready.go { color: var(--go); } .ready.warn { color: var(--warn); } .ready.stop { color: var(--stop); } .ready.cool { color: var(--cool); }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; height: calc(var(--tabs) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tab { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 700; padding: 6px 0; }
.tab.on { color: var(--wine); }
.tab.scan { width: 58px; height: 58px; margin: -18px auto 0; border-radius: 50%; background: var(--wine); color: var(--wine-ink); box-shadow: 0 8px 22px -8px rgba(80, 10, 20, 0.7); justify-content: center; }

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(20, 10, 8, 0.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 100dvh; height: 100dvh; overflow-y: auto; background: var(--paper); padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 24px); }
@media (min-width: 600px) { .sheet { height: auto; max-height: 92dvh; border-radius: 22px 22px 0 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: calc(-1 * (env(safe-area-inset-top) + 8px)); background: var(--paper); padding: 8px 0; z-index: 2; }
.sheet-head h2 { font-family: var(--display); font-size: 30px; font-weight: 600; margin: 0; }

/* scan */
.slot { position: relative; border-radius: 16px; overflow: hidden; background: var(--card); border: 1.5px dashed var(--line); aspect-ratio: 3 / 4; flex: 1; min-width: 0; }
.slot.big { aspect-ratio: 4 / 3; margin: 12px 0; border-color: var(--wine); }
.slot.has { border-style: solid; }
.slot img { width: 100%; height: 100%; object-fit: cover; }
.slot.big img { object-fit: contain; background: var(--soft); }
.slot-empty { width: 100%; height: 100%; background: none; border: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; }
.slot.big .slot-empty { color: var(--wine); font-size: 18px; }
.slot-empty small { font-weight: 500; }
.slot-clear { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.55); color: #fff; display: grid; place-items: center; }
.slot-label { position: absolute; left: 8px; bottom: 8px; font-size: 12px; font-weight: 700; color: #fff; background: rgba(0, 0, 0, 0.5); padding: 2px 8px; border-radius: 999px; }
.slot-row { display: flex; gap: 10px; }
.slot-row.small .slot { max-width: 110px; }

.hero-label { width: 100%; max-height: 300px; object-fit: contain; border-radius: 14px; background: var(--card); margin-bottom: 12px; }
.hero-label.small { width: 92px; height: 120px; object-fit: cover; margin: 0; flex: none; }
.id-head { display: flex; gap: 14px; align-items: flex-start; }
.wine-name { font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1.05; margin: 2px 0 6px; }
.known { background: var(--soft); border-radius: 14px; padding: 10px 14px; margin-top: 14px; font-size: 15px; }
.known p { margin: 4px 0; }
.big-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.choice { display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; min-height: 120px; border-radius: 18px; border: 1.5px solid var(--wine); background: var(--card); color: var(--wine); font-weight: 800; font-size: 17px; }
.choice:active { background: var(--wine); color: var(--wine-ink); }
.big-choice.compact .choice { min-height: 76px; flex-direction: row; font-size: 16px; }
.form { margin: 16px 0; }
.form .eyebrow { display: block; margin: 12px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 9px 14px; font-weight: 700; min-height: 40px; }
.chip.on { background: var(--wine); color: var(--wine-ink); border-color: var(--wine); }
.chip small { opacity: 0.7; font-weight: 600; }
.qty-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.stepper button { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; font-weight: 700; color: var(--wine); }
.stepper span { min-width: 36px; text-align: center; font-weight: 800; font-size: 18px; }
input, textarea { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px; min-height: 46px; font-size: 16px; }
textarea { resize: vertical; }
.bin-input, .place-input, .note-input { margin-top: 10px; }
label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 10px; }
label input { margin-top: 4px; color: var(--ink); font-weight: 500; }
label.inline { display: flex; align-items: center; gap: 10px; }
label.inline input { flex: 1; margin: 0; }
label.toggle { display: flex; gap: 10px; align-items: center; color: var(--ink); font-size: 16px; font-weight: 600; margin-top: 14px; }
label.toggle input { width: 22px; height: 22px; min-height: 0; accent-color: var(--wine); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.identity .chips { margin-top: 12px; }
.others { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 8px 0; font-size: 15px; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; }
.serve { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.serve > div { background: var(--soft); border-radius: 12px; padding: 10px; text-align: center; }
.serve b { display: block; font-size: 15px; }
.serve small { color: var(--muted); font-size: 12px; }
.serve .note { grid-column: 1 / -1; color: var(--muted); }
.quote { font-family: var(--display); font-size: 19px; font-style: italic; }
.quote small { font-family: var(--ui); font-style: normal; font-size: 12px; color: var(--muted); }
.spin-row { display: flex; gap: 10px; align-items: center; justify-content: center; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--wine); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* wset */
.wset .lede { font-family: var(--display); font-size: 21px; line-height: 1.25; }
.grade { background: var(--soft); border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.grade-head { display: flex; justify-content: space-between; align-items: center; }
.sat { margin: 12px 0; }
.sat-row { display: grid; grid-template-columns: 84px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.sat-row:first-child { grid-template-columns: 84px 1fr; }
.sat-row .val { font-size: 13px; color: var(--muted); text-align: right; }
.bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.bar i { height: 8px; border-radius: 4px; background: var(--line); }
.bar i.on { background: var(--wine); }
.aromas { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.aroma { background: var(--soft); border-radius: 999px; padding: 4px 10px; font-size: 14px; }

/* reaction */
.reaction { margin-top: 16px; border-color: var(--wine); }
.who { display: flex; gap: 8px; margin: 8px 0 12px; }
.who-btn { flex: 1; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px; font-weight: 800; display: flex; flex-direction: column; align-items: center; }
.who-btn.on { border-color: var(--who, var(--wine)); box-shadow: inset 0 0 0 1px var(--who, var(--wine)); }
.who-btn small { font-weight: 600; color: var(--muted); font-size: 12px; }
.tiers { display: grid; gap: 8px; }
.tier { display: grid; grid-template-columns: 72px 1fr; grid-template-rows: auto auto; text-align: left; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 10px 14px; min-height: 58px; align-items: center; }
.tier-dots { grid-row: 1 / 3; letter-spacing: 1px; font-size: 11px; color: var(--tc, var(--t3)); }
.tier-dots .dim { opacity: 0.2; }
.tier-label { font-weight: 800; font-size: 17px; }
.tier-hint { font-size: 13px; color: var(--muted); }
.tier.t1 { --tc: var(--t1); } .tier.t2 { --tc: var(--t2); } .tier.t3 { --tc: var(--t3); } .tier.t4 { --tc: var(--t4); } .tier.t5 { --tc: var(--t5); }
.tier.on { border-color: var(--tc); background: color-mix(in srgb, var(--tc) 16%, var(--card)); }
.tier.on .tier-label { color: var(--tc); }
.tier.t5.on { background: linear-gradient(100deg, color-mix(in srgb, var(--t5) 22%, var(--card)), var(--card)); }
.buy-again { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-weight: 700; }
.buy-again span { flex: 1; }
.confetti { text-align: center; font-size: 28px; letter-spacing: 6px; animation: pop 0.9s ease-out; }
@keyframes pop { from { transform: scale(0.4) translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* cellar */
.search { display: flex; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; margin: 12px 0; color: var(--muted); }
.search input { border: 0; padding: 12px 0; background: none; }
.bins { display: grid; gap: 10px; }
.bin { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 10px 10px; }
.bin-head { width: 100%; display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 10px 2px 4px; }
.bin-name { font-family: var(--display); font-size: 24px; font-weight: 700; min-width: 52px; text-align: left; }
.bin-thumbs { flex: 1; display: flex; gap: 4px; }
.bin-count { font-weight: 800; color: var(--wine); font-size: 18px; }
.bin .row-card { border: 0; background: var(--soft); }

/* wine page */
.wine-hero { display: flex; gap: 16px; align-items: flex-start; margin-top: 8px; }
.wine-hero img { width: 120px; height: 160px; object-fit: cover; border-radius: 12px; flex: none; }
.holdings .holding { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.holdings .bin-name { font-size: 20px; }
.edit-holding { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.edit-holding input { width: 90px; flex: none; }
.photos { margin-top: 14px; }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0; scroll-snap-type: x mandatory; }
.photo-thumb { flex: none; border: 0; padding: 0; background: none; position: relative; scroll-snap-align: start; }
.photo-thumb img { width: 110px; height: 146px; object-fit: cover; border-radius: 10px; }
.photo-thumb span { position: absolute; left: 6px; bottom: 6px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(0, 0, 0, 0.5); border-radius: 999px; padding: 1px 7px; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.92); display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox button { position: absolute; background: rgba(255, 255, 255, 0.12); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; display: grid; place-items: center; }
.lb-close { top: calc(env(safe-area-inset-top) + 12px); right: 12px; }
.lb-prev { left: 10px; top: 50%; } .lb-next { right: 10px; top: 50%; }
.big-num { font-family: var(--display); font-size: 54px; line-height: 1; margin: 4px 0; color: var(--wine); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs) + env(safe-area-inset-bottom) + 16px); z-index: 80; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-weight: 700; box-shadow: 0 8px 24px -10px rgba(0, 0, 0, 0.5); max-width: calc(100vw - 32px); }
.auth-wrap { min-height: 100dvh; }

/* picker */
.picker .row-card { margin-top: 10px; }
.picker .new-wine { border-style: dashed; }
.picker .link-btn { margin-top: 14px; }
.center-text { text-align: center; margin: -4px 0 8px; }
