:root {
  --bg: #ECEDE6;          /* green-coffee grey */
  --surface: #F8F8F3;
  --ink: #1E1A17;
  --muted: #67645A;
  --line: #D3D4C8;
  --accent: #A32E26;      /* coffee cherry */
  --accent-ink: #FFFFFF;
  --accent-soft: #F3DEDA;
  --shadow: 0 1px 2px rgba(30,26,23,.06), 0 6px 18px rgba(30,26,23,.07);

  --r1: #CFAA72; --r2: #AB7A42; --r3: #86562C; --r4: #5E3A1E; --r5: #382213;
  --r-off: #DCDCD2;

  --f-berry-bg: #F4DCE3; --f-berry: #8A2343;
  --f-citrus-bg: #F6EBC8; --f-citrus: #7A5A00;
  --f-floral-bg: #EADFF2; --f-floral: #5E3780;
  --f-sweet-bg: #F5E1CB; --f-sweet: #84461A;
  --f-cocoa-bg: #E6DAD0; --f-cocoa: #5A3A26;
  --f-spice-bg: #F1DCD3; --f-spice: #8B3317;
  --f-other-bg: #E0E4D8; --f-other: #3F4F33;

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161412; --surface: #211E1A; --ink: #EEE9E2; --muted: #A59E92; --line: #37322C;
    --accent: #E2685C; --accent-ink: #1A0F0D; --accent-soft: #3D1F1B;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 22px rgba(0,0,0,.28);
    --r-off: #3A352F;
    --f-berry-bg: #3E1F2A; --f-berry: #F2A9BF;
    --f-citrus-bg: #3A3216; --f-citrus: #EBCD72;
    --f-floral-bg: #33263F; --f-floral: #D4B6EC;
    --f-sweet-bg: #3D2A18; --f-sweet: #F0BC8A;
    --f-cocoa-bg: #33261D; --f-cocoa: #DDBFA8;
    --f-spice-bg: #3E2219; --f-spice: #F1A68C;
    --f-other-bg: #29301F; --f-other: #BFD1A8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161412; --surface: #211E1A; --ink: #EEE9E2; --muted: #A59E92; --line: #37322C;
  --accent: #E2685C; --accent-ink: #1A0F0D; --accent-soft: #3D1F1B;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 22px rgba(0,0,0,.28);
  --r-off: #3A352F;
  --f-berry-bg: #3E1F2A; --f-berry: #F2A9BF;
  --f-citrus-bg: #3A3216; --f-citrus: #EBCD72;
  --f-floral-bg: #33263F; --f-floral: #D4B6EC;
  --f-sweet-bg: #3D2A18; --f-sweet: #F0BC8A;
  --f-cocoa-bg: #33261D; --f-cocoa: #DDBFA8;
  --f-spice-bg: #3E2219; --f-spice: #F1A68C;
  --f-other-bg: #29301F; --f-other: #BFD1A8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  padding-block: env(safe-area-inset-top, 0px) calc(48px + env(safe-area-inset-bottom, 0px));
  margin: 0; -webkit-tap-highlight-color: transparent;
}
html { background: var(--bg); }
.wrap { max-width: 1180px; margin: 0 auto; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px; padding-block: 36px 24px; }
.brand { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.brand svg { flex: none; width: 46px; height: 46px; color: var(--accent); margin-top: 4px; }
.brand h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; line-height: 1; }
.brand p { margin: 8px 0 0; color: var(--muted); max-width: 46ch; }
.stats { font-family: var(--font-mono); font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin-top: 10px; font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--accent); }
.btn[disabled] { opacity: .55; cursor: progress; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding-block: 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.toolbar input[type="search"] { flex: 1 1 220px; min-width: 0; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.toolbar select { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }

.status { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }

/* Feed */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 22px; }
.card { background: var(--surface); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: pointer; text-align: left; border: 0; padding: 0; transition: transform .15s ease; }
.card:hover { transform: translateY(-2px); }
.photo { aspect-ratio: 4 / 5; max-width: 100%; width: 100%; object-fit: cover; display: block; background: var(--r-off); }
.placeholder { aspect-ratio: 4 / 5; width: 100%; display: grid; place-items: center; position: relative; color: #F5EFE6; }
.placeholder .mono { font-family: var(--font-display); font-weight: 800; font-size: 3.4rem; letter-spacing: -0.03em; }
.placeholder .lbl { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; font-family: var(--font-mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; opacity: .8; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.roaster { font-size: 11.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.card h3 { font-size: 1.3rem; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; overflow-wrap: anywhere; }
.card-foot { margin-top: auto; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.who { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); min-width: 0; }
.who img { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.roastbar { display: flex; gap: 3px; align-items: center; }
.roastbar i { width: 18px; height: 6px; border-radius: 2px; background: var(--r-off); }
.roastbar small { margin-left: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--f-other-bg); color: var(--f-other); }
.tag[data-f="berry"] { background: var(--f-berry-bg); color: var(--f-berry); }
.tag[data-f="citrus"] { background: var(--f-citrus-bg); color: var(--f-citrus); }
.tag[data-f="floral"] { background: var(--f-floral-bg); color: var(--f-floral); }
.tag[data-f="sweet"] { background: var(--f-sweet-bg); color: var(--f-sweet); }
.tag[data-f="cocoa"] { background: var(--f-cocoa-bg); color: var(--f-cocoa); }
.tag[data-f="spice"] { background: var(--f-spice-bg); color: var(--f-spice); }

.unrated { font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 1px 8px; white-space: nowrap; flex: none; }
.label-info { display: grid; gap: 4px; }
.label-info .lab { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.label-info p { margin: 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.beans { display: inline-flex; gap: 2px; color: var(--accent); flex: none; }
.beans svg { width: 12px; height: 15px; }
.beans .off { color: var(--line); }

/* Empty state */
.empty { border: 1.5px dashed var(--line); border-radius: 16px; padding: 48px 24px; text-align: center; display: grid; justify-items: center; gap: 10px; }
.empty h2 { font-size: 1.6rem; }
.empty p { margin: 0; color: var(--muted); max-width: 48ch; }

/* Dialogs */
dialog { border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--ink); width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(20,16,12,.55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { font-size: 1.35rem; }
.x { border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.dlg-body { padding: 20px 22px 24px; display: grid; gap: 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label, .field .lab { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field input, .field select, .field textarea { font-size: 16px; width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.field textarea { min-height: 96px; resize: vertical; }
.req { color: var(--accent); }

.photo-pick { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: center; }
.photo-prev { width: 120px; aspect-ratio: 4 / 5; border-radius: 10px; background: var(--bg); border: 1.5px dashed var(--line); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 12px; text-align: center; padding: 6px; }
.photo-prev img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: grid; gap: 8px; justify-items: start; }
.photo-actions p { margin: 0; font-size: 13px; color: var(--muted); }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.roast-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.roast-pick button { border: 2px solid transparent; border-radius: 8px; padding: 18px 2px 6px; font-size: 11px; cursor: pointer; color: #F5EFE6; font-weight: 600; line-height: 1.2; }
.roast-pick button[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }

.rate-pick { display: flex; gap: 6px; align-items: center; }
.rate-pick button { border: 0; background: transparent; padding: 2px; cursor: pointer; color: var(--line); }
.rate-pick button.on { color: var(--accent); }
.rate-pick svg { width: 22px; height: 28px; display: block; }
.rate-pick output { margin-left: 8px; font-family: var(--font-mono); font-size: 13px; color: var(--muted); }

.flavor-groups { display: grid; gap: 10px; }
.fg { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: start; }
.fg .fl { font-size: 12px; color: var(--muted); padding-top: 4px; }
.fg .tags .tag { cursor: pointer; border: 1.5px solid transparent; opacity: .7; }
.fg .tags .tag[aria-pressed="true"] { opacity: 1; border-color: currentColor; font-weight: 600; }
.custom-flavor { display: flex; gap: 8px; }
.custom-flavor input { flex: 1; min-width: 0; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); }
.chosen { display: flex; flex-wrap: wrap; gap: 5px; min-height: 26px; }
.chosen .tag { cursor: pointer; }
.chosen .tag::after { content: " ×"; }

.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-err { color: var(--accent); font-size: 14px; margin-right: auto; }

/* Detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; }
.detail .photo, .detail .placeholder { border-radius: 12px; }
.detail-info { display: grid; gap: 12px; align-content: start; min-width: 0; }
.detail-info h2 { font-size: 1.8rem; line-height: 1.1; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.facts dt { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dd.mono { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.notes { white-space: pre-wrap; margin: 0; padding: 14px 16px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 10px 10px 0; overflow-wrap: anywhere; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.detail-actions a { color: var(--accent); font-weight: 600; }
.where { display: grid; gap: 10px; padding: 14px 16px; background: var(--bg); border-radius: 12px; }
.where .lab { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.where > .btn.ghost { justify-self: start; }
.stores { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.stores li { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.stores li:last-child { border-bottom: 0; padding-bottom: 0; }
.store-main { display: grid; gap: 1px; min-width: 0; overflow-wrap: anywhere; }
.store-main a { color: var(--accent); font-weight: 600; }
.store-main span { font-size: 13.5px; }
.store-main small { color: var(--muted); font-size: 12px; }
.x.small { font-size: 20px; padding: 0 6px; }
.store-form { display: grid; gap: 10px; }
.buy-box { display: grid; gap: 4px; justify-items: start; flex-basis: 100%; }
.buy-box .btn.buy { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); text-decoration: none; }
.buy-box small { color: var(--muted); font-size: 12.5px; }

/* App chrome */
.top-actions { display: flex; gap: 10px; align-items: center; }
.avatar-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; display: grid; place-items: center; font-size: 14px; }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: 0 0 16px; padding: 12px 14px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); font-size: 14px; }
.banner p { margin: 0; }
.mode-note { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; border: 1px dashed var(--line); color: var(--muted); font-size: 13.5px; }

/* Sign-in */
.signin { max-width: 420px; margin: 8vh auto 0; display: grid; gap: 18px; text-align: left; }
.signin .brand { margin-bottom: 8px; }
.signin form { display: grid; gap: 12px; background: var(--surface); padding: 22px; border-radius: 16px; box-shadow: var(--shadow); }
.signin input { width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.signin .code { letter-spacing: .4em; font-family: var(--font-mono); text-align: center; font-size: 22px; }
.signin small { color: var(--muted); }
.linkish { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; justify-self: start; }

/* Account */
.toggle { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; padding: 14px 16px; border-radius: 12px; background: var(--bg); cursor: pointer; }
.toggle input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.toggle strong { display: block; }
.toggle span { color: var(--muted); font-size: 13.5px; }
.link-hint { font-size: 12.5px; color: var(--muted); min-height: 1em; }
.link-hint.ok { color: var(--f-other); }
.link-hint.warn { color: var(--accent); }
.partner-note { color: var(--muted); font-size: 12px; }
.club-code { font-family: var(--font-mono); font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; z-index: 10; }

@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; }
  .detail { grid-template-columns: 1fr; }
  .fg { grid-template-columns: 1fr; gap: 4px; }
  .photo-pick { grid-template-columns: 96px 1fr; }
  .photo-prev { width: 96px; }
  .dlg-body, .dlg-head { padding-inline: 16px; }
  dialog { width: calc(100vw - 16px); }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } .card:hover { transform: none; } }
