:root {
  --bg: #f6f8f3;
  --surface: #ffffff;
  --surface-2: #eaf1e7;
  --ink: #1f2a22;
  --ink-soft: #445143;
  --muted: #6c7c6e;
  --hair: #dde6da;

  --brand: #3f7a56;
  --brand-ink: #2c5a3f;
  --brand-soft: #dcedda;
  --brand-contrast: #ffffff;

  --gold: #b97a2a;
  --gold-ink: #8a5a1c;
  --gold-soft: #f3e6d2;

  --alert: #c1554b;
  --alert-soft: #f5e2df;

  --shadow: 0 1px 2px rgba(31, 42, 34, 0.06), 0 6px 20px -10px rgba(31, 42, 34, 0.22);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10160f;
    --surface: #182018;
    --surface-2: #1f2b1f;
    --ink: #e9f0e6;
    --ink-soft: #c1cec0;
    --muted: #8ea08d;
    --hair: #2a352a;

    --brand: #6fb98a;
    --brand-ink: #a8dcb8;
    --brand-soft: #21362a;
    --brand-contrast: #0d1710;

    --gold: #e0ac5f;
    --gold-ink: #f0cd97;
    --gold-soft: #3a2c17;

    --alert: #e2857a;
    --alert-soft: #3a2321;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 26px -12px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --bg: #10160f;
  --surface: #182018;
  --surface-2: #1f2b1f;
  --ink: #e9f0e6;
  --ink-soft: #c1cec0;
  --muted: #8ea08d;
  --hair: #2a352a;

  --brand: #6fb98a;
  --brand-ink: #a8dcb8;
  --brand-soft: #21362a;
  --brand-contrast: #0d1710;

  --gold: #e0ac5f;
  --gold-ink: #f0cd97;
  --gold-soft: #3a2c17;

  --alert: #e2857a;
  --alert-soft: #3a2321;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 26px -12px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Heiti TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; }
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

/* ---------- header ---------- */
header.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 10px;
  border-bottom: 1px solid var(--hair);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand-mark { display: flex; align-items: center; gap: 9px; }
.brand-mark .logo { width: 30px; height: 30px; flex: none; }
.brand-mark .name { font-size: 18px; font-weight: 700; letter-spacing: 0.01em; }
.privacy-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; color: var(--brand-ink);
  background: var(--brand-soft); padding: 5px 10px; border-radius: 999px;
  border: none; cursor: pointer;
}
.privacy-badge:active { transform: scale(0.97); }
.case-strip { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.case-strip .case-name { font-size: 14.5px; color: var(--ink-soft); }
.case-strip .case-name strong { color: var(--ink); }
.link-btn { background: none; border: none; color: var(--brand-ink); font-size: 13.5px; font-weight: 600; padding: 6px 4px; cursor: pointer; }

/* ---------- main / views ---------- */
main { flex: 1; padding: 16px 18px calc(env(safe-area-inset-bottom, 0px) + 96px); }
.view { display: none; }
.view.active { display: block; animation: fadein 0.18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view.active { animation: none; } }

h1.page-title { font-size: 21px; font-weight: 700; margin: 4px 0 14px; }
p.hint { color: var(--muted); font-size: 13.5px; margin: -8px 0 16px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius-lg);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h3 { margin: 0 0 8px; font-size: 15.5px; }
.card p { margin: 0; color: var(--ink-soft); font-size: 14px; }

/* ---------- reminder banner ---------- */
.banner {
  display: flex; align-items: flex-start; gap: 12px;
  border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 16px;
  border: 1px solid transparent;
}
.banner.alert { background: var(--alert-soft); border-color: color-mix(in srgb, var(--alert) 30%, transparent); }
.banner.ok { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 25%, transparent); }
.banner .icon { font-size: 20px; line-height: 1; flex: none; margin-top: 1px; }
.banner .body { flex: 1; }
.banner .title { font-weight: 700; font-size: 14.5px; margin-bottom: 3px; }
.banner.alert .title { color: var(--alert); }
.banner.ok .title { color: var(--brand-ink); }
.banner .desc { font-size: 13px; color: var(--ink-soft); }
.banner .cta {
  margin-top: 9px; display: inline-block; background: var(--alert); color: #fff;
  border: none; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: none; border-radius: 999px; padding: 13px 20px;
  font-size: 15.5px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; line-height: 1.2;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: var(--brand-contrast); }
