/* Drinkable — quiet editorial: cream paper, burgundy ink, olive accents. */
:root {
  --paper: #f6f0e4;
  --paper-2: #efe6d4;
  --card: #fbf8f1;
  --ink: #2b2420;
  --muted: #6d625a;
  --rule: #ddd0b9;
  --burgundy: #6d1f30;
  --burgundy-2: #8a2b40;
  --olive: #5b6634;
  --olive-soft: #e5e7cf;
  --amber: #8a6418;
  --amber-soft: #f3e6c4;
  --rose-soft: #f2dfdf;
  --danger: #9b2420;
  --radius: 10px;
  --tap: 48px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--sans);
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, h4, .wordmark { font-family: var(--serif); font-weight: normal; letter-spacing: 0.01em; }
h1 { font-size: 1.75rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h3 { font-size: 1.15rem; margin: 1.25rem 0 0.5rem; }
h4 { font-size: 1rem; margin: 1.25rem 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--sans); font-size: 0.78rem; }
a { color: var(--burgundy); }
code { font-size: 0.9em; background: var(--paper-2); padding: 0 0.25em; border-radius: 3px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
  background: rgba(246, 240, 228, 0.96);
  border-bottom: 1px solid var(--rule);
}
.wordmark { color: var(--burgundy); font-size: 1.45rem; text-decoration: none; }
.tabs { display: flex; gap: 0.25rem; margin-left: auto; }
.tab {
  min-height: var(--tap); padding: 0 1rem; border: 0; background: none;
  font: inherit; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer;
}
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--burgundy); }
.logout { margin: 0; }

main { max-width: 720px; margin: 0 auto; padding: 1rem; }
main.narrow { max-width: 460px; padding-top: 3rem; }
.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 0.88rem; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 1.1rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  font: inherit; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .link:focus-visible {
  outline: 3px solid rgba(109, 31, 48, 0.35); outline-offset: 2px;
}
.btn.primary { background: var(--burgundy); border-color: var(--burgundy); color: #fff; }
.btn.primary:hover { background: var(--burgundy-2); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--burgundy); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--burgundy); font: inherit; cursor: pointer; min-height: var(--tap); padding: 0 0.25rem; text-decoration: underline; }
.file-btn { position: relative; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.9rem 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 1rem 0 0.5rem; }
.photo-actions .quiet { grid-column: 1 / -1; }

