:root {
  --bg: #faf6f1;
  --card: #ffffff;
  --ink: #2a1f1f;
  --mute: #75625f;
  --line: #e8ded4;
  --soft: #f3ece4;
  --accent: #7b1e3a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4e9;
  --ok: #2f6b3a;
  --warn: #9a5b00;
  --bad: #a12626;
  --info: #3b5b8c;
  --star: #c8921a;
  --c-rouge: #7b1e3a;
  --c-blanc: #d8c065;
  --c-rose: #e79aa8;
  --c-bulles: #e9c46a;
  --c-liquoreux: #c8862a;
  --c-autre: #8a8a8a;
  --shadow: 0 6px 24px rgba(60, 20, 30, 0.12);
  --font-s: "Fraunces", Georgia, "Times New Roman", serif;
  --font-b: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1416;
    --card: #241c1f;
    --ink: #f1e8e3;
    --mute: #ad9f9f;
    --line: #3a2e32;
    --soft: #2d2327;
    --accent: #d2607f;
    --accent-ink: #1a1416;
    --accent-soft: #3d2129;
    --ok: #6cc27c;
    --warn: #e9a64a;
    --bad: #e27a7a;
    --info: #8fb0e6;
    --star: #e2b23f;
    --c-rouge: #b23a5a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1416;
  --card: #241c1f;
  --ink: #f1e8e3;
  --mute: #ad9f9f;
  --line: #3a2e32;
  --soft: #2d2327;
  --accent: #d2607f;
  --accent-ink: #1a1416;
  --accent-soft: #3d2129;
  --ok: #6cc27c;
  --warn: #e9a64a;
  --bad: #e27a7a;
  --info: #8fb0e6;
  --star: #e2b23f;
  --c-rouge: #b23a5a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font-b);
  padding-top: env(safe-area-inset-top, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--mute); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px calc(120px + var(--safe-b)); }

