:root {
  --bg: #f2f2f7;
  --card: #fff;
  --card-2: #f2f2f7;
  --label: #000;
  --secondary: rgba(60, 60, 67, .6);
  --tertiary: rgba(60, 60, 67, .3);
  --separator: rgba(60, 60, 67, .18);
  --fill: rgba(120, 120, 128, .12);
  --tint: #e07800;
  --tint-soft: rgba(255, 149, 0, .14);
  --green: #248a3d;
  --red: #d70015;
  --bar: rgba(249, 249, 249, .82);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
/* Dark: follows the system unless Setup picks light or dark (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --label: #fff;
    --secondary: rgba(235, 235, 245, .6);
    --tertiary: rgba(235, 235, 245, .3);
    --separator: rgba(84, 84, 88, .6);
    --fill: rgba(118, 118, 128, .24);
    --tint: #ff9f0a;
    --tint-soft: rgba(255, 159, 10, .18);
    --green: #30d158;
    --red: #ff453a;
    --bar: rgba(22, 22, 24, .8);
    --shadow: none;
  }
}
:root[data-theme=dark] {
  --bg: #000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --label: #fff;
  --secondary: rgba(235, 235, 245, .6);
  --tertiary: rgba(235, 235, 245, .3);
  --separator: rgba(84, 84, 88, .6);
  --fill: rgba(118, 118, 128, .24);
  --tint: #ff9f0a;
  --tint-soft: rgba(255, 159, 10, .18);
  --green: #30d158;
  --red: #ff453a;
  --bar: rgba(22, 22, 24, .8);
  --shadow: none;
}
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 17px/1.4 var(--font); letter-spacing: -.01em; background: var(--bg); color: var(--label); padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
a { color: var(--tint); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
main { max-width: 1080px; margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
footer { max-width: 1080px; margin: 0 auto; padding: 8px 20px 24px; font-size: 13px; color: var(--secondary); text-align: center; }
.loading { color: var(--secondary); text-align: center; padding: 30vh 0; }

/* Tab bar: bottom on phones, top on wide screens */
.tabbar { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; padding: 6px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--separator); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 500; color: var(--secondary); padding: 2px 0; }
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--tint); }
.tabbar a.active svg { stroke-width: 2.2; }
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-top: 56px; }
  .tabbar { top: 0; bottom: auto; justify-content: center; gap: 8px; padding: 8px; border-top: 0; border-bottom: .5px solid var(--separator); }
  .tabbar a { flex: 0 0 auto; flex-direction: row; gap: 6px; font-size: 14px; padding: 6px 14px; border-radius: 99px; }
  .tabbar a.active { background: var(--tint-soft); }
  .tabbar svg { width: 18px; height: 18px; }
}

