/* Layout: Cellar. A white page, near-black text, one grey hairline; the only colour is each coffee's own
   label colourway. Text nav in the header (a bottom bar on phones); Brew is home. */
:root {
  --bg: #FFFFFF;
  --ink: #141312;
  --muted: #74706B;
  --line: #E6E3DF;
  --tile: #F3F2F0;
  --tile-2: #ECEAE7;
  --card: #FFFFFF;
  --danger: #B3261E;
  --danger-ink: #FFFFFF;
  --ok: #2E6A44;
  --ok-soft: #DCEADF;
  --warn: #7A6400;
  --warn-soft: #F3EBBF;
  --frost: #2C6497;
  --frost-soft: #DAE7F3;
  --scrim: rgba(20, 19, 18, 0.4);
  --shadow: none;
  --cellar-shadow: rgba(20, 16, 12, 0.2);

  /* Helvetica everywhere. Windows has no Helvetica, so it falls back to Arial, which shares its metrics. */
  --display: Helvetica, "Helvetica Neue", Arial, "Liberation Sans", sans-serif;
  --body: Helvetica, "Helvetica Neue", Arial, "Liberation Sans", sans-serif;
  --mono: Helvetica, "Helvetica Neue", Arial, "Liberation Sans", sans-serif;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 2.5rem;
  --r: 6px;
  --gutter: clamp(16px, 4vw, 44px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110;
    --ink: #F1EFEC;
    --muted: #9C978F;
    --line: #2A2826;
    --tile: #1B1A19;
    --tile-2: #232120;
    --card: #171615;
    --danger: #F2867E;
    --danger-ink: #2A0B09;
    --ok: #7FC596;
    --ok-soft: #1F3527;
    --warn: #E6CF5A;
    --warn-soft: #36300F;
    --frost: #8EBDE8;
    --frost-soft: #1B2D3F;
    --scrim: rgba(0, 0, 0, 0.6);
    --cellar-shadow: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110;
  --ink: #F1EFEC;
  --muted: #9C978F;
  --line: #2A2826;
  --tile: #1B1A19;
  --tile-2: #232120;
  --card: #171615;
  --danger: #F2867E;
  --danger-ink: #2A0B09;
  --ok: #7FC596;
  --ok-soft: #1F3527;
  --warn: #E6CF5A;
  --warn-soft: #36300F;
  --frost: #8EBDE8;
  --frost-soft: #1B2D3F;
  --scrim: rgba(0, 0, 0, 0.6);
  --cellar-shadow: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-md)/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
/* File inputs stay in the layout (not display:none) so mobile browsers open the picker from their label. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
}
img { max-width: 100%; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
sub, sup { font-size: 0.72em; line-height: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.muted { color: var(--muted); }
.ico { width: 1em; height: 1em; flex: none; }

/* ---------- Header & tabs ---------- */
.app { min-height: 100%; }
.app-head {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px 28px;
  padding: 20px var(--gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; margin-right: auto; }
.brand-name { font: 700 1.35rem/1 var(--display); letter-spacing: -0.02em; }
.tabs { display: flex; gap: clamp(14px, 2.4vw, 30px); }
.tab {
  display: inline-flex;
  align-items: center;
  padding: 4px 0;
  border: 0;
  border-bottom: 1.5px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font: 400 var(--fs-sm)/1.2 var(--body);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab-count {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: 600 0.6875rem/1.4 var(--body);
  letter-spacing: 0;
}
.head-actions { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  display: grid;
}
.menu button {
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.menu button:hover { background: var(--tile); }

.banner {
  margin: 12px var(--gutter) 0;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--warn-soft);
  color: var(--ink);
  font-size: var(--fs-sm);
}
.banner[data-kind="local"] { background: var(--tile); color: var(--muted); }

main { padding: 20px var(--gutter) 48px; max-width: 1240px; margin: 0 auto; }

@media (max-width: 820px) {
  .app-head { gap: 10px; }
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    justify-content: space-around;
    gap: 0;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    border-top: 1px solid var(--line);
  }
  .tab {
    flex: 1;
    justify-content: center;
    padding: 12px 4px;
    border-bottom: 0;
    font-size: var(--fs-sm);
    white-space: nowrap;
  }
  .tab[aria-selected="true"] { color: var(--ink); font-weight: 600; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Buttons & controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink);
  font-weight: 400;
  font-size: var(--fs-sm);
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled, .btn.disabled { opacity: 0.55; pointer-events: none; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: 0.88; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.btn.ghost:hover { color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.primary.danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn.small { min-height: 34px; padding: 6px 12px; }
.btn.tiny { min-height: 28px; padding: 3px 10px; font-size: var(--fs-xs); }
.btn.freeze { color: var(--frost); border-color: color-mix(in srgb, var(--frost) 40%, var(--line)); background: transparent; }
.btn.thaw { color: var(--frost); background: var(--frost-soft); border-color: transparent; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--tile); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- View header & toolbar ---------- */
.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: clamp(12px, 3vw, 32px) 0 clamp(20px, 3vw, 32px);
}
.view-title {
  font: 400 var(--fs-2xl)/1.05 var(--display);
  letter-spacing: -0.03em;
}
.view-sub { margin-top: 8px; color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--tile);
}
.seg button {
  border: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
.inline-field { display: inline-flex; align-items: center; gap: 10px; font-size: var(--fs-sm); color: var(--muted); }
.inline-field select { min-width: min(280px, 70vw); }
.search-field { display: flex; flex: 1 1 260px; max-width: 520px; }

/* ---------- Empty states ---------- */
.empty {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 48px 20px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 14px;
}
.empty h2 { font: 500 var(--fs-xl)/1.1 var(--display); }
.empty p { max-width: 46ch; color: var(--muted); }
.empty .btn { margin-top: 6px; }
.empty-mark { color: var(--ink); }
.empty-mark .ico { width: 40px; height: 40px; }
.empty.small { padding: 28px 20px; }

/* ---------- Inventory: a product grid of bean cellars ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: clamp(32px, 3vw, 44px) clamp(16px, 2vw, 24px);
  align-items: start;
}
.card { display: grid; gap: 12px; min-width: 0; }
/* The tile shows the cellar; with a roaster's photo, hovering or focusing it fades to the photo. */
.tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  max-width: 100%;
  overflow: hidden;
  border-radius: 4px;
  background: var(--tile);
  transition: background 0.2s;
}
.card:hover .tile { background: var(--tile-2); }
.tile > svg { width: 88%; height: auto; display: block; }
/* The roaster's photo sits on white, so a cut-out never shows the cellar through it, and fades in slowly. */
.tile-photo { position: absolute; inset: 0; box-sizing: border-box; width: 100%; height: 100%; object-fit: cover; background: #fff; opacity: 0; transition: opacity 0.7s cubic-bezier(.4,0,.2,1); }
.tile-photo.cutout { object-fit: contain; padding: 4%; }
.tile:hover .tile-photo, .tile:focus-within .tile-photo, .tile:focus .tile-photo { opacity: 1; }
.card.status-finished .tile { opacity: 0.55; }
.card-head { display: grid; gap: 2px; margin-top: 2px; }
.cname { font: 500 var(--fs-md)/1.3 var(--display); overflow-wrap: anywhere; }
.roaster { color: var(--muted); font-size: var(--fs-sm); }
.card-stock { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.card-stock .muted { font-size: var(--fs-xs); }
.tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font: 600 0.6875rem/1.5 var(--body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font: 600 var(--fs-xs)/1.4 var(--body);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill-open { background: var(--tile); color: var(--ink); }
.pill-ready { background: var(--ok-soft); color: var(--ok); }
.pill-resting { background: var(--warn-soft); color: var(--warn); }
.pill-frozen { background: var(--frost-soft); color: var(--frost); }
.pill-finished { background: var(--tile); color: var(--muted); }

.specs {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs);
  line-height: 1.35;
}
.specs dt { color: var(--muted); }
.specs dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.specs dd.none { color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .tile, .tile-photo { transition: none; } }

.notes { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.notes li {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: var(--fs-sm);
  font-style: italic;
}

.lookup {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: var(--fs-sm);
  background: var(--tile);
}
.lookup .ico { width: 16px; height: 16px; margin-top: 2px; }
.lookup-pending { background: var(--warn-soft); }
.lookup-pending .ico { color: var(--warn); }
.lookup-done .ico { color: var(--ok); }
.lookup-failed .ico { color: var(--danger); }

/* What's left of the coffee (the bag's bar, the open bag, each cellar) in one lighter box. */
.card-beans { display: grid; gap: 10px; padding: 12px 14px; border-radius: 6px; background: var(--tile); }
.card-beans .bean-row { border-color: var(--line); }
.card-beans .stock-bar { background: var(--line); }
.lookup-info a { color: inherit; }
.stock { display: grid; gap: 6px; }
.stock-bar { height: 6px; border-radius: 999px; background: var(--tile); overflow: hidden; }
.stock-bar span { display: block; height: 100%; background: var(--ink); border-radius: inherit; }
.stock-text { font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.stock-text strong { color: var(--ink); font-family: var(--mono); font-weight: 500; }

.beans { margin: 0; padding: 0; list-style: none; display: grid; }
.bean-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 56px minmax(64px, auto) 62px;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 4px 0;
  border-top: 1px dashed var(--line);
  font-size: var(--fs-sm);
}
.bean-row:first-child { border-top: 0; }
.bean-ico { color: var(--muted); display: grid; place-items: center; }
.bean-ico .ico { width: 18px; height: 18px; }
.bean-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bean-g { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
/* The open bag's grams: tap to type what the scale reads. */
.bean-weigh { padding: 2px 0; border: 0; border-bottom: 1px dashed var(--muted); background: none; color: inherit; font: inherit; font-family: var(--mono); cursor: pointer; justify-self: end; }
.bean-weigh:hover { border-bottom-style: solid; }
.bean-input { width: 100%; min-width: 0; padding: 4px 6px; border: 1px solid var(--ink); border-radius: 4px; background: var(--bg); color: var(--ink); font: inherit; font-size: var(--fs-sm); text-align: right; font-variant-numeric: tabular-nums; }
.bean-day { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }
.bean-row .btn.tiny { justify-self: end; }
.bean-row.is-frozen .bean-ico, .bean-row.is-frozen .bean-day { color: var(--frost); }
.bean-row.is-used { color: var(--muted); }
.bean-row.is-used .bean-name { text-decoration: line-through; }
.bean-row.muted { grid-template-columns: 0 1fr; color: var(--muted); }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Brew log ---------- */
.chart-wrap {
  position: relative;
  margin: 0 0 24px;
  padding: 14px 16px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.chart-wrap figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 16px;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.chart-title { font: 500 var(--fs-lg)/1 var(--display); color: var(--ink); }
.chart-legend { display: inline-flex; align-items: center; gap: 6px; }
.legend-box { width: 14px; height: 10px; border-radius: 2px; background: var(--ok-soft); border: 1px solid var(--ok); }
.chart-scroll { overflow-x: auto; }
.chart-scroll svg { display: block; width: 100%; min-width: 420px; height: auto; }
.chart-scroll .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart-scroll .axis { stroke: var(--muted); stroke-width: 1; }
.chart-scroll .tick { fill: var(--muted); font: 11px var(--mono); }
.chart-scroll .axis-label { fill: var(--muted); font: 600 12px var(--body); letter-spacing: 0.04em; }
.chart-scroll .ideal { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1; stroke-dasharray: 4 3; opacity: 0.9; }
.chart-scroll .liked { fill: var(--tile); fill-opacity: 0.5; stroke: var(--ink); stroke-width: 1; stroke-dasharray: 4 3; }
.chart-scroll .liked-mean { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-linecap: round; }
.chart-scroll .pt { cursor: pointer; outline: none; }
.chart-scroll .hit { fill: transparent; }
.chart-scroll .dot { stroke-width: 1.6; }
.chart-scroll .pt.on .dot, .chart-scroll .pt:focus-visible .dot { stroke-width: 3; }
.chart-legends { display: inline-flex; flex-wrap: wrap; gap: 4px 16px; }
.legend-box.liked { background: var(--tile); border: 1px dashed var(--ink); }
.chart-note { max-width: 78ch; padding: 6px 0 8px; font-size: var(--fs-sm); color: var(--muted); }
/* A brew card floating over its dot. It lets the pointer through until a tap or click pins it. */
.chart-pop {
  position: absolute;
  z-index: 20;
  width: min(320px, 80vw);
  pointer-events: none;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.28));
}
.chart-pop.pinned { pointer-events: auto; }
.chart-pop .brew { box-shadow: none; }

/* A brew is a square card drawn as SVG in the tube label's style (see brewcard.js).
   The buttons sit in a column at the top of the dark band and are not part of the shared image. */
.brews { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px; }
.brew {
  --tone-ink: var(--t-dark);
  position: relative;
  container-type: inline-size;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
}
.brew:hover { border-color: var(--muted); }
.brew svg { display: block; width: 100%; height: 100%; }
.brew-actions {
  position: absolute;
  top: 1.6cqw;
  left: 91.4%;
  width: 8.6%;
  display: grid;
  justify-items: center;
  gap: 1.2cqw;
}
/* The dark band keeps the coffee's own colour in both themes, so the icons are always light. */
.brew-actions button {
  display: grid;
  place-items: center;
  width: 6.6cqw;
  height: 6.6cqw;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 1.4cqw;
  background: transparent;
  color: #FFFFFF;
  cursor: pointer;
}
.brew-actions svg { width: 64%; height: 64%; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.brew-actions button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.22); }
.brew-actions button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.34); border-color: #FFFFFF; }
.brew-actions button:disabled { opacity: 0.32; cursor: default; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brew { --tone-ink: var(--t-mid); }
}
:root[data-theme="dark"] .brew { --tone-ink: var(--t-mid); }

/* ---------- Dialog sheets ---------- */
dialog.sheet {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
dialog.sheet.small { width: min(520px, calc(100vw - 24px)); }
dialog.sheet.wide { width: min(960px, calc(100vw - 24px)); }
dialog.sheet[open] { display: flex; }
dialog::backdrop { background: var(--scrim); }
dialog.sheet > form { display: flex; flex-direction: column; width: 100%; max-height: inherit; min-height: 0; }
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font: 500 var(--fs-xl)/1.1 var(--display); }
.sheet-sub { margin-top: 2px; color: var(--muted); font-size: var(--fs-sm); }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px 20px;
  display: grid;
  gap: 18px;
  align-content: start;
}
.sheet-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.spacer { flex: 1; }
#data-text {
  width: 100%;
  font: 12px/1.4 var(--mono);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

@media (max-width: 560px) {
  dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    max-height: 94dvh;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
  }
  .sheet-head, .sheet-body, .sheet-foot { padding-left: 16px; padding-right: 16px; }
}

/* ---------- Forms ---------- */
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: 12px; }
legend {
  padding: 0;
  margin-bottom: 10px;
  font: 700 var(--fs-xs)/1 var(--display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 400px) {
  .grid, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}
.field { display: grid; gap: 4px; min-width: 0; }
.field > span:first-child {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.field small { color: var(--muted); font-size: var(--fs-xs); }
input:not([type="checkbox"]), select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: var(--fs-md);
}
/* The rule above would otherwise stretch hidden file pickers and make the page scroll sideways. */
input.visually-hidden { width: 1px; min-height: 0; padding: 0; border: 0; }
textarea { resize: vertical; line-height: 1.45; }
input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: transparent; }
.unit-input { position: relative; display: block; }
.unit-input input { padding-right: 44px; }
.unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: var(--fs-sm);
  pointer-events: none;
}
.readout output {
  display: flex;
  align-items: center;
  min-height: 40px;
  font: 500 var(--fs-lg)/1 var(--mono);
}
.field.filled input, .field.filled select, .field.filled textarea {
  background: var(--ok-soft);
  border-color: var(--ok);
}
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.hint { color: var(--muted); font-size: var(--fs-sm); }
.hint.warn, .form-error { color: var(--danger); }
.form-error { font-weight: 600; font-size: var(--fs-sm); }
.auto-tag {
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--tile);
  font-style: normal;
  font-size: 0.625rem;
  letter-spacing: 0.06em;
}

