:root {
  --plum-deep: #2a1b28;
  --plum-surface: #3c2838;
  --plum-surface-2: #4a3247;
  --cream: #f7efe4;
  --cream-dim: #d9c9cf;
  --rose: #e8b4b3;
  --rose-strong: #d98488;
  --gold: #d9a35b;
  --sage: #8fae94;
  --muted: #b3a0ae;
  --danger: #c96a5f;
  --radius: 18px;
  --radius-sm: 10px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", ui-serif, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plum-deep);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: 40px;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Onboarding ---------- */

.screen.onboard-inner,
.onboard-inner {
  padding: 48px 26px 32px;
}

.brandmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: 0.02em;
  color: var(--cream);
  margin-bottom: 40px;
}

.brandmark.small { margin-bottom: 0; font-size: 17px; }

#onboarding h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.25;
  margin: 0 0 16px;
}

.lede {
  color: var(--cream-dim);
  line-height: 1.6;
  font-size: 15px;
  margin: 0 0 36px;
}

.role-pick {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
}

.role-card {
  text-align: left;
  background: var(--plum-surface);
  border: 1px solid rgba(247,239,228,0.08);
  border-radius: var(--radius);
  padding: 20px 20px 22px;
  color: var(--cream);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color .15s ease, transform .15s ease;
}

.role-card:active { transform: scale(0.98); }
.role-card:hover { border-color: var(--rose); }

.role-eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--gold);
}

.role-title {
  font-family: var(--serif);
  font-size: 20px;
  margin: 2px 0 6px;
}

.role-desc {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--cream-dim);
}

.fine-print {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.link-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--rose);
  font-size: 13px;
  text-align: center;
  text-decoration: underline;
  margin-top: 22px;
  padding: 8px;
}

/* ---------- Setup / Settings shared ---------- */

.setup-inner {
  padding: 40px 24px 32px;
}

.setup-inner h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 26px;
  margin: 0 0 8px;
}

.setup-inner h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 17px;
  margin: 0 0 8px;
  color: var(--rose);
}

.section-gap { margin-top: 34px; }

.muted { color: var(--cream-dim); font-size: 13.5px; line-height: 1.55; margin: 0 0 20px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--cream-dim);
}

.field input, .field textarea, #import-code, #pairing-code-display, #recover-code, #recovery-code-display {
  background: var(--plum-surface);
  border: 1px solid rgba(247,239,228,0.12);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--cream);
  font-size: 15px;
  font-family: var(--sans);
}

#import-code, #pairing-code-display, #recover-code, #recovery-code-display {
  width: 100%;
  margin-bottom: 12px;
  letter-spacing: 0.06em;
  text-align: center;
  font-family: var(--sans);
}

.field input:focus, .field textarea:focus, #import-code:focus {
  outline: 2px solid var(--rose);
  outline-offset: 1px;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border-radius: 999px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.btn.primary { background: var(--rose); color: var(--plum-deep); }
.btn.primary:active { background: var(--rose-strong); }

.btn.secondary { background: var(--plum-surface-2); color: var(--cream); }

.btn.ghost { background: transparent; color: var(--rose); border: 1px solid var(--rose); }

.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.btn.small { width: auto; padding: 8px 14px; font-size: 12.5px; margin: 0; }

.error { color: var(--danger); font-size: 13px; margin-top: 4px; }

.settings-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.settings-header h2 { margin: 0; }

/* ---------- Install banner ---------- */

.install-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--plum-surface-2);
  color: var(--cream);
  padding: 10px 14px;
  font-size: 12.5px;
}

.install-banner span#install-banner-text { flex: 1; line-height: 1.4; }
.install-banner .icon-btn { font-size: 16px; width: 26px; height: 26px; flex-shrink: 0; }

