:root {
  color-scheme: light;
  --ink: #242721;
  --muted: #646b62;
  --faint: #8b9288;
  --paper: #f4f1e8;
  --paper-strong: #fffefa;
  --paper-soft: #f8f7f0;
  --accent: #316f67;
  --accent-deep: #244d47;
  --accent-soft: #e6f0ec;
  --warm: #9a674d;
  --warn: #9a5e22;
  --danger: #9b3f34;
  --good: #246b4f;
  --line: rgba(36, 39, 33, 0.11);
  --line-strong: rgba(36, 39, 33, 0.2);
  --shadow: 0 16px 36px rgba(31, 42, 36, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.94), rgba(244, 241, 232, 0.96)),
    var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(90deg, transparent, rgba(49, 111, 103, 0.035), transparent),
    linear-gradient(rgba(36, 39, 33, 0.027) 1px, transparent 1px);
  background-size:
    100% 100%,
    100% 76px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 72%);
}

button,
input,
select {
  font: inherit;
}

button,
input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  min-height: 42px;
  padding: 0 15px;
  color: var(--ink);
  background: rgba(255, 254, 250, 0.84);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    color 160ms ease,
    background-color 160ms ease;
}

button:hover {
  border-color: var(--line-strong);
  color: var(--accent-deep);
  background: var(--paper-strong);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(49, 111, 103, 0.26);
  outline-offset: 3px;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1240px, calc(100% - 44px));
  margin: 0 auto;
  padding: 26px 0 16px;
}

.brand,
.home-link {
  color: var(--ink);
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 680;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
  border-right-color: var(--accent);
  border-bottom-color: var(--warm);
  transform: rotate(45deg);
}

.home-link {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 254, 250, 0.58);
}

.checker-tool {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(1240px, calc(100% - 44px));
  margin: 0 auto;
  padding: 28px 0 58px;
  grid-template-columns: 1fr;
  gap: 16px;
}

.control-panel,
.derived-panel,
.attention-panel,
.interpretation-panel,
.metric-section,
.sources {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.84);
}

.control-panel {
  order: 2;
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(180px, 0.55fr) minmax(220px, 0.75fr);
  align-items: end;
  gap: 14px 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.result-panel {
  order: 1;
}

.control-panel .eyebrow,
.control-panel h1,
.control-panel .intro,
.scope-panel,
.category-tabs,
.action-row,
.status-message {
  grid-column: 1 / -1;
}

.control-panel h1 {
  margin-bottom: 0;
}

.control-panel .intro {
  max-width: 640px;
  margin-bottom: 0;
}

.scope-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 12px 14px;
}

.scope-panel p {
  margin: 0;
}

.eyebrow,
.section-kicker {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 780;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 12px;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 16px;
  font-size: 2.22rem;
  font-weight: 720;
  line-height: 1.14;
  text-wrap: balance;
}

h2 {
  margin-bottom: 0;
  font-size: 1.46rem;
  font-weight: 720;
  line-height: 1.25;
}

h3 {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.32;
}

h4 {
  margin-bottom: 7px;
  font-size: 0.98rem;
  line-height: 1.35;
}

.intro,
.summary,
.metric-label,
.scope-panel,
.status-message,
.panel-note,
.metric-meta,
.metric-message,
.sources,
.conversion-row,
.metric-details,
.empty-state {
  color: var(--muted);
}

.intro {
  margin-bottom: 24px;
  font-size: 1rem;
  line-height: 1.72;
}

.scope-panel {
  display: grid;
  gap: 9px;
  margin: 0 0 24px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(230, 240, 236, 0.62);
  font-size: 0.88rem;
  line-height: 1.62;
}

.scope-panel p {
  margin: 0;
}

.scope-panel strong {
  color: var(--ink);
  font-weight: 680;
}