/* Scan panel */
.scan {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: var(--tile);
}
.scan.unavailable { background: var(--tile); }
.scan.unavailable .scan-copy span { color: var(--muted); }
.scan-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.scan-copy { flex: 1 1 260px; display: grid; gap: 2px; }
.scan-copy strong { font: 500 var(--fs-lg)/1.1 var(--display); }
.scan-copy span { font-size: var(--fs-sm); }
.scan-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: var(--fs-sm);
}
.scan-status #scan-msg { flex: 1 1 200px; }
.scan-status[data-state="error"] #scan-msg { color: var(--danger); font-weight: 600; }
.scan-status[data-state="done"] #scan-msg { color: var(--ok); font-weight: 600; }
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.photo-field { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.photo-frame {
  width: 88px;
  height: 88px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--tile);
  display: grid;
  place-items: center;
}
.photo-frame img { width: 100%; height: 100%; object-fit: cover; }
.photo-empty { font-size: var(--fs-xs); color: var(--muted); }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cellars */
.split {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: var(--frost-soft);
}
.split-available { font-size: var(--fs-md); }
.split-available strong { font-family: var(--mono); font-weight: 500; }
.split-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.split-row .field { width: 120px; }
.split-row .field.date { width: 170px; }
.split-row .check { min-height: 40px; }
.split-x { padding-bottom: 10px; color: var(--muted); }
.cellar-list { display: grid; gap: 8px; }
.cellar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 100px minmax(0, 1.4fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.cellar-row.is-frozen { border-color: color-mix(in srgb, var(--frost) 45%, var(--line)); background: var(--frost-soft); }
.cl-meta { font-size: var(--fs-xs); color: var(--muted); }
.cl-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.cl-dates { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--fs-xs); color: var(--muted); }
.cl-dates label { display: inline-flex; align-items: center; gap: 6px; }
.cl-dates input { font: inherit; padding: 3px 6px; }
.btn.tagged { background: var(--tile); border-color: transparent; color: var(--ink); }
@media (max-width: 640px) {
  .cellar-row { grid-template-columns: minmax(0, 1fr) 96px auto; }
  .cl-meta { grid-column: 1 / 3; grid-row: 2; }
  .cl-actions { grid-column: 1 / -1; grid-row: 3; }
  .cl-dates { grid-row: 4; }
  .cellar-row .icon-btn { grid-column: 3; grid-row: 1; }
}

