:root {
  --bg: #fff7f9; --card: #fff; --text: #2b2230; --muted: #7d6f80; --line: #f0dde4;
  --pink: #e2557a; --pink-soft: #fde3ea; --red: #d93a4f; --red-soft: #fbd5da;
  --teal: #12a594; --teal-soft: #d4f3ee; --teal-mid: #8fdccf; --amber: #c98a00;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131a; --card: #221c26; --text: #f3e9f1; --muted: #a596a8; --line: #3a2f3f;
    --pink-soft: #4a2333; --red-soft: #4d2229; --teal-soft: #173b37; --teal-mid: #1f6f64;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--red); min-height: 1.2em; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }

header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px; background: var(--bg); }
main { padding: 0 14px calc(90px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
nav button { flex: 1; border: 0; background: none; color: var(--muted); font-size: 0.72rem; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav button span { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
nav button.active { color: var(--pink); font-weight: 600; }
nav button.active span { filter: none; opacity: 1; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; padding: 11px 16px; font-size: 0.95rem; cursor: pointer; }
.btn.primary { background: var(--pink); border-color: var(--pink); color: #fff; font-weight: 600; }
.btn.small { padding: 7px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; font-size: 1.4rem; color: var(--muted); cursor: pointer; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }

/* login */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box .logo { font-size: 3rem; }
.login-box form { display: grid; gap: 10px; margin-top: 16px; }

/* hero */
.hero { text-align: center; padding: 22px 16px; }
.hero .ring { width: 160px; height: 160px; margin: 0 auto 10px; position: relative; }
.hero .ring svg { transform: rotate(-90deg); }
.hero .ring .center { position: absolute; inset: 0; display: grid; place-content: center; }
.hero .big { font-size: 2.2rem; font-weight: 700; line-height: 1; }
.hero .phase { font-weight: 600; font-size: 1.1rem; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .8rem; font-weight: 600; }
.pill.period { background: var(--red-soft); color: var(--red); }
.pill.fertile, .pill.peak { background: var(--teal-soft); color: var(--teal); }
.pill.late { background: #fff1c9; color: var(--amber); }
.pill.neutral { background: var(--pink-soft); color: var(--pink); }

.rows { display: grid; gap: 10px; }
.row { display: flex; gap: 12px; align-items: flex-start; }
.row .ico { font-size: 1.4rem; width: 32px; text-align: center; }
.row .label { font-size: .82rem; color: var(--muted); }
.row .value { font-weight: 600; }
.row .sub { font-size: .85rem; color: var(--muted); }

.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--teal-soft); margin-bottom: 8px; }
.alert.warn { background: #fff1c9; color: #6b4a00; }
.alert.info { background: var(--pink-soft); }
@media (prefers-color-scheme: dark) { .alert.warn { background: #3d3214; color: #f5d98a; } }
.alert b { display: block; }

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick .btn { padding: 12px 4px; font-size: .85rem; }
.quick .btn.on { background: var(--pink-soft); border-color: var(--pink); }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { text-align: center; font-size: .75rem; color: var(--muted); padding: 4px 0; }
.cell { aspect-ratio: 1; border-radius: 12px; border: 0; background: var(--card); color: var(--text); position: relative; font: inherit; font-size: .95rem; padding: 0; cursor: pointer; }
.cell.other { opacity: .35; }
.cell.flow { background: var(--red); color: #fff; font-weight: 700; }
.cell.pred-period { background: var(--red-soft); box-shadow: inset 0 0 0 1.5px var(--red); }
.cell.fertile { background: var(--teal-soft); }
.cell.peak { background: var(--teal-mid); font-weight: 700; }
.cell.today { outline: 2.5px solid var(--pink); outline-offset: -2.5px; }
.cell .marks { position: absolute; bottom: 2px; left: 0; right: 0; font-size: .6rem; line-height: 1; letter-spacing: -1px; }
.cell .ov { position: absolute; top: 1px; right: 3px; font-size: .65rem; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: .78rem; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; }

/* cycles */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
td, th { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 1.3rem; }
.stats span { font-size: .75rem; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; margin-top: 8px; }
.bars div { flex: 1; background: var(--pink); border-radius: 6px 6px 0 0; position: relative; min-width: 8px; }
.bars div.bad { background: var(--muted); opacity: .4; }
.bars div span { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: .7rem; color: var(--muted); }

/* dialog */
dialog { border: 0; border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); width: 100%; max-width: 560px;
  margin: auto auto 0; background: var(--card); color: var(--text); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
#day-form { display: grid; gap: 12px; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggle { display: block; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { display: block; text-align: center; padding: 14px 8px; border-radius: 12px; border: 1.5px solid var(--line); font-weight: 600; }
.toggle.flow input:checked + span { background: var(--red-soft); border-color: var(--red); }
.toggle.sex input:checked + span { background: var(--pink-soft); border-color: var(--pink); }
.field { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.field input, .field select, .field textarea { color: var(--text); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--bg); color: var(--text); padding: 9px 2px; font: inherit; font-size: .85rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--pink); color: #fff; font-weight: 600; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.actions .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: .9rem; z-index: 20; max-width: 90vw; }
.stack { display: grid; gap: 10px; }
.hint { font-size: .85rem; color: var(--muted); }