.field-group {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

label {
  font-size: 0.92rem;
  font-weight: 720;
}

select,
input[type="search"],
.value-field input {
  min-height: 44px;
  width: 100%;
  padding: 0 13px;
  color: var(--ink);
  background: rgba(255, 254, 250, 0.92);
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.category-tabs button {
  min-height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  border-color: var(--cat-border, var(--line));
  color: var(--cat-ink, var(--muted));
  background: var(--cat-bg, rgba(255, 254, 250, 0.84));
  font-size: 0.86rem;
}

.category-tabs button.is-active {
  border-color: color-mix(in srgb, var(--cat-ink, var(--accent-deep)) 46%, transparent);
  color: var(--cat-active-ink, var(--cat-ink, var(--accent-deep)));
  background: var(--cat-active-bg, var(--cat-bg, var(--accent-soft)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cat-ink, var(--accent-deep)) 16%, transparent);
}

.category-tabs button[data-category-tone="all"],
.category-pill[data-category-tone="all"],
.metric-table tr[data-category-tone="all"] {
  --cat-ink: #2c615b;
  --cat-bg: rgba(230, 240, 236, 0.72);
  --cat-active-bg: rgba(213, 232, 225, 0.86);
  --cat-border: rgba(44, 97, 91, 0.2);
  --cat-bar: rgba(44, 97, 91, 0.38);
  --cat-row-bg: rgba(230, 240, 236, 0.25);
}

.category-tabs button[data-category-tone="core"],
.category-pill[data-category-tone="core"],
.metric-table tr[data-category-tone="core"] {
  --cat-ink: #44573d;
  --cat-bg: rgba(229, 237, 217, 0.72);
  --cat-active-bg: rgba(214, 228, 196, 0.88);
  --cat-border: rgba(68, 87, 61, 0.2);
  --cat-bar: rgba(68, 87, 61, 0.38);
  --cat-row-bg: rgba(229, 237, 217, 0.24);
}

.category-tabs button[data-category-tone="liver"],
.category-pill[data-category-tone="liver"],
.metric-table tr[data-category-tone="liver"] {
  --cat-ink: #8a5d29;
  --cat-bg: rgba(248, 232, 199, 0.72);
  --cat-active-bg: rgba(242, 218, 171, 0.88);
  --cat-border: rgba(138, 93, 41, 0.2);
  --cat-bar: rgba(138, 93, 41, 0.38);
  --cat-row-bg: rgba(248, 232, 199, 0.26);
}

.category-tabs button[data-category-tone="kidney"],
.category-pill[data-category-tone="kidney"],
.metric-table tr[data-category-tone="kidney"] {
  --cat-ink: #386171;
  --cat-bg: rgba(219, 235, 240, 0.72);
  --cat-active-bg: rgba(201, 225, 233, 0.88);
  --cat-border: rgba(56, 97, 113, 0.2);
  --cat-bar: rgba(56, 97, 113, 0.38);
  --cat-row-bg: rgba(219, 235, 240, 0.26);
}

.category-tabs button[data-category-tone="lipid"],
.category-pill[data-category-tone="lipid"],
.metric-table tr[data-category-tone="lipid"] {
  --cat-ink: #346451;
  --cat-bg: rgba(221, 238, 226, 0.74);
  --cat-active-bg: rgba(204, 228, 214, 0.9);
  --cat-border: rgba(52, 100, 81, 0.2);
  --cat-bar: rgba(52, 100, 81, 0.4);
  --cat-row-bg: rgba(221, 238, 226, 0.25);
}

.category-tabs button[data-category-tone="metabolic"],
.category-pill[data-category-tone="metabolic"],
.metric-table tr[data-category-tone="metabolic"] {
  --cat-ink: #93613d;
  --cat-bg: rgba(250, 227, 209, 0.72);
  --cat-active-bg: rgba(244, 211, 186, 0.88);
  --cat-border: rgba(147, 97, 61, 0.2);
  --cat-bar: rgba(147, 97, 61, 0.38);
  --cat-row-bg: rgba(250, 227, 209, 0.25);
}

.category-tabs button[data-category-tone="body"],
.category-pill[data-category-tone="body"],
.metric-table tr[data-category-tone="body"] {
  --cat-ink: #4d5f86;
  --cat-bg: rgba(226, 232, 246, 0.74);
  --cat-active-bg: rgba(211, 220, 242, 0.9);
  --cat-border: rgba(77, 95, 134, 0.2);
  --cat-bar: rgba(77, 95, 134, 0.38);
  --cat-row-bg: rgba(226, 232, 246, 0.25);
}

.category-tabs button[data-category-tone="thyroid"],
.category-pill[data-category-tone="thyroid"],
.metric-table tr[data-category-tone="thyroid"] {
  --cat-ink: #655384;
  --cat-bg: rgba(235, 226, 243, 0.74);
  --cat-active-bg: rgba(222, 210, 236, 0.9);
  --cat-border: rgba(101, 83, 132, 0.2);
  --cat-bar: rgba(101, 83, 132, 0.38);
  --cat-row-bg: rgba(235, 226, 243, 0.25);
}

.category-tabs button[data-category-tone="nutrient"],
.category-pill[data-category-tone="nutrient"],
.metric-table tr[data-category-tone="nutrient"] {
  --cat-ink: #7b5862;
  --cat-bg: rgba(244, 226, 229, 0.74);
  --cat-active-bg: rgba(235, 210, 216, 0.9);
  --cat-border: rgba(123, 88, 98, 0.2);
  --cat-bar: rgba(123, 88, 98, 0.38);
  --cat-row-bg: rgba(244, 226, 229, 0.25);
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
}

.action-row button {
  padding: 0 8px;
  white-space: nowrap;
}

.status-message {
  min-height: 20px;
  margin: 14px 0 0;
  font-size: 0.88rem;
}

.result-panel {
  min-width: 0;
}

.result-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

.stage-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  margin: 0 0 10px;
  padding: 0 11px;
  border: 1px solid rgba(49, 111, 103, 0.2);
  border-radius: 999px;
  color: var(--accent-deep);
  background: rgba(230, 240, 236, 0.74);
  font-size: 0.8rem;
  font-weight: 760;
}

.summary {
  max-width: 390px;
  margin: 4px 0 0;
  line-height: 1.62;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.metric-strip > div,
.derived-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.72);
}