/* Typography */
h1.large { font: 700 34px/1.15 var(--display); letter-spacing: .01em; margin: 8px 0 4px; }
h2 { font: 700 22px/1.2 var(--display); margin: 28px 0 10px; }
h3 { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
.sub { color: var(--secondary); margin: 0 0 16px; font-size: 15px; }
.muted { color: var(--secondary); }
.small { font-size: 13px; }
.section-label { font-size: 13px; text-transform: uppercase; letter-spacing: .02em; color: var(--secondary); margin: 24px 16px 6px; }

/* Controls */
.search { position: relative; margin: 4px 0 12px; }
.search input { width: 100%; height: 38px; border: 0; border-radius: 10px; background: var(--fill); padding: 0 12px 0 34px; font-size: 17px; outline: none; }
textarea { box-sizing: border-box; width: 100%; border: 0; border-radius: 10px; background: var(--fill); color: inherit; padding: 10px 12px; font: 15px ui-monospace, monospace; outline: none; }
.search svg { position: absolute; left: 10px; top: 10px; width: 18px; height: 18px; fill: none; stroke: var(--secondary); stroke-width: 2; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 600; font-size: 16px; background: var(--tint); color: #fff; cursor: pointer; }
.btn.secondary { background: var(--tint-soft); color: var(--tint); }
.btn.plain { background: var(--fill); color: var(--label); }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 99px; }
.btn.danger { background: transparent; color: var(--red); }
.btn:active { opacity: .7; }
.btn:disabled { opacity: .4; }
.icon-btn { border: 0; background: var(--fill); width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; cursor: pointer; color: var(--label); flex: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { background: var(--tint-soft); color: var(--tint); }
.icon-btn.on.like svg { fill: currentColor; }
.icon-btn.on.nope { background: rgba(255, 59, 48, .14); color: var(--red); }
:focus-visible { outline: 3px solid var(--tint); outline-offset: 2px; }

.segmented { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; margin: 0 0 16px; overflow-x: auto; scrollbar-width: none; }
.segmented button { flex: 1; border: 0; background: none; padding: 7px 12px; border-radius: 7px; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; color: var(--label); }
.segmented button[aria-pressed=true] { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) .segmented button[aria-pressed=true] { background: #636366; } }
:root[data-theme=dark] .segmented button[aria-pressed=true] { background: #636366; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding-inline: 16px; }
.chips::-webkit-scrollbar, .segmented::-webkit-scrollbar, .scroller::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 99px; padding: 7px 14px; background: var(--card); color: var(--label); font-size: 15px; cursor: pointer; box-shadow: var(--shadow); scroll-snap-align: start; white-space: nowrap; }
.chip small { color: var(--secondary); margin-left: 4px; }
.chip[aria-pressed=true] { background: var(--label); color: var(--bg); }
.chip[aria-pressed=true] small { color: inherit; opacity: .7; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 12px; flex-wrap: wrap; }
.toolbar select { border: 0; background: var(--fill); border-radius: 8px; padding: 6px 8px; font-size: 14px; }

/* Filters sheet */
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; box-shadow: var(--shadow); }
.range { margin-bottom: 18px; }
.range header { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 8px; }
.range header b { font-weight: 600; }
.range output { color: var(--secondary); font-variant-numeric: tabular-nums; }
.dual { position: relative; height: 28px; }
.dual .track { position: absolute; left: 0; right: 0; top: 12px; height: 4px; border-radius: 2px; background: var(--fill); }
.dual .fill { position: absolute; top: 12px; height: 4px; border-radius: 2px; background: var(--tint); left: var(--a); right: calc(100% - var(--b)); }
.dual.colour .track { height: 8px; top: 10px; border-radius: 4px; background: linear-gradient(90deg, #f8e08e, #f3b33d, #d77d1a, #a8501a, #7a2e0e, #4a1a08, #1e0c06); }
.dual.colour .fill { display: none; }
.dual input { position: absolute; inset: 0; width: 100%; margin: 0; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; height: 28px; }
.dual input::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 0.5px 4px rgba(0, 0, 0, .12), 0 6px 13px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); cursor: grab; }
.dual input::-moz-range-thumb { pointer-events: auto; width: 28px; height: 28px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0.5px 4px rgba(0, 0, 0, .12), 0 6px 13px rgba(0, 0, 0, .12); cursor: grab; }
.dual input::-moz-range-track { background: none; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.switch { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 99px; background: var(--fill); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15); transition: transform .2s; }
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

/* Beer cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.card { position: relative; display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 12px 12px 12px 0; color: var(--label); box-shadow: var(--shadow); overflow: hidden; min-height: 116px; transition: transform .15s; }
.card:active { transform: scale(.98); }
.card .glass { flex: none; width: 76px; align-self: stretch; display: grid; place-items: center; background: linear-gradient(160deg, color-mix(in srgb, var(--beer) 55%, transparent), color-mix(in srgb, var(--beer) 15%, transparent)); margin: -12px 0; }
.card .glass img { max-height: 96px; max-width: 46px; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .2)); }
.card .body { min-width: 0; flex: 1; }
.card h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 36px; }
.card p { margin: 0 0 6px; color: var(--secondary); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .icon-btn { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; background: transparent; }
.card .icon-btn.on { background: transparent; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--secondary); align-items: center; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--tint-soft); color: var(--tint); }
.pill.green { background: rgba(52, 199, 89, .15); color: var(--green); }
.pill.red { background: rgba(255, 59, 48, .12); color: var(--red); }
.pill.grey { background: var(--fill); color: var(--secondary); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--beer); box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .2); vertical-align: -1px; }
.empty { text-align: center; color: var(--secondary); padding: 48px 16px; }
.empty .btn { margin-top: 12px; }

/* Beer page */
.back { display: inline-flex; align-items: center; gap: 2px; font-size: 17px; margin: 4px 0 8px -4px; }
.back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.hero { display: flex; gap: 20px; align-items: center; background: linear-gradient(150deg, color-mix(in srgb, var(--beer) 45%, var(--card)), var(--card) 70%); border-radius: 20px; padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.hero img { width: 70px; max-height: 200px; object-fit: contain; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .25)); }
.hero h1 { font: 700 28px/1.15 var(--display); margin: 6px 0 4px; }
.hero p { margin: 0; color: var(--secondary); }
.hero .actions { display: flex; gap: 8px; margin-top: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.tile b { display: block; font: 600 20px/1.2 var(--display); font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--secondary); }
.prose { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; box-shadow: var(--shadow); }
.prose p { margin: 0 0 8px; }
.prose p:last-child { margin: 0; }
.scroller { display: flex; gap: 12px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 8px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.scroller .card { flex: 0 0 min(280px, 80vw); scroll-snap-align: start; }

/* Inset grouped lists */
.list { background: var(--card); border-radius: var(--radius); margin: 0 0 12px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 44px; position: relative; }
.row + .row::before, .row + details::before, details + .row::before, details + details::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--separator); }
.list details { position: relative; }
.row .grow { flex: 1; min-width: 0; }
.row .value { color: var(--secondary); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row .title { display: block; }
.row .detail { display: block; font-size: 13px; color: var(--secondary); }
.row label.grow { cursor: pointer; }
.row input[type=text], .row input[type=number], .row select { border: 0; background: transparent; text-align: right; color: var(--secondary); max-width: 55%; padding: 0; outline: none; }
.row select { text-align-last: right; appearance: none; -webkit-appearance: none; padding-right: 14px; background: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%2710%27 height=%276%27%3E%3Cpath d=%27M1 1l4 4 4-4%27 fill=%27none%27 stroke=%27%238e8e93%27 stroke-width=%271.5%27/%3E%3C/svg%3E") no-repeat right center; }
.row input[type=number] { width: 90px; }
summary.row { list-style: none; cursor: pointer; }
summary.row::-webkit-details-marker { display: none; }
summary.row::after { content: "›"; color: var(--tertiary); font-size: 22px; line-height: 1; transition: transform .2s; }
details[open] > summary.row::after { transform: rotate(90deg); }
.subs { padding: 0 16px 12px 52px; font-size: 14px; color: var(--secondary); }
.subs ul { margin: 4px 0 0; padding-left: 18px; }
.check { appearance: none; -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--tertiary); flex: none; margin: 0; cursor: pointer; display: grid; place-items: center; transition: all .15s; }
.check:checked { background: var(--tint); border-color: var(--tint); }
.check:checked::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.2px 2.2px 0; transform: translateY(-1px) rotate(45deg); }
.row.done .title { color: var(--secondary); text-decoration: line-through; }
.warn { background: rgba(255, 149, 0, .12); color: var(--label); border-radius: 12px; padding: 12px 14px; margin: 0 0 12px; font-size: 15px; }
.warn b { color: var(--tint); }

