/* allergy.melonoat.com — one stylesheet, no framework, no webfonts.
   Light and dark are both first-class; the palette is warm and calm on
   purpose. Red is reserved for the Class I severity signal so it keeps its
   meaning instead of becoming decoration. */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --text: #1b1a18;
  --muted: #5f5c57;
  --border: #e3dfd8;
  --accent: #0f6b68;
  --accent-text: #ffffff;
  --accent-soft: #e2f1f0;
  --sev-1: #b3261e;
  --sev-2: #8a5a00;
  --sev-3: #55524d;
  --sev-alert: #6b3fa0;
  --focus: #0f6b68;
  --radius: 10px;
  --maxw: 60rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1b1f23;
    --surface-2: #23282d;
    --text: #e9e7e4;
    --muted: #a2a8ad;
    --border: #2e343a;
    --accent: #4ecdc4;
    --accent-text: #06231f;
    --accent-soft: #1d3b39;
    --sev-1: #ff8f85;
    --sev-2: #e0ab4f;
    --sev-3: #9aa0a6;
    --sev-alert: #c4a2ee;
    --focus: #4ecdc4;
  }
}

/* The viewer's explicit theme toggle must win over the media query. */
:root[data-theme="light"] {
  --bg: #fbfaf8; --surface: #fff; --surface-2: #f4f2ee; --text: #1b1a18;
  --muted: #5f5c57; --border: #e3dfd8; --accent: #0f6b68;
  --accent-text: #fff; --accent-soft: #e2f1f0; --sev-1: #b3261e;
  --sev-2: #8a5a00; --sev-3: #55524d; --sev-alert: #6b3fa0; --focus: #0f6b68;
}
:root[data-theme="dark"] {
  --bg: #14171a; --surface: #1b1f23; --surface-2: #23282d; --text: #e9e7e4;
  --muted: #a2a8ad; --border: #2e343a; --accent: #4ecdc4;
  --accent-text: #06231f; --accent-soft: #1d3b39; --sev-1: #ff8f85;
  --sev-2: #e0ab4f; --sev-3: #9aa0a6; --sev-alert: #c4a2ee; --focus: #4ecdc4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 1rem; }

a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── header ─────────────────────────────────────────────────────────── */

header.site { padding: 2.2rem 0 1rem; }
h1 { font-size: 1.85rem; line-height: 1.2; margin: 0 0 .35rem; letter-spacing: -.02em; }
.tagline { margin: 0 0 .9rem; color: var(--muted); font-size: 1.02rem; max-width: 38rem; }
.meta-line { font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.meta-line .dot { opacity: .5; }

.stale {
  display: none;
  margin: .8rem 0 0;
  padding: .6rem .8rem;
  border-left: 3px solid var(--sev-2);
  background: var(--surface-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .88rem;
}
.stale.show { display: block; }

/* ── allergen selector ──────────────────────────────────────────────── */

.picker { margin: 1.4rem 0 .5rem; }
.picker > h2 {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 .55rem; font-weight: 600;
}
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin: 0; padding: 0; border: 0; }

.chip { position: relative; }
.chip input {
  position: absolute; opacity: 0; width: 100%; height: 100%;
  margin: 0; cursor: pointer;
}
.chip span {
  display: inline-block;
  padding: .44rem .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: .92rem;
  cursor: pointer;
  user-select: none;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
@media (prefers-reduced-motion: reduce) { .chip span { transition: none; } }
.chip input:hover + span { border-color: var(--accent); }
.chip input:checked + span {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); font-weight: 600;
}
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip .n { opacity: .65; font-size: .82em; margin-left: .25rem; }

details.more { margin-top: .9rem; }
details.more summary {
  cursor: pointer; font-size: .88rem; color: var(--accent);
  font-weight: 500; width: fit-content;
}
details.more > .picker { margin-top: .8rem; }

/* ── controls ───────────────────────────────────────────────────────── */

/* Grid, not flex: a <select> sizes itself to its widest <option>, which on a
   narrow screen pushed the whole document wider than the viewport. Grid
   tracks plus min-width:0 make the controls shrink instead. */
.controls {
  display: grid; gap: .5rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  margin: 1.3rem 0 .9rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}
.controls input[type="search"], .controls select {
  font: inherit; font-size: .92rem;
  padding: .48rem .6rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
  width: 100%;
}
@media (max-width: 46rem) {
  .controls input[type="search"] { grid-column: 1 / -1; }
}
@media (min-width: 46rem) {
  .controls { grid-template-columns: 2fr 1fr 1fr 1fr; }
}

.resultbar {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: baseline;
  justify-content: space-between;
  margin: 0 0 .8rem;
}
.count { font-weight: 600; font-size: 1.02rem; }
.count .sub { font-weight: 400; color: var(--muted); font-size: .88rem; }
button.clear {
  font: inherit; font-size: .86rem; cursor: pointer;
  background: none; border: 0; color: var(--accent);
  padding: .2rem .1rem; text-decoration: underline;
}
button.clear[hidden] { display: none; }

/* ── result cards ───────────────────────────────────────────────────── */

ol.results { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
ol.results > li[hidden] { display: none; }

.card {
  display: block;
  position: relative;
  padding: .85rem 2rem .85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--sev-3);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}
.card:hover { border-color: var(--accent); }
.card::after {
  content: "›"; position: absolute; right: .8rem; top: 50%;
  transform: translateY(-50%); color: var(--muted); font-size: 1.3rem;
}
.card.s-class-1 { border-left-color: var(--sev-1); }
.card.s-class-2 { border-left-color: var(--sev-2); }
.card.s-alert   { border-left-color: var(--sev-alert); }

.card h3 {
  margin: 0 0 .25rem; font-size: 1.02rem; line-height: 1.35;
  font-weight: 600; overflow-wrap: anywhere;
}
.card .sub { font-size: .84rem; color: var(--muted); margin: 0 0 .45rem; }
.card .sev { font-weight: 600; }
.card.s-class-1 .sev { color: var(--sev-1); }
.card.s-class-2 .sev { color: var(--sev-2); }
.card.s-alert   .sev { color: var(--sev-alert); }

.tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag {
  font-size: .74rem; padding: .12rem .45rem; border-radius: 4px;
  background: var(--accent-soft); color: var(--text);
  border: 1px solid transparent;
}
.tag.additive { background: var(--surface-2); color: var(--muted); }
.tag.guess { background: transparent; border-color: var(--border); color: var(--muted); font-style: italic; }

/* ── unspecified tail + load more ───────────────────────────────────── */

.tail { margin: 1.3rem 0 0; }
.tail[hidden] { display: none; }
.tail summary { cursor: pointer; font-size: .9rem; color: var(--muted); }
.tail summary strong { color: var(--text); }
.tail ol { margin-top: .7rem; }

.loadmore {
  display: block; width: 100%; margin: 1rem 0 0;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .7rem 1rem;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.loadmore:hover { border-color: var(--accent); }
.loadmore[hidden] { display: none; }

.empty { padding: 1.6rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty[hidden] { display: none; }
.empty p { margin: 0 0 .5rem; }
.empty p:last-child { margin: 0; color: var(--muted); font-size: .9rem; }

/* ── detail page ────────────────────────────────────────────────────── */

.back { display: inline-block; margin: 1.5rem 0 1rem; font-size: .9rem; }
article.detail { padding-bottom: 2rem; }
article.detail h1 { font-size: 1.5rem; }
.sevbanner {
  border-left: 4px solid var(--sev-3);
  background: var(--surface); padding: .8rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0 0 1.2rem;
}
.sevbanner.s-class-1 { border-left-color: var(--sev-1); }
.sevbanner.s-class-2 { border-left-color: var(--sev-2); }
.sevbanner.s-alert   { border-left-color: var(--sev-alert); }
.sevbanner strong { display: block; font-size: .95rem; }
.sevbanner.s-class-1 strong { color: var(--sev-1); }
.sevbanner.s-class-2 strong { color: var(--sev-2); }
.sevbanner.s-alert   strong { color: var(--sev-alert); }
.sevbanner p { margin: .25rem 0 0; font-size: .9rem; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1.2rem; margin: 0 0 1.5rem; font-size: .94rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

section.block { margin: 0 0 1.4rem; }
section.block h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .35rem; }
section.block p { margin: 0; }
section.block .verbatim {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem 1rem;
  font-size: .93rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.caveat { font-size: .84rem; color: var(--muted); margin: .4rem 0 0; }

.srclink {
  display: inline-block; margin-top: .3rem;
  padding: .6rem 1rem; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
  text-decoration: none; font-weight: 600; font-size: .94rem;
}

/* ── footer ─────────────────────────────────────────────────────────── */

footer.site {
  margin-top: 2.5rem; padding: 1.5rem 0 2.5rem;
  border-top: 1px solid var(--border);
  font-size: .85rem; color: var(--muted);
}
footer.site p { margin: 0 0 .5rem; max-width: 44rem; }
footer.site .warn { color: var(--text); font-weight: 600; }
.themetoggle {
  font: inherit; font-size: .85rem; cursor: pointer;
  background: none; border: 1px solid var(--border);
  color: var(--muted); border-radius: 999px; padding: .25rem .7rem;
}

table.feeds { border-collapse: collapse; font-size: .85rem; margin: .5rem 0 0; }
table.feeds td { padding: .15rem .8rem .15rem 0; }

@media (max-width: 30rem) {
  h1 { font-size: 1.5rem; }
  .card { padding-right: 1.6rem; }
  dl.facts { grid-template-columns: 1fr; gap: .1rem .5rem; }
  dl.facts dt { margin-top: .5rem; }
}