/* Pours */
.pour-head, .pour-row {
  display: grid;
  grid-template-columns: 22px minmax(70px, 1fr) 136px 92px 92px 100px 56px minmax(80px, 1.2fr) 36px;
  gap: 8px;
  align-items: center;
}
.pour-head span {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.pour-list { display: grid; gap: 8px; }
.pour-n { font: 500 var(--fs-sm) var(--mono); color: var(--muted); text-align: center; }
.pour-row .p-by { padding-left: 8px; padding-right: 4px; font-size: var(--fs-sm); }
.pour-row .p-at { font-family: var(--mono); }
.pour-row .unit-input input { padding-right: 38px; -moz-appearance: textfield; appearance: textfield; }
.pour-row .unit-input input::-webkit-inner-spin-button { display: none; }
.pour-row .unit-input .p-g { padding-right: 26px; }
.p-cum { font: 500 var(--fs-sm) var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.pour-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#pour-summary { font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 860px) {
  .pour-head { display: none; }
  .pour-row {
    grid-template-columns: 22px minmax(0, 1.5fr) minmax(0, 1fr) 56px;
    padding: 8px 0;
    border-top: 1px dashed var(--line);
  }
  .pour-row .p-label { grid-column: 2 / 4; grid-row: 1; }
  .pour-row .p-del { grid-column: 4; grid-row: 1; justify-self: end; }
  .pour-row .p-by { grid-column: 2; grid-row: 2; }
  .pour-row .p-at-cell { grid-column: 3; grid-row: 2; }
  .pour-row .p-g-cell { grid-column: 2; grid-row: 3; }
  .pour-row .p-rate-cell { grid-column: 3; grid-row: 3; }
  .pour-row .p-cum { grid-column: 4; grid-row: 3; text-align: right; }
  .pour-row .p-note { grid-column: 2 / 5; grid-row: 4; }
}

/* Agitation chips & rating */
.chip-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-toggle {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
}
.chip-toggle[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.ratings { display: grid; gap: 2px; }
.rating-q { margin-top: 10px; font-size: var(--fs-sm); font-weight: 600; }
.rating-q:first-child { margin-top: 0; }
.rating-q span { font-weight: 400; color: var(--muted); }
.rating {
  display: grid;
  grid-template-columns: 6.5em repeat(5, minmax(24px, 44px)) 2.5em;
  align-items: center;
  gap: 4px;
}
.rating-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.rating.eight { grid-template-columns: 9em repeat(8, minmax(14px, 26px)) 2.8em; gap: 3px; }
.flavor-form { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 16px; align-items: start; }
.flavor-wheel svg { display: block; width: 100%; height: auto; color: var(--ink); }
.flavor-wheel svg text { fill: var(--ink); }
@media (max-width: 720px) {
  .flavor-form { grid-template-columns: 1fr; }
  .flavor-wheel { max-width: 300px; justify-self: center; }
}
.pip {
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.pip::before {
  content: "";
  display: block;
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--tile);
}
.pip:hover::before { border-color: var(--muted); }
.pip[data-on]::before { background: var(--ink); border-color: var(--ink); }
.rating-value { font: 500 var(--fs-sm) var(--mono); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Water ---------- */
.w-sec { display: grid; gap: 14px; margin-bottom: 36px; }
.w-head { display: grid; gap: 4px; }
.w-head h2 { font: 500 var(--fs-xl)/1.1 var(--display); }
.w-head p { max-width: 68ch; color: var(--muted); font-size: var(--fs-sm); }
.w-panel {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.w-targets { display: grid; gap: 12px; align-content: start; padding: 16px; border-right: 1px solid var(--line); }
.w-target { display: grid; grid-template-columns: minmax(0, 1fr) 124px; align-items: center; gap: 12px; }
.w-target > span:first-child { font-weight: 500; }
.w-target .unit-input input { padding-right: 50px; }
.w-drops { display: grid; align-content: start; padding: 16px; }
.drop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px dashed var(--line);
}
.drop-row:first-child { padding-top: 0; border-top: 0; }
.drop-what { min-width: 0; font-size: var(--fs-sm); color: var(--muted); }
.drop-what b { display: block; color: var(--ink); font: 500 var(--fs-md)/1.3 var(--mono); }
.drop-n { font: 500 var(--fs-xl)/1 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.drop-n small { margin-left: 6px; font: 400 var(--fs-xs)/1 var(--body); color: var(--muted); }
.w-totals {
  display: grid;
  gap: 4px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.w-totals b { font: 500 var(--fs-sm) var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.w-save { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.w-save .field { flex: 1 1 220px; max-width: 420px; }
.waters { display: grid; }
.water-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 10px;
  padding: 10px 0;
  border-top: 1px dashed var(--line);
}
.water-name { font-weight: 600; overflow-wrap: anywhere; }
.water-nums { grid-column: 1; font: 400 var(--fs-xs)/1.4 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.water-row .btn { grid-row: 1 / span 2; }
.water-row .btn[data-water="load"] { grid-column: 2; }
.water-row .btn[data-water="delete"] { grid-column: 3; }

.bottles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 16px; }
.bottle {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.bottle-tag { font: 600 var(--fs-xs)/1.3 var(--body); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink); }
.bottle.kh .bottle-tag { color: var(--frost); }
.bottle-formula { margin-top: 2px; font: 700 1.3rem/1.15 var(--display); }
.bottle-name { font-size: var(--fs-sm); color: var(--muted); }
.bottle-weigh { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--tile); }
.bottle.kh .bottle-weigh { background: var(--frost-soft); }
.bottle-weigh b { font: 500 var(--fs-xl)/1.15 var(--mono); font-variant-numeric: tabular-nums; }
.bottle-weigh span { font-size: var(--fs-xs); }
.kv { display: grid; gap: 6px; margin: 0; }
.kv div { display: flex; justify-content: space-between; gap: 10px; font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font: 500 var(--fs-sm)/1.5 var(--mono); font-variant-numeric: tabular-nums; }
.sat { display: grid; gap: 5px; }
.sat-track { height: 6px; border-radius: 999px; background: var(--tile); overflow: hidden; }
.sat-fill { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.sat-fill.warn { background: var(--warn); }
.sat-fill.stop { background: var(--danger); }
.sat-text { font: 400 var(--fs-xs)/1.4 var(--mono); color: var(--muted); }
.sat-text.warn { color: var(--warn); }
.sat-text.stop { color: var(--danger); }

.calib { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; padding: 16px; }
.calib-out {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--tile);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.calib-out b { font: 500 var(--fs-sm) var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }

.w-notes { display: grid; margin: 0; }
.w-notes div {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 6px 20px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.w-notes dt { font: 600 var(--fs-xs)/1.8 var(--body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.w-notes dd { margin: 0; max-width: 68ch; font-size: var(--fs-sm); }
.w-notes b { font-weight: 600; }
.w-stop { color: var(--danger); }
.w-foot { max-width: 72ch; padding-top: 14px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); }

@media (max-width: 660px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .w-targets { border-right: 0; border-bottom: 1px solid var(--line); }
  .calib { grid-template-columns: minmax(0, 1fr); }
  .w-notes div { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Labels ---------- */
.lq { display: grid; }
.lq-group { display: grid; gap: 8px; padding: 12px 0; border-top: 1px dashed var(--line); }
.lq-group:first-child { padding-top: 0; border-top: 0; }
.lq-head { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.lq-head strong { font: 700 1.0625rem/1.2 var(--display); overflow-wrap: anywhere; }
.lq-head .btn { margin-left: auto; }
.lq-items { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.lq-items li {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 2px 1px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.lq-items .icon-btn { width: 30px; height: 30px; }
.lq-note { font-size: var(--fs-sm); font-weight: 600; color: var(--warn); }
.lq-tools { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.lq-tools .field { width: 260px; max-width: 100%; }
.sheets { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 520px)); gap: 16px; }
.print-sheet { border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow); overflow: hidden; }
.print-sheet svg, .label-preview svg { display: block; width: 100%; height: auto; }
.label-preview { max-width: 640px; border: 1px solid var(--line); border-radius: 3px; box-shadow: var(--shadow); overflow: hidden; }
.swatches { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 3px solid var(--bg);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}
.tone-picker { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tone-chip {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--a) 0 72%, var(--b) 72%);
  box-shadow: 0 0 0 1px var(--line);
}
.tone-rows { display: grid; gap: 8px; min-width: 0; }
.tone-rows > div { display: grid; gap: 4px; }
.tone-label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--ink); }
.head-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.scan-msg { font-size: var(--fs-sm); color: var(--muted); }
.scan-msg.error { color: var(--danger); font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(92vw, 480px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: var(--danger-ink); }
@media (max-width: 820px) {
  .toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Brewing ---------- */
.bw-status { padding: 10px 14px; margin: 0 0 6px; border-radius: var(--r); background: var(--tile); color: var(--muted); font-size: var(--fs-sm); line-height: 1.4; }
.bw-status.ok { background: var(--ok-soft); color: var(--ok); }
.bw-status.error { background: var(--warn-soft); color: var(--warn); }
.linklike { padding: 0; border: 0; background: none; color: var(--ink); font: inherit; text-decoration: underline; cursor: pointer; }
.bw-battery { margin-left: auto; font-size: var(--fs-xs); color: var(--muted); }
.bw-chart .gl { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.bw-chart .tk { fill: var(--muted); font: 11px var(--mono); }
.bw-chart .ax { fill: var(--muted); font: 600 12px var(--body); letter-spacing: 0.04em; }
.bw-chart .trace { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.bw-chart .area { fill: var(--tile); fill-opacity: 0.55; }
.bw-chart .ghost { fill: none; stroke: var(--muted); stroke-width: 2; stroke-dasharray: 6 5; }
.bw-chart .band { fill: var(--frost-soft); fill-opacity: 0.6; }
.bw-chart .head { fill: var(--ink); stroke: var(--bg); stroke-width: 2; }
.bw-chart .hint { fill: var(--muted); font: 600 13px var(--body); }
.legend-line { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--ink); border-radius: 2px; }
.legend-line.ghost { border-top: 2px dashed var(--muted); }
/* "This recording" and "Saved recordings": open sections under a hairline, lined up with the readings strip. */
.bw-summary { margin: 0; padding: 20px 0 0; border-top: 1px solid var(--line); }
.bw-summary h2 { margin: 0 0 14px; font: 500 var(--fs-lg)/1.2 var(--display); }
.bw-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 16px 20px; margin: 0 0 18px; }
.bw-stats div { display: grid; gap: 2px; align-content: start; min-width: 0; }
.bw-stats dt { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bw-stats dd { margin: 0; font: 400 clamp(1.15rem, 3.6vw, 1.5rem)/1.15 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bw-stats dd .btn { justify-self: start; margin-top: 4px; }
.bw-stats .bw-stat-tds dd { display: grid; }
.bw-pours { max-width: 460px; margin: 0 0 18px; padding: 0; list-style: none; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.bw-pours li { display: grid; grid-template-columns: minmax(0, 1fr) 4em 4.5em 3.5em; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); }
.bw-pours li span { color: var(--muted); text-align: right; }
.bw-pours li.none { display: block; color: var(--muted); }
.bw-save { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bw-save select { min-width: 0; max-width: 100%; flex: 1 1 220px; }
.bw-downloads { margin-left: auto; display: inline-flex; align-items: center; color: var(--muted); font-size: var(--fs-sm); }
.bw-downloads .btn { padding-inline: 6px; }
@media (max-width: 640px) {
  .bw-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 12px; }
  .bw-downloads { margin-left: 0; }
}
.bw-saved { margin: 0; padding: 0; list-style: none; display: grid; }
.bw-saved li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: var(--fs-sm); }
.bw-saved li:first-child { border-top: 0; }
.bw-saved .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bw-saved .m { color: var(--muted); font-variant-numeric: tabular-nums; }
.bw-saved .a { display: inline-flex; gap: 4px; }
.bw-file { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0; font-size: var(--fs-xs); color: var(--muted); }
.bw-file .btn { padding-left: 0; }
@media (max-width: 560px) {
  .bw-saved li { grid-template-columns: minmax(0, 1fr) auto; }
  .bw-saved .m { grid-column: 1; grid-row: 2; }
  .bw-saved .a { grid-column: 2; grid-row: 1 / span 2; }
}

.bw-chart .trace.coffee { stroke: var(--muted); stroke-width: 2; }
.bw-chart .head.coffee { fill: var(--muted); }
.bw-chart .band { fill: var(--tile); fill-opacity: 1; }
.legend-line.coffee { border-top-color: var(--muted); border-top-width: 2px; }
.legend-box.pour { background: var(--tile); border-color: var(--line); }

/* ---------- Brew: both steps fill the window ---------- */
/* On Brew the page runs edge to edge: each step is sized to the window below the header (and above the
   phone's bottom bar), measured in brewing.js as --stage-h, so nothing scrolls until the extras below. */
body.on-brew main { max-width: none; padding: 0; }

/* Step 1: a stage in the tile colour. A small title row, the shelf taking the rest, the coffee's panel below. */
.stage { display: flex; flex-direction: column; height: var(--stage-h, 640px); min-height: 440px; background: var(--tile); overflow: hidden; }
.stage-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 18px var(--gutter) 0; }
.stage-title { font: 400 clamp(1.15rem, 2.4vw, 1.5rem)/1.2 var(--display); letter-spacing: -0.02em; }
.shelf { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
.shelf-track { display: flex; align-items: center; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; outline-offset: -2px; }
.shelf-track::-webkit-scrollbar { display: none; }
/* The front cellar is as large as fits: the width limit or the height left above the panel, whichever is smaller.
   Its scale and fade follow the scroll position (set frame by frame in brewing.js), so no CSS transition here. */
.shelf-slide {
  --w: max(170px, calc(0.7 * min(70vw, 1000px, calc((var(--stage-h, 640px) - var(--panel-h, 300px) - 104px) * 2.9))));
  flex: 0 0 var(--w);
  padding: 0 clamp(4px, 1.2vw, 14px);
  border: 0;
  background: none;
  cursor: pointer;
  scroll-snap-align: center;
  opacity: 0.45;
  transform: scale(0.72);
  transform-origin: 50% 55%;
  will-change: transform, opacity;
}
.shelf-slide:first-child { margin-left: calc(50% - var(--w) / 2); }
.shelf-slide:last-child { margin-right: calc(50% - var(--w) / 2); }
.shelf-slide.on { cursor: default; }
.shelf-slide > svg, .rec-thumb > svg { display: block; width: 100%; height: auto; }
.shelf-arrows { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; pointer-events: none; }
.shelf-arrows button { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: var(--bg); color: var(--ink); font-size: 1.1rem; cursor: pointer; pointer-events: auto; }
/* The dots show where you are; press and hold (or press and slide) to scrub through the shelf. */
.shelf-dots { position: relative; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 0 12px; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.shelf-dots.scrub { cursor: grabbing; }
.shelf-dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--line); transition: width 0.3s cubic-bezier(.2,.7,.2,1), height 0.3s, background 0.3s; }
.shelf-dots i.pick:not(.on) { background: var(--muted); }
.shelf-dots i.on { width: 18px; background: var(--ink); }
.shelf-dots.scrub i { width: 9px; height: 9px; border-radius: 5px; }
.shelf-dots.scrub i.on { width: 26px; }
.scrub-bubble { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); max-width: min(80vw, 420px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 7px 12px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: var(--fs-xs); pointer-events: none; opacity: 0; transition: opacity 0.12s; }
.scrub-bubble span { margin-left: 6px; opacity: 0.6; font-variant-numeric: tabular-nums; }
.shelf-dots.scrub .scrub-bubble { opacity: 1; }
/* The panel keeps one height whatever it holds, so the cellar above never shifts between coffees. */
.shelf-panel { display: grid; justify-items: center; align-content: start; gap: 10px; box-sizing: border-box; width: 100%; max-width: 620px; flex: 0 0 var(--panel-h, 300px); height: var(--panel-h, 300px); overflow-y: auto; scrollbar-width: none; margin: 0 auto; padding: 0 16px clamp(18px, 3vh, 32px); text-align: center; }
.shelf-for-you { color: var(--muted); font-size: var(--fs-xs); }
.shelf-for-you b { color: var(--ink); font-weight: 600; }
.shelf-name { font: 400 1.75rem/1.15 var(--display); letter-spacing: -0.02em; text-wrap: balance; }
.shelf-sub { color: var(--muted); font-size: var(--fs-sm); }
.shelf-sub a { color: var(--ink); }
.shelf-facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin: 2px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: var(--fs-xs); }
.shelf-facts b { color: var(--ink); font-weight: 400; }
.shelf-stock { font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.shelf-sources { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
.shelf-src { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; cursor: pointer; }
.shelf-src[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.shelf-go { margin-top: 8px; padding: 11px 22px; font-size: var(--fs-md); }
.free-form { display: grid; gap: 8px; width: min(100%, 360px); margin-top: 6px; text-align: left; }
.free-form label { display: grid; gap: 4px; color: var(--muted); font-size: var(--fs-xs); }
.free-two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Step 2: the graph takes the top, the coffee's bar sits under it, and the readings share one line at the
   bottom, just above the navigation. Each reading opens its device's controls; the extras sit below. */
.rec-screen { display: flex; flex-direction: column; height: var(--stage-h, 640px); min-height: 440px; }
.rec-graph { position: relative; flex: 1; min-height: 0; display: flex; padding: 12px var(--gutter) 0; }
.bw-chart { flex: 1; min-width: 0; min-height: 0; }
.bw-chart svg { display: block; width: 100%; height: 100%; }
.rec-overlay { position: absolute; top: 12px; left: calc(var(--gutter) + 56px); right: var(--gutter); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; pointer-events: none; font-variant-numeric: tabular-nums; }
.rec-overlay .chart-legends { margin-left: auto; font-size: var(--fs-xs); }
.bw-status { margin: 0 var(--gutter); }
.rec-bar { display: grid; grid-template-columns: 132px minmax(0, 1fr) auto auto; grid-template-areas: "thumb who change go"; align-items: center; gap: 12px 18px; margin: 0 var(--gutter); padding: 12px 0; border-top: 1px solid var(--line); }
.rec-thumb { grid-area: thumb; }
.rec-who { grid-area: who; display: grid; gap: 2px; min-width: 0; }
.rec-who b { font-weight: 500; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rec-who span { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-change { grid-area: change; justify-self: start; }
.rec-go { grid-area: go; min-width: 120px; }
.rec-dock { position: relative; }
.rec-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.rec-cell { display: grid; gap: 2px; min-width: 0; padding: 12px clamp(10px, 2.5vw, 24px) 14px; border: 0; background: none; text-align: left; cursor: pointer; }
.rec-cell + .rec-cell { border-left: 1px solid var(--line); }
.rec-cell.open, .rec-cell:hover { background: var(--tile); }
.rec-cell small { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-val { font: 400 clamp(1.25rem, 4.4vw, 1.9rem)/1.1 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rec-val small { margin-left: 2px; font-size: 0.55em; }
.rec-dev::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; vertical-align: 1px; background: var(--line); }
.rec-dev.on::before { background: var(--ok); }
/* A device's controls open just above the strip, over the graph. */
.rec-devices { position: absolute; left: var(--gutter); right: var(--gutter); bottom: calc(100% + 8px); z-index: 5; display: grid; gap: 10px; max-width: 560px; margin: 0 auto; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18); }
.rec-devices .bw-slot { padding: 0; border: 0; }
.rec-devices-foot { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); font-size: var(--fs-xs); }
.rec-devices-foot .btn { justify-self: start; }
.rec-more { display: grid; gap: 24px; padding: 8px clamp(10px, 2.5vw, 24px) 48px; }
.rec-time { cursor: default; }
.rec-time:hover { background: none; }

/* Brewing: the device panels */
.bw-slot { display: grid; gap: 8px; }
.bw-slot-head { display: grid; gap: 2px; }
.bw-slot-head h2 { margin: 0; font: 500 var(--fs-md)/1.2 var(--display); }
.bw-slot-hint { font-size: var(--fs-xs); color: var(--muted); }
.bw-slot-status { margin: 0; font-size: var(--fs-sm); line-height: 1.3; color: var(--muted); }
.bw-slot-status.ok { color: var(--ok); }
.bw-slot-status.error { color: var(--warn); }
.bw-pi-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pis-list { margin: 8px 0 0; padding: 0; list-style: none; }
.pis-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.pis-list .who { min-width: 0; }
.pis-list .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pis-list .who small { color: var(--muted); }
.pis-list .acts { display: inline-flex; gap: 6px; }
.bw-endask { position: fixed; z-index: 40; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(340px, calc(100vw - 32px)); display: grid; gap: 10px; padding: 14px 16px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.18); }
.bw-endask p { margin: 0; }
.bw-endask-btns { display: flex; justify-content: flex-end; gap: 8px; }
.bw-slot-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.bw-slot-raw { font: 400 var(--fs-xl)/1 var(--display); font-variant-numeric: tabular-nums; }
.bw-slot-raw small { margin-left: 3px; font-size: var(--fs-sm); color: var(--muted); }
.bw-slot-btns { display: inline-flex; gap: 6px; }

@media (max-width: 820px) {
  body.on-brew main { padding-bottom: 0; }
  .rec-more { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 560px) {
  .shelf-slide { --w: max(170px, calc(0.7 * min(94vw, calc((var(--stage-h, 640px) - var(--panel-h, 340px) - 104px) * 2.9)))); padding: 0 4px; }
  .shelf-arrows { display: none; }

  .shelf-facts { gap: 2px 12px; }
  .rec-overlay { left: calc(var(--gutter) + 44px); }
  .rec-overlay .chart-legends { display: none; }
  .rec-bar { grid-template-columns: 96px minmax(0, 1fr); grid-template-areas: "thumb who" "change go"; gap: 14px; }
  .rec-go { justify-self: end; min-width: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .shelf-dots i, .scrub-bubble { transition: none; }
}

/* ---------- Recipes ---------- */
.recipes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: clamp(24px, 3vw, 36px) clamp(16px, 2vw, 24px);
  align-items: start;
}
.recipe { display: grid; gap: 10px; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 4px; background: var(--card); }
.recipe-head { display: grid; gap: 2px; }
.recipe-head h2 { margin: 0; font-size: 1.125rem; font-weight: 600; text-wrap: balance; }
.recipe-sum { margin: 0; font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.recipe-graph { height: 72px; padding: 6px; border-radius: 4px; background: var(--tile); color: var(--ink); }
.recipe-graph svg, .recipe-plan svg { display: block; width: 100%; height: 100%; }
.recipe-pours { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: var(--fs-sm); }
.recipe-notes { margin: 0; font-size: var(--fs-sm); }
.recipe-use { margin: 0; font-size: var(--fs-xs); color: var(--muted); }
.recipe-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: var(--fs-sm); }
.recipe-plan { height: 120px; margin-top: 8px; color: var(--ink); }
.recipe-plan:empty { display: none; }
.recipe-warnings { margin: 8px 0 0; padding-left: 1.2em; font-size: var(--fs-sm); color: var(--warn, var(--muted)); }
.p-at-est { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); gap: 4px; }
.p-at-est .p-est { min-width: 0; font-family: var(--mono); font-size: var(--fs-sm); }

/* Brew page: the recipe being followed */
.rec-recipe { justify-self: start; margin-top: 2px; padding: 0; border: 0; background: none; color: var(--ink); font: 500 var(--fs-sm)/1.3 var(--body); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.rec-recipe:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.bw-chart .target { fill: none; stroke: var(--plan, var(--ink)); stroke-width: 5; stroke-opacity: 0.22; stroke-linecap: round; stroke-linejoin: round; }
.bw-chart .target.sketched { stroke-width: 2.5; stroke-opacity: 0.4; stroke-dasharray: 7 6; }
.bw-cue { margin: 6px var(--gutter) 0; font-size: 1rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.recipe-picks { display: grid; gap: 6px; margin-bottom: 16px; }
.recipe-picks .pick { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.recipe-picks .pick span { color: var(--muted); font-size: var(--fs-sm); }
.recipe-picks .pick.on { border-color: var(--ink); }