/* Brew steps */
.step { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 10px; box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start; }
.step .check { margin-top: 1px; }
.step h3 { font-size: 17px; }
.step p { margin: 0; color: var(--secondary); font-size: 15px; grid-column: 2; }
.step.done { opacity: .55; }
.step.done h3 { text-decoration: line-through; }
.step.current { box-shadow: 0 0 0 2px var(--tint), var(--shadow); }
.timer { grid-column: 2; display: flex; align-items: center; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.ring { --p: 0; width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--tint) calc(var(--p) * 1%), var(--fill) 0); position: relative; flex: none; }
.ring::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--card); }
.ring b { position: relative; font: 600 17px/1 var(--display); font-variant-numeric: tabular-nums; }
.timer .btns { display: flex; gap: 8px; }
.alarms { grid-column: 2; list-style: none; padding: 0; margin: 10px 0 0; font-size: 14px; }
.alarms li { display: flex; gap: 10px; padding: 6px 0; border-top: .5px solid var(--separator); }
.alarms li b { min-width: 52px; font-variant-numeric: tabular-nums; color: var(--tint); }
.alarms li.fired { color: var(--secondary); text-decoration: line-through; }
.alarms li.fired b { color: var(--secondary); }
.when { grid-column: 2; margin-top: 6px; }

/* Stock */
.add-stock { display: grid; grid-template-columns: 1fr 96px auto; gap: 8px; align-items: center; }
.add-stock input { height: 40px; border: 0; border-radius: 10px; background: var(--fill); padding: 0 12px; min-width: 0; outline: none; }
.score { --p: 0; width: 44px; height: 44px; border-radius: 50%; background: conic-gradient(var(--green) calc(var(--p) * 1%), var(--fill) 0); display: grid; place-items: center; position: relative; flex: none; font-size: 12px; font-weight: 700; }
.score::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--card); }
.score span { position: relative; }

/* Toast banner */
#toast { position: fixed; z-index: 30; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translate(-50%, -150%); width: min(92vw, 440px); background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-radius: 18px; padding: 14px 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); transition: transform .35s cubic-bezier(.2, .9, .3, 1.2); font-size: 15px; }
#toast.show { transform: translate(-50%, 0); }
#toast b { display: block; margin-bottom: 2px; }
#toast .btn { margin-top: 10px; }
#toast ul { margin: 6px 0 0; padding-left: 20px; }
#toast li { margin: 3px 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Brew list button on cards, boil additions */
.card .body { padding-right: 24px; }
.card .icon-btn.plan { top: auto; bottom: 8px; }
.card .icon-btn.plan.on { color: var(--green); }
.step.addition { background: var(--tint-soft); box-shadow: none; }
.step.addition h3 { color: var(--tint); }
.step.addition.done h3 { color: inherit; }
.timer [data-boil-left] { flex-basis: 100%; }

/* Bottom sheet for brew days */
dialog#sheet { border: 0; padding: 0; margin: auto auto 0; width: min(100%, 560px); max-height: 85vh; border-radius: 16px 16px 0 0; background: var(--bg); color: var(--label); box-shadow: 0 -10px 40px rgba(0, 0, 0, .3); }
dialog#sheet::backdrop { background: rgba(0, 0, 0, .4); }
@media (min-width: 900px) { dialog#sheet { margin: auto; border-radius: 16px; } }
.sheet-body { padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-body::before { content: ""; display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--tertiary); margin: 0 auto 8px; }
.sheet-body header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet-body input[type=date], .sheet-body input[type=text] { max-width: 60%; }
.sheet-body .row input[type=date], .sheet-body .row input[type=text] { border: 0; background: transparent; text-align: right; color: var(--secondary); outline: none; font: inherit; }
