:root {
  --bg: #fdf3f1;
  --bg-2: #fbe6e6;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #fffaf8;
  --border: rgba(201, 86, 106, 0.14);
  --text: #4a2a36;
  --muted: #9a7480;
  --rose-light: #f6a9b2;
  --rose: #e47c8c;
  --rose-deep: #c9566a;
  --rose-wash: #fde0e3;
  --lav: #a98fdc;
  --lav-wash: #ece4fb;
  --gold: #e7a94b;
  --track: #f5dcdc;
  --blob1: #ffd0d6;
  --blob2: #ffe2cf;
  --blob3: #eadcff;
  --shadow: 0 10px 30px rgba(166, 70, 90, 0.12), 0 2px 6px rgba(166, 70, 90, 0.06);
  --blossom-center: #fff3f0;
  --radius: 22px;
  --spring: cubic-bezier(.2, 1.25, .35, 1);
  --ease: cubic-bezier(.22, .8, .25, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #22141b;
    --bg-2: #2d1922;
    --surface: rgba(62, 36, 48, 0.62);
    --surface-solid: #34202a;
    --border: rgba(246, 169, 178, 0.14);
    --text: #fbe9ec;
    --muted: #c49aa6;
    --rose-light: #f7b2bb;
    --rose: #ee8d9c;
    --rose-deep: #d8667a;
    --rose-wash: rgba(238, 141, 156, 0.18);
    --lav: #bca5ee;
    --lav-wash: rgba(188, 165, 238, 0.18);
    --track: rgba(246, 169, 178, 0.14);
    --blob1: #6a2a3d;
    --blob2: #5a2f2a;
    --blob3: #3d2a5e;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --blossom-center: #34202a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; margin: 0; }

/* ---------- Ambient background ---------- */
.ambient { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .85; animation: drift 18s ease-in-out infinite alternate; }
.b1 { width: 60vmax; height: 60vmax; background: var(--blob1); top: -20vmax; left: -15vmax; }
.b2 { width: 50vmax; height: 50vmax; background: var(--blob2); bottom: -18vmax; right: -18vmax; animation-duration: 22s; animation-delay: -6s; }
.b3 { width: 38vmax; height: 38vmax; background: var(--blob3); top: 40%; left: 45%; animation-duration: 26s; animation-delay: -12s; opacity: .6; }
@keyframes drift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(6vmax, 4vmax) scale(1.08); }
  100% { transform: translate(-4vmax, 7vmax) scale(.95); }
}
.petals { position: absolute; inset: 0; transition: opacity .8s; }
.petal {
  position: absolute; top: -40px; width: 14px; height: 18px;
  background: linear-gradient(135deg, var(--rose-light), var(--rose));
  border-radius: 80% 0 80% 0; opacity: .55;
  animation: fall linear infinite;
}
@keyframes fall {
  0% { transform: translate3d(0, -40px, 0) rotate(0deg); }
  50% { transform: translate3d(var(--sway), 50vh, 0) rotate(200deg); }
  100% { transform: translate3d(0, 110vh, 0) rotate(400deg); }
}
body.in-app .petals { opacity: 0; }

/* ---------- Splash ---------- */
.splash { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; transition: opacity .4s; }
.splash.out { opacity: 0; pointer-events: none; }
.logo { width: 64px; height: 64px; color: var(--rose); }
.pulse { animation: heartbeat 1.2s ease-in-out infinite; }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }

/* ---------- Screens ---------- */
.screen { position: relative; z-index: 1; min-height: 100dvh; }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); }
.login-card {
  width: min(100%, 380px);
  background: var(--surface);
  -webkit-backdrop-filter: blur(24px) saturate(140%); backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--border); border-radius: 30px;
  padding: 36px 26px 28px; box-shadow: var(--shadow);
  text-align: center;
  animation: rise .9s var(--spring) both;
}
.login-card .logo { margin: 0 auto 6px; width: 72px; height: 72px; animation: bloom 1.4s var(--spring) .15s both, spin 30s linear 1.6s infinite; }
@keyframes bloom { from { transform: scale(.2) rotate(-90deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
.login-card h1 { font-size: 40px; letter-spacing: -.5px; animation: rise .8s var(--ease) .25s both; }
.tagline { margin: 4px 0 26px; color: var(--muted); animation: rise .8s var(--ease) .35s both; }
.login-card .field { animation: rise .8s var(--ease) both; }
.login-card .field:nth-of-type(1) { animation-delay: .45s; }
.login-card .field:nth-of-type(2) { animation-delay: .55s; }
.login-card .btn { animation: rise .8s var(--ease) .65s both; }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.login-card.shake { animation: shake .5s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); }
}
.login-card.leaving { animation: leave .55s var(--ease) both; }
@keyframes leave { to { opacity: 0; transform: scale(.92) translateY(-10px); filter: blur(6px); } }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 6px 4px; letter-spacing: .3px; }
.field input, .sheet input[type=date] {
  width: 100%; height: 50px; padding: 0 16px;
  font-size: 16px; /* prevents iOS zoom */
  background: var(--surface-solid); border: 1.5px solid var(--border); border-radius: 16px;
  outline: none; transition: border-color .2s, box-shadow .25s;
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .sheet input[type=date]:focus { border-color: var(--rose); box-shadow: 0 0 0 4px var(--rose-wash); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 50px; }
.pw-toggle { position: absolute; right: 6px; top: 6px; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.pw-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.pw-toggle.on { color: var(--rose-deep); }
.login-error { min-height: 20px; margin: 0 0 10px; color: var(--rose-deep); font-weight: 700; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  position: relative; overflow: hidden;
  width: 100%; height: 54px; border-radius: 18px;
  font-weight: 800; font-size: 17px; letter-spacing: .2px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .2s var(--spring), box-shadow .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { color: #fff; background: linear-gradient(135deg, var(--rose-light), var(--rose-deep)); box-shadow: 0 10px 24px rgba(201, 86, 106, .35); }
.btn.soft { background: var(--rose-wash); color: var(--rose-deep); }
.btn.ghost { background: transparent; color: var(--muted); height: 46px; }
.btn.danger { background: transparent; color: #c0394f; height: 46px; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.shimmer::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .45) 50%, transparent 70%);
  transform: translateX(-120%); animation: shimmer 3.2s ease-in-out 1.6s infinite;
}
@keyframes shimmer { 0%, 60% { transform: translateX(-120%); } 100% { transform: translateX(120%); } }
.heart-loader { display: none; width: 18px; height: 18px; background: #fff; transform: rotate(45deg); animation: hb 0.9s ease-in-out infinite; position: relative; }
.heart-loader::before, .heart-loader::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; }
.heart-loader::before { left: -9px; } .heart-loader::after { top: -9px; }
@keyframes hb { 0%, 100% { transform: rotate(45deg) scale(.7); } 50% { transform: rotate(45deg) scale(.9); } }
.btn.loading .label { display: none; }
.btn.loading .heart-loader { display: block; }
.ripple { position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .5); transform: scale(0); animation: ripple .6s ease-out forwards; pointer-events: none; }
@keyframes ripple { to { transform: scale(4); opacity: 0; } }

.icon-btn { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--rose-deep); transition: transform .2s var(--spring); }
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- App shell ---------- */
.app { padding: calc(14px + var(--safe-top)) 18px calc(96px + var(--safe-bottom)); max-width: 520px; margin: 0 auto; animation: appIn .7s var(--ease) both; }
@keyframes appIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.greet { margin: 0; line-height: 1.15; font-family: 'Fraunces', serif; font-size: 26px; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.chip { white-space: nowrap; font-size: 12px; font-weight: 800; padding: 6px 10px; border-radius: 99px; background: var(--lav-wash); color: var(--lav); }

.view { animation: viewIn .5s var(--ease) both; }
.view.from-left { animation-name: viewInL; }
@keyframes viewIn { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes viewInL { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }

/* ---------- Ring ---------- */
.ring-wrap { position: relative; width: min(86vw, 320px); aspect-ratio: 1; margin: 8px auto 14px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring circle { fill: none; }
.ring-track { stroke: var(--track); stroke-width: 22; }
.ring-seg { stroke-width: 22; stroke-linecap: round; opacity: 0; animation: segIn .8s var(--ease) forwards; }
.ring-seg.period { stroke: var(--rose-light); stroke-opacity: .45; }
.ring-seg.fertile { stroke: var(--lav); stroke-opacity: .35; }
@keyframes segIn { to { opacity: 1; } }
.ring-progress { stroke: url(#gradRose); stroke-width: 22; stroke-linecap: round; transition: stroke-dashoffset 1.6s var(--ease); }
#ringDotG { transform-origin: 150px 150px; transition: transform 1.6s var(--ease); }
.ring-dot { fill: #fff; stroke: var(--rose-deep); stroke-width: 5; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.ring-kicker { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); }
.ring-big { margin: 0; font-family: 'Fraunces', serif; font-size: 68px; line-height: 1.05; font-weight: 600; color: var(--rose-deep); }
.ring-big.small { font-size: 34px; line-height: 1.2; }
.ring-phase { margin: 2px 0 0; font-weight: 800; font-size: 15px; color: var(--text); }
.ring-phase .pill { display: inline-block; padding: 4px 12px; border-radius: 99px; background: var(--rose-wash); color: var(--rose-deep); }
.ring-phase .pill.Fertile, .ring-phase .pill.Ovulation { background: var(--lav-wash); color: var(--lav); }
.ring-phase .pill.Late { background: #fff0d9; color: #b77a1d; }
.ring.breathe { animation: breathe 5s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: rotate(-90deg) scale(1); } 50% { transform: rotate(-90deg) scale(1.025); } }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  animation: rise .7s var(--ease) both;
}
.card.wide { grid-column: 1 / -1; }
.card .k { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.card .k i { width: 8px; height: 8px; border-radius: 50%; background: var(--rose); display: inline-block; }
.card .k i.lav { background: var(--lav); }
.card .k i.gold { background: var(--gold); }
.card .v { margin: 6px 0 0; font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; }
.card .s { margin: 2px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.actions { display: grid; gap: 10px; animation: rise .7s var(--ease) .3s both; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 14px; }
.cal-head h2 { font-size: 24px; }
.cal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 10px 10px; box-shadow: var(--shadow); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 6px; }
.cal-viewport { overflow: hidden; touch-action: pan-y; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid.slide-l { animation: calL .38s var(--ease); }
.cal-grid.slide-r { animation: calR .38s var(--ease); }
@keyframes calL { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
@keyframes calR { from { opacity: 0; transform: translateX(-40px); } to { opacity: 1; transform: none; } }
.day {
  position: relative; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  transition: transform .2s var(--spring), background .3s;
}
.day:active { transform: scale(.88); }
.day.out { opacity: .28; }
.day.period { background: linear-gradient(135deg, var(--rose-light), var(--rose-deep)); color: #fff; }
.day.period-est { background: var(--rose-wash); color: var(--rose-deep); border: 2px dashed var(--rose); }
.day.predicted { border: 2px dashed var(--rose-light); color: var(--rose-deep); }
.day.fertile { background: var(--lav-wash); color: var(--lav); }
.day.ovulation { background: var(--lav); color: #fff; }
.day.ovulation::after { content: '★'; position: absolute; top: -3px; right: -1px; font-size: 11px; color: var(--gold); }
.day.today { box-shadow: 0 0 0 2.5px var(--text) inset; }
.day.period.today, .day.ovulation.today { box-shadow: 0 0 0 2.5px var(--surface-solid) inset, 0 0 0 2px var(--text); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin: 16px 0 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.lg.period { background: linear-gradient(135deg, var(--rose-light), var(--rose-deep)); }
.lg.predicted { border: 2px dashed var(--rose-light); }
.lg.fertile { background: var(--lav-wash); border: 1px solid var(--lav); }
.lg.ovulation { background: var(--lav); }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0; }

/* ---------- History ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 20px; }
.stat { text-align: center; padding: 16px 8px; }
.stat .v { font-size: 32px; color: var(--rose-deep); margin: 0; }
.stat .s { font-size: 12px; margin-top: 2px; }
.section-title { font-size: 19px; margin: 6px 4px 10px; }
.history { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 10px; }
.history li {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 14px 14px 14px 16px;
  animation: rise .6s var(--ease) both;
}
.history .drop { width: 38px; height: 38px; flex: none; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: linear-gradient(135deg, var(--rose-light), var(--rose-deep)); }
.history .info { flex: 1; min-width: 0; }
.history .t { margin: 0; font-weight: 800; }
.history .m { margin: 2px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.history .edit { color: var(--rose-deep); font-weight: 800; font-size: 14px; padding: 8px 10px; border-radius: 12px; background: var(--rose-wash); }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.settings-card .hint { text-align: left; margin: -4px 4px 12px; }
.stepper-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--rose-wash); border-radius: 14px; padding: 4px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; font-size: 20px; font-weight: 800; color: var(--rose-deep); }
.stepper button:active { background: var(--surface-solid); }
.stepper output { min-width: 34px; text-align: center; font-weight: 800; }
body.viewer .owner-only { display: none !important; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; z-index: 3; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + var(--safe-bottom)); width: min(calc(100% - 28px), 420px);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); -webkit-backdrop-filter: blur(24px) saturate(150%); backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid var(--border); border-radius: 26px; padding: 6px; box-shadow: var(--shadow);
}
.tab-indicator { position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc((100% - 12px) / 3); border-radius: 20px; background: var(--rose-wash); transition: transform .45s var(--spring); }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 12px; font-weight: 800; color: var(--muted); transition: color .3s; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .35s var(--spring); }
.tab.active { color: var(--rose-deep); }
.tab.active svg { transform: translateY(-1px) scale(1.1); }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 8; background: rgba(60, 20, 35, .35); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fadeIn .3s both; }
.sheet-backdrop.closing { animation: fadeOut .25s both; }
@keyframes fadeIn { from { opacity: 0; } } @keyframes fadeOut { to { opacity: 0; } }
.sheet {
  position: fixed; z-index: 9; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 520px;
  background: var(--surface-solid); border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom)); box-shadow: 0 -10px 40px rgba(80, 20, 40, .2);
  animation: sheetUp .5s var(--spring) both;
}
.sheet.closing { animation: sheetDown .28s var(--ease) both; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheetDown { to { transform: translateY(100%); } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; background: var(--track); }
.sheet h3 { font-size: 22px; margin: 0 0 4px; }
.sheet p.s { margin: 0 0 16px; color: var(--muted); font-weight: 600; }
.sheet .field { margin-bottom: 16px; }
.sheet .btns { display: grid; gap: 8px; margin-top: 6px; }
.sheet .err { color: var(--rose-deep); font-weight: 700; min-height: 18px; margin: 0 0 6px; font-size: 14px; }

/* ---------- Toast + burst ---------- */
.toast {
  position: fixed; z-index: 10; left: 50%; top: calc(14px + var(--safe-top));
  transform: translate(-50%, -150%); background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 16px; font-weight: 700; font-size: 14px;
  transition: transform .45s var(--spring), opacity .3s; max-width: calc(100% - 32px); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.burst { position: fixed; z-index: 11; pointer-events: none; width: 14px; height: 14px; color: var(--rose); animation: burst 1s var(--ease) forwards; }
@keyframes burst { 0% { transform: translate(0, 0) scale(.4); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(var(--rot)); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .petals, .blob { display: none; }
}
