:root {
  --bg: #FDF8F6;
  --surface: #FFFFFF;
  --text: #4A3B42;
  --text-muted: #9B8A91;
  --accent-period: #E8896F;
  --accent-fertile: #F0A8C0;
  --accent-ovulation: #C9A3D8;
  --accent-normal: #BFE0CB;
  --accent-normal-dark: #7FAE8F;
  --ring-track: #F1E7E9;
  --shadow: 0 10px 30px -12px rgba(74, 59, 66, 0.18);
  --shadow-soft: 0 4px 14px -6px rgba(74, 59, 66, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

.screen { display: flex; flex-direction: column; flex: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(20px + env(safe-area-inset-top)) 22px 6px;
}

.brand {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.3px;
  color: var(--text);
}

.icon-btn {
  background: var(--surface);
  border: none;
  border-radius: 14px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.content {
  padding: 10px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Cycle dial ---------- */
.dial-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 8px auto 4px;
  aspect-ratio: 1 / 1;
}
#cycle-dial { width: 100%; height: 100%; }

.dial-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 30px;
}
.dial-day {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
}
.dial-phase {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}

/* ---------- cards ---------- */
.card-row { display: flex; gap: 12px; }

.mini-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
}
.mini-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.mini-value {
  font-family: 'Quicksand', sans-serif;
  font-size: 19px;
  font-weight: 700;
  margin-top: 4px;
}

.mode-toggle {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
  margin-top: 6px;
}
.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 6px;
  border-radius: 999px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
}
.mode-btn.active {
  background: var(--accent-fertile);
  color: #fff;
}

.primary-btn {
  border: none;
  background: linear-gradient(135deg, var(--accent-fertile), var(--accent-ovulation));
  color: #fff;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 16px;
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.primary-btn:active { transform: scale(0.985); }

.secondary-btn {
  border: none;
  background: var(--surface);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14.5px;
  padding: 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  width: 100%;
}
.secondary-btn:active { transform: scale(0.985); }

.danger-btn {
  border: none;
  background: transparent;
  color: #C05A5A;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  padding-top: 4px;
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.dot-period { background: var(--accent-period); }
.dot-fertile { background: var(--accent-fertile); }
.dot-ovulation { background: var(--accent-ovulation); }
.dot-normal { background: var(--accent-normal-dark); }

/* ---------- calendar ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 2px;
}
.month-label {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 18px;
}
.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-muted);
  padding: 10px 0 4px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
}
.cal-cell.empty { visibility: hidden; cursor: default; }
.cal-cell.today { border-color: var(--text); }
.cal-cell.type-period { background: var(--accent-period); color: #fff; }
.cal-cell.type-fertile { background: var(--accent-fertile); color: #fff; }
.cal-cell.type-ovulation { background: var(--accent-ovulation); color: #fff; }
.cal-cell.predicted { opacity: 0.55; }
.cal-cell.log-start::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

/* ---------- history / you ---------- */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}
.stat-value {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 34px;
}
.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 2px;
}

.section-title {
  font-family: 'Quicksand', sans-serif;
  font-size: 15px;
  font-weight: 700;
  margin: 4px 2px -6px;
  color: var(--text);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-soft);
  font-size: 14px;
}
.history-row .hr-date { font-weight: 800; }
.history-row .hr-sub { color: var(--text-muted); font-size: 12px; font-weight: 700; }
.hr-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.empty-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  padding: 10px;
}

.settings-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 700;
  gap: 12px;
}
.field input {
  width: 76px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1.5px solid var(--ring-track);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  background: var(--bg);
  color: var(--text);
}

.disclaimer-card {
  background: #FBEFE9;
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #7A5C50;
}

.version-tag {
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  opacity: 0.6;
  padding: 4px 0 2px;
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 44px);
  max-width: 436px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
  display: flex;
  padding: 8px;
  z-index: 20;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 7px;
  border-radius: 999px;
  color: var(--text-muted);
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 10.5px;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--bg);
  color: var(--text);
}

/* ---------- sheet / modal ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(74, 59, 66, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg);
  border-radius: 28px 28px 0 0;
  padding: 10px 22px 28px;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: var(--ring-track);
  margin: 6px auto 16px;
}
.sheet h3 {
  font-family: 'Quicksand', sans-serif;
  margin: 0 0 6px;
  font-size: 18px;
}
.sheet p { font-size: 13.5px; color: var(--text-muted); margin: 0 0 18px; line-height: 1.5; }
.sheet .sheet-actions { display: flex; gap: 10px; }
.sheet .sheet-actions button { flex: 1; }
.sheet input[type="date"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--ring-track);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 16px;
  background: var(--surface);
  color: var(--text);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .toast { animation: none; }
}

@media (max-width: 360px) {
  .dial-day { font-size: 34px; }
}
