* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: #fafafa;
  color: #222;
  overflow: hidden;
  font-size: 18px;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.page {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

.page.active {
  display: flex;
}

.title-bar {
  position: relative;
  flex: 0 0 auto;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid #eee;
  text-align: center;
}

.title-bar h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.sync-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #bbb;
  vertical-align: middle;
  margin-left: 6px;
  transition: background 0.3s;
}
.sync-dot.busy { background: #ffb74d; }
.sync-dot.ok   { background: #66bb6a; }
.sync-dot.err  { background: #e57373; }

.title-bar .today {
  margin-top: 4px;
  font-size: 16px;
  color: #777;
}

.back-btn {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 20px;
  color: #007aff;
  padding: 8px 12px;
  cursor: pointer;
}

.top-right-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: #007aff;
  color: #fff;
  border: none;
  font-size: 18px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}

.top-right-btn:active {
  background: #005bbb;
}

.grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.big-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fff;
  border: 2px solid #e5e5e5;
  border-radius: 24px;
  font-size: 28px;
  font-weight: 600;
  color: #222;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,0.05);
  min-height: 0;
}

.big-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.05);
}

.big-btn .emoji {
  font-size: 56px;
  line-height: 1;
}

.big-btn .label {
  font-size: 30px;
}

.big-btn .big-num {
  font-size: 48px;
  font-weight: 700;
}

.big-btn .sub {
  font-size: 18px;
  font-weight: 400;
  color: #666;
  min-height: 22px;
}

.big-btn .sub.since {
  font-size: 24px;
  font-weight: 700;
  color: #d84315;
  min-height: 30px;
}

.color-milk { background: #fff3e0; border-color: #ffcc80; }
.color-poop { background: #efebe9; border-color: #bcaaa4; }
.color-food { background: #e8f5e9; border-color: #a5d6a7; }

/* 首页维生素按钮跟随当天颜色 */
.home-vit-D {
  background: #ffeb3b !important;
  border-color: #fbc02d !important;
  color: #000 !important;
}

.home-vit-AD {
  background: #66bb6a !important;
  border-color: #2e7d32 !important;
  color: #000 !important;
}

.home-vit-D .sub,
.home-vit-AD .sub {
  color: #333 !important;
}

.taken {
  opacity: 0.55;
}

/* 历史记录 */
.history {
  flex: 0 0 auto;
  max-height: 38vh;
  overflow-y: auto;
  background: #fff;
  border-top: 1px solid #eee;
  padding: 12px 16px 20px;
}

.history h2 {
  margin: 0 0 8px;
  font-size: 18px;
  color: #555;
  font-weight: 600;
}

.history ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history li {
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 20px;
  display: flex;
  justify-content: space-between;
}

.history li:last-child {
  border-bottom: none;
}

.history .empty {
  color: #999;
  font-size: 16px;
  padding: 8px 0;
}

/* 历史回顾页 */
.history-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  background: #fff;
  border-bottom: 1px solid #eee;
  gap: 8px;
}

.day-nav {
  background: #f0f0f0;
  border: none;
  font-size: 18px;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: 12px;
  color: #333;
  cursor: pointer;
  min-width: 88px;
}

.day-nav:active { background: #e0e0e0; }

.history-date {
  flex: 1 1 auto;
  text-align: center;
  position: relative;
}

.history-date-label {
  font-size: 22px;
  font-weight: 700;
  color: #222;
  pointer-events: none;
}

.history-date-pick {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
}

.history-jump {
  flex: 0 0 auto;
  padding: 8px 12px 4px;
  text-align: center;
  background: #fafafa;
}

.history-jump button {
  background: transparent;
  border: 1px solid #007aff;
  color: #007aff;
  font-size: 16px;
  padding: 6px 18px;
  border-radius: 999px;
  cursor: pointer;
}

.history-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 12px 32px;
  background: #fafafa;
}

.history-card {
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}

.history-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.history-card-title {
  font-size: 20px;
  font-weight: 700;
  color: #222;
}

.history-card-total {
  font-size: 16px;
  color: #666;
}

.history-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history-card li {
  padding: 8px 0;
  border-top: 1px solid #f0f0f0;
  font-size: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-card li:first-child { border-top: none; }

.history-card .empty {
  color: #999;
  font-size: 16px;
  padding: 4px 0;
}

.history-card.vit-D { background: #fffde7; }
.history-card.vit-AD { background: #e8f5e9; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 14px 26px;
  border-radius: 999px;
  font-size: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
  max-width: 80%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
