:root {
  --bg: #f7f1e8;
  --panel: #fffaf4;
  --text: #2f241a;
  --muted: #725e4b;
  --border: rgba(94, 63, 31, 0.14);
  --feed: #e37c5e;
  --solids: #d5a021;
  --diaper: #4f8f79;
  --sleep: #5677b9;
  --shadow: 0 4px 16px rgba(75, 49, 24, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", "WenQuanYi Micro Hei", -apple-system, sans-serif;
  font-size: 17px;
  color: var(--text);
  background: linear-gradient(180deg, #f3e3cc 0%, var(--bg) 45%, #f5eee5 100%);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 calc(48px + env(safe-area-inset-bottom));
  display: grid;
  gap: 20px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: stretch;
}

.hero-copy-block {
  display: grid;
  gap: 12px;
}

.hero,
.panel,
.stat-card,
.week-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero,
.panel {
  padding: 24px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 4vw, 3rem);
  line-height: 1.1;
  font-weight: 700;
}

h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.hero-copy {
  margin-top: 10px;
  max-width: 34rem;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--muted);
}

.hero-meta,
.records-list {
  display: grid;
  gap: 14px;
}

.mobile-tip-panel {
  padding-block: 14px;
}

.mobile-tip {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  font-size: 1rem;
}

.mobile-tip strong {
  font-size: 1.05rem;
}

.mobile-tip span {
  color: var(--muted);
  line-height: 1.5;
}

.meta-card,
.stat-card {
  padding: 18px 20px;
}

.meta-card {
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(94, 63, 31, 0.1);
}

.meta-card span,
.stat-card span,
.record-meta,
.settings-tip,
.week-card span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.storage-hint {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.meta-card strong,
.stat-card strong,
.week-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.5rem;
  font-weight: 700;
}

.settings-grid,
.quick-actions,
.stats-grid,
.weekly-grid,
.form-grid {
  display: grid;
  gap: 16px;
}

.settings-grid {
  grid-template-columns: 1.1fr 1fr;
}

.auth-grid {
  margin-top: 16px;
}

.auth-actions {
  display: flex;
  gap: 12px;
  align-items: end;
}

.auth-actions-wide {
  margin-top: 12px;
}

.family-status-card {
  margin-top: 16px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(79, 143, 121, 0.12);
  border: 1px solid rgba(79, 143, 121, 0.16);
}

.family-status-card span {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.family-status-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.4rem;
}

.family-status-text {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.6);
}

.toggle-row strong,
label span {
  display: block;
  margin-bottom: 8px;
  font-size: 1rem;
  font-weight: 700;
}