/* ---------- Header ---------- */
.top { display: flex; align-items: center; gap: 8px; padding: 14px 0 6px; }
.brand { flex: 1; min-width: 0; }
.brand h1 { font: 700 26px/1.1 var(--font-s); margin: 0; letter-spacing: -0.01em; }
.brand .sub { color: var(--mute); font-size: 13px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; font-size: 18px; flex: none;
}

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 12px; }
.stat {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 8px 10px; min-width: 0;
}
.stat b { display: block; font: 700 20px/1.15 var(--font-s); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat span { font-size: 12px; color: var(--mute); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.alert b { color: var(--warn); }
.stat[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
@media (max-width: 560px) {
  .stats { gap: 6px; }
  .stat { padding: 7px 8px; border-radius: 12px; }
  .stat b { font-size: 17px; }
  .stat span { font-size: 11px; }
}

/* ---------- Tonight ---------- */
.tonight {
  background: linear-gradient(135deg, var(--accent-soft), var(--card));
  border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 14px;
}
.tonight h2 { font: 700 18px/1.2 var(--font-s); margin: 0 0 8px; }
.tonight form { display: flex; gap: 8px; }
.tonight input { flex: 1; min-width: 0; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.suggestions { display: grid; gap: 8px; margin-top: 10px; }
.sugg {
  display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px;
}
.sugg .thumb { width: 44px; height: 58px; }
.sugg .body { flex: 1; min-width: 0; }
.sugg .why { font-size: 12.5px; color: var(--mute); }
.tonight .note { font-size: 13px; color: var(--mute); margin-top: 8px; }

/* ---------- Inputs and buttons ---------- */
input[type="search"], input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; min-height: 44px;
}
textarea { resize: vertical; min-height: 70px; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 9px 14px;
  min-height: 44px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
a.btn { text-decoration: none; color: inherit; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 36px; padding: 6px 10px; font-size: 13.5px; border-radius: 10px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px;
  font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; white-space: nowrap;
  flex: none;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip[aria-pressed="true"] .dot { box-shadow: 0 0 0 2px var(--accent-ink); }
.chip .x { opacity: 0.8; font-size: 15px; line-height: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: var(--c-autre); }
.dot.rouge { background: var(--c-rouge); }
.dot.blanc { background: var(--c-blanc); }
.dot.rose { background: var(--c-rose); }
.dot.bulles { background: var(--c-bulles); box-shadow: 0 0 0 2px var(--soft); }
.dot.liquoreux { background: var(--c-liquoreux); }

/* ---------- Search and filters ---------- */
.searchbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 8px 0 6px;
  margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.searchbar.stuck { box-shadow: 0 6px 12px -10px rgba(0, 0, 0, 0.35); }
.search { position: relative; }
.search input { padding-left: 38px; padding-right: 40px; font-size: 16px; -webkit-appearance: none; appearance: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.search .glass { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--mute); pointer-events: none; }
.search .clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none;
  width: 38px; height: 38px; font-size: 18px; color: var(--mute);
}
.parsed { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 8px; }
.parsed:empty { display: none; }
.parsed .chip { background: var(--accent-soft); border-color: transparent; }
.parsed .hint { font-size: 12.5px; color: var(--mute); align-self: center; }
.filters { display: grid; gap: 6px; padding-top: 8px; }
.frow { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.frow::-webkit-scrollbar { display: none; }
.frow .sep { width: 1px; background: var(--line); flex: none; margin: 4px 2px; }

.listhead { display: flex; align-items: center; gap: 8px; margin: 10px 0 8px; }
.listhead .count { flex: 1; font-size: 13.5px; color: var(--mute); }
.listhead select { width: auto; min-height: 38px; padding: 6px 10px; font-size: 13.5px; }
.viewtoggle { display: none; }
@media (min-width: 900px) { .viewtoggle { display: inline-flex; gap: 4px; } }

/* ---------- Bottle cards ---------- */
/* min(): a card never asks for more than the screen; min-width 0 lets long names wrap. */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 10px; }
.cards > * { min-width: 0; }
.bottle {
  display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 10px; align-items: stretch; cursor: pointer; text-align: left; width: 100%;
}
.bottle:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.thumb {
  width: 64px; height: 86px; border-radius: 10px; background: var(--soft); flex: none; overflow: hidden;
  display: grid; place-items: center; font-size: 26px; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .band { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--c-autre); }
.thumb .band.rouge { background: var(--c-rouge); }
.thumb .band.blanc { background: var(--c-blanc); }
.thumb .band.rose { background: var(--c-rose); }
.thumb .band.bulles { background: var(--c-bulles); }
.thumb .band.liquoreux { background: var(--c-liquoreux); }
.bottle .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bottle .name { font: 700 16px/1.2 var(--font-s); overflow-wrap: anywhere; }
.bottle .sub { font-size: 13px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.vint { font-weight: 700; }
.price { font-weight: 600; }
.pairs { font-size: 15px; letter-spacing: 2px; }
.side { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 6px; }
.qty { font-weight: 700; font-size: 13px; background: var(--soft); border-radius: 999px; padding: 2px 9px; }
.drink {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--soft);
  font-size: 20px; display: grid; place-items: center;
}
.drink:active { transform: scale(0.94); }
.badge { font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 2px 8px; border: 1px solid currentColor; white-space: nowrap; }
.badge.ready { color: var(--ok); }
.badge.soon, .badge.past { color: var(--warn); }
.badge.keep { color: var(--info); }
.badge.rebuy { color: var(--accent); }
.stars { color: var(--star); letter-spacing: 1px; white-space: nowrap; }
.stars .off { opacity: 0.25; }

.empty { text-align: center; padding: 40px 16px; color: var(--mute); }
.empty .big { font-size: 46px; }
.empty .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

/* ---------- Table (desktop) ---------- */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
table { border-collapse: collapse; width: 100%; min-width: 860px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--mute); background: var(--soft); white-space: nowrap; }
th button { background: none; border: 0; padding: 0; font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit; }
th button[data-on="true"] { color: var(--accent); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--soft); }
tr:last-child td { border-bottom: 0; }
td .thumb { width: 36px; height: 48px; font-size: 16px; border-radius: 6px; }
td .drink { width: 38px; height: 38px; font-size: 17px; }

/* ---------- Add button ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--safe-b)); z-index: 30;
  display: flex; gap: 10px; align-items: center;
}
.fab-main {
  display: inline-flex; align-items: center; gap: 8px; background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; padding: 0 22px; height: 58px; font-weight: 700; font-size: 16px; box-shadow: var(--shadow);
  cursor: pointer; border: 0;
}
.fab-main .ico { font-size: 22px; }
.fab-mini {
  width: 50px; height: 50px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  font-size: 20px; box-shadow: var(--shadow);
}

/* ---------- Sheets (dialogs) ---------- */
dialog {
  border: 0; padding: 0; background: var(--card); color: var(--ink); width: 100%; max-width: 680px;
  max-height: calc(100dvh - 24px); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(20, 8, 12, 0.55); }
@media (max-width: 680px) {
  dialog {
    margin: auto 0 0; max-width: none; border-radius: 22px 22px 0 0; max-height: calc(100dvh - 32px);
  }
}
.shead { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.shead h2 { flex: 1; margin: 0; font: 700 19px/1.2 var(--font-s); min-width: 0; }
/* flex-basis auto: with 0 (flex: 1), WebKit sizes the sheet without its content. */
.sbody { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.sfoot {
  display: flex; gap: 8px; padding: 10px 14px calc(10px + var(--safe-b)); border-top: 1px solid var(--line);
  background: var(--card);
}
.sfoot .grow { flex: 1; }

.hero { display: flex; gap: 14px; align-items: flex-start; }
.hero .photo {
  width: 120px; height: 160px; border-radius: 14px; overflow: hidden; background: var(--soft); flex: none;
  display: grid; place-items: center; font-size: 44px; border: 0; padding: 0;
}
.hero .photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero .title { font: 700 22px/1.15 var(--font-s); margin: 0 0 4px; overflow-wrap: anywhere; }
.hero .facts { color: var(--mute); font-size: 14px; display: grid; gap: 2px; }
.photos-alt { display: flex; gap: 6px; margin-top: 8px; }
.photos-alt button { width: 36px; height: 48px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); padding: 0; background: var(--soft); }
.photos-alt button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.photos-alt img { width: 100%; height: 100%; object-fit: cover; }

.actionbar { display: grid; grid-template-columns: 2fr 0.8fr 1.2fr; gap: 8px; }
.actionbar .btn { padding: 8px 6px; }
.starpick { display: flex; gap: 2px; align-items: center; }
.starpick button { background: none; border: 0; font-size: 30px; line-height: 1; padding: 2px 3px; color: var(--line); }
.starpick button.on { color: var(--star); }
.starpick .lbl { font-size: 13px; color: var(--mute); margin-left: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fact { background: var(--soft); border-radius: 12px; padding: 8px 10px; }
.fact span { display: block; font-size: 11.5px; color: var(--mute); text-transform: uppercase; letter-spacing: 0.04em; }
.fact b { font-weight: 600; }
.section h3 { font: 700 16px/1.2 var(--font-s); margin: 0 0 6px; }
.section p { margin: 0; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 13px; background: var(--soft); border-radius: 999px; padding: 3px 10px; }

.window { position: relative; height: 10px; background: var(--soft); border-radius: 999px; margin: 8px 0 4px; }
.window .span { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--ok) 45%, transparent); border-radius: 999px; }
.window .now { position: absolute; top: -4px; width: 3px; height: 18px; background: var(--ink); border-radius: 2px; }
.window-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--mute); }

