:root {
  --bg: #fafaf9;
  --panel: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --faint: #a8a29e;
  --line: #e7e5e4;
  --accent: #a51c30;
  --accent-soft: rgba(165, 28, 48, 0.08);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131211;
    --panel: #1c1a19;
    --ink: #ece9e6;
    --muted: #9c948e;
    --faint: #6b645f;
    --line: #2b2826;
    --accent: #e0546a;
    --accent-soft: rgba(224, 84, 106, 0.14);
  }
}
:root[data-theme="dark"] {
  --bg: #131211; --panel: #1c1a19; --ink: #ece9e6; --muted: #9c948e; --faint: #6b645f;
  --line: #2b2826; --accent: #e0546a; --accent-soft: rgba(224, 84, 106, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* iOS: don't inflate text in landscape, no grey flash on tap */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
a, button, label, summary { -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* the safe-area insets keep content clear of the notch and home bar */
  padding: 0 max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  max-width: 1500px;
  margin: 0 auto;
}
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* header */
.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 6px 24px;
  padding: 28px 0 18px;
}
.brand h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand .sub { margin: 2px 0 0; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.weeknav { display: flex; align-items: center; gap: 4px; }
.range { min-width: 120px; text-align: center; font-weight: 500; font-variant-numeric: tabular-nums; }
.icon {
  width: 30px; height: 30px; border-radius: 8px;
  font-size: 20px; line-height: 1; color: var(--muted);
}
.icon:hover:not(:disabled) { background: var(--line); color: var(--ink); }
.icon:disabled { opacity: 0.3; cursor: default; }
.chips { display: flex; gap: 6px; }
.chip {
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip:hover:not(.on) { color: var(--ink); }
.search {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; width: 120px; outline: none;
  transition: width 0.15s;
}
.search:focus, .search:not(:placeholder-shown) { width: 180px; border-color: var(--muted); }
.search::-webkit-search-cancel-button { -webkit-appearance: none; }
.search { -webkit-appearance: none; appearance: none; } /* Safari's own search-field look */
.toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

/* open/closed status + hours popover */
.status { position: relative; justify-self: center; margin-bottom: 7px; font-size: 12.5px; color: var(--muted); }
.status summary {
  display: inline-flex; align-items: center; gap: 7px;
  list-style: none; cursor: pointer; user-select: none;
  font-variant-numeric: tabular-nums;
}
.status summary::-webkit-details-marker { display: none; }
.status summary:hover { color: var(--ink); }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.status.open .dot { background: #16a34a; box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.16); }
.status.open summary { color: var(--ink); }
.hours {
  position: absolute; z-index: 10; top: calc(100% + 8px); left: 0;
  width: 250px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.hours table { border-collapse: collapse; width: 100%; }
.hours th { text-align: left; font-weight: 500; color: var(--ink); padding: 3px 0; }
.hours td { text-align: right; padding: 3px 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hours small { color: var(--faint); font-size: 11px; }
.hours p { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11.5px; line-height: 1.4; }

/* mobile day tabs */
.daytabs {
  display: none;
  gap: 4px;
  overflow-x: auto;
  padding: 2px 0 12px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.daytabs::-webkit-scrollbar { display: none; }
.daytab {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  display: flex; flex-direction: column; align-items: center; line-height: 1.2;
  scroll-snap-align: start;
}
.daytab b { font-weight: 600; color: var(--ink); font-size: 15px; }
.daytab.on { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.daytab.today b { color: var(--accent); }

.stale {
  margin: 0 0 12px; padding: 8px 12px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent); font-size: 13px;
}

/* grid */
.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}
.loading, .empty { color: var(--muted); grid-column: 1 / -1; padding: 40px 0; text-align: center; }
.day {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  min-width: 0;
}
.day.past { opacity: 0.72; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dayhead {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.dayhead .wd { font-weight: 600; font-size: 15px; }
.dayhead .dt { color: var(--muted); font-variant-numeric: tabular-nums; }
.day.today .wd { color: var(--accent); }
.day { padding-bottom: 12px; }
.pill {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 999px;
}

.grp { padding: 6px 0 2px; }
.grp + .grp { padding-top: 12px; }
.grp h4 {
  margin: 0 0 3px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint);
}
.grp ul { list-style: none; margin: 0; padding: 0; }
.grp li { display: flex; align-items: baseline; gap: 6px; padding: 2px 0; }
.grp li span { min-width: 0; overflow-wrap: anywhere; }
.searching .day { display: block; }
.hint { color: var(--muted); font-size: 13px; margin: 14px 0 0; }
.hint button { color: var(--accent); padding: 0; }
.grp.staples li { color: var(--muted); }
.more {
  display: block; margin: 8px 0 2px; padding: 0;
  font-size: 12px; color: var(--muted);
}
.more:hover { color: var(--accent); }
.none { color: var(--faint); font-style: italic; }
.mealnote {
  margin: 8px 0 0; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
.with { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }
.basics { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }

/* footer */
.foot {
  display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center;
  margin-top: 26px; color: var(--muted); font-size: 12.5px;
}
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--ink); }
.foot .credit { margin-left: auto; color: var(--muted); }
.foot .credit span { text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 3px; }
.foot .credit:hover { color: var(--accent); }
.foot .credit:hover span { text-decoration-color: currentColor; }
.foot .meta { display: contents; }

/* add-to-home-screen button + sheet */
.homebtn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 12.5px; font-weight: 500;
}
.homebtn svg { color: var(--accent); }
.homebtn:hover { border-color: var(--muted); }
.homebtn[hidden] { display: none; }
.homedlg {
  width: min(360px, calc(100vw - 32px)); padding: 20px 20px 16px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}
.homedlg::backdrop { background: rgba(0, 0, 0, 0.35); }
.homedlg h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.homedlg .lede { margin: 4px 0 14px; color: var(--muted); font-size: 13.5px; }
.homedlg section:not([hidden]) + section:not([hidden]) { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.homedlg h3 {
  margin: 0 0 6px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--faint);
}
.homedlg ol { margin: 0; padding-left: 20px; }
.homedlg li { padding: 2px 0; }
.homedlg b { font-weight: 600; }
.homedlg .glyph { display: inline-flex; vertical-align: -2px; color: var(--accent); }
.homedlg .install, .homedlg .done {
  display: block; width: 100%; margin-top: 16px; padding: 9px; border-radius: 10px; font-weight: 500;
}
.homedlg .install { margin: 0 0 14px; background: var(--accent); color: #fff; }
.homedlg .install[hidden] { display: none; }
.homedlg .done { background: var(--line); }
.homedlg .step { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
.homedlg .step[hidden] { display: none; }
.homedlg .note { margin: 12px 0 0; color: var(--muted); font-size: 12.5px; }
.homedlg .linkbtn { padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* responsive */
@media (max-width: 1180px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1080px) {
  /* not enough room between title and controls: status goes back under the title */
  .status { grid-column: 1; grid-row: 2; justify-self: start; margin: 0; }
  .controls { grid-column: 3; grid-row: 1 / span 2; }
}
@media (max-width: 860px) {
  body { font-size: 15px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

  /* header: title + search on one line, then a segmented meal control */
  .top {
    display: grid; grid-template-columns: 1fr auto; align-items: center;
    gap: 2px 12px; padding: 20px 0 10px;
  }
  .brand h1 { font-size: 22px; }
  .brand .sub { display: none; }
  .status { grid-column: 1; grid-row: auto; font-size: 13px; }
  .controls { display: contents; grid-row: auto; }
  .weeknav { display: none; }
  /* 16px: any smaller and iPhone Safari zooms the page in on focus */
  .search { grid-column: 2; grid-row: 1 / span 2; justify-self: end; width: 96px; font-size: 16px; padding: 6px 12px; }
  .search:focus, .search:not(:placeholder-shown) { width: 150px; }
  .chips {
    grid-column: 1 / -1; margin-top: 10px;
    display: flex; gap: 0;
    padding: 3px; border-radius: 10px; background: var(--line);
  }
  .chip { flex: 1 1 auto; border: 0; border-radius: 8px; padding: 7px 6px; text-align: center; color: var(--muted); white-space: nowrap; font-size: 14px; }
  .chip.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

  /* day strip: arrows at the ends, seven equal tabs between */
  .daytabs {
    display: grid; grid-template-columns: 24px repeat(7, 1fr) 24px; align-items: center;
    gap: 0; overflow: visible; padding: 2px 0 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
  }
  .daytabs .icon { width: 24px; height: 32px; font-size: 18px; }
  .daytab { padding: 6px 0 4px; border-radius: 8px; font-size: 12px; scroll-snap-align: none; }
  .daytab b { font-size: 16px; }
  .daytab.on { background: var(--ink); box-shadow: none; color: var(--bg); }
  .daytab.on b { color: var(--bg); }
  .daytab.today:not(.on) b { color: var(--accent); }
  .searching .daytabs { display: none; }

  /* content: a flat list, no card; swipe left/right to change day */
  /* the stage spans the full screen width and clips the day sliding past it */
  .stage { margin: 0 -16px; padding: 0 16px; overflow: hidden; overflow: clip visible; }
  .grid { display: block; position: relative; min-height: 40vh; }
  body { touch-action: pan-y pinch-zoom; }
  .day.peek { position: absolute; left: 0; top: 0; width: 100%; background: var(--bg); pointer-events: none; }
  .day { display: none; border: 0; background: none; padding: 4px 0 0; box-shadow: none; opacity: 1; }
  .day.active { display: block; }
  .day.today { box-shadow: none; }
  .dayhead { display: none; }
  .grp { padding: 10px 0 4px; }
  .grp + .grp { padding-top: 16px; }
  .grp li { padding: 5px 0; }
  .more { margin-top: 10px; font-size: 14px; }

  /* search: stack every matching day with its own heading */
  .searching .day { display: block; padding-top: 12px; }
  .searching .dayhead { display: flex; }
  .searching .day + .day { border-top: 1px solid var(--line); margin-top: 8px; }

  /* short days: keep the footer at the bottom of the screen, not mid-page */
  body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
  body > * { flex: none; }
  .stage { flex: 1 0 auto; }

  /* footer: the two controls on one row, then a quiet line of small print */
  .foot {
    display: grid; grid-template-columns: 1fr auto; align-items: center;
    gap: 14px 12px; margin-top: 32px; padding-top: 16px;
    border-top: 1px solid var(--line); font-size: 14px;
  }
  .foot .toggle { grid-column: 1; }
  .foot .homebtn { grid-column: 2; grid-row: 1; padding: 7px 13px 7px 11px; font-size: 13px; }
  .foot .meta {
    grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: baseline;
    gap: 4px 0; font-size: 12px; color: var(--faint);
  }
  .foot .meta a { color: var(--muted); }
  .foot .meta #source::before { content: "·"; margin: 0 7px; }
  .foot .meta #updated:empty + #source::before { content: none; }
  .foot .credit { flex-basis: 100%; margin: 0; }
}

/* share: an icon in each card's header on desktop, a labelled button on phones */
.dayhead .share { width: 26px; height: 22px; margin: -4px -6px -4px 4px; display: inline-flex; align-items: center; justify-content: center; color: var(--faint); opacity: 0; transition: opacity 0.12s; }
.dayhead .wd { margin-right: auto; }
.day:hover .dayhead .share, .dayhead .share:focus-visible, .dayhead .share.copied { opacity: 1; }
.dayhead .share:hover, .share.copied { color: var(--accent); }
.share.bar { display: none; }
.searching .share { display: none; }
@media (hover: none) { .dayhead .share { opacity: 1; } }
@media (max-width: 860px) {
  .cardfoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
  .cardfoot .more { margin: 0; }
  .share.bar {
    display: inline-flex; align-items: center; gap: 5px; margin-left: auto;
    padding: 5px 11px 5px 9px; border-radius: 999px; border: 1px solid var(--line);
    color: var(--muted); font-size: 13px;
  }
  .share.bar:active { background: var(--line); }
  .share.bar.copied { color: var(--accent); border-color: var(--accent); }
  .searching .share.bar { display: none; }
}