.toggle-row small {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.toggle-row input[type="checkbox"] {
  width: 28px;
  height: 28px;
  min-height: auto;
}

.settings-tip {
  margin-top: 14px;
  line-height: 1.6;
}

.sync-section {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.sync-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: none;
  border: 0;
  padding: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
}

.sync-toggle-arrow {
  color: var(--muted);
  font-size: 0.85rem;
  transition: transform 200ms ease;
  flex-shrink: 0;
}

.sync-section.open .sync-toggle-arrow {
  transform: rotate(180deg);
}

.sync-body {
  display: none;
  margin-top: 16px;
}

.sync-section.open .sync-body {
  display: block;
}

.quick-actions,
.stats-grid,
.weekly-grid {
  grid-template-columns: 1fr;
}

.quick-actions,
.stats-grid {
  margin: 0;
}

.quick-card {
  border: 0;
  border-radius: 26px;
  min-height: 92px;
  width: 100%;
  padding: 20px 22px;
  color: #fffdf9;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.quick-action-item {
  display: grid;
  gap: 10px;
}

.feed-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.feed-custom {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 10px;
}

.diaper-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.feed-option-button {
  min-height: 60px;
  border: 0;
  border-radius: 18px;
  background: rgba(227, 124, 94, 0.14);
  color: #9a4028;
  font-size: 1rem;
  font-weight: 800;
  touch-action: manipulation;
}

.feed-option-button-other {
  background: rgba(114, 94, 75, 0.12);
  color: var(--text);
}

.feed-custom-confirm {
  min-height: 60px;
  border: 0;
  border-radius: 18px;
  padding: 0 18px;
  background: #9a4028;
  color: #fff9f1;
  font-size: 1rem;
  font-weight: 800;
  touch-action: manipulation;
}

.diaper-option-button {
  min-height: 60px;
  border: 0;
  border-radius: 18px;
  background: rgba(79, 143, 121, 0.14);
  color: #295645;
  font-size: 1rem;
  font-weight: 800;
  touch-action: manipulation;
}

.quick-feedback {
  min-height: 0;
  color: #fff9f1;
  font-size: 1rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity 160ms ease;
  white-space: nowrap;
}

.quick-feedback.visible {
  opacity: 1;
}

.quick-card.sleep.running {
  background: linear-gradient(135deg, #27498d, #18396f);
  box-shadow: 0 18px 50px rgba(24, 57, 111, 0.28);
}

.quick-card.sleep.running .quick-feedback {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 1;
}

.quick-card.sleep.running .quick-feedback::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #fff6cf;
  box-shadow: 0 0 0 0 rgba(255, 246, 207, 0.65);
  animation: sleep-pulse 1.5s ease-out infinite;
}

.quick-card.feed { background: linear-gradient(135deg, #de7150, var(--feed)); }
.quick-card.solids { background: linear-gradient(135deg, #c98c0c, var(--solids)); }
.quick-card.diaper { background: linear-gradient(135deg, #2f6f58, var(--diaper)); }
.quick-card.sleep { background: linear-gradient(135deg, #415f9d, var(--sleep)); }

.quick-card:active,
.action-button:active {
  transform: translateY(1px);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.panel-head.compact {
  margin-bottom: 14px;
}

.head-actions {
  display: flex;
  gap: 10px;
}

.ghost-button,
.primary-button,
.danger-button {
  border-radius: 999px;
  padding: 15px 22px;
  border: 0;
  font-weight: 700;
  font-size: 1rem;
  min-height: 54px;
  touch-action: manipulation;
  cursor: pointer;
}

.ghost-button {
  background: rgba(114, 94, 75, 0.12);
  color: var(--text);
}

.primary-button {
  background: var(--text);
  color: #fffdf9;
  min-width: 180px;
}

.danger-button {
  background: rgba(195, 74, 49, 0.12);
  color: #8f2f18;
}

.form-reveal-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 18px;
  border: 1.5px dashed var(--border);
  border-radius: 22px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
  touch-action: manipulation;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.form-reveal-button:hover,
.form-reveal-button:focus-visible {
  background: rgba(255, 255, 255, 0.6);
  color: var(--text);
}

.undo-toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fffdf9;
  border-radius: 999px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 8px 32px rgba(47, 36, 26, 0.28);
  z-index: 200;
  white-space: nowrap;
  animation: toast-in 180ms ease-out both;
}

.undo-toast.hidden {
  display: none;
}

.undo-toast-button {
  border: 0;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  font: inherit;
  font-weight: 800;
  border-radius: 999px;
  padding: 8px 16px;
  min-height: auto;
  touch-action: manipulation;
  cursor: pointer;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.form-grid {
  grid-template-columns: repeat(2, 1fr);
}

label {
  display: block;
}

input,
select {
  width: 100%;
  min-height: 58px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.8);
  padding: 0 16px;
  font-size: 1.05rem;
  color: var(--text);
}

.wide {
  grid-column: 1 / -1;
}

.form-actions,
.history-toolbar {
  margin-top: 20px;
}

.week-card {
  padding: 18px;
  border-radius: 22px;
}

.record-card {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.75);
}

.record-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.record-type {
  font-size: 1.35rem;
  font-weight: 800;
}

.record-badge {
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  color: #fffdf9;
}

.badge-feed { background: var(--feed); }
.badge-solids { background: var(--solids); }
.badge-diaper { background: var(--diaper); }
.badge-sleep { background: var(--sleep); }

.record-body {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.record-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  line-height: 1.6;
  font-size: 1rem;
}

.hidden {
  display: none;
}

@keyframes sleep-pulse {
  0% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(255, 246, 207, 0.55);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 10px rgba(255, 246, 207, 0);
  }
  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(255, 246, 207, 0);
  }
}

@media (max-width: 820px) {
  .hero,
  .stats-grid,
  .weekly-grid,
  .form-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 12px;
    gap: 16px;
  }

  .hero,
  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .quick-card {
    min-height: 88px;
    font-size: 1.8rem;
    padding: 20px 18px;
  }

  .feed-options {
    grid-template-columns: repeat(2, 1fr);
  }

  .feed-custom {
    grid-template-columns: 1fr;
  }

  .diaper-options {
    grid-template-columns: 1fr;
  }

  .quick-feedback {
    font-size: 0.98rem;
  }

  .panel-head,
  .record-head,
  .toggle-row,
  .auth-actions,
  .record-actions,
  .head-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-copy,
  .settings-tip,
  .record-body,
  .mobile-tip span {
    font-size: 1rem;
  }

  .meta-card strong,
  .stat-card strong,
  .week-card strong {
    font-size: 1.35rem;
  }

  .record-actions button,
  .auth-actions button,
  .head-actions button,
  #exportCsvButton,
  #refreshButton {
    width: 100%;
  }

  .ghost-button,
  .primary-button,
  .danger-button {
    min-height: 58px;
    font-size: 1.05rem;
  }

  #historyDate,
  #familyCode,
  #familyAccessCode,
  #startedAt,
  #endedAt,
  #amount,
  #foodName,
  #diaperKind,
  #type,
  #note {
    font-size: 1rem;
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: min(100% - 14px, 1120px);
    gap: 12px;
  }

  .hero,
  .panel {
    padding: 16px;
    border-radius: 18px;
  }

  .quick-actions {
    gap: 12px;
  }

  .quick-card {
    min-height: 88px;
    font-size: 1.55rem;
    border-radius: 22px;
  }

  h1 {
    font-size: 2rem;
  }

  .mobile-tip {
    flex-direction: column;
    align-items: flex-start;
  }
}
