:root {
  --bg: #f5efe6;
  --surface: #fffdf9;
  --ink: #261d17;
  --muted: #7a6a5d;
  --line: #e6dccf;
  --accent: #8b5a36;
  --accent-ink: #fff;
  --accent-soft: #f1e3d5;
  --gh: #8b5a36;
  --kh: #6d8a77;
  --warn-bg: #fbeedb;
  --warn-ink: #7a4a12;
  --danger: #b0413e;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 8px 24px rgb(60 40 20 / 6%);
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120f;
    --surface: #211b16;
    --ink: #f1e8de;
    --muted: #a8988a;
    --line: #362c24;
    --accent: #d39a6a;
    --accent-ink: #1a120c;
    --accent-soft: #3a2a1e;
    --gh: #d39a6a;
    --kh: #8fb59b;
    --warn-bg: #3b2a14;
    --warn-ink: #f3cf9a;
    --danger: #e0716c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; line-height: 1.15; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }
b { font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.lede { color: var(--muted); max-width: 60ch; margin-bottom: 1.25rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; color: var(--accent); margin-bottom: .5rem; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 1.25rem .75rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  max-width: 920px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--ink); text-decoration: none; font-family: var(--serif); font-size: 1.2rem; font-weight: 600; }
.brand svg { width: 22px; height: 22px; fill: var(--accent); }
.chip {
  display: inline-flex; align-items: center; gap: .45rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: .4rem .85rem; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kh); }

/* tabs: bottom bar on phones, inline on wide screens */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .55rem 0 .5rem; font-size: .7rem; color: var(--muted); text-decoration: none;
}
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); }
@media (min-width: 760px) {
  body { padding-bottom: 2rem; }
  .tabs {
    position: static; display: flex; justify-content: center; gap: .25rem;
    background: none; border: 0; max-width: 920px; margin: 0 auto 1rem; padding: 0 1.25rem;
  }
  .tabs a { flex-direction: row; gap: .4rem; padding: .5rem .9rem; border-radius: 999px; font-size: .9rem; }
  .tabs svg { width: 18px; height: 18px; }
  .tabs a[aria-current="page"] { background: var(--accent-soft); }
}

main { max-width: 920px; margin: 0 auto; padding: .5rem 1.25rem 2rem; }
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 1rem; }

/* hero / bottle routine */
.hero { padding: 1.75rem 1.5rem; background: linear-gradient(160deg, var(--surface), var(--accent-soft)); }
.hero h1 { font-size: clamp(2rem, 7vw, 3rem); margin-bottom: 1.25rem; }
.dose { color: var(--accent); white-space: nowrap; }
.steps { list-style: none; counter-reset: s; padding: 0; margin: 0; display: grid; gap: .75rem; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 2rem 1fr; gap: .75rem; align-items: start; font-size: 1.05rem; }
.steps li::before {
  content: counter(s); display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .9rem;
}
.steps.compact li { font-size: 1rem; }

.fill-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.fill-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: .8rem; padding-bottom: .25rem; }
.fill-table td { padding: .45rem 0; border-top: 1px solid var(--line); }
.fill-table td:last-child, .fill-table th:last-child { text-align: right; }
.fill-table td:last-child { font-weight: 650; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .75rem; }
.stats div { display: flex; flex-direction: column; }
.stats span { font-size: .75rem; color: var(--muted); }
.stats b { font-family: var(--serif); font-size: 1.8rem; line-height: 1.1; }
.stats i { font-style: normal; font-size: .75rem; color: var(--muted); }