.wiki { display: flex; gap: 10px; background: var(--soft); border-radius: 14px; padding: 10px; }
.wiki img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; }
.wiki .t { font-weight: 600; }
.wiki p { font-size: 13.5px; margin: 2px 0 4px; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.wiki p.open { -webkit-line-clamp: unset; display: block; }
.wiki .src { font-size: 12px; }
.estimate { font-size: 12px; color: var(--mute); }

.banner { border-radius: 14px; padding: 10px 12px; background: var(--soft); display: flex; gap: 10px; align-items: center; font-size: 14px; }
.banner.match { background: var(--accent-soft); }
.banner .grow { flex: 1; }
.banner.error { color: var(--bad); }

form.edit { display: flex; flex-direction: column; gap: 12px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--mute); font-weight: 600; }
label.f input, label.f select, label.f textarea { color: var(--ink); font-weight: 400; font-size: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .row3 { grid-template-columns: 1fr 1fr; } }
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); min-height: 44px; }
.stepper button { border: 0; background: none; width: 44px; height: 44px; font-size: 20px; }
.stepper input { border: 0; text-align: center; min-height: 42px; padding: 0; border-radius: 0; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 4px 0; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more[open] summary { margin-bottom: 10px; }
details.more > div { display: flex; flex-direction: column; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 15px; color: var(--ink); font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.ai-fill { display: flex; gap: 8px; }
.ai-fill input { flex: 1; min-width: 0; }
.filled { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--card); } }