/* forms */
label, legend { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.25rem; }
input:not([type=radio]):not([type=checkbox]), select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule); border-radius: 8px;
  background: #fff; color: var(--ink);
  font: inherit; font-size: 16px; /* prevents iOS zoom */
}
textarea { min-height: 7rem; resize: vertical; }
.fields { display: grid; gap: 0.85rem; }
.fields.compact { grid-template-columns: 1fr 1fr; }
.fields.compact button { grid-column: 1 / -1; justify-self: start; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.segmented label {
  display: inline-flex; align-items: center; gap: 0.4rem;
  min-height: 44px; padding: 0 0.85rem; margin: 0;
  border: 1px solid var(--rule); border-radius: 999px; background: #fff; color: var(--ink); cursor: pointer;
}
.segmented label:has(input:checked) { border-color: var(--olive); background: var(--olive-soft); }
.confirm-check {
  display: flex; gap: 0.75rem; align-items: center;
  min-height: var(--tap); margin-top: 1rem; padding: 0.75rem;
  background: var(--paper-2); border-radius: 8px; color: var(--ink); font-size: 1rem;
}
.confirm-check input { width: 1.4rem; height: 1.4rem; accent-color: var(--olive); }

.verdicts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0.5rem 0 1rem; }
.verdict {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 56px; margin: 0; padding: 0.25rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: #fff; color: var(--ink); font-size: 1rem; cursor: pointer;
}
.verdict input { position: absolute; opacity: 0; pointer-events: none; }
.verdict:has(input:focus-visible) { outline: 3px solid rgba(109, 31, 48, 0.35); }
.v-drinkable:has(input:checked) { background: var(--olive); border-color: var(--olive); color: #fff; }
.v-undecided:has(input:checked) { background: var(--amber); border-color: var(--amber); color: #fff; }
.v-not_for_me:has(input:checked) { background: var(--burgundy); border-color: var(--burgundy); color: #fff; }

/* status + notices */
.scan-progress { display: flex; align-items: center; gap: 0.75rem; }
.scan-progress:has(> :not([hidden])) { margin-top: 1rem; }
.scan-progress .status { flex: 1; min-width: 0; margin-top: 0; }
/* Thumbnail of the photo just taken, beside the reading status. */
.preview { flex: none; margin: 0; }
.preview img { display: block; width: 64px; height: 86px; object-fit: cover; border-radius: 6px; border: 1px solid var(--rule); background: var(--paper-2); }
.status { margin-top: 1rem; padding: 0.75rem 1rem; border-radius: 8px; background: var(--paper-2); }
.status.busy::before {
  content: ""; display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.6em; vertical-align: -0.05em;
  border: 2px solid var(--burgundy); border-right-color: transparent; border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.status.error, .notice.error { background: var(--rose-soft); color: var(--danger); }
.status.ok { background: var(--olive-soft); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .status.busy::before { animation: none; } }
.notice { padding: 0.75rem 1rem; border-radius: 8px; background: var(--amber-soft); }
.notice.ok { background: var(--olive-soft); }
#product-shot { margin: 0.75rem 0; }
#product-shot img, #compare-camera img { width: min(100%, 220px); border-radius: 8px; background: var(--cream, #f6f1e7); }
.photo-compare { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: start; margin: 0.75rem 0; }
.label-text { white-space: pre-wrap; font-family: var(--serif); color: var(--muted); }

/* candidates */
.candidates, #confirm-panel { scroll-margin-top: calc(5rem + env(safe-area-inset-top)); }
.candidates:empty { display: none; }
.candidate {
  border-left: 4px solid var(--rule); padding: 0.6rem 0.9rem; margin: 0.6rem 0;
  background: #fff; border-radius: 0 8px 8px 0;
}
.candidate.exact { border-left-color: var(--olive); }
.candidate.same_wine_other_bottle { border-left-color: var(--amber); }
.candidate .c-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.candidate .c-head { flex-wrap: wrap; }
.c-body { margin-top: 0.6rem; }
.c-body.has-photo { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 0.85rem; align-items: start; }
.c-copy { min-width: 0; overflow-wrap: anywhere; }
.c-photo-button { padding: 0; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper, #f6f0e4); overflow: hidden; cursor: pointer; }
.c-photo { display: block; width: 100%; height: 128px; object-fit: contain; }
.c-photo-button:focus-visible { outline: 2px solid var(--olive); outline-offset: 3px; }
.candidate .c-title { font-family: var(--serif); font-size: 1.05rem; }
.candidate .c-explain { font-size: 0.9rem; color: var(--muted); margin: 0.2rem 0; }
.candidate .c-notes { white-space: pre-wrap; font-size: 0.95rem; margin: 0.25rem 0; }
.match-tag { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* verdict pill */
.pill { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px; font-size: 0.82rem; white-space: nowrap; }
.pill.drinkable { background: var(--olive-soft); color: var(--olive); }
.pill.undecided { background: var(--amber-soft); color: var(--amber); }
.pill.not_for_me { background: var(--rose-soft); color: var(--burgundy); }
.badge { display: inline-block; font-size: 0.75rem; padding: 0 0.4rem; border-radius: 4px; background: var(--paper-2); color: var(--muted); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }

/* library */
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; margin-top: 0.75rem; }
.search-row select { width: auto; }
.swipe-row { position: relative; overflow: hidden; }
.swipe-delete {
  position: absolute; top: 0; right: 0; bottom: 0; width: 96px;
  border: 0; background: var(--danger); color: #fff; font: inherit;
}
.wine-item { transition: transform 160ms ease; background: var(--paper, #fff); position: relative; z-index: 1; touch-action: pan-y; }
.wine-item.dragging { transition: none; }
.wine-list li { border-top: 1px solid var(--rule); }
.wine-item {
  display: grid; grid-template-columns: 96px 1fr auto; gap: 0.2rem 0.75rem; align-items: center;
  width: 100%; min-height: 76px; padding: 0.65rem 0.25rem;
  border: 0; background: var(--card); text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.wine-item .w-photo { grid-row: 1 / span 2; width: 96px; height: 64px; object-fit: contain; border-radius: 6px; background: #f6f1e7; }
.wine-item .w-copy { display: contents; }
.wine-item .w-title { font-family: var(--serif); font-size: 1.15rem; }
.wine-item .w-meta { grid-column: 2; color: var(--muted); font-size: 0.88rem; }
.empty { color: var(--muted); padding: 1.5rem 0; text-align: center; }

/* Journal hierarchy and shelf browsing */
.eyebrow { margin: 0 0 .3rem; font: 700 .73rem/1.4 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--burgundy); }
.intro { max-width: 48ch; color: var(--muted); margin: .45rem 0 1rem; }
#capture-panel, #view-library > .panel { border-top: 3px solid var(--burgundy); }
#capture-panel h1, #view-library h1 { font-size: clamp(1.85rem, 5vw, 2.5rem); line-height: 1.12; }
.wine-list { list-style: none; margin: 0; padding: 0; }
.wine-item { grid-template-columns: 96px minmax(0, 1fr) auto; }
.wine-item .w-copy { display: grid; gap: .15rem; overflow-wrap: anywhere; }
.wine-item .w-meta, .wine-item .w-photo { grid-area: auto; }
.w-photo.missing::after { content: '—'; display: grid; height: 100%; place-items: center; color: var(--muted); }
.file-btn:focus-within, .wine-item:focus-visible { outline: 2px solid var(--burgundy); outline-offset: -3px; }
.swipe-delete:focus-visible { z-index: 2; }
.photo-compare { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
.photo-compare figure, #product-shot { margin: 0; min-width: 0; }
#product-shot img, #compare-camera img { width: 100%; height: clamp(8rem,32vw,14rem); object-fit: contain; background: var(--paper-2); }
.sheet { overflow-wrap: anywhere; }
.sheet-head { position: sticky; top: -1rem; background: var(--card); padding: .65rem 0; z-index: 1; border-bottom: 1px solid var(--rule); margin-bottom: 1rem; }
@media (max-width: 480px) {
  .topbar { gap: .35rem; padding-inline: .65rem; }
  .wine-item { grid-template-columns: 76px minmax(0,1fr); }
  .wine-item .w-photo { width: 76px; grid-row: span 2; }
  .wine-item .pill { grid-column: 2; justify-self: start; }
  .search-row { grid-template-columns: minmax(0,1fr); }
  .search-row select { justify-self: start; }
}
@media (prefers-reduced-motion: reduce) { .wine-item { transition: none; } }

/* dialog sheet */
.sheet {
  width: min(720px, 100vw); max-width: 100vw; max-height: 100dvh;
  margin: auto; padding: 1rem 1.25rem 2rem;
  border: 0; border-radius: var(--radius);
  background: var(--card); color: var(--ink);
}
.answer-box { width: min(26rem, calc(100% - 2rem)); max-height: 85dvh; overflow: auto; overflow-wrap: anywhere; padding: 1.25rem; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); color: var(--ink); }
.answer-box .row { justify-content: flex-end; margin-bottom: 0; }
.answer-box::backdrop, .sheet::backdrop { background: rgba(43, 36, 32, 0.45); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.d-photo { display: block; max-width: 100%; max-height: 40vh; margin: 0 auto 1rem; border-radius: 8px; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { border-top: 1px solid var(--rule); padding: 0.55rem 0; font-size: 0.93rem; }
.plain-list .h-notes { white-space: pre-wrap; color: var(--muted); }
.price-line { display: flex; flex-wrap: wrap; gap: 0.4rem 0.75rem; align-items: baseline; }
.price-amount { font-family: var(--serif); font-size: 1.15rem; }
.prices { border-top: 1px solid var(--rule); margin-top: 1.25rem; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  main { padding: 0.75rem; }
  .panel { padding: 1rem; }
  .tab { padding: 0 0.6rem; }
  .logout .link { font-size: 0.9rem; }
  .fields.compact { grid-template-columns: 1fr; }
  .sheet { border-radius: 0; min-height: 100dvh; }
}

/* ---- layout fixes ---- */
/* Sheet header: never let the close control get squeezed by a long wine title. */
.sheet-head h2 { margin: 0; min-width: 0; }
.sheet-head .link { flex-shrink: 0; white-space: nowrap; }
/* Status lines that are filled in later shouldn't show as empty bars. */
.status:empty { display: none; }
/* Login: breathing room between the token field and the button. */
.login form .btn { margin-top: 0.9rem; }
/* Library count + export on one baseline. */
.row-between { margin: 0.75rem 0 0.5rem; gap: 1rem; }
.row-between .link { display: inline-flex; align-items: center; }
/* Bottles are portrait: give thumbnails a portrait frame. */
.wine-item { grid-template-columns: 64px minmax(0, 1fr) auto; }
.wine-item .w-photo { width: 64px; height: 88px; object-fit: contain; }
@media (max-width: 480px) {
  .wine-item { grid-template-columns: 56px minmax(0, 1fr); }
  .wine-item .w-photo { width: 56px; height: 76px; }
  .search-row { grid-template-columns: minmax(0, 1fr) auto; }
}
/* Desktop: float the sheet off the window edges. */
@media (min-width: 561px) {
  .sheet { max-height: calc(100dvh - 3rem); }
}

/* Library: the bottle that was just saved. */
.swipe-row.just-saved .wine-item {
  background: var(--olive-soft);
  box-shadow: inset 4px 0 0 var(--olive);
  animation: just-saved 1.6s ease-out;
}
.swipe-row.just-saved .pill { background: var(--card); box-shadow: inset 0 0 0 1px currentColor; }
.saved-tag { font: 700 0.7rem/1.4 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--olive); }
@keyframes just-saved { 0%, 35% { background: #d3d8a8; } 100% { background: var(--olive-soft); } }
@media (prefers-reduced-motion: reduce) { .swipe-row.just-saved .wine-item { animation: none; } }

/* Live camera viewfinder on the Scan page. */
.viewfinder {
  position: relative; overflow: hidden;
  width: 100%; max-width: 480px; aspect-ratio: 3 / 4; max-height: 62vh;
  margin: 1rem auto 0; border-radius: var(--radius); background: #1d1714;
}
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.vf-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  margin: 0; padding: 1.5rem; text-align: center; color: #f6f0e4;
}
.vf-shutter {
  position: absolute; left: 50%; bottom: 1rem; transform: translateX(-50%);
  width: 72px; height: 72px; padding: 0; border-radius: 50%;
  border: 4px solid #fff; background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.25), 0 4px 14px rgba(0, 0, 0, 0.35);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform 90ms ease;
}
.vf-shutter:active:not(:disabled) { transform: translateX(-50%) scale(0.9); }
.vf-shutter:disabled { opacity: 0.35; cursor: default; }
.vf-shutter:focus-visible { outline: 3px solid var(--amber-soft); outline-offset: 4px; }
.vf-torch {
  position: absolute; top: 0.75rem; right: 0.75rem;
  min-height: 44px; padding: 0 1rem; border: 0; border-radius: 999px;
  background: rgba(0, 0, 0, 0.5); color: #fff; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.vf-torch[aria-pressed="true"] { background: var(--amber-soft); color: var(--ink); }
.vf-torch:focus-visible { outline: 3px solid var(--amber-soft); outline-offset: 2px; }
/* With the live camera, Choose photo and Enter by hand share one row under it. */
.photo-actions.live .quiet { grid-column: auto; }
#camera-note { margin: 0.75rem 0 0; }
@media (prefers-reduced-motion: reduce) { .vf-shutter { transition: none; } }

/* Footer: sign in on another device. */
.app-footer { max-width: 720px; margin: 0 auto; padding: 0 1rem calc(2rem + env(safe-area-inset-bottom)); text-align: center; }
.app-footer .link { color: var(--muted); font-size: 0.92rem; }
/* QR code dialog. The white square holds its place while the code loads. */
.device-qr {
  display: grid; place-items: center;
  width: min(240px, 100%); aspect-ratio: 1; margin: 1rem auto 0.25rem;
  background: #fff; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden;
}
.device-qr img { display: block; width: 100%; height: auto; }
.device-expiry { margin: 0.25rem 0; text-align: center; font-variant-numeric: tabular-nums; }
.device-box .row { flex-wrap: wrap; }