.btn-secondary { background: var(--surface-2); color: var(--ink); }
.btn-outline { background: transparent; color: var(--brand-ink); border: 1.5px solid var(--brand); }
.btn-gold { background: var(--gold); color: #fff; }
.btn-ghost { background: none; color: var(--ink-soft); }
.btn-sm { padding: 8px 14px; font-size: 13.5px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- forms ---------- */
label.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
label.field-label:first-child { margin-top: 0; }
input[type="text"], input[type="date"], input[type="time"], input[type="number"], textarea, select {
  width: 100%; font-size: 16px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--hair); background: var(--surface); color: var(--ink); font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

/* ---------- chip choices ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--hair); background: var(--surface); color: var(--ink-soft);
  border-radius: 999px; padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip.selected { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.chip.add-chip { border-style: dashed; color: var(--muted); }

/* ---------- category grid on entry view ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 6px; }
.cat-btn {
  background: var(--surface); border: 1.5px solid var(--hair); border-radius: var(--radius-md);
  padding: 16px 8px; text-align: center; cursor: pointer;
}
.cat-btn .emoji { font-size: 26px; display: block; margin-bottom: 6px; }
.cat-btn .label { font-size: 13.5px; font-weight: 700; color: var(--ink); }
.cat-btn:active { transform: scale(0.97); }
.cat-btn.milk { background: var(--brand-soft); }
.cat-btn.sleep-start, .cat-btn.sleep-end { background: var(--surface-2); }

/* quick amount buttons */
.amt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 4px; }
.amt-btn {
  border: 1.5px solid var(--hair); background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 4px; font-weight: 700; font-size: 14.5px; color: var(--ink); cursor: pointer;
}
.amt-btn.selected { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }

/* ---------- date nav ---------- */
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.date-nav .date-main { font-size: 17px; font-weight: 700; text-align: center; flex: 1; }
.date-nav .date-sub { font-size: 12.5px; color: var(--muted); font-weight: 400; display: block; margin-top: 2px; }
.round-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--hair);
  background: var(--surface); font-size: 18px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.round-btn:active { background: var(--surface-2); }

/* ---------- timeline ---------- */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.timeline-empty { text-align: center; color: var(--muted); font-size: 14px; padding: 30px 10px; }
.entry-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border: 1px solid var(--hair); border-radius: var(--radius-md); padding: 12px 14px;
}
.entry-row .dot { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex: none; background: var(--surface-2); }
.entry-row .info { flex: 1; min-width: 0; }
.entry-row .info .line1 { font-size: 14.5px; font-weight: 700; }
.entry-row .info .line2 { font-size: 12.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-row .time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.entry-row .del { background: none; border: none; color: var(--muted); font-size: 18px; padding: 4px 2px; cursor: pointer; flex: none; }

/* ---------- case list ---------- */
.case-card .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.case-card .actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.case-card .actions-row .btn { flex: 0 0 auto; }
.status-pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.status-pill.active { background: var(--brand-soft); color: var(--brand-ink); }
.status-pill.ended { background: var(--surface-2); color: var(--muted); }

/* ---------- export view ---------- */
.range-choices { display: flex; gap: 8px; margin-bottom: 4px; }
.book-card {
  background: linear-gradient(155deg, var(--gold-soft), var(--surface));
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
}
.book-card h3 { color: var(--gold-ink); }

/* ---------- bottom nav ---------- */
nav.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
}
.bottom-nav-inner {
  width: 100%; max-width: 480px; background: var(--surface); border-top: 1px solid var(--hair);
  display: flex; padding: 8px 6px calc(env(safe-area-inset-bottom, 0px) + 8px);
  box-shadow: 0 -6px 20px -14px rgba(0,0,0,0.3);
}
.nav-btn {
  flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 6px 2px; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; border-radius: 12px;
}
.nav-btn .ic { font-size: 21px; }
.nav-btn.active { color: var(--brand-ink); }
.nav-btn.active .ic { transform: translateY(-1px); }

/* ---------- modal / sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 20, 15, 0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 480px; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 22px); max-height: 86vh; overflow-y: auto;
  transform: translateY(12px); transition: transform 0.18s;
}
.overlay.show .sheet { transform: none; }
.sheet .sheet-handle { width: 38px; height: 4px; border-radius: 999px; background: var(--hair); margin: 0 auto 14px; }
.sheet h2 { font-size: 18px; margin: 0 0 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 8px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; z-index: 60; opacity: 0; pointer-events: none; transition: all 0.2s;
  max-width: 86%; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- misc ---------- */
.section-gap { height: 6px; }
.muted-link { color: var(--muted); font-size: 12.5px; text-decoration: underline; background: none; border: none; padding: 0; cursor: pointer; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
