/* 爸爸的飲食日記 — cream ground, golden selection, sage data. 18px base on every viewport. */
:root {
  --ground: #faf7ef;
  --surface: #ffffff;
  --surface-2: #f3ecdc;
  --ink: #2b2620;
  --ink-2: #5b5246;
  --line: #e5dac3;
  --line-strong: #cdbd9c;
  --gold: #e8aa32;
  --gold-hover: #dc9a1c;
  --gold-soft: #fcefd0;
  --gold-ink: #835500;
  --sage: #4f7d5b;
  --sage-soft: #a9c3ad;
  --sage-band: #dce9d9;
  --danger: #a63a26;
  --danger-soft: #fbe9e4;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(70, 48, 12, .06), 0 6px 18px -6px rgba(70, 48, 12, .12);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --font: "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", "Heiti TC",
          system-ui, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; scrollbar-color: var(--line-strong) var(--ground); }
body {
  margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font);
  font-size: 1rem; line-height: 1.6; caret-color: var(--gold-ink); overflow-x: hidden;
}
::selection { background: var(--gold-soft); color: var(--ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 2px solid var(--ground); }
::-webkit-scrollbar-track { background: var(--ground); }
img { max-width: 100%; display: block; }
a { color: var(--gold-ink); text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--gold-ink); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { line-height: 1.25; margin: 0; text-wrap: balance; letter-spacing: 0; }
h1, .page-title { font-size: 1.8rem; font-weight: 700; }
h2 { font-size: 1.8rem; font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 700; }
p { margin: 0; }
.sprite { display: none; }
.icon { width: 1.3em; height: 1.3em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---- shell */
.topbar { background: var(--ground); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { max-width: 880px; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center;
  justify-content: space-between; gap: .75rem; min-height: 64px; }
.brand { color: var(--ink); text-decoration: none; min-width: 0; }
.brand-name { font-size: 1.8rem; font-weight: 700; line-height: 1.2; display: block; white-space: nowrap; }
.topnav { display: flex; align-items: center; gap: .25rem; }
.inline-form { margin: 0; display: contents; }
.page { max-width: 880px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.lede { color: var(--ink-2); margin-bottom: 1.25rem; max-width: 40em; }

/* ---- controls */
.btn, .icon-btn {
  font: inherit; font-size: 1rem; min-height: 48px; display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; border-radius: 999px; border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background-color .2s var(--ease-out), border-color .2s var(--ease-out), color .2s var(--ease-out);
}
.btn { padding: .5rem 1.25rem; font-weight: 600; color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.btn:hover { background: var(--gold-soft); border-color: var(--gold); text-decoration: none; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn-primary:hover { background: var(--gold-hover); border-color: var(--gold-hover); }
.btn-quiet { background: transparent; border-color: var(--line-strong); }
.btn-danger { background: transparent; color: var(--danger); border-color: #dfb1a6; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }
.icon-btn { background: transparent; color: var(--ink); padding: .4rem .75rem; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.square { width: 48px; padding: 0; }
.topnav .label { font-size: .9rem; }

/* ---- date bar + tabs */
.datebar { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.date-pick { position: relative; flex: 1; min-width: 0; min-height: 52px; display: flex; align-items: center;
  justify-content: center; gap: .5rem; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 0 1rem; cursor: pointer; }
.date-pick:hover { border-color: var(--gold); }
.date-pick:focus-within { outline: 3px solid var(--gold-ink); outline-offset: 2px; }
.date-label { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums; }
.date-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; font-size: 1rem; }
.date-pick input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 999px;
  padding: 4px; margin-bottom: 1.5rem; }
.tabs [role="tab"] { font: inherit; font-size: 1.05rem; font-weight: 700; min-height: 48px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-2); cursor: pointer; transition: background-color .2s var(--ease-out); }
.tabs [role="tab"][aria-selected="true"] { background: var(--gold); color: var(--ink); box-shadow: var(--shadow); }
.tabs [role="tab"]:hover:not([aria-selected="true"]) { color: var(--ink); background: rgba(255, 255, 255, .6); }

/* ---- summary */
.view[aria-busy="true"] .summary, .view[aria-busy="true"] .details { opacity: .5; }
.summary { margin-bottom: 2rem; }
.summary-date { font-size: 1.8rem; font-weight: 700; margin-bottom: .75rem; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; padding: 1rem 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { min-width: 0; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere; }
.stat-value .unit { font-size: 1rem; font-weight: 600; margin-left: .15em; color: var(--ink-2); }
.stat-value.unknown { color: var(--ink-2); }
.stat-label { color: var(--ink-2); font-size: .95rem; }
.fine-print { color: var(--ink-2); font-size: .95rem; margin-top: .6rem; }

/* ---- chart */
.chart-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1rem 1rem; margin-bottom: 2.5rem; box-shadow: var(--shadow); }
.block-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: .25rem 1rem; margin-bottom: .75rem; }
.chart { width: 100%; min-height: 240px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--ink-2); }
.chart .axis-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .band { fill: var(--sage-band); }
.chart .band-edge { stroke: var(--sage-soft); stroke-width: 1; }
.chart .series { stroke: var(--sage); stroke-width: 3; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .whisker { stroke: var(--sage-soft); stroke-width: 6; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--sage); stroke-width: 3; }
.chart .value-label { fill: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .day-label { fill: var(--ink-2); }
.chart .col { cursor: pointer; outline: none; }
.chart .col-hit { fill: transparent; }
.chart .col:hover .col-hit, .chart .col:focus-visible .col-hit { fill: var(--gold-soft); }
.chart .col.selected .col-hit { fill: rgba(232, 170, 50, .16); }
.chart .col.selected .day-label { fill: var(--ink); font-weight: 700; }
.chart .col.selected .dot { stroke: var(--gold-ink); fill: var(--gold); }
.chart .col:focus-visible .col-hit { stroke: var(--gold-ink); stroke-width: 2; }
.chart .nodata { fill: var(--ink-2); font-size: 12px; }
.legend { list-style: none; margin: .75rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.25rem;
  color: var(--ink-2); font-size: .95rem; }
.legend li { display: flex; align-items: center; gap: .45rem; }
.swatch { width: 26px; height: 14px; flex: none; border-radius: 3px; }
.swatch-line { height: 3px; background: var(--sage); border-radius: 2px; }
.swatch-range { width: 8px; height: 18px; background: var(--sage-soft); border-radius: 4px; }
.swatch-band { background: var(--sage-band); border: 1px solid var(--sage-soft); }
.chart-details { margin-top: .75rem; }
.chart-details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--gold-ink);
  font-weight: 600; }
.chart-list { list-style: none; margin: 0; padding: 0; }
.chart-list li { border-top: 1px solid var(--line); }
.chart-list button { font: inherit; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  min-height: 48px; padding: .5rem .25rem; display: flex; justify-content: space-between; gap: 1rem; color: var(--ink); }
.chart-list button:hover { background: var(--gold-soft); }
.chart-list .num { font-weight: 700; }

/* ---- notices */
.notice { background: var(--gold-soft); border-radius: var(--radius-sm); padding: .75rem 1rem; margin-bottom: 1rem;
  color: var(--ink); }
.notice-error { background: var(--danger-soft); color: var(--danger); }
.notice:empty { display: none; }
.caution { background: var(--surface-2); border-radius: var(--radius-sm); padding: 1rem; margin: 1rem 0 1.5rem;
  max-width: 42em; }

/* ---- day details */
.details { animation: settle .45s var(--ease-out); }
.meal-group { margin-bottom: 2.5rem; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.meal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); }
.meal + .meal { margin-top: 1rem; }
.meal-photos { display: grid; gap: 4px; background: var(--surface-2); }
.meal-photos.count-1 { grid-template-columns: 1fr; }
.meal-photos.count-2 { grid-template-columns: 1fr 1fr; }
.meal-photos.count-many { grid-template-columns: 2fr 1fr; grid-auto-rows: 1fr; }
.meal-photos.count-many .photo-btn:first-child { grid-row: span 2; }
.photo-btn { padding: 0; border: 0; background: var(--surface-2); cursor: zoom-in; display: block; width: 100%;
  aspect-ratio: 4 / 3; overflow: hidden; position: relative; }
.meal-photos.count-1 .photo-btn { aspect-ratio: 16 / 10; max-height: 440px; }
.meal-photos.count-2 .photo-btn { max-height: 340px; }
.meal-photos.count-many { max-height: 460px; }
.meal-photos.count-many .photo-btn:first-child { max-height: 460px; }
.meal-photos.count-many .photo-btn:not(:first-child) { aspect-ratio: auto; min-height: 90px; }
.photo-btn img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s var(--ease-out); }
.photo-btn:hover img { transform: scale(1.02); }
.photo-btn .more { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(43, 38, 32, .55); color: #fff; font-weight: 700; font-size: 1.3rem; }
.photo-tag { position: absolute; left: .5rem; bottom: .5rem; background: rgba(250, 247, 239, .92); color: var(--ink);
  border-radius: 999px; padding: .1rem .6rem; font-size: .85rem; font-weight: 600; }
.meal-body { padding: 1rem 1.1rem 1.1rem; }
.meal-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.meal-title { font-size: 1.3rem; overflow-wrap: anywhere; }
.meal-nutrition { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin: .35rem 0 .75rem; font-variant-numeric: tabular-nums; }
.meal-nutrition strong { font-size: 1.15rem; }
.food-list { list-style: none; margin: 0; padding: 0; }
.food-list li { padding: .6rem 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto;
  gap: .1rem 1rem; }
.food-name { font-weight: 600; overflow-wrap: anywhere; }
.food-portion { color: var(--ink-2); }
.food-nums { text-align: right; color: var(--ink-2); font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.food-notes { grid-column: 1 / -1; color: var(--ink-2); font-size: .95rem; }
.meal-notes { margin-top: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.meal-source { margin-top: .75rem; color: var(--ink-2); font-size: .9rem; }
.empty-meal { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--ink-2); }
.empty-meal .icon { color: var(--line-strong); width: 1.8em; height: 1.8em; }
.empty-meal-text { display: flex; align-items: center; gap: .6rem; }
.empty-day { text-align: center; padding: 2rem 1rem; border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
  margin-bottom: 2.5rem; }
.empty-day h2 { margin-bottom: .5rem; }
.empty-day .actions { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; margin-top: 1.25rem; }
.source-summary { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.source-summary summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600;
  color: var(--gold-ink); }
.source-summary pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 1rem; margin: .5rem 0 0; max-width: 70ch; }

/* ---- week rows */
.week-heading { margin-bottom: 1rem; }
.week-list { list-style: none; margin: 0 0 2rem; padding: 0; background: var(--surface-2); border-radius: var(--radius);
  overflow: hidden; }
.week-list li + li { border-top: 1px solid var(--line); }
.week-row { font: inherit; color: var(--ink); width: 100%; background: transparent; border: 0; cursor: pointer;
  display: grid; grid-template-columns: 4.2rem 1fr auto; align-items: center; gap: .75rem; padding: .75rem 1rem;
  text-align: left; min-height: 84px; }
.week-row:hover { background: var(--gold-soft); }
.week-row.is-selected { background: rgba(232, 170, 50, .18); }
.week-date { font-size: 1.3rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.week-date small { display: block; font-size: .9rem; font-weight: 400; color: var(--ink-2); }
.week-thumbs { display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.week-thumbs img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 2px solid var(--surface); flex: none; }
.week-thumbs .no-photo { color: var(--ink-2); font-size: .95rem; }
.week-sum { text-align: right; font-variant-numeric: tabular-nums; }
.week-sum strong { display: block; font-size: 1.2rem; color: var(--sage); white-space: nowrap; }
.week-sum span { color: var(--ink-2); font-size: .9rem; white-space: nowrap; }

/* ---- forms */
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.form { max-width: 720px; }
.page-title { margin: .5rem 0 1rem; }
.back-link { display: inline-flex; align-items: center; gap: .35rem; min-height: 44px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field.grow { flex: 1; }
.field-label { font-weight: 600; font-size: .95rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); min-height: 48px; padding: .55rem .75rem; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #7d7262; }
input:hover, select:hover, textarea:hover { border-color: var(--gold); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--gold-ink); outline-offset: 1px; }
[aria-invalid="true"] { border-color: var(--danger) !important; background: #fffaf8; }
.field-error { color: var(--danger); font-size: .9rem; min-height: 0; }
.field-error:empty { display: none; }
.help { color: var(--ink-2); font-size: .95rem; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0; background: var(--surface);
  display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.fieldset legend { font-weight: 700; font-size: 1.15rem; padding: 0 .4rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.items { display: flex; flex-direction: column; gap: 1rem; }
.item-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .9rem; background: var(--ground);
  display: flex; flex-direction: column; gap: .75rem; }
.item-foot { display: flex; align-items: flex-end; gap: .75rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.form-actions .btn-danger { margin-left: auto; }
.file-btn { position: relative; align-self: flex-start; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file-btn:focus-within { outline: 3px solid var(--gold-ink); outline-offset: 2px; }
.photo-edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.photo-edit-grid:empty { display: none; }
.photo-edit { display: flex; flex-direction: column; gap: .4rem; }
.photo-edit img { aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); width: 100%; }
.photo-edit .btn { min-height: 44px; padding: .3rem .8rem; font-size: .95rem; }
.photo-edit input { min-height: 44px; font-size: 1rem; }
.radio-list { display: flex; flex-direction: column; gap: .25rem; }
.radio { display: flex; align-items: center; gap: .6rem; min-height: 48px; cursor: pointer; }
.radio input { width: 22px; height: 22px; accent-color: var(--gold-ink); flex: none; }
.computed { font-weight: 700; font-size: 1.2rem; color: var(--sage); font-variant-numeric: tabular-nums; }
.computed:empty { display: none; }
.reference, .export { margin-top: 2.5rem; max-width: 720px; }
.reference h2, .export h2 { margin-bottom: .75rem; }
.reference ul { padding-left: 1.2rem; }
.export p { margin-bottom: 1rem; color: var(--ink-2); }

/* ---- login */
.login { max-width: 420px; margin: 3rem auto; }
.login-title { margin-bottom: .5rem; }
.login .lede { margin-bottom: 1.5rem; }

/* ---- photo dialog */
.photo-dialog { border: 0; padding: 0; background: var(--ground); border-radius: var(--radius); max-width: min(96vw, 1100px);
  max-height: 94vh; width: auto; box-shadow: 0 10px 40px rgba(20, 14, 4, .35); overflow: auto; }
.photo-dialog::backdrop { background: rgba(32, 26, 18, .72); }
.photo-dialog[open] { animation: settle .35s var(--ease-out); }
.photo-dialog-bar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem; }
.photo-dialog img { max-height: calc(94vh - 9rem); width: auto; max-width: 100%; margin: 0 auto; object-fit: contain; }
.photo-caption { padding: .75rem 1rem 1rem; overflow-wrap: anywhere; }
.photo-caption:empty { display: none; }

@keyframes settle { from { opacity: .4; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- responsive */
@media (max-width: 640px) {
  .topbar-inner { padding: .4rem .75rem; }
  .brand-name { font-size: 1.8rem; }
  .topnav .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .topnav .icon-btn { width: 48px; padding: 0; }
  .page { padding: 1rem .9rem 3rem; }
  .datebar { gap: .35rem; }
  .datebar .btn-quiet { padding: .5rem .85rem; }
  .date-pick { padding: 0 .6rem; gap: .35rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:first-child { grid-column: 1 / -1; }
  .chart-block { padding: 1rem .6rem .75rem; margin-left: -.15rem; margin-right: -.15rem; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .week-row { grid-template-columns: 3.6rem 1fr auto; gap: .5rem; padding: .7rem .75rem; }
  .week-thumbs img { width: 52px; height: 52px; }
  .week-thumbs img:nth-child(n+3) { display: none; }
  .form-actions .btn-danger { margin-left: 0; }
  .item-foot { flex-direction: column; align-items: stretch; }
}
@media (max-width: 380px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 359px) {
  .brand-name { font-size: 1.6rem; }
}
@media (min-width: 900px) {
  .page { padding-top: 2rem; }
  .stat-value { font-size: 2.4rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
