:root {
  color-scheme: light dark;
  --bg: #f7f2ee;
  --panel: #ffffff;
  --panel-2: #f3e9e4;
  --text: #2a1418;
  --muted: #7d6268;
  --line: #e6d8d3;
  --wine: #6b1530;
  --wine-2: #8f1f3f;
  --on-wine: #fff;
  --chip-on: #6b1530;
  --ok: #2e7d4f;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(60, 10, 20, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17100f;
    --panel: #231a1a;
    --panel-2: #2e2222;
    --text: #f1e6e3;
    --muted: #b49c9f;
    --line: #3d2e2f;
    --wine: #c2416a;
    --wine-2: #d65a80;
    --chip-on: #a8325a;
    --ok: #5cbf86;
    --danger: #f2827a;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--wine); color: var(--on-wine);
}
@media (prefers-color-scheme: dark) { .top { background: #3a1220; } }
.brand { font-weight: 700; font-size: 18px; text-decoration: none; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; }
.top .btn { background: rgba(255,255,255,.16); color: #fff; border-color: transparent; }

main { width: min(720px, 100%); margin: 0 auto; padding: 16px; display: grid; gap: 14px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.panel h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .full { grid-column: 1 / -1; }

label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); font-size: 16px; /* 16px : pas de zoom iOS */
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--wine-2); outline-offset: -1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--wine); border-color: var(--wine); color: var(--on-wine); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; padding: 13px; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 4px 8px; }

/* choix : boutons segmentés, échelles, puces */
.q { display: grid; gap: 6px; }
.q-label { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button, .chip {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 14px; line-height: 1.2;
}
.seg button.on, .chip.on { background: var(--chip-on); border-color: var(--chip-on); color: #fff; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.scale button {
  padding: 10px 2px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 12px; line-height: 1.15; min-height: 46px;
  overflow-wrap: anywhere;
}
.scale button.on { background: var(--chip-on); border-color: var(--chip-on); color: #fff; }
.scale button.fill { background: color-mix(in srgb, var(--chip-on) 22%, var(--panel-2)); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip .n { opacity: .65; font-size: 12px; margin-left: 3px; }
details.fam { border-top: 1px solid var(--line); padding-top: 10px; }
details.fam summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.fam summary::after { content: "▾"; color: var(--muted); }
details.fam[open] summary::after { content: "▴"; }
details.fam .chips { margin-top: 8px; }
.picked { font-size: 13px; color: var(--wine-2); font-weight: 600; }

input[type=range] { padding: 0; accent-color: var(--wine); height: 36px; background: none; border: 0; }
.score-big { font-size: 46px; font-weight: 800; text-align: center; color: var(--wine-2); line-height: 1; }
.score-big small { font-size: 20px; color: var(--muted); font-weight: 600; }

/* assistant */
.steps { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.steps button {
  flex: 1 0 auto; border: 0; background: none; padding: 6px 8px 8px; font-size: 13px; color: var(--muted);
  border-bottom: 3px solid var(--line);
}
.steps button.on { color: var(--text); font-weight: 700; border-color: var(--wine-2); }
.steps button.done { border-color: color-mix(in srgb, var(--wine-2) 45%, var(--line)); }
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 10px; justify-content: space-between;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.bottom-bar .btn { flex: 1; padding: 13px; }

/* photo */
.photo-zone { display: flex; gap: 12px; align-items: center; }
.photo-zone img { width: 84px; height: 112px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.photo-zone .ph { width: 84px; height: 112px; border-radius: 10px; border: 1px dashed var(--line); display: grid; place-items: center; font-size: 30px; color: var(--muted); }
.photo-zone .col { display: grid; gap: 8px; flex: 1; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--panel-2); font-size: 14px; display: grid; gap: 6px; }

/* liste */
.search { position: relative; }
.search input { padding-left: 38px; }
.search::before { content: "🔎"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 15px; opacity: .6; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cards { display: grid; gap: 10px; }
.card {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; box-shadow: var(--shadow);
}
.card img, .card .ph { width: 56px; height: 72px; border-radius: 8px; object-fit: cover; }
.card .ph { display: grid; place-items: center; background: var(--panel-2); font-size: 24px; }
.card .t { font-weight: 700; line-height: 1.25; }
.card .s { font-size: 13px; color: var(--muted); }
.card .tags { font-size: 12px; color: var(--wine-2); margin-top: 2px; }
.score { font-weight: 800; font-size: 20px; color: var(--wine-2); text-align: right; min-width: 48px; }
.score small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: 0; border: 1px solid rgba(0,0,0,.15); }
.dot.rouge { background: #7b1027; } .dot.blanc { background: #f1e3a0; } .dot.rosé { background: #f4a7b0; }
.dot.effervescent { background: #f7efc4; } .dot.liquoreux { background: #d79a2b; } .dot.orange { background: #e08a3c; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

/* fiche */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; }
.hero img { width: 110px; border-radius: 12px; border: 1px solid var(--line); }
.hero h1 { font-size: 22px; line-height: 1.2; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.notes { white-space: pre-wrap; }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--panel); border-radius: var(--radius); padding: 14px; width: min(460px, 100%); display: grid; gap: 10px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
#reader { width: 100%; min-height: 200px; border-radius: 10px; overflow: hidden; background: #000; }
#reader video { width: 100% !important; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw;
}
