:root {
  --bg: #F7F3EC;
  --surface: #FFFDF9;
  --surface-2: #F0EAE0;
  --ink: #1F2A24;
  --ink-2: #56615A;
  --ink-3: #8A928C;
  --line: #E3DBCF;
  --brand: #2F5D50;
  --brand-ink: #FFFFFF;
  --brand-soft: #DCE8E2;
  --accent: #D9532B;
  --accent-soft: #F9E1D7;
  --good: #3C8D5A;
  --good-soft: #DDEFE2;
  --warn: #B7791F;
  --warn-soft: #F8ECD4;
  --bad: #C0392B;
  --shadow: 0 1px 2px rgba(31, 42, 36, .06), 0 6px 20px rgba(31, 42, 36, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816; --surface: #1C211F; --surface-2: #252B28; --ink: #EEF1EE; --ink-2: #B4BDB7; --ink-3: #7E8882;
    --line: #2F3633; --brand: #7FB8A4; --brand-ink: #0F1A16; --brand-soft: #22332D; --accent: #F0845F; --accent-soft: #3A261F;
    --good: #6FC28B; --good-soft: #1E3326; --warn: #E3B563; --warn-soft: #36301F; --bad: #F07A6B;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141816; --surface: #1C211F; --surface-2: #252B28; --ink: #EEF1EE; --ink-2: #B4BDB7; --ink-3: #7E8882;
  --line: #2F3633; --brand: #7FB8A4; --brand-ink: #0F1A16; --brand-soft: #22332D; --accent: #F0845F; --accent-soft: #3A261F;
  --good: #6FC28B; --good-soft: #1E3326; --warn: #E3B563; --warn-soft: #36301F; --bad: #F07A6B;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.15; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 13px; }
.hidden { display: none !important; }

/* Layout */
.app { min-height: 100dvh; }
.main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.view-head .sub { color: var(--ink-2); font-size: 14px; margin-top: 4px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); z-index: 30;
}
.nav button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .02em; position: relative;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.active { color: var(--brand); }
.nav .badge { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--accent); color: #fff; font-size: 10px; border-radius: 99px; padding: 1px 6px; }
.brand-mark { display: none; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; }
  .nav { position: sticky; top: 0; height: 100dvh; grid-template-columns: 1fr; grid-auto-rows: min-content; border-top: 0; border-right: 1px solid var(--line); padding: 20px 12px; gap: 4px; align-content: start; }
  .nav button { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 10px 14px; border-radius: 12px; font-weight: 500; }
  .nav button.active { background: var(--brand-soft); }
  .nav .badge { position: static; margin-left: auto; }
  .brand-mark { display: flex; align-items: center; gap: 10px; padding: 4px 14px 20px; font-family: var(--display); font-size: 22px; font-weight: 600; }
  .main { padding: 28px 32px 48px; max-width: 980px; }
}

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.section { margin-top: 20px; }
.section-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: 15px; min-height: 44px; transition: transform .06s ease, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { border: 0; background: var(--surface-2); width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; }
.icon-btn svg { width: 18px; height: 18px; }

.field { display: block; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 12px; min-height: 44px; outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { min-height: 80px; resize: vertical; }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 12px; font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.soft { background: var(--surface-2); border-color: transparent; }
.chip .x { border: 0; background: none; padding: 0 0 0 2px; color: inherit; opacity: .6; font-size: 16px; line-height: 1; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }

.range { width: 100%; accent-color: var(--brand); }
.range-val { font-family: var(--display); font-size: 20px; font-weight: 600; }

details.more { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 10px; }
details.more summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-2); list-style: none; display: flex; align-items: center; gap: 6px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: '+'; font-size: 18px; width: 16px; }
details.more[open] summary::before { content: '–'; }

