:root {
  --bg: #fff8f8;
  --surface: #ffffff;
  --surface-soft: #fff0f2;
  --text: #2b2426;
  --muted: #74686b;
  --border: #eadcdf;
  --primary: #df6575;
  --primary-dark: #bd4c5d;
  --danger: #b43d49;
  --shadow: 0 10px 28px rgba(115, 72, 80, 0.10);
  --menstrual: #ee7f8d;
  --menstrual-soft: #fbd7dc;
  --follicular: #f4c79e;
  --follicular-soft: #fce9d8;
  --ovulation: #aebce0;
  --ovulation-soft: #e4e9f7;
  --luteal: #b7d8c2;
  --luteal-soft: #e3f2e8;
  --none: #ece7e8;
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #fffafa 0%, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: var(--primary-dark); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(18px, calc((100vw - 1180px) / 2));
  background: rgba(255, 250, 250, 0.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(234, 220, 223, 0.8);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { width: 44px; height: 44px; border-radius: 13px; object-fit: cover; box-shadow: 0 5px 14px rgba(124, 70, 80, 0.15); }
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: .04em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .78rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 7px 10px;
  background: #f8e4e7;
  color: #8d4150;
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-badge.online { background: #e5f3e9; color: #3b7050; }
.status-badge.neutral { background: #f0ecee; color: #62575a; }

.content {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 calc(96px + var(--safe-bottom));
}
.view { display: none; animation: fadeIn .18s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card h2, .card h3 { margin-top: 0; }
.card-kicker {
  color: var(--primary-dark);
  font-size: .74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .09em;
  margin-bottom: 7px;
}
.hero-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; }
.today-card { background: linear-gradient(135deg, #fff 0%, #fff0f2 100%); }
.today-card h2 { margin-bottom: 18px; }
.prediction-card { background: linear-gradient(135deg, #fff 0%, #f2f5fc 100%); }
.prediction-card h2 { font-size: clamp(1.45rem, 3vw, 2.15rem); margin-bottom: 6px; }
.phase-display { display: flex; align-items: center; gap: 14px; margin: 12px 0 24px; }
.phase-dot { width: 48px; height: 48px; border-radius: 50%; box-shadow: inset 0 0 0 8px rgba(255,255,255,.45); flex: 0 0 auto; }
.phase-title { font-size: 1.35rem; font-weight: 800; }
.phase-none { background: var(--none); }
.phase-menstrual { background: var(--menstrual); }
.phase-follicular { background: var(--follicular); }
.phase-ovulation { background: var(--ovulation); }
.phase-luteal { background: var(--luteal); }
.quick-actions, .form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.button {
  border: 0;
  border-radius: 13px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 800;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .5; }
.button-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 18px rgba(223, 101, 117, .25); }
.button-secondary { background: #f4edef; color: #55484b; }
.button-danger { background: #fde6e8; color: var(--danger); }
.button.compact { padding: 8px 11px; font-size: .78rem; }
.text-button { border: 0; background: none; color: var(--primary-dark); font-weight: 800; cursor: pointer; }
.icon-button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: white; font-size: 1.55rem; cursor: pointer; }

.confidence-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; font-size: .9rem; }
.progress-track { height: 8px; margin-top: 9px; border-radius: 99px; background: #e6e9f1; overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 18%; border-radius: inherit; background: #7489bf; transition: width .25s ease; }

.summary-card { margin-top: 18px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-heading h2, .section-heading h3 { margin-bottom: 0; }
.page-heading { margin-bottom: 18px; }
.page-heading h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.15rem); }
.compact-heading { align-items: center; margin-bottom: 16px; }
.summary-grid, .stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.summary-item, .stat-card {
  border: 1px solid var(--border);
  background: #fffafa;
  border-radius: 16px;
  padding: 15px;
}
.summary-item strong, .stat-card strong { display: block; font-size: 1.35rem; margin-top: 6px; }
.summary-item span, .stat-card span { color: var(--muted); font-size: .8rem; }
.notice-card { margin-top: 18px; display: flex; gap: 14px; align-items: flex-start; box-shadow: none; background: #fffdf4; border-color: #efe4bd; }
.notice-card p { margin: 5px 0 0; color: #6f6652; }
.notice-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #f2d983; font-weight: 900; flex: 0 0 auto; }

.month-controls { display: flex; gap: 8px; align-items: center; }
.calendar-card { padding: 18px; }
.calendar-header { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 16px; }
.calendar-header h3 { margin: 0; font-size: 1.35rem; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 11px; height: 11px; border-radius: 4px; }
.weekday-row, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekday-row { color: var(--muted); font-size: .78rem; text-align: center; padding-bottom: 8px; }
.calendar-grid { border-left: 1px solid var(--border); border-top: 1px solid var(--border); }
.calendar-day {
  position: relative;
  min-height: 102px;
  border: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fff;
  padding: 8px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}
.calendar-day.outside { opacity: .38; }
.calendar-day:hover { filter: brightness(.99); }
.calendar-day.selected { box-shadow: inset 0 0 0 3px #6e6070; z-index: 1; }
.calendar-day.today .day-number { background: #3f3538; color: #fff; }
.day-number { display: inline-grid; place-items: center; width: 27px; height: 27px; border-radius: 50%; font-weight: 800; font-size: .82rem; }
.day-phase-band { position: absolute; inset: 0; opacity: .42; pointer-events: none; }
.calendar-day.actual .day-phase-band { opacity: .68; }
.calendar-day.predicted .day-phase-band { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.38), rgba(255,255,255,.38) 5px, transparent 5px, transparent 10px); }
.calendar-day .day-number, .calendar-day .day-labels { position: relative; z-index: 2; }
.day-labels { margin-top: 7px; display: grid; gap: 4px; font-size: .67rem; line-height: 1.25; }
.day-label { display: block; padding: 3px 5px; border-radius: 7px; background: rgba(255,255,255,.65); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-label.deviation { color: #8a3340; font-weight: 800; }
.calendar-note { margin-top: 12px; color: var(--muted); font-size: .75rem; }
.actual-marker, .predicted-marker { display: inline-block; width: 18px; height: 10px; border-radius: 4px; vertical-align: middle; background: var(--menstrual); }
.predicted-marker { opacity: .55; background-image: repeating-linear-gradient(135deg, #fff7 0 3px, transparent 3px 6px); }
.selected-day-card { margin-top: 18px; box-shadow: none; }
.selected-day-card h3 { margin-bottom: 8px; }

.record-layout { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(0, 1.2fr); gap: 18px; }
.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field > span { font-weight: 750; font-size: .88rem; }
.field small { color: var(--muted); line-height: 1.45; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus { border-color: #d78a95; box-shadow: 0 0 0 3px rgba(223,101,117,.12); }
textarea { resize: vertical; }
.form-message { border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; font-size: .84rem; background: #f3eef0; }
.form-message.error { background: #fde8ea; color: #8b2f3b; }
.form-message.success { background: #e8f4eb; color: #34684a; }
.records-list { display: grid; gap: 10px; max-height: 680px; overflow: auto; padding-right: 3px; }
.record-item { border: 1px solid var(--border); border-radius: 16px; padding: 14px; background: #fffafa; }
.record-item-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.record-item h4 { margin: 0 0 5px; font-size: 1rem; }
.record-meta { color: var(--muted); font-size: .8rem; line-height: 1.5; }
.record-actions { display: flex; gap: 6px; }
.mini-button { border: 0; border-radius: 9px; padding: 7px 9px; background: #f0e9eb; cursor: pointer; font-size: .75rem; font-weight: 700; }
.timing-badge { display: inline-flex; margin-top: 8px; padding: 5px 8px; border-radius: 999px; font-size: .72rem; font-weight: 800; background: #f0e9eb; }
.timing-badge.early { background: #e8edf8; color: #485f96; }
.timing-badge.late { background: #f9e6e8; color: #994453; }
.timing-badge.ontime { background: #e8f3eb; color: #477254; }
.record-notes { margin: 10px 0 0; white-space: pre-wrap; font-size: .83rem; }
.empty-state { margin: 18px 0 0; text-align: center; color: var(--muted); }

.stats-grid { margin-top: 0; margin-bottom: 18px; }
.stat-card { background: white; box-shadow: var(--shadow); }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-card canvas { width: 100%; height: auto; max-height: 330px; }
.timing-card { margin-top: 18px; }
.timing-breakdown { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.timing-group { border-radius: 16px; padding: 16px; background: #fff8f8; border: 1px solid var(--border); }
.timing-group strong { display: block; font-size: 1.5rem; margin-bottom: 4px; }
.timing-group small { color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-card h3 { margin-bottom: 16px; }
.input-with-unit { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.input-with-unit span { color: var(--muted); }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.stack-actions { display: grid; gap: 10px; }
.file-button { display: block; text-align: center; }
.file-button input { display: none; }
.medical-card ul { padding-left: 1.25rem; color: #5f5356; line-height: 1.65; }
details { margin-top: 14px; }
summary { cursor: pointer; font-weight: 800; }
.source-list { display: grid; gap: 8px; margin-top: 12px; font-size: .82rem; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 18px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(14px);
  box-shadow: 0 -8px 28px rgba(79, 51, 57, .12);
}
.nav-item { border: 0; background: transparent; border-radius: 14px; padding: 7px 4px; color: var(--muted); cursor: pointer; display: grid; place-items: center; gap: 2px; }
.nav-item span { font-size: 1.2rem; line-height: 1; }
.nav-item small { font-size: .68rem; }
.nav-item.active { color: var(--primary-dark); background: #fff0f2; font-weight: 800; }
.nav-primary span { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: white; margin-top: -21px; box-shadow: 0 7px 16px rgba(223,101,117,.3); }

.modal { border: 0; border-radius: 20px; width: min(430px, calc(100% - 28px)); box-shadow: 0 30px 70px rgba(43, 31, 34, .3); }
.modal::backdrop { background: rgba(38, 25, 29, .45); backdrop-filter: blur(2px); }
.modal p { color: var(--muted); line-height: 1.55; }
.toast { position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom)); transform: translate(-50%, 20px); z-index: 50; opacity: 0; pointer-events: none; background: #352d2f; color: white; border-radius: 999px; padding: 10px 16px; font-size: .82rem; transition: .2s ease; max-width: calc(100% - 30px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .hero-grid, .charts-grid, .record-layout, .settings-grid { grid-template-columns: 1fr; }
  .summary-grid, .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-day { min-height: 88px; }
}

@media (max-width: 620px) {
  .topbar { padding: 10px 14px; }
  .brand p { display: none; }
  .brand-icon { width: 39px; height: 39px; }
  .topbar-actions .button { display: none; }
  .content { width: min(100% - 20px, 1180px); padding-top: 14px; }
  .card { padding: 17px; border-radius: 18px; }
  .summary-grid, .stats-grid { gap: 8px; }
  .summary-item, .stat-card { padding: 12px; }
  .calendar-card { padding: 10px; }
  .calendar-header { align-items: flex-start; flex-direction: column; }
  .calendar-grid, .weekday-row { min-width: 0; }
  .calendar-day { min-height: 70px; padding: 5px; }
  .day-number { width: 24px; height: 24px; font-size: .75rem; }
  .day-labels { margin-top: 3px; }
  .day-labels .day-label:not(.deviation) { display: none; }
  .day-label.deviation { font-size: .54rem; padding: 2px 3px; white-space: normal; }
  .legend { gap: 7px; font-size: .66rem; }
  .timing-breakdown { grid-template-columns: 1fr; }
  .record-item-header { flex-direction: column; }
  .bottom-nav { width: 100%; border-radius: 18px 18px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