.metric-strip > div {
  padding: 13px 14px;
}

.metric-label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.78rem;
}

.metric-strip strong,
.derived-card strong {
  font-size: 1.28rem;
  font-weight: 760;
}

.derived-panel,
.attention-panel,
.interpretation-panel,
.metric-section,
.sources {
  padding: 18px;
  margin-top: 14px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-kicker {
  margin: 0 0 7px;
}

.panel-note {
  flex: none;
  font-size: 0.84rem;
}

.derived-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.derived-card {
  display: grid;
  gap: 7px;
  padding: 14px;
}

.derived-card p {
  margin: 0;
  line-height: 1.55;
}

.formula-line,
.dependency-line {
  font-size: 0.84rem;
}

.formula-line {
  color: var(--ink);
}

.dependency-line {
  color: var(--faint);
}

.derived-footnote {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(248, 247, 240, 0.72);
  font-size: 0.86rem;
}

.interpretation-summary {
  margin: -4px 0 14px;
  color: var(--muted);
  line-height: 1.62;
}

.interpretation-list {
  display: grid;
  gap: 8px;
}

.interpretation-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.74);
}

.interpretation-order {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-size: 0.82rem;
  font-weight: 780;
}

.interpretation-card strong {
  display: block;
  margin-bottom: 5px;
}

.interpretation-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.attention-list {
  display: grid;
  gap: 10px;
}

.attention-item {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(100px, auto);
  gap: 6px 14px;
  padding: 14px;
  border: 1px solid rgba(154, 94, 34, 0.18);
  border-radius: 8px;
  background: rgba(255, 250, 238, 0.82);
}

.attention-item[data-tone="attention"] {
  border-color: rgba(155, 63, 52, 0.22);
  background: rgba(255, 245, 241, 0.86);
}

.attention-item span {
  justify-self: end;
  color: var(--muted);
  font-size: 0.9rem;
}

.attention-item p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  line-height: 1.58;
}

.empty-state {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(248, 247, 240, 0.68);
}

.metric-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.72);
}

.metric-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.84rem;
}

.metric-table th,
.metric-table td {
  padding: 10px 9px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.metric-table th:last-child,
.metric-table td:last-child {
  border-right: 0;
}

.metric-table tbody tr:last-child td {
  border-bottom: 0;
}

.metric-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--accent-deep);
  background: rgba(230, 240, 236, 0.9);
  font-size: 0.76rem;
  font-weight: 780;
  white-space: nowrap;
}

.metric-table tr[data-tone="attention"] td {
  background: rgba(255, 241, 238, 0.36);
}

.metric-table tr[data-tone="watch"] td {
  background: rgba(255, 244, 224, 0.36);
}

.category-cell {
  width: 118px;
  background:
    linear-gradient(90deg, var(--cat-row-bg, transparent), transparent 72%),
    rgba(255, 254, 250, 0.32);
  box-shadow: inset 3px 0 0 var(--cat-bar, transparent);
  color: var(--cat-ink, var(--faint));
  font-weight: 680;
  white-space: nowrap;
}

.category-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border: 1px solid var(--cat-border, var(--line));
  border-radius: 999px;
  color: var(--cat-ink, var(--muted));
  background: var(--cat-bg, rgba(248, 247, 240, 0.8));
  font-size: 0.72rem;
  font-weight: 760;
  line-height: 1;
  white-space: nowrap;
}

