:root {
  --bg: #FBF4EA;
  --card: #FFFFFF;
  --ink: #4E3D32;
  --muted: #A68F7D;
  --line: #EFE2D2;
  --pink: #ED8BA3;
  --pink-deep: #D96B87;
  --pink-soft: #FDEBF0;
  --apricot: #F0A96F;
  --apricot-soft: #FCEBDD;
  --sage: #8FBE9F;
  --sage-soft: #E6F1E9;
  --gold: #DFAE55;
  --gold-soft: #F8EDD6;
  --shadow: 0 6px 20px rgba(180, 140, 110, 0.10);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: linear-gradient(180deg, #FDF6EC 0%, #FBF1E5 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}

.hidden { display: none !important; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px 96px;
}

.app-header {
  text-align: center;
  padding: 22px 0 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

.view { animation: fadeIn 0.25s ease; padding-top: 4px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.card-sub { font-size: 13px; color: var(--muted); font-weight: 400; }

.tiny-note {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0 6px;
}

/* ---------- greeting ---------- */
.greeting-card {
  background: linear-gradient(135deg, #FFF6F8 0%, #FFF9F1 100%);
}

.greeting-title {
  font-size: 22px;
  font-weight: 800;
}

.greeting-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.wave { display: inline-block; }

/* ---------- reminder ---------- */
.reminder-card {
  background: var(--gold-soft);
  border: 1px solid #F3DFAE;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reminder-text { font-size: 14px; }

/* ---------- buttons ---------- */
.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn.block { display: block; width: 100%; }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

.btn-primary { background: var(--pink); color: #fff; font-weight: 600; }
.btn-pink { background: var(--pink); color: #fff; font-weight: 600; }
.btn-pink-outline { background: var(--pink-soft); color: var(--pink-deep); border: 1.5px solid #F6C8D5; font-weight: 600; }
.btn-outline { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: #E4686B; color: #fff; font-weight: 600; }
.btn-danger-outline { background: #FDEBEB; color: #C95356; border: 1.5px solid #F3C4C5; }

.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- progress ---------- */
.progress {
  height: 10px;
  border-radius: 999px;
  background: #F3E7DA;
  overflow: hidden;
  margin: 4px 0 14px;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #F0A96F, #ED8BA3);
  transition: width 0.3s ease;
}

/* ---------- habits ---------- */
.habit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.habit-row.done {
  background: #F1F0ED;
  border-color: #E0DED8;
}

.habit-row.done .habit-emoji {
  filter: grayscale(1);
  opacity: 0.55;
}

.habit-row.done .habit-name {
  color: var(--muted);
}

.habit-left { display: flex; align-items: center; gap: 10px; }

.habit-emoji {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.habit-emoji.apricot { background: var(--apricot-soft); }
.habit-emoji.sage { background: var(--sage-soft); }
.habit-emoji.blue { background: #E7EDFB; }

.habit-name { font-weight: 600; font-size: 16px; }

.habit-pill {
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
  background: #F5EEE4;
}

.habit-pill.done {
  background: #C2BEB7;
  color: #fff;
  font-weight: 600;
}

.habit-right { display: flex; align-items: center; gap: 8px; }

.row-delete {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #C2BEB7;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}

.row-delete:active { background: #E9E6E1; }

/* ---------- meals ---------- */
.meals-label { font-size: 14px; font-weight: 600; margin: 14px 0 10px; }

.meals-row { display: flex; gap: 8px; }

.meal-pill {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 4px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #fff;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.meal-pill .meal-emoji { font-size: 20px; }

.meal-pill.done {
  background: #F1F0ED;
  border-color: #E0DED8;
  color: var(--muted);
  font-weight: 600;
}

.meal-check {
  position: absolute;
  top: 6px;
  right: 8px;
  color: #B4AFA7;
  font-weight: 800;
  font-size: 13px;
}

.add-custom-form { margin: 4px 0 10px; }
.add-form-row { display: flex; gap: 8px; }
.emoji-input { flex: 0 0 72px; text-align: center; }
.empty-hint { color: var(--muted); font-size: 13px; padding: 6px 0 10px; }

.custom-manage-list { margin-bottom: 10px; }
.custom-manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

/* ---------- note ---------- */
.note-box { margin-top: 16px; }
.note-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }

.text-input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
  resize: vertical;
}

.text-input:focus {
  outline: none;
  border-color: var(--pink);
}

/* ---------- period card ---------- */
.period-card {
  background: linear-gradient(135deg, #FDEBF0 0%, #FFF6F2 100%);
  border: 1px solid #F6D4DE;
}

.period-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.period-icon { font-size: 20px; }
.period-title { font-weight: 700; font-size: 16px; }

.period-status { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.period-date { color: var(--pink-deep); }
.period-sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.pink-text { color: var(--pink-deep); font-weight: 600; }

.period-edit-link {
  margin-top: 10px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}

.link { color: var(--pink-deep); font-weight: 600; cursor: pointer; }

/* ---------- calendar ---------- */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.cal-title { font-size: 17px; font-weight: 700; }

.cal-nav {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 12px;
  background: #F6EEE2;
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  font-family: inherit;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-weekday {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 0 6px;
}

.cal-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
}

.cal-cell.blank { visibility: hidden; }
.cal-cell.today { outline: 2px solid var(--pink); outline-offset: -2px; }

.cal-cell.period { background: var(--pink-soft); }
.cal-cell.predicted { background: #FDF2F5; box-shadow: inset 0 0 0 1.5px dashed #F0B9C8; }

.cal-cell .day-num {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
}

.cal-cell.period .day-num { background: var(--pink); color: #fff; }

.cal-cell .dots {
  display: flex;
  gap: 3px;
  margin-top: 3px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.dot.apricot { background: var(--apricot); }
.dot.sage { background: var(--sage); }
.dot.gold { background: var(--gold); }
.dot.blue { background: #9FB8E8; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; gap: 5px; }

.legend-period {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--pink);
  display: inline-block;
}

.legend-predicted {
  width: 10px;
  height: 10px;
  border-radius: 4px;
  background: #FDF2F5;
  border: 1.5px dashed #F0B9C8;
  display: inline-block;
}

.cal-tip .tip-text { color: var(--muted); font-size: 13px; }

/* ---------- stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-cell {
  background: #FBF4EA;
  border-radius: 16px;
  padding: 12px;
  text-align: center;
}

.stat-num { font-size: 20px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.stat-line {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

.stat-line:last-child { border-bottom: none; }
.stat-line .val { font-weight: 600; }

.week-list { display: flex; flex-direction: column; gap: 8px; }

.week-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.week-label { width: 34px; font-size: 13px; color: var(--muted); }
.week-day { width: 38px; font-size: 13px; font-weight: 600; }

.square {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: #F0E4D6;
}

.square.apricot { background: var(--apricot); }
.square.sage { background: var(--sage); }
.square.gold { background: var(--gold); }
.square.blue { background: #9FB8E8; }

.week-squares { display: flex; flex-wrap: wrap; gap: 6px; }

.name-row { display: flex; gap: 10px; }
.name-row .text-input { flex: 1; }

.tip-text { color: var(--muted); font-size: 12px; margin-top: 8px; }

.footer-heart {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 18px 0 8px;
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-family: inherit;
  padding: 6px 0;
  cursor: pointer;
  border-radius: 14px;
  transition: color 0.15s ease, background 0.15s ease;
}

.tab-btn.active {
  color: var(--pink-deep);
  font-weight: 700;
  background: var(--pink-soft);
}

.tab-emoji { font-size: 20px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(70, 48, 36, 0.38);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: #fff;
  width: 100%;
  max-width: 520px;
  max-height: 84dvh;
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-title { font-size: 17px; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #F5EEE4;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.modal-date { font-size: 15px; color: var(--muted); margin-bottom: 8px; }
.modal-section {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin: 16px 0 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.period-line { font-size: 14px; margin-bottom: 6px; }

.onboard { text-align: center; }
.onboard-icon { font-size: 40px; margin: 6px 0 10px; }
.onboard-title { font-size: 19px; font-weight: 800; margin-bottom: 8px; }
.onboard-text { color: var(--muted); font-size: 14px; margin-bottom: 16px; }

.field-label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 6px;
}

.confirm-title { font-size: 17px; font-weight: 700; text-align: center; margin: 4px 0 8px; }
.confirm-text { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  bottom: 92px;
  background: rgba(78, 61, 50, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

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

@media (min-width: 560px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 24px; padding: 20px 24px; }
}