/* ---------- Main ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 22px 10px;
}

.pill-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-pill {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  border: 1px solid rgba(217,163,91,0.4);
  padding: 4px 10px;
  border-radius: 999px;
}

.sync-status {
  font-size: 10.5px;
  color: var(--muted);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--cream);
  font-size: 20px;
  width: 34px;
  height: 34px;
  line-height: 1;
  border-radius: 50%;
}
.icon-btn:active { background: var(--plum-surface); }

.status-card {
  margin: 10px 20px 22px;
  background: linear-gradient(155deg, var(--plum-surface), var(--plum-surface-2));
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  border: 1px solid rgba(232,180,179,0.15);
}

.status-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.status-label {
  font-family: var(--serif);
  font-size: 22px;
}

.status-day {
  font-size: 13px;
  color: var(--muted);
}

.status-detail {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--cream-dim);
  line-height: 1.5;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  margin-bottom: 6px;
}

.cal-nav h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 18px;
  margin: 0;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 16px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  margin-bottom: 4px;
}

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

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-size: 13px;
  color: var(--cream);
  background: transparent;
  border: none;
  position: relative;
  gap: 3px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform .12s ease;
}

.cal-day.pressing { transform: scale(0.92); background: var(--plum-surface-2); }

.cal-day.empty { visibility: hidden; }
.cal-day.other-month { color: rgba(247,239,228,0.25); }

.cal-day .num { line-height: 1; }

.cal-day .marks { display: flex; gap: 2px; height: 4px; }
.cal-day .marks i { width: 4px; height: 4px; border-radius: 50%; display: block; }

.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--cream); }

.cal-day.is-period { background: var(--rose-strong); color: var(--plum-deep); font-weight: 600; }
.cal-day.is-predicted-period { box-shadow: inset 0 0 0 1.5px var(--rose); }
.cal-day.is-fertile { background: rgba(217,163,91,0.28); }
.cal-day.is-ovulation { background: var(--gold); color: var(--plum-deep); font-weight: 700; }
.cal-day.is-fertile.is-ovulation { background: var(--gold); }

.cal-day:not(.empty):active { background: var(--plum-surface-2); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 18px 20px 4px;
  font-size: 11.5px;
  color: var(--muted);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.period { background: var(--rose-strong); }
.dot.fertile { background: rgba(217,163,91,0.55); }
.dot.ovulation { background: var(--gold); }
.dot.predicted { border: 1.5px solid var(--rose); }

.tracker-hint {
  margin: 16px 20px 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

.history-card {
  margin: 26px 20px 0;
  padding-top: 18px;
  border-top: 1px solid rgba(247,239,228,0.1);
}

.history-card h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 16px;
  color: var(--rose);
  margin: 0 0 10px;
}

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

.history-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--cream-dim);
  padding: 8px 12px;
  background: var(--plum-surface);
  border-radius: var(--radius-sm);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--cream);
  color: var(--plum-deep);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 50;
}

@media (min-width: 520px) {
  #app { border-left: 1px solid rgba(247,239,228,0.06); border-right: 1px solid rgba(247,239,228,0.06); }
}

/* ---------- Cal day log marker ---------- */

.cal-day .marks i { background: currentColor; opacity: 0.55; }

/* ---------- Cycle insights ---------- */

.insight-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 70px;
  margin: 4px 2px 18px;
}

.insight-bar {
  flex: 1;
  min-width: 0;
  background: var(--rose-strong);
  border-radius: 6px 6px 2px 2px;
  position: relative;
}

.insight-bar span {
  position: absolute;
  left: 0;
  right: 0;
  top: -18px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

/* ---------- Toggle field (reminders) ---------- */

.toggle-field {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-field span { color: var(--cream); font-size: 14px; }

#reminders-toggle {
  width: 20px;
  height: 20px;
  accent-color: var(--rose);
  flex-shrink: 0;
}

/* ---------- Toast action button ---------- */

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast-action {
  background: none;
  border: none;
  color: var(--rose-strong);
  font-weight: 700;
  font-size: 13px;
  padding: 4px 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* ---------- Day detail modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,12,19,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--plum-surface);
  border-radius: 20px 20px 0 0;
  padding: 22px 22px 28px;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.4);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.modal-header h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 18px;
  margin: 0;
  color: var(--cream);
}

#day-detail-period-toggle { margin-bottom: 20px; }

.period-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.period-actions .btn { margin-bottom: 0; }

.period-actions .btn.active {
  background: var(--rose-strong);
  border-color: var(--rose-strong);
  color: var(--plum-deep);
}

.small-hint {
  font-size: 12px;
  margin: 0 0 18px;
  color: var(--gold);
}

.segmented {
  display: flex;
  gap: 6px;
}

.segmented button {
  flex: 1;
  background: var(--plum-surface-2);
  border: 1px solid rgba(247,239,228,0.12);
  color: var(--cream-dim);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  font-size: 12.5px;
}

.segmented button.active {
  background: var(--rose-strong);
  border-color: var(--rose-strong);
  color: var(--plum-deep);
  font-weight: 700;
}

.segmented button:disabled, .chip:disabled { opacity: 0.55; }

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--plum-surface-2);
  border: 1px solid rgba(247,239,228,0.12);
  color: var(--cream-dim);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12.5px;
}

.chip.active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--plum-deep);
  font-weight: 700;
}

