:root {
  color-scheme: light;
  --ink: #102f33;
  --ink-soft: #466267;
  --teal: #176d70;
  --teal-dark: #104e52;
  --teal-pale: #dceeed;
  --paper: #f7faf9;
  --surface: #ffffff;
  --line: #d4dfdd;
  --line-strong: #aebfbc;
  --low: #2c8069;
  --low-bg: #e3f2ec;
  --mid: #9a6b16;
  --mid-bg: #f9eecb;
  --high: #bb5e27;
  --high-bg: #fae0c0;
  --very-high: #a63d3d;
  --very-high-bg: #f5c8c8;
  --neutral: #60777b;
  --low-row: #edf7f3;
  --low-row-hover: #e2f0e9;
  --mid-row: #f9eecb;
  --mid-row-hover: #f3e3ab;
  --high-row: #fae0c0;
  --high-row-hover: #f4cd9f;
  --very-high-row: #f5c8c8;
  --very-high-row-hover: #efb0b0;
  --shadow: 0 18px 52px rgba(16, 47, 51, 0.12);
  --radius: 14px;
  --font-sans: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-number: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button,
select,
summary {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(23, 109, 112, 0.28);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 8px 12px;
  color: #fff;
  background: var(--ink);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-family: var(--font-number);
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.masthead {
  color: #fff;
  background: var(--ink);
  border-bottom: 5px solid #62aaa3;
}

.masthead__inner,
.masthead__intro,
main,
.site-footer {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}

.masthead__inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 15px;
  padding-top: 28px;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.masthead__intro {
  max-width: 1120px;
  padding: 12px 0 27px;
  margin-bottom: 0;
  color: #cfe0de;
  font-size: 0.9rem;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  gap: 4px;
  width: 30px;
  height: 30px;
  place-content: center;
  border: 1px solid #739b99;
}

.brand-mark span {
  width: 9px;
  height: 9px;
  background: #8bc5bf;
}

.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
  background: #d7e9e6;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  padding: 9px;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 50%;
  place-items: center;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-button svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

main {
  padding: 26px 0 56px;
}

.query-panel {
  position: relative;
  z-index: 2;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(16, 47, 51, 0.06);
}

.search-field {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  min-height: 56px;
  padding: 0 12px;
  background: #f1f6f5;
  border: 2px solid transparent;
}

.search-field:focus-within {
  background: #fff;
  border-color: var(--teal);
}

.search-field > svg {
  width: 23px;
  height: 23px;
  margin-right: 10px;
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-width: 1.8;
}

.search-field input {
  width: 100%;
  min-width: 0;
  padding: 13px 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 1.03rem;
}

.search-field input::placeholder {
  color: #78908f;
}

.search-field input::-webkit-search-cancel-button,
.search-field input::-webkit-search-decoration {
  appearance: none;
  -webkit-appearance: none;
  display: none;
}

.search-field kbd {
  padding: 1px 7px;
  margin-inline: 8px;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  font-family: var(--font-number);
  font-size: 0.74rem;
}

.clear-search {
  display: none;
  padding: 6px 8px;
  color: var(--teal-dark);
  background: transparent;
  border: 0;
  font-size: 0.82rem;
  font-weight: 700;
}

.search-field.has-value .clear-search {
  display: block;
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 14px;
}

.basis-switch {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: #eef4f3;
}

.basis-switch button {
  padding: 7px 12px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  font-size: 0.82rem;
}

.basis-switch button.is-active {
  color: #fff;
  background: var(--teal-dark);
  font-weight: 700;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.sort-control select {
  max-width: 168px;
  min-height: 38px;
  padding: 5px 30px 5px 9px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
}

.category-scroller {
  display: flex;
  gap: 8px;
  padding-top: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  cursor: grab;
}

.category-scroller::-webkit-scrollbar {
  display: none;
}

.category-scroller.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.category-scroller.scroll-right {
  mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
}

.category-scroller.scroll-left {
  mask-image: linear-gradient(to right, transparent, #000 26px);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 26px);
}

.category-scroller.scroll-left.scroll-right {
  mask-image: linear-gradient(to right, transparent, #000 26px, #000 calc(100% - 26px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 26px, #000 calc(100% - 26px), transparent);
}

.category-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 11px;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.category-button:hover,
.category-button.is-active {
  color: var(--teal-dark);
  background: var(--teal-pale);
  border-color: #8bbfba;
}

.category-button.is-active {
  font-weight: 700;
}

.result-section {
  padding-top: 34px;
}

.result-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.result-heading h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  line-height: 1.2;
}

.result-count {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--font-number);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.list-legend {
  display: none;
  grid-template-columns: minmax(0, 1fr) 180px 200px;
  gap: 16px;
  padding: 0 18px 8px 24px;
  color: #6b8282;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.list-legend span:last-child {
  text-align: right;
}

.food-list {
  border-top: 1px solid var(--line-strong);
}

.food-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100%;
  min-height: 88px;
  padding: 14px 14px 14px 18px;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 0;
  border-bottom: 1px solid var(--line);
}

.food-row::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 5px;
  background: var(--neutral);
  content: "";
}

.food-row:hover {
  z-index: 1;
  background: #f0f7f5;
  box-shadow: 0 6px 20px rgba(16, 47, 51, 0.08);
}

.food-row.level-low::before {
  background: var(--low);
}

.food-row.level-mid::before {
  background: var(--mid);
}

.food-row.level-high::before {
  background: var(--high);
}

.food-row.level-very-high::before {
  background: var(--very-high);
}

.food-row.level-low {
  background: var(--low-row);
}

.food-row.level-mid {
  background: var(--mid-row);
}

.food-row.level-high {
  background: var(--high-row);
}

.food-row.level-very-high {
  background: var(--very-high-row);
}

.food-row.level-low:hover {
  background: var(--low-row-hover);
}

.food-row.level-mid:hover {
  background: var(--mid-row-hover);
}

.food-row.level-high:hover {
  background: var(--high-row-hover);
}

.food-row.level-very-high:hover {
  background: var(--very-high-row-hover);
}

.food-main {
  min-width: 0;
  padding-right: 12px;
  align-self: center;
}

.food-name {
  display: block;
  overflow: hidden;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.food-meta,
.food-range {
  display: block;
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.food-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.food-category::after {
  margin: 0 6px;
  color: #9db0ae;
  content: "·";
}

.food-range {
  display: none;
  align-self: center;
  margin: 0;
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
}

.food-value {
  display: flex;
  align-items: baseline;
  align-self: center;
  justify-content: end;
  min-width: 110px;
  color: var(--ink);
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.food-value__number {
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.035em;
}

.food-value__unit {
  width: 48px;
  margin-left: 6px;
  color: var(--ink-soft);
  font-size: 0.65rem;
  line-height: 1.05;
  text-align: left;
}

.food-value.no-data .food-value__number {
  color: var(--ink-soft);
  font-size: 0.9rem;
  letter-spacing: 0;
}

.food-value.no-data .food-value__unit {
  display: none;
}

.load-more,
.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--teal-dark);
  font-weight: 800;
}

.load-more {
  display: block;
  width: 100%;
  margin-top: 16px;
  color: var(--teal-dark);
  background: transparent;
}

.load-more[hidden] {
  display: none;
}

.load-more:hover,
.secondary-button:hover {
  background: var(--teal-pale);
}

.primary-button {
  color: #fff;
  background: var(--teal-dark);
}

.primary-button:hover {
  background: var(--teal);
}

.secondary-button {
  color: var(--teal-dark);
  background: #fff;
}

.empty-state {
  padding: 58px 20px;
  text-align: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.empty-state__symbol {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  color: var(--teal);
  border: 2px solid var(--teal);
  border-radius: 50%;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
}

.empty-state h3 {
  margin: 0;
}

.empty-state p {
  margin: 6px 0 20px;
  color: var(--ink-soft);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
  padding: 24px 0 34px;
  color: #627878;
  border-top: 1px solid var(--line);
  font-size: 0.73rem;
}

.site-footer p {
  margin: 0;
}

dialog {
  max-width: none;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
}

dialog::backdrop {
  background: rgba(9, 32, 35, 0.68);
  backdrop-filter: blur(2px);
}

.detail-dialog {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
}

.dialog-shell,
.guide-shell {
  overflow: auto;
  max-height: calc(100vh - 24px);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 16px;
  padding: 20px 20px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  line-height: 1.3;
}

.dialog-close {
  width: 38px;
  height: 38px;
  color: var(--ink-soft);
}

.dialog-close:hover {
  background: #edf4f3;
}

.detail-summary {
  display: grid;
  grid-template-columns: minmax(170px, 0.8fr) 1.2fr;
  gap: 20px;
  padding: 22px 20px 18px;
  background: #eef6f4;
  border-bottom: 1px solid var(--line);
}

.detail-value {
  display: flex;
  align-items: baseline;
  color: var(--teal-dark);
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
}

.detail-value strong {
  font-size: clamp(2.4rem, 11vw, 4rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

.detail-value span {
  max-width: 70px;
  margin-left: 9px;
  color: var(--ink-soft);
  font-size: 0.74rem;
  line-height: 1.12;
}

.detail-facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.detail-facts div {
  padding: 10px;
  background: rgba(255, 255, 255, 0.76);
  border-left: 2px solid #98bbb7;
}

.detail-facts dt {
  color: var(--ink-soft);
  font-size: 0.7rem;
}

.detail-facts dd {
  margin: 3px 0 0;
  font-family: var(--font-number);
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.calculation-note {
  padding: 13px 20px;
  margin: 0;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  font-size: 0.75rem;
}

.record-section,
.add-record-panel {
  padding: 20px;
}

.section-heading h3 {
  margin: 0;
  font-size: 1.15rem;
}

.record-list {
  margin-top: 12px;
  border-top: 1px solid var(--line-strong);
}

.record-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 18px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.record-source {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
}

.record-source a {
  color: var(--teal-dark);
  text-underline-offset: 3px;
}

.record-original,
.record-note {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.73rem;
  overflow-wrap: anywhere;
}

.record-number {
  margin: 0;
  font-family: var(--font-number);
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.record-number span {
  display: block;
  color: var(--ink-soft);
  font-size: 0.65rem;
  font-weight: 500;
}

.delete-record {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 2px 0;
  color: #9d3e3e;
  background: transparent;
  border: 0;
  font-size: 0.74rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.add-record-panel {
  margin: 0 20px 24px;
  padding: 0;
  border: 1px solid var(--line-strong);
}

.add-record-panel summary {
  padding: 13px 15px;
  color: var(--teal-dark);
  font-weight: 800;
}

.add-record-panel > p {
  padding: 0 15px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.add-record-panel form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
  padding: 15px;
}

.add-record-panel label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 0.76rem;
  font-weight: 700;
}

.add-record-panel input {
  width: 100%;
  min-height: 43px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
}

.input-with-unit {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--line-strong);
}

.input-with-unit input {
  border: 0;
}

.input-with-unit span {
  padding: 0 10px;
  color: var(--ink-soft);
  font-family: var(--font-number);
  font-size: 0.72rem;
}

.form-wide {
  grid-column: 1 / -1;
}

.guide-dialog {
  width: min(620px, calc(100% - 24px));
}

.guide-content {
  padding: 20px;
}

.guide-content > p:first-child {
  margin-top: 0;
}

.level-guide {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 20px 0 12px;
  border: 1px solid var(--line);
}

.level-guide__item {
  display: grid;
  gap: 4px;
  min-height: 80px;
  padding: 12px 8px;
  border-right: 1px solid rgba(16, 47, 51, 0.12);
}

.level-guide__item:last-child {
  border-right: 0;
}

.level-guide__item span {
  font-family: var(--font-number);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.level-guide__item strong {
  align-self: end;
}

.level-guide__item.level-low {
  background: var(--low-bg);
}

.level-guide__item.level-mid {
  background: var(--mid-bg);
}

.level-guide__item.level-high {
  background: var(--high-bg);
}

.level-guide__item.level-very-high {
  background: var(--very-high-bg);
}

.guide-footnote,
.guide-content li {
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.guide-content ul {
  padding-left: 1.25rem;
  margin-bottom: 0;
}

.guide-content li + li {
  margin-top: 7px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  padding: 11px 15px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 780px) {
  .masthead__inner {
    padding-top: 36px;
  }

  .query-panel {
    padding: 20px;
  }

  .list-legend {
    display: grid;
  }

  .food-row {
    grid-template-columns: minmax(0, 1fr) 180px 200px;
    gap: 16px;
    min-height: 82px;
    padding: 12px 18px 12px 24px;
  }

  .food-range {
    display: block;
  }

  .food-value {
    min-width: 170px;
  }

  .food-value__number {
    font-size: 2.05rem;
  }

  .food-value__unit {
    width: 62px;
  }
}

@media (max-width: 620px) {
  .masthead__inner,
  .masthead__intro,
  main,
  .site-footer {
    width: min(100% - 24px, 1120px);
  }

  .masthead__inner {
    padding-top: 14px;
  }

  .masthead__intro {
    padding: 8px 0 16px;
    font-size: 0.85rem;
  }

  main {
    padding-top: 10px;
  }

  .query-panel {
    padding: 11px;
  }

  .search-field {
    grid-template-columns: auto 1fr auto;
    min-height: 52px;
  }

  .search-field kbd {
    display: none;
  }

  .filter-row {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .basis-switch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .sort-control {
    justify-content: space-between;
  }

  .sort-control select {
    flex: 1;
    max-width: 72%;
  }

  .result-section {
    padding-top: 20px;
  }

  .food-row {
    min-height: 82px;
    padding-left: 15px;
  }

  .food-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    max-height: 2.7em;
    font-size: 0.96rem;
    line-height: 1.35;
    white-space: normal;
  }

  .food-value {
    min-width: 96px;
  }

  .food-value__unit {
    width: 42px;
    font-size: 0.59rem;
  }

  .detail-dialog,
  .guide-dialog {
    width: 100%;
    max-height: 100vh;
    margin: auto 0 0;
  }

  .dialog-shell,
  .guide-shell {
    max-height: 94vh;
    border-radius: 16px 16px 0 0;
  }

  .detail-summary {
    grid-template-columns: 1fr;
  }

  .detail-facts {
    grid-template-columns: repeat(3, 1fr);
  }

  .detail-facts div {
    padding: 8px;
  }

  .detail-facts dd {
    font-size: 0.8rem;
  }

  .add-record-panel form {
    grid-template-columns: 1fr;
  }

  .form-wide {
    grid-column: auto;
  }

  .level-guide {
    grid-template-columns: repeat(2, 1fr);
  }

  .level-guide__item:nth-child(2) {
    border-right: 0;
  }

  .level-guide__item:nth-child(-n + 2) {
    border-bottom: 1px solid rgba(16, 47, 51, 0.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
