/* Layout: sign-in gate, then a sidebar app (New recipe, Past recipes, Favourites, Profile). Sidebar becomes a bottom tab bar on phones. */
:root {
  --bg: #F1F5EE;
  --surface: #FBFDF9;
  --sunken: #E4ECE0;
  --ink: #15231B;
  --muted: #4F6358;
  --line: #CCD8C8;
  --accent: #1D6A45;
  --on-accent: #FFFFFF;
  --have-bg: #DAEADB;
  --need: #A8351F;
  --need-bg: #F8E3DD;
  --heart: #B8324F;
  --f-display: ui-rounded, system-ui, sans-serif;
  --f-body: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1612;
    --surface: #16211B;
    --sunken: #1E2C25;
    --ink: #E6EFE9;
    --muted: #9BB0A3;
    --line: #2B3C33;
    --accent: #5FC48C;
    --on-accent: #0A1A11;
    --have-bg: #21392C;
    --need: #FF9078;
    --need-bg: #3A211B;
    --heart: #FF7A95;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1612;
  --surface: #16211B;
  --sunken: #1E2C25;
  --ink: #E6EFE9;
  --muted: #9BB0A3;
  --line: #2B3C33;
  --accent: #5FC48C;
  --on-accent: #0A1A11;
  --have-bg: #21392C;
  --need: #FF9078;
  --need-bg: #3A211B;
  --heart: #FF7A95;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--f-body);
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
h1, h2, h3 { font-family: var(--f-display); letter-spacing: -0.015em; text-wrap: balance; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lede { color: var(--muted); font-size: 1.0625rem; max-width: 52ch; }
.hint { font-size: 0.875rem; color: var(--muted); }
.lbl { font-weight: 600; font-size: 0.9375rem; }
.sublbl { font-size: 0.8125rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.stack { display: grid; gap: 18px; min-width: 0; }
.field { display: grid; gap: 8px; min-width: 0; }
.status { color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }

.btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 10px 18px;
  border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
a.btn { text-decoration: none; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9375rem; }
.btn.link { border-color: transparent; color: var(--muted); padding-inline: 8px; }
.btn.danger { color: var(--need); }
.ico { width: 20px; height: 20px; flex: none; display: inline-grid; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fav[aria-pressed="true"] { color: var(--heart); border-color: var(--heart); }
.fav[aria-pressed="true"] .ico svg { fill: currentColor; }

/* Gate (sign-in, loading, tutorial) */
.center { min-height: calc(100dvh - 60px); display: grid; place-items: center; }
.gate { width: min(100%, 520px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 18px; }
.gate h1 { font-size: clamp(2rem, 7vw, 2.6rem); line-height: 1.05; }
.gate h2 { font-size: 1.5rem; }
.who { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--sunken); border-radius: 10px; }
.who img { width: 40px; height: 40px; border-radius: 50%; flex: none; }
.gate-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--sunken); border-radius: 10px; }
.seg button { font: inherit; font-weight: 600; min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.dots { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.dots li { height: 6px; flex: 1; border-radius: 3px; background: var(--line); }
.dots li.on { background: var(--accent); }
.tour { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.tour li { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; align-items: start; }
.tour .ico { width: 36px; height: 36px; padding: 8px; border-radius: 10px; background: var(--have-bg); color: var(--accent); }
.tour b { display: block; }

/* App shell */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 24px; align-items: start; max-width: 1200px; margin-inline: auto; }
.side { position: sticky; top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 16px; }
.brand { font-family: var(--f-display); font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; padding: 2px 8px; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 9px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--sunken); }
.nav a[aria-current="page"] { background: var(--have-bg); color: var(--accent); font-weight: 600; }
.me { display: flex; gap: 10px; align-items: center; padding: 12px 8px 0; border-top: 1px solid var(--line); min-width: 0; }
.me img { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.me span { font-size: 0.9375rem; overflow-wrap: anywhere; }
.main { min-width: 0; display: grid; gap: 20px; align-content: start; }
.vhead h1 { font-size: clamp(1.7rem, 5vw, 2.3rem); font-weight: 700; line-height: 1.1; }
.vhead p { color: var(--muted); margin-top: 6px; }
.mbrand { display: none; font-family: var(--f-display); font-weight: 700; font-size: 1.2rem; }
.dietline { font-size: 0.9375rem; color: var(--muted); }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .mbrand { display: block; }
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 20;
    border-radius: 0; border-width: 1px 0 0; padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }
  .brand, .me { display: none; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 0.75rem; text-align: center; }
  .main { padding-bottom: 84px; }
}

/* New recipe */
.workbench { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1040px) { .workbench { grid-template-columns: minmax(0, 1fr); } }
.tray, .stage, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; min-width: 0; }
.tray { display: grid; gap: 20px; }
.panel { display: grid; gap: 18px; }
.panel h2 { font-size: 1.25rem; }
.addrow { display: flex; gap: 8px; }
.addrow input { flex: 1; min-width: 0; }
.chips, .pills { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; background: var(--have-bg); border-radius: 999px; font-size: 0.9375rem; max-width: 100%; }
.chip span { overflow-wrap: anywhere; }
.chip button { font: inherit; width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; line-height: 1; }
.chip button:hover { color: var(--ink); background: var(--sunken); }
.pill { font: inherit; font-size: 0.9375rem; min-height: 36px; padding: 4px 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
.pill:hover { border-color: var(--accent); }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.quick { display: grid; gap: 8px; }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; width: max-content; background: var(--bg); }
.stepper button { font: inherit; font-size: 1.25rem; width: 44px; height: 42px; border: 0; background: transparent; color: var(--ink); cursor: pointer; }
.stepper button:hover:not(:disabled) { color: var(--accent); }
.stepper button:disabled { opacity: 0.4; cursor: not-allowed; }
.stepper output { min-width: 40px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 8px; }
.checks .check { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .primary { flex: 1 1 180px; }

.stage-empty { display: grid; gap: 14px; max-width: 46ch; }
.stage-empty h2 { font-size: 1.6rem; font-weight: 700; }
.how { margin: 0; padding-left: 1.25rem; color: var(--muted); display: grid; gap: 6px; }
.skel { display: grid; gap: 12px; margin: 18px 0 20px; }
.skel i { display: block; height: 14px; border-radius: 6px; background: var(--sunken); }
.skel i:nth-child(1) { height: 30px; width: 60%; }
.skel i:nth-child(3) { width: 85%; }
.skel i:nth-child(5) { width: 70%; }
@media (prefers-reduced-motion: no-preference) {
  .skel i { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.45; } }
}

/* Recipe card */
.recipe { display: grid; gap: 22px; min-width: 0; }
.recipe h2 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 700; line-height: 1.1; }
.blurb { color: var(--muted); margin-top: 6px; max-width: 60ch; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding: 0; list-style: none; }
.meta li { padding: 3px 12px; border-radius: 999px; background: var(--sunken); font-size: 0.875rem; font-weight: 500; }
.recipe h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 10px; }
.ings { list-style: none; margin: 0; padding: 0; display: grid; }
.ings li { display: grid; grid-template-columns: minmax(70px, 110px) minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ings .amt { color: var(--muted); font-variant-numeric: tabular-nums; }
.ings .nm { overflow-wrap: anywhere; }
.tag { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--need-bg); color: var(--need); white-space: nowrap; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; }
.steps li::before { content: counter(s); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 0.9375rem; }
.steps li span { padding-top: 3px; overflow-wrap: anywhere; }
.callout { padding: 12px 14px; border-radius: 10px; background: var(--sunken); font-size: 0.9375rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.act-status { font-size: 0.875rem; color: var(--muted); }
.swap { display: grid; gap: 8px; padding-top: 18px; border-top: 1px solid var(--line); }
.swap .addrow { flex-wrap: wrap; }
.swap .addrow input { flex: 1 1 220px; }
.err { display: grid; gap: 14px; max-width: 52ch; }
.err h2 { font-size: 1.4rem; }

/* Lists */
.filter { max-width: 420px; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.row { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; }
@media (max-width: 560px) { .row { grid-template-columns: minmax(0, 1fr); } }
.row h3 { font-size: 1.1rem; overflow-wrap: anywhere; }
.row p { font-size: 0.875rem; color: var(--muted); overflow-wrap: anywhere; }
.empty { padding: 28px 8px; display: grid; gap: 12px; justify-items: start; color: var(--muted); max-width: 46ch; }
.back { justify-self: start; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 30; max-width: min(92vw, 460px); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 10px; font-size: 0.9375rem; }
@media (max-width: 760px) { .toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); } }
.foot { font-size: 0.875rem; color: var(--muted); max-width: 70ch; }
.gate form { display: grid; gap: 14px; }
.gate p { overflow-wrap: anywhere; }
.gate .callout[role="alert"] { background: var(--need-bg); color: var(--need); }

[hidden] { display: none !important; }

.units { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.units .btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px 16px; text-align: left; height: auto; }
.units .btn .hint { margin: 0; color: inherit; opacity: .8; }
@media (max-width: 420px) { .units { grid-template-columns: 1fr; } }