.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list .btn { justify-content: flex-start; }
.menu-list .group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.menu-list .group span { flex: 1; font-weight: 600; min-width: 90px; }

.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; flex: none; }
@keyframes sp { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--soft), var(--line), var(--soft)); background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: 10px; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); z-index: 60;
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
.toast button { background: none; border: 0; color: var(--bg); font-weight: 700; text-decoration: underline; padding: 6px; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form {
  width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.login h1 { font: 700 28px/1.1 var(--font-s); margin: 0; text-align: center; }
.login .glass-icon { font-size: 44px; text-align: center; }
.login .err { color: var(--bad); font-size: 14px; min-height: 20px; }

/* ---------- Wine finder (Vivino suggestions) ---------- */
.finder { display: flex; flex-direction: column; gap: 8px; }
.finder .hint { font-size: 13px; }
.cands { display: flex; flex-direction: column; gap: 6px; }
.cands .note { font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.cand {
  display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 14px; padding: 6px 10px 6px 6px;
  background: var(--card); cursor: pointer; text-align: left;
}
.cand:hover, .cand:focus-visible { border-color: var(--accent); }
.cand .cimg { width: 40px; height: 64px; flex: none; display: grid; place-items: center; font-size: 22px; background: #fff; border-radius: 8px; overflow: hidden; }
.cand .cimg img { width: 100%; height: 100%; object-fit: contain; }
.cand .body { flex: 1; min-width: 0; font-size: 14px; }
.cand .body b { display: block; line-height: 1.25; }
.cand .muted { font-size: 12.5px; }
.cand .chev { font-size: 24px; color: var(--mute); }
.muted-ink { opacity: 0.8; font-weight: 500; }
.banner .mini { width: 30px; height: 48px; object-fit: contain; background: #fff; border-radius: 6px; flex: none; }
.vivino { display: inline-block; margin-top: 6px; font-size: 14px; text-decoration: none; color: var(--ink); }
.viv { font-size: 12.5px; color: var(--star); font-weight: 600; white-space: nowrap; }
.thumb img.contain { object-fit: contain; background: #fff; }
.hero .photo img.contain { object-fit: contain; background: #fff; }
.vintages { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.vintages .muted { font-size: 13.5px; margin-right: 4px; }
.guess { border: 1px dashed var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.guess.primary { border: 1px solid var(--accent); background: var(--accent-soft); }
.guess .gtitle { font-size: 12.5px; font-weight: 600; color: var(--mute); }
.guess .btn { margin-top: 4px; }
