/* Sourdough Calculator — mobile-first styles */
:root {
  --bg: #f6f1e9;
  --card: #fffdf9;
  --ink: #2b2118;
  --muted: #7a6a5a;
  --line: #e9dfd2;
  --field: #f8f3ec;
  --field-line: #dccfbf;
  --accent: #a9561f;
  --accent-ink: #fff;
  --accent-soft: #f4e3d4;
  --neg: #b3261e;
  --warn-bg: #fdecea;
  --radius: 16px;
  --tabbar-h: 64px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1612;
    --card: #25201b;
    --ink: #f1e8dd;
    --muted: #a8998a;
    --line: #3a3129;
    --field: #1e1915;
    --field-line: #4a3f35;
    --accent: #e08b4a;
    --accent-ink: #1b1612;
    --accent-soft: #3b2a1d;
    --neg: #ff8a80;
    --warn-bg: #3d1f1c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font: 600 1.05rem var(--serif); }
.topbar-title { color: var(--muted); font-size: .9rem; }

/* ---------- layout ---------- */
main {
  max-width: 1080px; margin: 0 auto;
  padding: 8px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
.view-head { padding: 14px 4px 10px; }
.view-head h1 { font: 600 1.6rem/1.15 var(--serif); margin: 0; letter-spacing: -.01em; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.grid { display: grid; gap: 12px; }
.col { display: grid; gap: 12px; align-content: start; }
@media (min-width: 860px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 16px; }
  .col { gap: 16px; }
  .view-head h1 { font-size: 2rem; }
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  box-shadow: 0 1px 2px rgba(60, 40, 20, .04);
}
.card h2 { font: 600 1.08rem var(--serif); margin: 0 0 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.card-head h2 { margin: 0; }
.card.main { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, 0 2px 10px rgba(169, 86, 31, .08); }
.hint { margin: 0 0 8px; color: var(--muted); font-size: .84rem; }
.pill {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 3px 10px; font-size: .9rem; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- fields & steppers ---------- */
.field {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.field label { display: flex; flex-direction: column; min-width: 0; }
.field label small { color: var(--muted); font-size: .78rem; }
.stepper { display: flex; align-items: stretch; flex: none; }
.stepper .num { width: 84px; border-radius: 0; border-left: 0; border-right: 0; }
.step {
  width: 44px; min-height: 44px; border: 1px solid var(--field-line); background: var(--field);
  font-size: 1.3rem; line-height: 1; cursor: pointer; touch-action: manipulation;
}
.step:first-child { border-radius: 12px 0 0 12px; }
.step:last-child { border-radius: 0 12px 12px 0; }
.step:active { background: var(--accent-soft); }

.num, .text, .time {
  width: 100%; min-height: 44px;
  font-size: 16px;            /* ≥16px stops iOS zooming on focus */
  padding: 8px 10px;
  border: 1px solid var(--field-line); border-radius: 10px;
  background: var(--field);
  font-variant-numeric: tabular-nums;
}
.num { text-align: right; }
.num:focus, .text:focus, .time:focus, .name:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.num.auto {
  display: flex; align-items: center; justify-content: flex-end;
  border-style: dashed; background: transparent; color: var(--muted);
}
.neg { color: var(--neg) !important; font-weight: 700; }

/* ---------- ingredient rows ---------- */
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) 82px 70px;
  gap: 8px; align-items: center; padding: 5px 0;
  border-bottom: 1px solid var(--line);
}
.row.head { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; padding: 2px 0 6px; }
.row.head span:not(:first-child) { text-align: right; }
.row.total { border-bottom: 0; font-weight: 600; padding-top: 8px; }
.row.total .num.auto { border: 0; color: var(--ink); min-height: 0; padding-right: 10px; }
.row .w, .row output { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.row.flour .name { font-weight: 600; }
.name {
  width: 100%; min-height: 44px; border: 0; border-bottom: 1px dashed transparent;
  background: transparent; padding: 6px 2px; font-size: 16px; border-radius: 6px;
}
.name:hover { border-bottom-color: var(--field-line); }
.lbl { min-width: 0; overflow-wrap: anywhere; }
.row.kv { grid-template-columns: minmax(0, 1fr) 92px 38px; }
.row.bake { grid-template-columns: minmax(0, 1fr) 70px 70px; }
.unit { color: var(--muted); font-size: .85rem; }

/* ---------- main dough ---------- */
.mrow {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--line); font-size: 1.06rem;
}
.mrow.zero { display: none; }
.mrow.ferm span:first-child { color: var(--accent); font-weight: 600; }
.mrow.total { border-bottom: 0; font-weight: 700; }
.mw { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mw output { font-weight: 700; font-size: 1.12rem; }
.mw small { color: var(--muted); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.stat { background: var(--field); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.slabel { color: var(--muted); font-size: .78rem; }
.sval b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.sval small, .stat > small { color: var(--muted); font-size: .8rem; }

/* ---------- warnings & buttons ---------- */
.warn {
  background: var(--warn-bg); color: var(--neg); border-radius: 12px;
  padding: 10px 12px; margin: 0 0 12px; font-size: .9rem;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; padding: 18px 0 8px; }
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600;
  touch-action: manipulation;
}
.btn.small { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--field-line); }

/* ---------- temperature ---------- */
.result { text-align: center; }
.big-wrap { display: flex; justify-content: center; align-items: baseline; gap: 4px; margin: 6px 0; }
.big { font: 600 4rem/1 var(--serif); font-variant-numeric: tabular-nums; color: var(--accent); }
.big-unit { font-size: 1.5rem; color: var(--muted); }
.steps { margin: 0; padding-left: 1.2em; }
.steps li { margin: 0 0 10px; }

/* ---------- tracker ---------- */
.stack { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: .9rem; color: var(--muted); }
.stack .text { color: var(--ink); }
.loghead { font: 600 .82rem var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin: 14px 0 2px; }
.logrow { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.logtop { display: grid; grid-template-columns: minmax(0, 1fr) 112px auto; gap: 8px; align-items: center; }
.logtop .lbl { font-weight: 600; }
.logmid { display: grid; grid-template-columns: 76px 76px minmax(0, 1fr); gap: 8px; align-items: end; }
.logmid label { display: flex; flex-direction: column; gap: 2px; }
.logmid small { color: var(--muted); font-size: .72rem; padding-left: 2px; }
.time { padding: 6px 8px; }
.btn.now { min-height: 44px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.1; }
@media (min-width: 860px) {
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: 480px; bottom: 14px; border: 1px solid var(--line); border-radius: 20px; height: var(--tabbar-h); padding: 0; box-shadow: 0 6px 24px rgba(40, 25, 10, .12); }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem;
  transition: opacity .2s, transform .2s; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 360px) {
  .row { grid-template-columns: minmax(0, 1fr) 74px 62px; gap: 6px; }
  .stepper .num { width: 70px; }
  .step { width: 40px; }
}
@media print {
  .tabbar, .topbar, .actions, .btn, .toast { display: none !important; }
  body { padding: 0; background: #fff; }
  .view[hidden] { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
