:root {
  color-scheme: light;
  --canvas: #f6f7f5;
  --card: #fff;
  --ink: #1b1f1d;
  --muted: #5d6661;
  --line: #e3e6e2;
  --tomato: #c13a1f;
  --tomato-ink: #8f2a15;
  --tomato-tint: #fdece7;
  --herb: #2e7d4f;
  --herb-tint: #e7f3ec;
  --r: 14px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --shadow: 0 1px 2px rgba(27, 31, 29, .06), 0 6px 20px rgba(27, 31, 29, .06);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; padding-bottom: 96px; }
h1, h2 { margin: 0; letter-spacing: -.02em; line-height: 1.15; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
a { color: var(--tomato-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--tomato); outline-offset: 2px; }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px 16px; max-width: 1240px; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; min-height: 36px; gap: 8px; font-weight: 750; font-size: 1.15rem; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.mark { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle, #fff 0 36%, var(--tomato) 37%); }
.tagline { margin: 0 auto 0 0; color: var(--muted); font-size: .9rem; display: none; }
.pill { background: var(--herb-tint); color: var(--herb); font-weight: 700; font-size: .8rem; padding: 4px 10px; border-radius: 99px; }

/* jump nav */
.jump { position: sticky; top: 0; z-index: 20; display: flex; gap: 4px; padding: 8px 12px; background: rgba(246, 247, 245, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); overflow-x: auto; }
.jump a { flex: 1 1 0; text-align: center; padding: 8px 10px; border-radius: 10px; font-weight: 600; font-size: .92rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.jump a:hover { background: #eceeea; }
.count { display: inline-block; min-width: 1.4em; padding: 0 6px; margin-left: 2px; border-radius: 99px; background: var(--tomato); color: #fff; font-size: .75rem; line-height: 1.5; }
.count:empty { display: none; }

/* layout */
main { max-width: 1240px; margin: 0 auto; padding: 8px 12px 24px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
main > section { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 14px; box-shadow: var(--shadow); min-width: 0; }
.sec-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent; font-weight: 650; font-size: .95rem; white-space: nowrap; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: .88rem; }
.btn.icon { width: 44px; padding: 0; font-size: 1.4rem; line-height: 1; }
.btn.primary { background: var(--tomato); color: #fff; }
.btn.primary:hover { background: #c23c22; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: #c9cec8; background: #fafbfa; }
.btn.danger { color: #b3261e; }
.left { font-weight: 500; font-size: .78rem; color: var(--muted); }
.left:empty { display: none; }
.btn.primary .left { color: #ffe3dc; }

/* week nav */
.weeknav { display: flex; gap: 6px; }

/* plan grid, mobile: one card per day */
.grid { display: grid; gap: 10px; }
.day { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.day.today { border-color: var(--tomato); box-shadow: inset 3px 0 0 var(--tomato); }
.day-name { font-weight: 700; font-size: .95rem; margin: 0 0 6px; display: flex; gap: 8px; align-items: baseline; }
.day-name small { color: var(--muted); font-weight: 500; }
.slot { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px; align-items: start; padding: 6px 0; border-top: 1px dashed var(--line); }
.slot:first-of-type { border-top: 0; }
.slot-name { font-size: .8rem; color: var(--muted); font-weight: 600; padding-top: 9px; }
.cell { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.chip { max-width: 100%; min-height: 36px; padding: 6px 10px; border-radius: 10px; border: 0; background: var(--tomato-tint); color: var(--tomato-ink); font-weight: 600; font-size: .86rem; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { background: #fadbd1; }
.chip .srv { font-weight: 500; opacity: .75; margin-left: 4px; }
.add { min-height: 36px; padding: 6px 10px; border-radius: 10px; border: 1px dashed #c9cec8; background: transparent; color: var(--muted); font-size: .86rem; cursor: pointer; white-space: nowrap; }
.add:hover { border-color: var(--tomato); color: var(--tomato-ink); }
.slot-head { display: none; }
.plan-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* receipt */
.receipt { position: relative; background: #fffef9; font-family: var(--mono); font-size: .88rem; padding: 18px 16px 24px; margin: 4px 0 18px; border: 1px solid #ecebe3; border-bottom: 0; }
.receipt::after { content: ""; position: absolute; left: -1px; right: -1px; bottom: -8px; height: 8px; background: linear-gradient(-45deg, transparent 6px, #fffef9 0) 0 0 / 12px 8px repeat-x, linear-gradient(45deg, transparent 6px, #fffef9 0) 0 0 / 12px 8px repeat-x; }
.r-title { text-align: center; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin: 0; }
.r-meta { text-align: center; color: var(--muted); font-size: .8rem; margin: 2px 0 10px; }
.r-rule { border: 0; border-top: 1px dashed #c9c7bb; margin: 10px 0; }
.r-aisle { font-weight: 700; font-size: .78rem; letter-spacing: .1em; color: var(--muted); margin: 14px 0 4px; }
.r-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 6px; align-items: center; min-height: 40px; cursor: pointer; border-radius: 6px; }
.r-row:hover { background: #f6f5ec; }
.r-row input { width: 20px; height: 20px; margin: 0; accent-color: var(--herb); cursor: pointer; }
.r-item { overflow-wrap: anywhere; }
.r-item small { display: block; color: var(--muted); font-size: .72rem; }
.r-amt { font-weight: 700; text-align: right; white-space: nowrap; }
.r-row.done .r-item, .r-row.done .r-amt { text-decoration: line-through; color: #9aa19c; }
.r-row.have { opacity: .6; cursor: default; }
.r-total { display: flex; justify-content: space-between; font-weight: 700; }
.r-empty { text-align: center; color: var(--muted); padding: 18px 0; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pantry { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.pantry summary { cursor: pointer; font-weight: 650; min-height: 32px; }
.pantry label { display: block; color: var(--muted); font-size: .86rem; margin: 6px 0; }
textarea, input:not([type=checkbox]), select { width: 100%; border: 1px solid #cfd4ce; border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 16px; }
textarea { resize: vertical; }

/* library */
.lib { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.meal { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.meal h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.meal p { margin: 0; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.meal .row { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; }
.lib-empty { color: var(--muted); margin: 0; }
.backup { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }

/* footer + toast */
.faq { max-width: 1240px; margin: 8px auto 0; padding: 0 16px; }
.faq h2 { font-size: 1.15rem; margin: 0 0 8px; }
.faq details { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.faq summary { font-weight: 600; cursor: pointer; min-height: 24px; }
.faq p { margin: 8px 0 0; color: var(--muted); font-size: .9rem; }
.legal a { display: inline-block; min-height: 24px; line-height: 24px; }
.site { max-width: 1240px; margin: 0 auto; padding: 8px 16px 24px; color: var(--muted); font-size: .84rem; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); margin: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 60; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* editor */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 20px)); max-height: calc(100% - 20px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink); }
dialog::backdrop { background: rgba(27, 31, 29, .45); }
#ed-form { display: grid; gap: 12px; padding: 16px; }
#ed-form > label, .two label { display: grid; gap: 4px; font-size: .86rem; font-weight: 600; color: var(--muted); }
.ed-head { display: flex; justify-content: space-between; align-items: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview { list-style: none; margin: 0; padding: 8px 10px; background: var(--canvas); border-radius: 10px; font-family: var(--mono); font-size: .8rem; display: grid; gap: 2px; max-height: 140px; overflow: auto; }
.preview:empty { display: none; }
.preview b { color: var(--herb); }
.check { display: flex !important; align-items: center; gap: 8px; color: var(--ink) !important; }
.check input { width: 20px; height: 20px; accent-color: var(--herb); }
.ed-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

@media (min-width: 560px) {
  .tagline { display: block; }
  main { padding: 12px 20px 32px; }
  main > section { padding: 22px 22px; }
  .jump { justify-content: center; }
  .jump a { flex: 0 0 auto; padding: 8px 18px; }
}
@media (min-width: 720px) {
  .grid { gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
  .slot-head, .day { display: grid; grid-template-columns: 96px repeat(3, minmax(0, 1fr)); }
  .slot-head { background: #f1f3f0; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
  .slot-head span { padding: 8px 10px; }
  .day { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 0; }
  .day.today { box-shadow: inset 3px 0 0 var(--tomato); }
  .day-name { flex-direction: column; gap: 0; margin: 0; padding: 10px; }
  .slot { display: block; padding: 8px; border-top: 0; border-left: 1px solid var(--line); }
  .slot-name { display: none; }
  .cell { flex-direction: column; align-items: stretch; }
  .chip, .add { width: 100%; }
}
@media (min-width: 1000px) {
  main { grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: auto 1fr; align-items: start; }
  #plan { grid-column: 1; grid-row: 1; }
  #library { grid-column: 1; grid-row: 2; }
  #list { grid-column: 2; grid-row: 1 / span 2; }
}

@media print {
  body { background: #fff; padding: 0; }
  .top, .jump, .btn, .add, .plan-foot, .weeknav, #library, .actions, .pantry, .site, .toast, #tp-bar, [class^="tp-"], dialog { display: none !important; }
  main { display: block; padding: 0; }
  main > section { box-shadow: none; border: 0; padding: 0 0 16px; break-inside: avoid; }
  .chip { background: none; padding: 0; white-space: normal; min-height: 0; }
  .receipt { border: 0; background: #fff; }
  .receipt::after { display: none; }
  .r-row input { appearance: none; border: 1px solid #000; }
}
