:root {
  --canvas: #f1f4f9;
  --paper: #fff;
  --ink: #182841;
  --soft-ink: #51627b;
  --line: #dce4f0;
  --blue: #3155ab;
  --mint: #126c58;
  --display: "Songti SC", STSong, "Noto Serif CJK SC", SimSun, serif;
  --body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --numbers: "Aptos", "SF Pro Display", "Segoe UI", var(--body);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 15px/1.6 var(--body); }
button, input, select { font: inherit; }
a { color: var(--blue); text-underline-offset: 3px; }
button { color: inherit; }
button:not(:disabled), summary { cursor: pointer; }
svg { display: block; }
code { font-family: "SFMono-Regular", Consolas, monospace; font-size: .88rem; white-space: pre-wrap; overflow-wrap: anywhere; }
p, h1, h2, dl { margin: 0; }
h1 { font: 700 clamp(2rem, 5vw, 3rem)/1.2 var(--display); letter-spacing: -.025em; }
h2 { font-size: 1.08rem; line-height: 1.35; letter-spacing: -.015em; }
:focus-visible { outline: 3px solid #5278d8; outline-offset: 3px; }
#main:focus { outline: none; }
:is(#food, #connect, #verify) { scroll-margin-top: 18px; }

.sr-only, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 5; padding: 10px 16px; background: var(--paper); }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.top { background: var(--ink); color: #fff; }
.top-inner {
  min-height: 64px; width: min(1120px, 100%); margin: auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #dce8ff; color: var(--blue); }
.brand-icon svg { width: 25px; height: 25px; }
.nav { display: flex; align-items: center; gap: 5px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 8px 14px; min-height: 43px; text-decoration: none; color: #cdd8ed; border-radius: 7px; white-space: nowrap; }
.nav a:hover { color: #fff; background: #263a56; }
.nav a[aria-current] { color: #fff; background: #314767; }
.nav .icon { width: 17px; height: 17px; }
.quiet { border: 0; background: transparent; color: #d9e4f7; padding: 10px 4px 10px 10px; min-height: 44px; }
.quiet:hover { color: #fff; text-decoration: underline; }
.shell { width: min(1020px, 100%); padding: 38px 24px 48px; margin: auto; }
.shell.wide { width: min(1120px, 100%); }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 24px; }
.page-heading p { margin-top: 6px; }
.page-heading .heading-date { font-size: .86rem; font-weight: 650; color: var(--soft-ink); margin: 0 0 5px; }
.panel {
  min-width: 0; background: var(--paper); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 3px 10px rgba(25, 47, 85, .035);
}
.muted { color: var(--soft-ink); }
.small { font-size: .85rem; }
.stack { display: grid; gap: 12px; }
.stack label, .date-filter label { display: grid; gap: 5px; color: var(--soft-ink); font-size: .86rem; }
.stack input, .stack select, .date-filter input {
  width: 100%; min-width: 0; min-height: 42px; padding: 7px 10px;
  color: var(--ink); border: 1px solid #c6d3e6; background: #fff; border-radius: 7px; font-size: 1rem;
}
.stack input::placeholder { color: #697991; }
.stack .button { justify-self: start; }
.button {
  display: inline-flex; justify-content: center; align-items: center; gap: 7px; min-height: 44px;
  padding: 9px 15px; border: 1px solid transparent; border-radius: 8px;
  text-decoration: none; font-weight: 650; line-height: 1.3; text-align: center;
}
.button .icon, .text-link .icon { width: 17px; height: 17px; }
.primary { color: #fff; background: var(--blue); }
.primary:hover { background: #254695; }
.secondary { color: #294a92; background: #fff; border-color: #ccd9ee; }
.secondary:hover { background: #eaf0fd; }
.text-link { font-weight: 650; display: inline-flex; align-items: center; gap: 6px; }
.link-button { padding: 6px 0; min-height: 36px; border: 0; background: transparent; color: var(--blue); text-align: start; text-decoration: underline; text-underline-offset: 3px; }
.badge { display: inline-flex; align-items: center; min-height: 27px; padding: 3px 9px; border-radius: 5px; background: #edf1f7; color: #495d7b; font-size: .77rem; font-weight: 650; white-space: nowrap; }
.badge.verified { background: #dff3ed; color: #0d5e4d; }
.notice { background: #e9f6f2; color: #115747; margin-bottom: 14px; padding: 10px 12px; border-radius: 7px; font-size: .91rem; }
.notice-error { color: #8e3245; background: #fff0f2; }
.section-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }

.auth-panel { max-width: 420px; margin: clamp(20px, 8vh, 100px) auto 0; padding: clamp(24px, 5vw, 39px); }
.auth-mark { margin-bottom: 18px; }
.auth-mark .brand-icon { width: 47px; height: 47px; }
.auth-mark .brand-icon svg { width: 32px; height: 32px; }
.auth-panel h1 { font-size: 2rem; margin-bottom: 8px; }
.auth-panel .stack, .auth-setup { margin-top: 20px; }
.auth-panel .stack .button { justify-self: stretch; }
.auth-panel .notice { margin-top: 14px; }

.home-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sync-link { display: inline-flex; align-items: center; gap: 7px; padding: 7px 0; color: var(--soft-ink); font-size: .86rem; text-decoration: none; }
.sync-link:hover { color: var(--blue); text-decoration: underline; }
.sync-link .icon { width: 16px; height: 16px; }
.food-panel, .trend-panel, .settings-panel, .week-detail { padding: clamp(16px, 3vw, 23px); }
.food-panel { margin-bottom: 16px; }
.food-panel > .section-top { margin-bottom: 14px; align-items: center; }
.food-form fieldset { min-width: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0; border: 0; margin: 0; }
.food-option {
  display: flex; flex-direction: row-reverse; align-items: center; justify-content: space-between; gap: 6px;
  min-height: 49px; padding: 8px 11px; background: #f6f8fc; border: 1px solid #e0e8f6; border-radius: 8px;
  font-size: .91rem; cursor: pointer;
}
.food-option:has(input:checked) { background: #eaf1ff; border-color: #819bd7; }
.food-option span { display: flex; align-items: center; gap: 7px; }
.food-option .icon { width: 17px; height: 17px; color: var(--blue); }
.food-option input { margin: 0; width: 17px; height: 17px; accent-color: var(--blue); flex: 0 0 auto; }
.food-actions { display: flex; flex-wrap: wrap; gap: 7px 9px; margin-top: 12px; }
.food-actions .link-button { padding-inline: 3px; }
.week-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 18px 0 6px; color: var(--soft-ink); font-size: .79rem; }
.day-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.strip-day {
  display: grid; justify-items: center; gap: 1px; padding: 5px 1px 6px; border: 1px solid transparent;
  border-radius: 6px; background: #f4f6fb; text-decoration: none; color: #50637f;
  font-size: .72rem; line-height: 1.35;
}
.strip-day strong { font: 700 1.05rem/1.2 var(--numbers); color: var(--ink); }
.strip-day .day-mark { width: 15px; height: 15px; display: grid; place-items: center; }
.strip-day .day-mark:empty::before { content: ""; height: 4px; width: 4px; border-radius: 100%; background: #9aacbf; }
.strip-day .icon { width: 14px; height: 14px; }
.strip-day.logged { background: #e2f2ed; color: #0d5e4d; }
.strip-day.future { opacity: .63; }
.strip-day.today { border-color: #829bd5; }
a.strip-day:hover { border-color: #6c88cf; background: #e6eefc; }
.weight-readout { display: flex; align-items: baseline; gap: 7px; font-variant-numeric: tabular-nums; }
.weight-readout strong { font: 650 clamp(2.45rem, 6vw, 3.3rem)/1.04 var(--numbers); letter-spacing: -.075em; }
.weight-readout > span { color: var(--soft-ink); font-weight: 650; }
.trend-panel .section-top { margin-bottom: 16px; }
.weight-readout { margin-top: 7px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px 13px; font-size: .82rem; color: var(--soft-ink); }
.legend span { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.legend-dot { width: 8px; height: 8px; background: var(--blue); border-radius: 100%; }
.legend-line { width: 16px; height: 2px; background: var(--mint); }
.chart-empty {
  display: grid; place-items: center; min-height: 132px; padding: 10px; text-align: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: repeating-linear-gradient(to right, #f7f9fc 0, #f7f9fc 1px, transparent 1px, transparent calc(100% / 29));
}
.chart-empty p { margin-top: 2px; color: var(--soft-ink); font-size: .86rem; }
.plot { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: stretch; gap: 9px; }
.axis-values { display: flex; flex-direction: column; justify-content: space-between; font: 500 .75rem/1.2 var(--numbers); color: var(--soft-ink); text-align: end; padding: 3px 0; }
.weight-chart { display: block; width: 100%; height: clamp(112px, 22vw, 174px); }
.grid-lines { fill: none; stroke: #e0e8f3; stroke-width: 1; }
.weight-dot, .average-line, .avg-dot { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.weight-dot { stroke: var(--blue); stroke-width: 7; }
.avg-dot { stroke: var(--mint); stroke-width: 5; }
.average-line { stroke: var(--mint); stroke-width: 2.2; }
.chart-cursor { stroke: #97a9cc; stroke-width: 1; stroke-dasharray: 3 3; }
.chart-dates { display: flex; justify-content: space-between; gap: 5px; color: var(--soft-ink); font: 500 .8rem/1.4 var(--numbers); margin-top: 4px; }
.chart-dates.labelled { margin-left: 40px; }
.chart-controls { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.chart-slider { flex: 1 1 130px; display: flex; align-items: center; min-height: 36px; }
.chart-slider input { width: 100%; accent-color: var(--blue); }
.chart-controls output { color: var(--ink); font-size: .84rem; font-variant-numeric: tabular-nums; }
.chart-caption { font-size: .8rem; color: var(--soft-ink); margin-top: 10px; }
.shell-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 7px; padding: 12px 1px 0; color: var(--soft-ink); font-size: .84rem; }

.report-controls { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.pager { display: flex; flex-wrap: wrap; gap: 6px; }
.report-controls .date-filter { padding: 0; }
.date-filter { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px; }
.date-filter label { min-width: 0; }
.single-date { margin-bottom: 12px; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.summary-card { padding: 15px 17px; }
.summary-card > p { color: #526482; margin: 5px 0 2px; }
.summary-card strong { color: var(--ink); font: 640 1.95rem/1 var(--numbers); font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.summary-card > span { font-size: .84rem; color: var(--soft-ink); }
.advice-panel, .review-panel { margin-bottom: 12px; padding: 17px 22px; }
.advice-panel { border-left: 4px solid var(--mint); background: #f9fdfb; }
.advice-panel h2 { color: #105e4b; font-size: .89rem; }
.advice-action { font-weight: 700; font-size: clamp(1.08rem, 2.8vw, 1.34rem); margin-top: 4px; }
.advice-reason { margin-top: 3px; color: var(--soft-ink); }
.evidence { margin-top: 8px; color: var(--soft-ink); font-size: .83rem; }
.evidence summary { width: fit-content; color: var(--blue); }
.evidence p { margin-top: 3px; }
.review-panel p { margin-top: 5px; color: var(--soft-ink); }
.week-detail { margin-top: 12px; }
.week-detail > p { margin: 6px 0; }

.ledger { overflow: hidden; }
.ledger .date-filter { padding: 15px 18px; }
/* iOS WebKit can add date-input padding outside a declared 100% width. */
.ledger-date-field {
  display: block; min-width: 0; padding-inline: 10px;
  border: 1px solid #c6d3e6; border-radius: 7px; background: #fff;
}
.ledger-date-field input { display: block; max-width: 100%; margin: 0; padding: 0; border: 0; background: transparent; }
.ledger-date-field:focus-within { outline: 3px solid #5278d8; outline-offset: 3px; }
.ledger-date-field input:focus-visible { outline: none; }
.ledger-caption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 7px; padding: 0 18px 10px; color: var(--soft-ink); font-size: .82rem; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.ledger-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.ledger-table :is(thead, tbody tr:nth-child(even)) { background: #f5f8fc; }
.ledger-table :is(th, td) { padding: 9px 13px; text-align: left; border-top: 1px solid #e8edf5; }
.ledger-table tr > :first-child { padding-left: 17px; white-space: nowrap; }
.ledger-table tbody th, .ledger-table tbody td:nth-child(-n+2) { font-family: var(--numbers); font-variant-numeric: tabular-nums; }
.ledger-table thead th { color: var(--soft-ink); }
.empty-value { color: var(--soft-ink); }
.day-edit { display: inline-block; min-height: 26px; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 12px; }
.settings-panel h2, .week-detail h2 { margin-bottom: 9px; }
.facts > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--soft-ink); font-size: .86rem; }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.copy-field { display: grid; gap: 2px; min-width: 0; margin: 13px 0; padding: 9px 11px; background: #edf2fa; border-radius: 8px; }
.copy-field > span { color: var(--soft-ink); font-size: .79rem; }
.copy-field > button { justify-self: start; }
.secret-box { padding: 11px; }
.secret-box p { font-size: .82rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.verify-box { border-top: 1px solid var(--line); margin-top: 9px; }
.verify-box summary { display: flex; align-items: center; justify-content: space-between; gap: 7px; padding: 8px 0; }
.verify-box summary strong::before { content: "▸"; font-size: .7rem; color: var(--soft-ink); margin-right: 5px; }
.verify-box[open] summary strong::before { content: "▾"; }
.verify-inner { font-size: .88rem; }
.verify-inner .stack { gap: 9px; }
.verify-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 7px; }
.danger { margin-top: 13px; padding: 14px 19px; }
.danger h2 { display: inline; font-size: .98rem; }
.danger p { margin: 10px 0; }
.danger form { max-width: 340px; }
.destructive { border-color: #d7a1ad; color: #8a3045; background: #fff; }
.destructive:hover { background: #fff0f2; }
.guide-panel + .guide-panel { margin-top: 12px; }
.guide-panel li + li { margin-top: 6px; }
.guide-panel :is(ul, ol) { padding-inline-start: 25px; }
.guide-panel pre { padding: 10px; background: #eef2f9; border-radius: 6px; overflow-wrap: anywhere; white-space: pre-wrap; }
.import-instructions { margin-top: 0; }
.import-form { margin-top: 15px; }
.import-form .button:disabled { opacity: .5; }
.import-form label { max-width: 500px; }
.import-form input[type="file"] { padding: 8px; }
.import-form input[type="file"]::file-selector-button {
  border: 0; border-radius: 5px; padding: 5px 9px; margin-right: 8px;
  background: #eaf0fc; color: #274793; font: inherit; cursor: pointer;
}
.mijia-review[hidden] { display: none; }
.mijia-review { max-width: 300px; }
#mijia-status { margin: 0; }
.apple-import > summary { font-weight: 600; }
.apple-import[open] > summary { margin-bottom: 12px; }

.body-featured { margin-top: 16px; }
.body-featured > .section-top { align-items: baseline; margin-bottom: 12px; }
.body-featured-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 11px; }
.body-tile {
  display: grid; align-content: center; gap: 3px; min-height: 64px; padding: 8px 12px;
  background: #f4f7fc; border: 1px solid var(--line); border-radius: 8px; text-decoration: none;
}
.body-tile:hover { border-color: #8ca4d5; background: #eaf0fc; }
.body-tile span { font-size: .85rem; color: var(--soft-ink); }
.body-tile strong { font: 650 1.25rem/1.25 var(--numbers); color: var(--blue); font-variant-numeric: tabular-nums; }
.body-tile strong.empty-value { color: var(--soft-ink); }
.body-recent { font-size: .85rem; }
.body-reading { margin-bottom: 12px; }
.body-reading > .section-top { align-items: baseline; }
.body-weight { font: 650 1.65rem/1.1 var(--numbers); font-variant-numeric: tabular-nums; }
.body-weight span { color: var(--soft-ink); font-size: .9rem; }
.body-readings, .body-reading-inputs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; }
.body-readings { margin-block: 14px; }
.body-readings > div { padding-block: 7px; border-top: 1px solid var(--line); }
.body-readings dt { color: var(--soft-ink); font-size: .84rem; }
.body-readings dd { margin: 2px 0 0; font: 600 1.1rem/1.3 var(--numbers); font-variant-numeric: tabular-nums; }
.body-readings dd.empty-value { font: .85rem/1.5 var(--body); }
#reading-review > summary { font-weight: 650; }
#reading-review[open] > summary { margin-bottom: 8px; }
#reading-review > p { margin-bottom: 12px; }
.body-filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 19px; }
.body-filter { display: flex; align-items: stretch; flex: 0 1 275px; gap: 6px; }
.body-filter label { flex: 1; min-width: 0; }
.body-filter .button { white-space: nowrap; padding-inline: 10px; }
.body-ranges { display: flex; gap: 4px; padding: 2px; background: #f1f4f9; border: 1px solid var(--line); border-radius: 8px; }
.body-ranges a {
  display: flex; align-items: center; justify-content: center; min-height: 40px; padding-inline: 10px;
  border-radius: 6px; color: var(--soft-ink); text-decoration: none; white-space: nowrap; font-size: .88rem;
}
.body-ranges a[aria-current], .body-ranges a:hover { background: var(--paper); color: var(--blue); box-shadow: 0 1px 4px #d5dfef; }
.body-change { align-self: end; max-width: 50%; color: var(--soft-ink); text-align: end; font-size: .83rem; }
.body-plot { cursor: crosshair; touch-action: pan-y; }
.body-trace, .body-point { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.body-trace { stroke: var(--mint); stroke-width: 2; }
.body-point { stroke: var(--blue); stroke-width: 6; }
.body-chart-controls .chart-slider { flex-basis: 100%; min-height: 40px; }
.body-chart-controls output { flex: 1 1 auto; }
[data-chart-reading] { font-size: .88rem; min-height: 38px; }
[data-chart-reading][hidden] { display: none; }

@media (max-width: 720px), (pointer: coarse) {
  .chart-slider { flex-basis: 100%; }
}

@media (max-width: 720px) {
  .top-inner { min-height: 54px; padding-inline: 15px; }
  .brand-icon { width: 30px; height: 30px; }
  .nav {
    position: fixed; z-index: 3; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px;
    background: #fff; border-top: 1px solid #d6e0ef; padding: 4px max(5px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(5px, env(safe-area-inset-left));
  }
  .nav a { flex-direction: column; justify-content: center; padding: 5px 1px; gap: 2px; color: #4e627d; min-height: 45px; font-size: .71rem; }
  .nav a:hover, .nav a[aria-current] { color: #274793; background: #eaf0fc; }
  .nav .icon { width: 18px; height: 18px; }
  .shell { padding: 22px 13px 88px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .page-heading { flex-wrap: wrap; margin-bottom: 14px; }
  .home-heading { flex-wrap: nowrap; align-items: flex-end; }
  .home-actions { justify-content: flex-end; }
  .home-actions .button { min-height: 40px; padding: 6px 9px; font-size: .84rem; }
  .home-actions .button .icon { display: none; }
  .settings-grid { grid-template-columns: 1fr; gap: 10px; }
  .food-panel { margin-bottom: 10px; }
  .summary-grid { gap: 5px; }
  .summary-card { padding: 10px 8px; }
  .summary-card h2 { font-size: .87rem; }
  .summary-card strong { font-size: clamp(1.05rem, 4vw, 1.75rem); }
  .summary-card > span { font-size: .73rem; }
  .summary-card > p { font-size: .75rem; }
  .advice-panel, .review-panel { padding: 14px; }
  .ledger .date-filter { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; }
  .ledger .date-filter label { grid-template-columns: minmax(0, 1fr); }
  .ledger .date-filter button { grid-column: 1 / -1; }
  .ledger-caption { padding-inline: 12px; }
  .ledger-table { font-size: .78rem; }
  .ledger-table :is(th, td) { padding: 8px 4px; }
  .ledger-table tr > :first-child { padding-left: 8px; }
  .body-featured-grid, .body-readings, .body-reading-inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .body-filter { flex-basis: 100%; }
  .body-ranges { width: 100%; }
  .body-ranges a { flex: 1; }
}

@media (max-width: 440px) {
  .ledger .date-filter { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 360px) {
  .food-option { padding-inline: 7px; font-size: .83rem; }
  .food-option span { gap: 4px; }
  .food-option .icon { width: 13px; height: 13px; }
  .home-heading { align-items: flex-start; }
  .heading-date { white-space: nowrap; }
}

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