:root {
  color-scheme: light;
  --ink: #26312d;
  --muted: #67736d;
  --brand: #c85f35;
  --brand-dark: #9b4326;
  --brand-soft: #fff1e9;
  --green: #39735d;
  --green-soft: #e8f4ee;
  --warn: #9a6815;
  --warn-soft: #fff4d8;
  --line: #dedfd9;
  --paper: #fffefb;
  --surface: #f5f3ed;
  --shadow: 0 10px 30px rgb(47 54 49 / 8%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgb(255 222 203 / 58%), transparent 28rem),
    var(--surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.65;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 72px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.brand-heading { display: flex; align-items: center; gap: 14px; }
.brand-icon { width: 58px; height: 58px; object-fit: contain; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: clamp(1.55rem, 3vw, 2.15rem); line-height: 1.3; }
.app-subtitle { margin-bottom: 0; color: var(--muted); }
.status { margin: 0; color: var(--green); font-weight: 700; white-space: nowrap; }

.intro-card,
.filter-panel,
.results-panel {
  border: 1px solid rgb(202 199 190 / 80%);
  border-radius: 22px;
  background: rgb(255 254 251 / 94%);
  box-shadow: var(--shadow);
}

.intro-card { margin-bottom: 18px; padding: 17px 22px; }
.intro-card p { margin: 0; color: #58625d; font-size: .7rem; line-height: 1.7; }
.workspace { display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); gap: 20px; align-items: start; }
.filter-panel { padding: 24px; }
.results-panel { min-height: 520px; padding: 24px; }

.filter-heading,
.result-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--brand);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.filter-heading h2,
.result-heading h2 { margin-bottom: 0; line-height: 1.25; }
.result-heading h2 { font-size: 2.15rem; color: var(--brand-dark); }
.result-heading h2 small { margin-left: 5px; font-size: .9rem; color: var(--muted); }

.reset-button {
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reset-button:disabled { color: #a2a5a0; cursor: default; text-decoration: none; }

.status-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 21px 0 4px;
  padding: 14px;
  border: 1px solid #efc7ae;
  border-radius: 15px;
  background: var(--brand-soft);
  cursor: pointer;
}

.status-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; flex: 0 0 42px; width: 42px; height: 24px; border-radius: 20px; background: #bcbdb8; transition: .2s; }
.toggle-track span { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: .2s; }
.status-toggle input:checked + .toggle-track { background: var(--brand); }
.status-toggle input:checked + .toggle-track span { transform: translateX(18px); }
.status-toggle input:focus-visible + .toggle-track { outline: 3px solid rgb(200 95 53 / 32%); outline-offset: 2px; }
.status-toggle-secondary { margin-top: 9px; border-color: #d7d5cf; background: #f3f2ee; }
.status-toggle-secondary input:checked + .toggle-track { background: #777b77; }
.status-toggle strong, .status-toggle small { display: block; }
.status-toggle strong { font-size: .91rem; }
.status-toggle small { color: var(--muted); font-size: .76rem; line-height: 1.45; }

.product-search { display: grid; gap: 7px; margin-top: 17px; }
.product-search span { font-size: .88rem; font-weight: 800; }
.product-search input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  outline: none;
}
.product-search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(200 95 53 / 14%); }
.product-search input::placeholder { color: #969d98; }

.filter-section { margin: 24px 0 0; padding: 22px 0 0; border: 0; border-top: 1px solid var(--line); }
.filter-section legend,
.filter-section h3 { margin: 0 0 9px; padding: 0; font-size: 1rem; font-weight: 800; }
.section-help { margin: -3px 0 12px; color: var(--muted); font-size: .8rem; }
.preset-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.preset-button {
  min-height: 46px;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}
.preset-button:hover { border-color: #d69a7b; background: #fffaf7; }
.preset-button.is-active { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }

.category-checks { display: grid; gap: 7px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; padding: 7px 8px; border-radius: 9px; cursor: pointer; }
.check-row:hover { background: #f8f5ef; }
.check-row input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--brand); }
.check-row span { font-size: .87rem; }

.ingredient-accordions { display: grid; gap: 8px; }
.ingredient-group { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: white; }
.ingredient-group summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 13px; cursor: pointer; font-size: .85rem; font-weight: 800; list-style: none; }
.ingredient-group summary::-webkit-details-marker { display: none; }
.ingredient-group summary::after { content: "+"; color: var(--brand); font-size: 1.2rem; }
.ingredient-group[open] summary::after { content: "−"; }
.group-count { margin-left: auto; color: var(--muted); font-size: .73rem; font-weight: 600; }
.ingredient-options { display: grid; gap: 2px; max-height: 275px; overflow-y: auto; padding: 3px 8px 10px; border-top: 1px solid #eeeae2; }
.ingredient-choice-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: center; padding: 7px 5px; border-radius: 9px; }
.ingredient-choice-row:hover { background: #f8f5ef; }
.ingredient-choice-name { min-width: 0; font-size: .8rem; overflow-wrap: anywhere; }
.ingredient-choice-buttons { display: flex; gap: 5px; }
.ingredient-choice { padding: 4px 7px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--muted); font-size: .69rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.ingredient-choice:hover { border-color: #d69a7b; }
.include-choice.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); box-shadow: inset 0 0 0 1px var(--brand); }
.exclude-choice.is-active { border-color: #8b7770; background: #eee8e5; color: #674d43; box-shadow: inset 0 0 0 1px #8b7770; }
.ingredient-choice:focus-visible { outline: 3px solid rgb(200 95 53 / 20%); outline-offset: 1px; }

.result-sticky { margin-bottom: 16px; }
.visible-summary { margin: 10px 0 0; color: var(--muted); font-size: .84rem; }
.active-filters { display: flex; flex-wrap: wrap; gap: 7px; min-height: 0; margin-top: 12px; }
.filter-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid #efc5ae; border-radius: 999px; padding: 5px 8px 5px 10px; background: var(--brand-soft); color: var(--brand-dark); font-size: .76rem; font-weight: 700; cursor: pointer; }
.filter-chip:hover { border-color: var(--brand); background: #ffe8dc; }
.filter-chip:focus-visible { outline: 3px solid rgb(200 95 53 / 22%); outline-offset: 2px; }
.chip-remove { font-size: 1rem; line-height: 1; }
.filter-chip.status-chip { border-color: #e6cc8a; background: var(--warn-soft); color: #76500e; }
.filter-chip.discontinued-chip { border-color: #ccccc8; background: #eeeeeb; color: #626662; }
.filter-chip.exclude-chip { border-color: #bda9a1; background: #f0e9e6; color: #674d43; }
.no-filter-note { color: var(--muted); font-size: .8rem; }

.product-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.product-card { display: flex; flex-direction: column; align-self: start; min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.product-card.is-unconfirmed { border-color: #e8d29d; background: #fffdf7; }
.product-card.is-discontinued { border-color: #d7d5cf; background: #f7f7f5; }
.product-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.product-name { margin: 0; font-size: 1rem; line-height: 1.5; overflow-wrap: anywhere; }
.status-pill { flex: 0 0 auto; border-radius: 999px; padding: 4px 8px; background: var(--green-soft); color: var(--green); font-size: .68rem; font-weight: 800; white-space: nowrap; }
.status-pill.is-unconfirmed { background: var(--warn-soft); color: var(--warn); }
.status-pill.is-discontinued { background: #e9e9e6; color: #666a66; }
.meta-list { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 13px; }
.meta-pill { border-radius: 7px; padding: 3px 7px; background: #f1f1ed; color: #5f6964; font-size: .7rem; }
.ingredient-list { display: grid; gap: 6px; margin: 0; padding: 11px 0 0; border-top: 1px solid #ece9e2; list-style: none; }
.ingredient-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 3px 5px; border-left: 3px solid transparent; border-radius: 7px; font-size: .78rem; }
.ingredient-item.is-match { border-left-color: var(--brand); background: var(--brand-soft); }
.ingredient-name { overflow-wrap: anywhere; }
.ingredient-concentration { color: var(--brand-dark); font-weight: 700; text-align: right; white-space: pre-line; }
.ingredient-category { display: block; color: #8a918d; font-size: .67rem; }

.more-button { display: block; width: min(360px, 100%); margin: 22px auto 0; padding: 12px 18px; border: 0; border-radius: 12px; background: var(--brand); color: white; font-weight: 800; cursor: pointer; box-shadow: 0 6px 16px rgb(155 67 38 / 20%); }
.more-button:hover { background: var(--brand-dark); }
.empty-state { margin-top: 18px; padding: 34px 18px; border: 1px dashed #d5d3cc; border-radius: 16px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state p { margin: 5px 0 0; }
.is-hidden { display: none !important; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .product-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .app-shell { width: min(100% - 20px, 620px); padding: 20px 0 48px; }
  .app-header { align-items: flex-start; }
  .brand-icon { width: 48px; height: 48px; }
  .status { display: none; }
  .intro-card, .filter-panel, .results-panel { border-radius: 17px; }
  .filter-panel, .results-panel { padding: 18px; }
  .product-list { grid-template-columns: 1fr; }
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
  .ingredient-item { grid-template-columns: minmax(0, 1fr) minmax(70px, auto); }
}

@media (max-width: 430px) {
  .ingredient-choice-row { grid-template-columns: 1fr; }
  .ingredient-choice-buttons { justify-content: flex-start; }
}

@media (max-width: 380px) {
  .preset-grid { grid-template-columns: 1fr; }
  .product-top { display: block; }
  .status-pill { display: inline-block; margin-top: 7px; }
}