/* Recipe cards */
.results-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 16px 0 10px; font-size: 13px; color: var(--ink-2); }
.rgrid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 620px) { .rgrid { grid-template-columns: 1fr 1fr; } }
.rcard { display: grid; grid-template-columns: 108px 1fr; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: var(--shadow); text-align: left; padding: 0; width: 100%; }
.rcard .thumb { width: 108px; height: 100%; min-height: 118px; background: var(--surface-2) center/cover no-repeat; }
.rcard .body { padding: 12px 12px 12px 0; min-width: 0; }
.rcard h3 { font-size: 16px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rcard .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rcard .src { font-size: 12px; color: var(--ink-3); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 99px; }

/* Week builder */
.wday { display: grid; grid-template-columns: 58px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.wday:last-child { border-bottom: 0; }
.wday .d { text-align: center; }
.wday .d b { display: block; font-family: var(--display); font-size: 22px; line-height: 1; }
.wday .d small { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.wday .d.today b { color: var(--accent); }
.slot-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.pick { display: flex; gap: 10px; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 8px; }
.pick + .pick { margin-top: 8px; }
.pick .pthumb { width: 52px; height: 52px; border-radius: 10px; background: var(--line) center/cover no-repeat; flex: none; }
.pick .pbody { flex: 1; min-width: 0; }
.pick .ptitle { font-weight: 600; font-size: 15px; line-height: 1.25; cursor: pointer; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pick .pmeta { font-size: 12px; color: var(--ink-2); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pick.locked { background: var(--brand-soft); outline: 2px solid var(--brand); }
.pick .acts { display: flex; gap: 4px; align-items: center; flex: none; }
.vote { border: 0; background: var(--surface); border-radius: 99px; height: 32px; min-width: 32px; padding: 0 8px; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.vote svg { width: 16px; height: 16px; }
.vote.up.on { background: var(--good); color: #fff; }
.vote.down.on { background: var(--bad); color: #fff; }
.dots { display: inline-flex; }
.dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--surface-2); margin-left: -5px; font-size: 9px; font-weight: 800; color: #fff; display: inline-grid; place-items: center; }
.dot:first-child { margin-left: 0; }
.dot.neg { opacity: .45; text-decoration: line-through; }
.add-slot { border: 1px dashed var(--line); background: none; border-radius: 12px; padding: 8px 10px; width: 100%; text-align: left; color: var(--ink-3); font-size: 14px; font-weight: 600; margin-top: 8px; }
.adder { margin-top: 8px; background: var(--surface-2); border-radius: 12px; padding: 10px; }
.adder .opts { max-height: 240px; overflow: auto; margin-top: 8px; }
.adder .opt { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; }
.adder .opt:hover { background: var(--surface); }
.adder .opt i { width: 36px; height: 36px; border-radius: 8px; background: var(--line) center/cover; flex: none; }

/* Recipe page */
.page { position: fixed; inset: 0; background: var(--bg); z-index: 50; overflow-y: auto; -webkit-overflow-scrolling: touch; animation: slideUp .22s ease; }
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.page-bar { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.page-inner { max-width: 760px; margin: 0 auto; padding: 0 16px calc(40px + env(safe-area-inset-bottom)); }
.hero { width: 100%; aspect-ratio: 16/10; border-radius: var(--radius); background: var(--surface-2) center/cover no-repeat; margin-bottom: 16px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.fact b { display: block; font-family: var(--display); font-size: 20px; }
.fact small { font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-weight: 700; }
.ing { list-style: none; padding: 0; margin: 0; }
.ing li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ing li:last-child { border-bottom: 0; }
.ing .box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); flex: none; margin-top: 1px; display: grid; place-items: center; }
.ing li.done .box { background: var(--brand); border-color: var(--brand); }
.ing li.done .box::after { content: ''; width: 10px; height: 6px; border: 2px solid var(--brand-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.ing li.done .txt { color: var(--ink-3); text-decoration: line-through; }
.ing .txt { flex: 1; }
.ing .q { font-weight: 700; }
.ing .note { color: var(--ink-3); }
.steps { list-style: none; padding: 0; margin: 0; counter-reset: s; }
.steps .sec { font-family: var(--display); font-size: 17px; margin: 18px 0 6px; }
.steps li.step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.steps li.step .n { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 800; display: grid; place-items: center; font-size: 14px; }
.timer-btn { margin-top: 8px; }
.tips { background: var(--warn-soft); border-radius: 12px; padding: 12px 14px; margin-top: 16px; }
.tips li { margin: 4px 0; }

/* Cook mode */
.cook { position: fixed; inset: 0; z-index: 60; background: var(--surface); display: grid; grid-template-rows: auto 1fr auto; }
.cook-top { display: flex; justify-content: space-between; align-items: center; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
.cook-body { padding: 16px 24px; display: flex; flex-direction: column; justify-content: center; overflow-y: auto; max-width: 820px; margin: 0 auto; width: 100%; }
.cook-body .sec { color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 13px; }
.cook-body .big { font-family: var(--display); font-size: clamp(24px, 5.2vw, 38px); line-height: 1.3; font-weight: 500; margin-top: 10px; }
.cook-body .ings { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.cook-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.progress { height: 4px; background: var(--surface-2); }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.timers { position: fixed; right: 12px; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.timer { background: var(--ink); color: var(--bg); border-radius: 99px; padding: 8px 14px; font-weight: 700; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.timer.done { background: var(--accent); animation: pulse 1s infinite; }
.timer button { border: 0; background: none; color: inherit; font-weight: 800; }
@keyframes pulse { 50% { transform: scale(1.05); } }

/* Grocery */
.aisle { margin-top: 16px; }
.aisle h3 { font-size: 13px; font-family: var(--body); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; }
.gitem { display: flex; gap: 12px; align-items: center; padding: 11px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; cursor: pointer; }
.gitem .box { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.gitem.done { opacity: .55; }
.gitem.done .box { background: var(--good); border-color: var(--good); }
.gitem.done .box::after { content: ''; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.gitem.done .gname { text-decoration: line-through; }
.gitem .gname { font-weight: 600; }
.gitem .gsub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gitem .gmain { flex: 1; min-width: 0; }
.gitem .qty { font-weight: 700; color: var(--ink-2); font-size: 14px; white-space: nowrap; }

/* Pantry */
.pantry-chips .chip { background: var(--surface); }

/* Misc */
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty .art { font-size: 40px; margin-bottom: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 8px); } }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 28px; color: var(--ink-2); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); height: 118px; }
@keyframes sk { to { background-position: -200% 0; } }
.welcome { max-width: 440px; margin: 0 auto; padding: 48px 20px; }
.welcome .logo { font-family: var(--display); font-size: 40px; font-weight: 600; letter-spacing: -0.02em; }
.welcome .logo span { color: var(--accent); }
.code-box { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 26px; font-weight: 800; letter-spacing: .18em; background: var(--surface-2); border-radius: 12px; padding: 10px 14px; text-align: center; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px; flex: none; }
.warnbox { background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 0; }

@media (max-width: 599px) {
  #planDays .pick { flex-wrap: wrap; }
  #planDays .pick .pbody { flex: 1 1 calc(100% - 64px); }
  #planDays .pick .acts { width: 100%; justify-content: flex-end; padding-left: 62px; gap: 6px; }
  .wday { grid-template-columns: 44px 1fr; gap: 10px; }
  .card#planDays { padding: 12px; }
}