.name-cell {
  width: 190px;
}

.name-cell strong {
  display: block;
  line-height: 1.35;
}

.default-unit {
  display: block;
  margin-top: 4px;
  color: var(--faint);
  font-size: 0.76rem;
}

.value-cell {
  width: 122px;
}

.unit-cell {
  width: 98px;
}

.conversion-cell {
  width: 168px;
  color: var(--muted);
  line-height: 1.45;
}

.range-cell {
  width: 138px;
  color: var(--muted);
  line-height: 1.5;
}

.note-cell {
  width: 220px;
  color: var(--muted);
  line-height: 1.5;
}

.status-cell {
  width: 86px;
}

.metric-table input,
.metric-table select {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 0 9px;
  font-size: 0.82rem;
}

.metric-table .unit-select {
  color: var(--accent-deep);
  background: rgba(230, 240, 236, 0.48);
  font-weight: 680;
}

.status-pill {
  display: inline-flex;
  flex: none;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(248, 247, 240, 0.8);
  font-size: 0.76rem;
  font-weight: 760;
  white-space: nowrap;
}

.status-pill[data-tone="good"],
.metric-card[data-tone="good"] .status-pill {
  border-color: rgba(36, 107, 79, 0.22);
  color: var(--good);
  background: rgba(228, 241, 233, 0.82);
}

.status-pill[data-tone="ok"],
.metric-card[data-tone="ok"] .status-pill {
  border-color: rgba(49, 111, 103, 0.22);
  color: var(--accent-deep);
  background: rgba(230, 240, 236, 0.74);
}

.status-pill[data-tone="watch"],
.metric-card[data-tone="watch"] .status-pill {
  border-color: rgba(154, 94, 34, 0.26);
  color: var(--warn);
  background: rgba(255, 244, 224, 0.9);
}

.status-pill[data-tone="attention"],
.metric-card[data-tone="attention"] .status-pill {
  border-color: rgba(155, 63, 52, 0.28);
  color: var(--danger);
  background: rgba(255, 241, 238, 0.92);
}

.metric-detail-panel {
  display: grid;
  grid-column: 1 / -1;
  gap: 13px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.76);
}

.metric-detail-panel[data-state="empty"] {
  color: var(--muted);
  background: rgba(248, 247, 240, 0.68);
}

.detail-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.detail-panel-header h3,
.metric-detail-panel h3 {
  margin-bottom: 0;
}

.detail-unit-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.detail-chip {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 0 9px;
  border: 1px solid rgba(30, 87, 77, 0.14);
  border-radius: 999px;
  color: var(--accent-deep);
  background: rgba(230, 240, 236, 0.58);
  font-size: 0.78rem;
  font-weight: 720;
}

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

.detail-item {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 247, 240, 0.48);
}

.detail-item dt {
  color: var(--ink);
  font-weight: 720;
}

.detail-item dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.58;
  white-space: pre-line;
}

.detail-empty {
  margin: 0;
  line-height: 1.58;
}

.sources {
  color: var(--muted);
  line-height: 1.72;
}

.sources p {
  margin-bottom: 0;
}

@media (max-width: 980px) {
  .checker-tool {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: 2;
    position: static;
    display: block;
  }

  .result-panel {
    order: 1;
  }
}

@media (max-width: 720px) {
  .topbar,
  .checker-tool {
    width: min(100% - 28px, 1240px);
  }

  .checker-tool {
    padding-top: 16px;
  }

  h1 {
    font-size: 1.86rem;
  }

  .result-heading,
  .section-heading {
    display: grid;
  }

  .summary {
    max-width: none;
  }

  .metric-strip,
  .derived-list,
  .detail-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel-header {
    display: grid;
  }

  .detail-unit-row {
    justify-content: flex-start;
  }

  .interpretation-card {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .interpretation-card .status-pill {
    grid-column: 2;
    justify-self: start;
  }

  .action-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .attention-item {
    grid-template-columns: 1fr;
  }

  .attention-item span {
    justify-self: start;
  }
}

@media print {
  body {
    background: #fff;
  }

  body::before,
  .topbar,
  .control-panel,
  .metric-details {
    display: none;
  }

  .checker-tool {
    display: block;
    width: 100%;
    padding: 0;
  }

  .derived-panel,
  .attention-panel,
  .metric-section,
  .sources,
  .metric-card,
  .metric-strip > div {
    break-inside: avoid;
    background: #fff;
  }
}
