:root {
  --bg: #f7f4ef;
  --surface: #fffdf9;
  --surface-strong: #ffffff;
  --text: #2d2925;
  --muted: #746c64;
  --line: #e5ded5;
  --primary: #3d6657;
  --primary-dark: #2f5044;
  --primary-soft: #e6f0ec;
  --accent: #b56d50;
  --danger: #a13e3e;
  --danger-dark: #812f2f;
  --error-bg: #fff0ee;
  --radius: 18px;
  --shadow: 0 4px 20px rgba(53, 44, 36, .06);
}

* { box-sizing: border-box; }
html { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); line-height: 1.5; }
body { margin: 0; min-width: 320px; }
a { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; }
button, .button, input, select { min-height: 46px; }
button, .button { touch-action: manipulation; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.65rem, 7vw, 2.25rem); line-height: 1.15; letter-spacing: -.025em; }
h2 { line-height: 1.2; }
code { overflow-wrap: anywhere; background: #eee9e1; border-radius: 5px; padding: .12em .35em; }

.site-header { min-height: 64px; padding: 0 max(18px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); background: rgba(255,253,249,.94); }
.site-header form { margin: 0; }
.brand { color: var(--text); font-weight: 800; text-decoration: none; font-size: 1.1rem; }
.brand span, .muted { color: var(--muted); font-weight: 500; }
.link-button { border: 0; background: transparent; color: var(--primary-dark); padding: 0 4px; cursor: pointer; font-weight: 650; }
.container { width: min(100% - 28px, 1040px); margin: 0 auto; padding: 26px 0 max(60px, env(safe-area-inset-bottom)); }
.container--narrow { width: min(100% - 28px, 520px); min-height: 100vh; display: grid; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.eyebrow { margin-bottom: 6px; color: var(--accent); font-size: .76rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-strong); color: var(--text); padding: 10px 16px; font-weight: 750; text-align: center; text-decoration: none; cursor: pointer; }
.button:hover { border-color: #c9beb2; }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(61,102,87,.28); outline-offset: 2px; }
.button--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button--primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button--secondary { background: var(--primary-soft); border-color: #cddfd8; color: var(--primary-dark); }
.button--quiet { background: transparent; }
.button--danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button--danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }
.button--wide { width: 100%; }
.text-link, .back-link { display: inline-flex; min-height: 44px; align-items: center; font-weight: 700; }
.back-link { margin-bottom: 12px; text-decoration: none; }
.stack { display: grid; gap: 10px; }

.login-card { padding: 28px 22px; }
.login-card h1 { margin-bottom: 10px; }
.login-card form { margin-top: 24px; }
.setup { align-self: center; }
.error-summary, .flash { border-radius: 12px; padding: 13px 15px; margin: 0 0 18px; }
.error-summary { color: #782f2f; background: var(--error-bg); border: 1px solid #ebc2bd; }
.flash { color: #244d3e; background: var(--primary-soft); border: 1px solid #c5ddd4; }

.top-actions { display: flex; flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 18px; }
.top-actions h1 { margin-bottom: 0; }
.hero-card { position: relative; overflow: hidden; border-color: #cadbd4; background: linear-gradient(145deg, #f4faf7, #fffdf9); }
.hero-card::after { content: ""; position: absolute; width: 140px; height: 140px; right: -70px; top: -70px; border-radius: 50%; background: #d9e9e2; opacity: .55; }
.hero-card h2 { margin: 2px 0; font-size: clamp(2.7rem, 14vw, 4.2rem); letter-spacing: -.055em; color: var(--primary-dark); }
.hero-date { color: var(--muted); }
.hero-summary { margin: 18px 0 0; padding-top: 15px; border-top: 1px solid #d6e4de; font-weight: 750; }
.summary-grid { display: grid; gap: 10px; margin: 12px 0 30px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.summary-card { display: flex; flex-direction: column; min-width: 0; padding: 15px; box-shadow: none; }
.summary-label { margin-bottom: 8px; color: var(--muted); font-size: .78rem; font-weight: 750; }
.summary-card strong { font-size: .95rem; }
.summary-card span { margin-top: 4px; color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.daily-section { margin: 0 0 28px; }
.daily-grid { display: grid; gap: 10px; }
.daily-card { box-shadow: none; }
.daily-card--done { background: #f1f7f4; border-color: #c5ddd4; }
.daily-card__title { display: flex; align-items: flex-start; gap: 11px; }
.daily-card__title h3 { margin-bottom: 2px; }
.daily-card__title strong { color: var(--primary-dark); font-size: .9rem; }
.daily-card > p { margin: 13px 0; color: var(--muted); font-size: .85rem; }
.check-mark { flex: 0 0 30px; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); font-weight: 900; }
.daily-action { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 15px; }
.daily-action label { font-size: .78rem; font-weight: 750; }
.daily-done { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 15px; color: var(--primary-dark); font-size: .86rem; font-weight: 750; }
.daily-done form { margin: 0; }
.progress-text { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.medical-note { margin: 10px 0 0; color: var(--muted); font-size: .78rem; }
.daily-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 14px; }
.daily-footer .text-link { font-size: .82rem; }
.attention-setup { margin-bottom: 20px; box-shadow: none; }
.attention-setup h2 { margin-bottom: 6px; font-size: 1.15rem; }
.attention-setup p:last-child { margin-bottom: 0; color: var(--muted); }
.balance-card { display: grid; gap: 12px; margin: -15px 0 30px; box-shadow: none; }
.balance-card h2 { margin-bottom: 4px; font-size: 1.18rem; }
.balance-card p { margin-bottom: 0; }
.suggestion { display: flex; flex-direction: column; border-left: 3px solid var(--primary); padding-left: 12px; }
.suggestion span { color: var(--muted); font-size: .78rem; }
.empty-state { text-align: center; padding: 34px 22px; margin: 8vh auto 30px; max-width: 600px; }
.empty-state .button { margin-top: 10px; }
.empty-small { color: var(--muted); box-shadow: none; }

.timeline-section { margin-top: 28px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 14px; }
.section-heading h2 { margin-bottom: 0; }
.filter-form { margin: 0 0 24px; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.55); }
.filter-form > label { display: block; margin-bottom: 7px; font-size: .87rem; font-weight: 750; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-row input { flex: 1; min-width: 150px; }
.day-heading { position: sticky; top: 0; z-index: 2; width: fit-content; margin: 25px 0 10px; padding: 6px 11px; border-radius: 8px; background: var(--bg); color: var(--muted); font-size: .9rem; }
.day-group { position: relative; display: grid; gap: 10px; padding-left: 14px; border-left: 2px solid #d8cec4; }
.timeline-card { position: relative; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); padding: 15px; }
.timeline-card::before { content: ""; position: absolute; left: -21px; top: 22px; width: 10px; height: 10px; background: var(--primary); border: 3px solid var(--bg); border-radius: 50%; }
.timeline-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 11px; color: var(--muted); font-size: .87rem; }
.timeline-meta time { color: var(--text); font-size: 1.12rem; font-weight: 850; }
.entry-actions { display: flex; gap: 4px; margin-left: auto; }
.entry-actions a { display: inline-flex; min-height: 38px; align-items: center; padding: 0 6px; font-size: .82rem; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; min-height: 30px; border: 1px solid #d8e2de; border-radius: 999px; background: #eff5f2; padding: 4px 9px; color: #334e43; font-size: .82rem; font-weight: 700; }
.detail, .notes { margin: 12px 0 0; overflow-wrap: anywhere; }
.detail { color: var(--muted); font-size: .9rem; }
.notes { padding-top: 12px; border-top: 1px solid var(--line); white-space: normal; }
.pagination { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 26px; color: var(--muted); font-size: .9rem; }

.form-heading { margin-bottom: 20px; }
.form-heading h1 { margin-bottom: 6px; }
.form-heading p { color: var(--muted); }
.log-form { display: grid; gap: 14px; }
.form-section { padding: 19px; box-shadow: none; }
.form-section > h2 { margin-bottom: 18px; font-size: 1.12rem; }
.section-title { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 21px; }
.section-title h2 { margin-bottom: 2px; font-size: 1.2rem; }
.section-title p { margin: 0; color: var(--muted); font-size: .88rem; }
.section-number { flex: 0 0 30px; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); font-weight: 850; }
.two-fields { display: grid; gap: 16px; }
.field { min-width: 0; margin: 0 0 17px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field > legend { display: block; margin-bottom: 7px; font-weight: 750; }
.hint { display: block; margin: -4px 0 7px; color: var(--muted); font-size: .78rem; }
input, select, textarea { width: 100%; border: 1px solid #cfc5ba; border-radius: 11px; background: #fff; color: var(--text); padding: 10px 12px; }
textarea { min-height: 100px; resize: vertical; }
select { padding-right: 34px; }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { min-width: 0; border-radius: 11px 0 0 11px; }
.input-suffix span { display: flex; align-items: center; border: 1px solid #cfc5ba; border-left: 0; border-radius: 0 11px 11px 0; background: #f2eee8; padding: 0 12px; color: var(--muted); white-space: nowrap; }
.input-short { max-width: 210px; }
.field--error input, .field--error select, .field--error textarea { border-color: var(--danger); }
.field-error { display: block; margin-top: 6px; color: var(--danger); font-size: .82rem; font-weight: 650; }
.subsection { min-width: 0; margin: 0 0 18px; padding: 14px; border: 1px solid var(--line); border-radius: 13px; }
.subsection:last-child { margin-bottom: 0; }
.subsection > legend { padding: 0 5px; font-weight: 800; }
.radio-field { padding: 0; border: 0; }
.radio-field legend { padding: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.segmented span { display: grid; place-items: center; min-height: 46px; border: 1px solid #cfc5ba; border-radius: 11px; background: #fff; cursor: pointer; font-weight: 700; }
.segmented input:checked + span { border: 2px solid var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.segmented input:focus-visible + span { outline: 3px solid rgba(61,102,87,.28); outline-offset: 2px; }
.conditional-fields { margin-top: 17px; padding-top: 17px; border-top: 1px solid var(--line); }
.conditional-fields[hidden] { display: none; }
.feeding-hint { display: flex; flex-direction: column; gap: 2px; margin: -7px 0 14px; border-left: 3px solid var(--primary); padding-left: 11px; color: var(--muted); font-size: .84rem; }
.feeding-hint strong { color: var(--primary-dark); }
.feeding-timer { margin-bottom: 20px; border: 1px solid #cddfd8; border-radius: 14px; background: #f3f8f5; padding: 15px; }
.timer-top { display: grid; gap: 15px; }
.timer-label { display: block; color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.timer-display { display: block; color: var(--primary-dark); font-size: 2.2rem; line-height: 1.1; font-variant-numeric: tabular-nums; font-weight: 850; }
.timer-side { display: block; margin-top: 3px; font-size: .84rem; font-weight: 700; }
.timer-reminder label { display: block; margin-bottom: 5px; font-size: .78rem; font-weight: 750; }
.timer-reminder .input-suffix { max-width: 145px; }
.timer-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.timer-buttons [hidden] { display: none; }
.timer-message { margin: 12px 0 0; color: var(--muted); font-size: .78rem; }
.timer-message--alarm { border-radius: 9px; background: #fff1d6; color: #704e11; padding: 9px; font-weight: 750; }
.sticky-save { position: sticky; bottom: 0; z-index: 3; margin: 2px -14px -20px; padding: 12px 14px max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 20%); }
.confirm-card { max-width: 620px; margin: 5vh auto; }
.confirm-card .badges { margin-bottom: 18px; }

@media (min-width: 640px) {
  .container { padding-top: 36px; }
  .site-header { padding-left: max(28px, calc((100vw - 1040px) / 2)); padding-right: max(28px, calc((100vw - 1040px) / 2)); }
  .top-actions { flex-direction: row; justify-content: space-between; align-items: end; }
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .daily-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .daily-action { grid-template-columns: minmax(120px, .7fr) 1fr; align-items: end; }
  .daily-action label { grid-column: 1; }
  .daily-action select { grid-column: 1; }
  .daily-action .button { grid-column: 2; grid-row: 2; }
  .balance-card { grid-template-columns: 1fr 1fr; align-items: center; }
  .balance-card .medical-note { grid-column: 1 / -1; }
  .two-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timer-top { grid-template-columns: 1fr auto; align-items: end; }
  .form-section { padding: 25px; }
  .sticky-save { position: static; width: min(360px, 100%); margin: 5px 0 0 auto; padding: 0; background: transparent; }
  .timeline-card { padding: 18px; }
}

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