/* buttons */
.actions { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; margin: 1.25rem 0 .5rem; }
.btn {
  appearance: none; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: 600 .95rem var(--sans);
  padding: .75rem 1.3rem; min-height: 44px;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.btn.small { padding: .35rem .9rem; min-height: 32px; font-size: .85rem; }
.link { background: none; border: 0; padding: 0; font: inherit; font-size: .8rem; cursor: pointer; color: var(--muted); text-decoration: underline; }
.link.danger { color: var(--danger); }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

/* forms */
.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: .35rem; font-size: .85rem; color: var(--muted); font-weight: 500; }
.row3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
input, select {
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem; width: 100%; min-height: 44px;
}
.unit { position: relative; display: block; }
.unit input { padding-right: 4.5rem; }
.unit i { position: absolute; right: .8rem; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: .85rem; pointer-events: none; }
.seg { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.seg legend { font-size: .85rem; color: var(--muted); font-weight: 500; margin-bottom: .35rem; padding: 0; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: flex; flex-direction: column; gap: .1rem; padding: .7rem .9rem; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); color: var(--ink); font-weight: 600; font-size: 1rem;
}
.seg small { font-weight: 400; color: var(--muted); font-size: .8rem; }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.seg input:focus-visible + span { outline: 2.5px solid var(--accent); outline-offset: 2px; }

/* results */
.result dl { margin: 0; display: grid; gap: .6rem; }
.result dl div { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.result dt { color: var(--muted); }
.result dd { margin: 0; font-family: var(--serif); font-size: 1.9rem; font-variant-numeric: tabular-nums; }
.result dd i, .big i { font-style: normal; font-family: var(--sans); font-size: .85rem; color: var(--muted); margin-left: .25rem; }
.result .total { border-top: 1px solid var(--line); padding-top: .6rem; }
.result .total dd { color: var(--accent); }
.big { font-family: var(--serif); font-size: 2.4rem; margin: 0; font-variant-numeric: tabular-nums; }
.alert { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: .85rem 1rem; margin-bottom: 1rem; font-size: .95rem; }

/* recipes */
.recipe-list { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-bottom: 1rem; }
.recipe-list .card { margin: 0; }
.recipe header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.recipe h3 { margin: 0; }
.recipe.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), var(--shadow); }
.badge { background: var(--accent-soft); color: var(--accent); font-size: .75rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px; }
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--line); gap: 2px; margin-bottom: .6rem; }
.bar .gh { background: var(--gh); }
.bar .kh { background: var(--kh); }
.kv { display: flex; flex-wrap: wrap; gap: .35rem 1rem; font-size: .85rem; margin-bottom: .4rem; font-variant-numeric: tabular-nums; }
.kv span { display: inline-flex; align-items: center; gap: .35rem; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.gh { background: var(--gh); }
.sw.kh { background: var(--kh); }

/* log */
.log-list { list-style: none; padding: 0; margin: 0; }
.log-list .card { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; margin-bottom: .6rem; }
.log-list .card p { margin: .25rem 0 0; }
.log-list .right { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; white-space: nowrap; font-size: .85rem; color: var(--muted); }
.log-list .empty { text-align: center; padding: 2rem 0; }
.tds { color: var(--accent); font-weight: 600; }

/* dialog */
dialog {
  border: 0; border-radius: var(--radius); padding: 1.25rem; width: min(420px, calc(100% - 2rem));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(20 12 6 / 45%); backdrop-filter: blur(2px); }
.dialog-list { display: grid; gap: .4rem; margin-bottom: 1rem; max-height: 60vh; overflow: auto; }
.pick {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem; text-align: left;
  background: var(--bg); color: var(--ink); border: 1.5px solid transparent; border-radius: 12px; padding: .75rem .9rem; font: inherit; cursor: pointer;
}
.pick span { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.pick.active { border-color: var(--accent); }

/* print: just the fridge card */
#print-card { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .topbar, .tabs, main, dialog { display: none !important; }
  #print-card { display: block; font-family: var(--sans); max-width: 14cm; margin: 1cm auto; border: 2px solid #000; border-radius: 12px; padding: 1cm; }
  #print-card h1 { font-size: 26pt; margin: 0 0 .2cm; }
  #print-card .big { font-size: 20pt; font-weight: 700; margin-bottom: .4cm; }
  #print-card ol { font-size: 14pt; padding-left: 1.2em; line-height: 1.5; }
  #print-card .small { font-size: 10pt; margin-top: .4cm; }
}
