:root {
  --paper: #f6f1e7; --card: #fffdf8; --ink: #1f2a24; --muted: #5d6660; --line: #e2d9c8;
  --leaf: #3d6b4f; --leaf-dk: #2f5640; --leaf-wash: #e5eee6; --amber: #c4785a; --amber-dk: #a35c3f;
  --late: #a8492a; --frost: #eef4f1; --glass: #c9dbd1;
  --radius: 14px; --shadow: 0 1px 0 rgba(31,42,36,.04), 0 6px 18px rgba(31,42,36,.07);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--leaf); }
[hidden] { display: none !important; }
.opt { font-weight: 400; color: var(--muted); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 920px; margin: 0 auto; padding: 18px 18px 6px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; font-family: Georgia, "Iowan Old Style", serif; }
.sub { margin: 0; color: var(--muted); font-size: .92rem; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

main { max-width: 920px; margin: 0 auto; padding: 6px 18px 32px; }
.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0 12px; padding: 10px 14px; border-radius: 12px; background: var(--leaf-wash); color: var(--leaf-dk); font-size: .93rem; }
.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--leaf-dk); text-decoration: underline; font-weight: 600; cursor: pointer; }

.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 18px; margin-bottom: 16px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-head h2 { margin: 0; font-size: 1.1rem; font-family: Georgia, "Iowan Old Style", serif; }
.step-no { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--leaf); color: #fff; font-weight: 700; font-size: .9rem; flex: none; }
.step-aside { margin-left: auto; color: var(--muted); font-size: .86rem; text-align: right; }
.hint { color: var(--muted); font-size: .9rem; margin: 2px 0 4px; min-height: 1.3em; }
.hint strong { color: var(--ink); }
.empty { color: var(--muted); font-style: italic; margin: 8px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 9px 14px; min-height: 42px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(61,107,79,.35); outline-offset: 2px; }
.primary { background: var(--leaf); color: #fff; font-weight: 600; }
.primary:hover { background: var(--leaf-dk); }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover { background: #f1eadc; }
.sm { min-height: 34px; min-width: 34px; padding: 4px 9px; font-weight: 700; }
.danger { color: var(--late); }
.amber-btn { background: var(--amber); color: #fff; font-weight: 600; }
.amber-btn:hover { background: var(--amber-dk); }

.field { margin: 0 0 12px; min-width: 0; }
.field label, .chips-label, .mode legend { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
input[type="text"], input[type="date"], input[type="number"], select {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fffefb; min-height: 40px; width: 100%; min-width: 0;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.mode { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.mode legend { width: 100%; padding: 0; }
.seg { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fffefb; cursor: pointer; font-size: .92rem; }
.seg input { accent-color: var(--leaf); margin: 0; }
.seg:has(input:checked) { border-color: var(--leaf); background: var(--leaf-wash); color: var(--leaf-dk); font-weight: 600; }

.when { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; align-items: end; }
#add-form[data-mode="date"] .when-opened, #add-form[data-mode="opened"] .when-date { display: none; }
#edit-form[data-mode="date"] .e-opened, #edit-form[data-mode="opened"] .e-date { display: none; }
.chips-field { grid-column: span 2; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 40px; align-items: center; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 99px; min-height: 34px; padding: 3px 12px; font-size: .86rem; }
.chip:hover { border-color: var(--leaf); color: var(--leaf); }
.chip.on { background: var(--leaf); border-color: var(--leaf); color: #fff; }

.msg { margin: 8px 0 0; font-size: .92rem; color: var(--muted); }
.msg.err { color: var(--late); }

/* Hero: a fridge shelf with tubs, cartons and jars standing on it */
.hero {
  background: linear-gradient(150deg, #fffdf8 0%, #e9f1ec 55%, #f8ebe3 100%);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px 18px; margin-bottom: 16px;
}
.hero-kicker { margin: 0 0 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted); }
.hero-title { margin: 0 0 6px; font-family: Georgia, "Iowan Old Style", serif; font-size: 1.55rem; line-height: 1.25; }
.hero-title .emph { color: var(--leaf); }
.hero-title .warn { color: var(--late); }
.hero-title .amber { color: var(--amber-dk); }
.hero-sub { margin: 12px 0 0; color: var(--muted); font-size: .92rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.hero.empty-hero { background: var(--card); }
.hero.empty-hero .hero-title { color: var(--muted); font-size: 1.25rem; font-weight: 400; }

.fridge {
  position: relative; display: flex; align-items: flex-end; gap: 16px; flex-wrap: nowrap; overflow-x: auto;
  padding: 26px 16px 0; margin-top: 12px; min-height: 40px;
  background: linear-gradient(180deg, rgba(238,244,241,.0) 0%, rgba(238,244,241,.9) 40%, var(--frost) 100%);
  border: 1px solid #d7e4dc; border-bottom: 10px solid var(--glass); border-radius: 14px 14px 4px 4px;
  box-shadow: 0 8px 0 -4px rgba(40,70,55,.16), inset 0 -2px 0 rgba(255,255,255,.8);
  scrollbar-width: thin;
}
.fridge:empty { display: none; }
.food { flex: none; display: grid; justify-items: center; gap: 6px; width: 104px; }
.food .thing { position: relative; display: grid; place-items: end center; height: 82px; }
.tag {
  position: absolute; top: -12px; right: -10px; z-index: 1; padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 800;
  color: #fff; background: var(--leaf); white-space: nowrap; box-shadow: 0 2px 4px rgba(0,0,0,.12);
}
.food.overdue .tag { background: var(--late); }
.food.today .tag { background: var(--amber); }
.food-name { font-size: .8rem; font-weight: 700; text-align: center; line-height: 1.2; color: var(--leaf-dk); margin-bottom: 8px; max-width: 104px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* shapes */
.shape { position: relative; }
.shape.leftover { width: 84px; height: 44px; background: rgba(255,255,255,.75); border: 2px solid #b7cbbf; border-top: 0; border-radius: 0 0 10px 10px; }
.shape.leftover::before { content: ""; position: absolute; left: -5px; right: -5px; top: -10px; height: 11px; border-radius: 6px; background: #5f8f74; }
.shape.leftover::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 6px; height: 20px; border-radius: 4px 4px 6px 6px; background: #d79a62; opacity: .85; }
.shape.dairy { width: 46px; height: 70px; background: #fbfaf5; border: 2px solid #cfd8d2; border-radius: 3px; }
.shape.dairy::before { content: ""; position: absolute; left: -2px; right: -2px; top: -16px; height: 16px; background: linear-gradient(135deg, transparent 49%, #e6ece8 50%) left / 50% 100% no-repeat, linear-gradient(225deg, transparent 49%, #dce5df 50%) right / 50% 100% no-repeat; }
.shape.dairy::after { content: ""; position: absolute; left: 6px; right: 6px; top: 18px; height: 22px; border-radius: 3px; background: #8fb3c9; }
.shape.produce { width: 62px; height: 56px; border-radius: 50% 50% 46% 46%; background: radial-gradient(circle at 35% 35%, #9ccc7c, #5d9a52 70%); }
.shape.produce::before { content: ""; position: absolute; left: 50%; top: -9px; width: 14px; height: 10px; border-radius: 10px 0; background: #3d6b4f; transform: translateX(-10%) rotate(-20deg); }
.shape.opened { width: 50px; height: 58px; border-radius: 8px 8px 10px 10px; background: linear-gradient(180deg, rgba(255,255,255,.6), rgba(255,255,255,.2)), #a8b764; border: 2px solid rgba(60,80,40,.25); }
.shape.opened::before { content: ""; position: absolute; left: 2px; right: 2px; top: -12px; height: 12px; border-radius: 4px; background: var(--amber); }
.shape.opened::after { content: ""; position: absolute; left: 7px; right: 7px; top: 18px; height: 16px; border-radius: 2px; background: #fffdf8; }
.shape.other { width: 60px; height: 46px; border-radius: 4px; background: #d9c4a5; border: 1px solid #bba383; }
.shape.other::after { content: ""; position: absolute; left: 8px; right: 8px; top: 10px; height: 10px; border-radius: 2px; background: #fffdf8; }
.food.overdue .shape { filter: saturate(.55) brightness(.97); transform: rotate(-3deg); transform-origin: bottom left; }
.food.today .thing::before { content: ""; position: absolute; inset: auto -6px -2px -6px; height: 10px; border-radius: 50%; background: radial-gradient(ellipse, rgba(196,120,90,.35), transparent 70%); }

/* Groups and cards */
#fridge-groups { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); align-items: start; }
.group { min-width: 0; }
.group-h { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--muted); }
.group-h .pip { width: 9px; height: 9px; border-radius: 50%; background: var(--leaf); }
.group.overdue .group-h { color: var(--late); }
.group.overdue .pip { background: var(--late); }
.group.today .group-h { color: var(--amber-dk); }
.group.today .pip { background: var(--amber); }
.group.soon .pip { background: #7fa98d; }
.group.later .pip, .group.unknown .pip { background: #b9c7be; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: 1fr; }
.card { border: 1px solid var(--line); border-radius: 12px; background: #fffefb; padding: 12px 14px; display: grid; gap: 8px; align-content: start; }
.card.is-overdue { border-color: #e6bfae; box-shadow: inset 3px 0 0 var(--late); }
.card.is-today { border-color: #ecc9b6; box-shadow: inset 3px 0 0 var(--amber); background: #fffaf5; }
.card.is-soon { box-shadow: inset 3px 0 0 #7fa98d; }
.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card-title { margin: 0; font-size: 1.05rem; font-weight: 700; font-family: Georgia, "Iowan Old Style", serif; flex: 1 1 auto; overflow-wrap: anywhere; }
.card-meta { color: var(--muted); font-size: .88rem; margin: 0; }
.card-notes { font-size: .88rem; margin: 0; padding: 6px 10px; background: #f6f1e7; border-radius: 8px; color: #3a4540; overflow-wrap: anywhere; }
.cat { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--leaf-dk); background: var(--leaf-wash); border-radius: 6px; padding: 1px 6px; margin-right: 6px; vertical-align: 1px; }
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: var(--leaf-wash); color: var(--leaf-dk); white-space: nowrap; }
.badge.overdue { background: #f6e3da; color: var(--late); }
.badge.today { background: #f9e7dc; color: var(--amber-dk); }
.badge.later, .badge.unknown { background: #eef0ec; color: var(--muted); }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.card-actions { gap: 5px; }
.card-actions button { min-height: 34px; padding: 5px 9px; font-size: .85rem; }
.card-actions [data-act="delete"] { margin-left: auto; border-color: transparent; padding: 5px 6px; }

.tally { margin: 0 0 10px; font-size: .93rem; }
.tally .bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: #eee6d7; margin-top: 6px; max-width: 360px; }
.tally .bar .e { background: var(--leaf); }
.tally .bar .t { background: var(--late); opacity: .75; }
.done { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.done li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; background: #fbf8f1; }
.done .d-name { font-weight: 600; text-decoration: line-through; text-decoration-color: rgba(61,107,79,.5); color: #4a5450; }
.done li.tossed .d-name { text-decoration-color: rgba(168,73,42,.5); }
.done .d-how { font-size: .74rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 6px; background: var(--leaf-wash); color: var(--leaf-dk); }
.done li.tossed .d-how { background: #f6e3da; color: var(--late); }
.done .d-meta { color: var(--muted); font-size: .85rem; }
.done .d-actions { margin-left: auto; display: flex; gap: 6px; }
.done button { min-height: 32px; padding: 4px 10px; font-size: .85rem; }

dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(31,42,36,.35); }
.dlg { padding: 16px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; font-size: 1.15rem; font-family: Georgia, "Iowan Old Style", serif; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 10; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; }
.toast button { min-height: 30px; padding: 2px 10px; background: transparent; color: #cfe3d5; border: 1px solid rgba(255,255,255,.3); }
.foot { color: var(--muted); font-size: .84rem; text-align: center; margin-top: 8px; }

.check-list { display: grid; gap: 6px; margin: 8px 0; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--leaf); }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .chips-field { grid-column: auto; }
  .brand h1 { font-size: 1.3rem; }
  .hero-title { font-size: 1.35rem; }
  .food { width: 88px; }
  .cards { grid-template-columns: 1fr; }
}
