:root {
  --bg: #faf6f4;
  --card: #ffffff;
  --ink: #2a2024;
  --muted: #7a6c71;
  --line: #ece2e4;
  --soft: #f4ecee;
  --accent: #7a1f3d;
  --accent-ink: #ffffff;
  --p: 184 46 88;            /* period colour as r g b */
  --f: 42 140 131;           /* fertile colour */
  --mind: #7b5cc4;
  --body: #d0742a;
  --sign: #2a8c83;
  --danger: #b3261e;
  --ok: #2e7d32;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(60 20 35 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161113;
    --card: #211a1d;
    --ink: #f3eaed;
    --muted: #a6979c;
    --line: #362b30;
    --soft: #2b2226;
    --accent: #e0789a;
    --accent-ink: #1a0f13;
    --p: 226 98 132;
    --f: 79 186 174;
    --mind: #a68bf0;
    --body: #f0a05c;
    --sign: #5cc3b8;
    --danger: #ff8a80;
    --ok: #81c784;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* ---------- lock screen ---------- */
.lock { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.lock-card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.lock-logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 4px; display: block; }
.lock h1 { text-align: center; font-size: 26px; }
.lock p { margin: 0; text-align: center; }

.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(var(--p) / .18); }
.pw-row { position: relative; }
.pw-row .input { padding-right: 64px; }
.pw-row .peek { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); font-size: 13px; padding: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: .55; }
.btn.secondary { background: var(--soft); color: var(--ink); }
.btn.ghost { background: none; color: var(--accent); padding: 8px 10px; }
.btn.danger { background: none; color: var(--danger); border: 1px solid currentColor; }
.btn.block { width: 100%; }
.error { color: var(--danger); font-size: 14px; text-align: center; min-height: 1em; }

/* ---------- app shell ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 0 8px;
}
.top-row { display: flex; align-items: center; gap: 8px; }
.people { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.person {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px 6px 8px; display: flex; align-items: center; gap: 7px; white-space: nowrap; font-weight: 600; font-size: 15px;
}
.person[aria-pressed="true"] { border-color: var(--ink); }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 10px; color: var(--ink); display: grid; place-items: center; }
.icon-btn:active { background: var(--soft); }
.sync { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.sync.saving { background: #e0a100; }
.sync.offline { background: var(--muted); }
.sync.error { background: var(--danger); }
.sync-label { font-size: 12px; color: var(--muted); }

main { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px max(8px, env(safe-area-inset-bottom));
}
.nav-inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 1.2fr 1fr; align-items: center; }
.nav button { border: 0; background: none; display: grid; justify-items: center; gap: 2px; font-size: 12px; color: var(--muted); padding: 4px; }
.nav button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav .log-btn { background: var(--accent); color: var(--accent-ink); border-radius: 14px; padding: 9px 6px; font-weight: 600; font-size: 13px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; }
.stack { display: grid; gap: 14px; }

/* ---------- status ---------- */
.status { display: grid; gap: 10px; }
.status-big { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.status-lines { display: grid; gap: 6px; }
.status-line { display: flex; gap: 10px; align-items: baseline; font-size: 15px; }
.status-line .k { width: 10px; height: 10px; border-radius: 50%; flex: none; transform: translateY(1px); }
.k.period { background: rgb(var(--p)); }
.k.fertile { background: rgb(var(--f) / .55); }
.k.ov { background: rgb(var(--f)); }
.note { font-size: 13px; color: var(--muted); background: var(--soft); border-radius: 10px; padding: 8px 10px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 4px 0 8px; }
.cal-title { font-size: 19px; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; touch-action: pan-y; }
.dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 2px; }
.day {
  position: relative; aspect-ratio: 1 / 1.08; border: 0; border-radius: 12px;
  background: var(--card); padding: 0; display: grid; grid-template-rows: 1fr auto; justify-items: center;
  font-size: 15px; font-weight: 500;
}
.day .num { align-self: center; margin-top: 3px; position: relative; z-index: 1; }
.day.out { opacity: .38; }
.day.future { color: var(--muted); }
.day.fertile { background: rgb(var(--f) / .16); }
.day.pred::after {
  content: ""; position: absolute; inset: 2px; border-radius: 10px;
  border: 2px dashed rgb(var(--p) / .7); pointer-events: none;
}
.day.predr::after {
  content: ""; position: absolute; inset: 4px; border-radius: 9px;
  border: 1.5px dotted rgb(var(--p) / .45); pointer-events: none;
}
.lg.predr { border: 1.5px dotted rgb(var(--p) / .55); }
ul.changes { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
ul.changes li.gp::marker { color: var(--danger); }
.gp-tag { display: inline-block; margin-left: 6px; font-size: 12px; font-weight: 600; color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--card)); border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
.day.f1::before { content: ""; position: absolute; top: 5px; left: 5px; width: 8px; height: 8px; border-radius: 50% 0 50% 50%; transform: rotate(-45deg); background: rgb(var(--p)); }
.day.f2 { background: rgb(var(--p) / .26); }
.day.f3 { background: rgb(var(--p) / .5); }
.day.f4 { background: rgb(var(--p) / .78); color: #fff; }
.day.f5 { background: rgb(var(--p)); color: #fff; }
.day.today { box-shadow: inset 0 0 0 2px var(--ink); font-weight: 800; }
.day.selected { outline: 3px solid var(--accent); outline-offset: 1px; }
.ovmark {
  position: absolute; top: 4px; right: 4px; width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid rgb(var(--f)); background: transparent;
}
.ovmark.likely, .ovmark.confirmed { background: rgb(var(--f)); }
.ovmark.confirmed { box-shadow: 0 0 0 2px var(--card); }
.dots { display: flex; gap: 3px; height: 9px; margin-bottom: 5px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }
.dots .mind { background: var(--mind); }
.dots .body { background: var(--body); }
.dots .sign { background: var(--sign); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 14px; border-radius: 4px; display: inline-block; position: relative; }
.lg.period { background: rgb(var(--p) / .6); }
.lg.pred { border: 2px dashed rgb(var(--p) / .7); }
.lg.fertile { background: rgb(var(--f) / .2); }
.lg.ov { border-radius: 50%; width: 10px; height: 10px; background: rgb(var(--f)); }
.lg.ove { border-radius: 50%; width: 10px; height: 10px; border: 2px solid rgb(var(--f)); }
.lg.dot { width: 7px; height: 7px; border-radius: 50%; }
.cal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- sheet (day editor, dialogs) ---------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 94dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
@media (min-width: 600px) { .scrim { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head {
  position: sticky; top: 0; background: var(--bg); z-index: 2;
  display: flex; align-items: center; gap: 4px; padding: 12px 0 8px; border-bottom: 1px solid var(--line); margin-bottom: 12px;
}
.sheet-head .title { flex: 1; text-align: center; }
.sheet-head .title b { display: block; font-size: 17px; }
.sheet-head .title span { font-size: 13px; color: var(--muted); }
.saved { font-size: 12px; color: var(--ok); text-align: center; height: 16px; margin-top: -6px; }

.section { display: grid; gap: 10px; margin-bottom: 18px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg.five { grid-template-columns: repeat(5, 1fr); }
.seg button, .chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 6px;
  font-size: 14px; font-weight: 500; position: relative;
}
.seg button[aria-pressed="true"] { border-color: transparent; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg.flow button[aria-pressed="true"] { background: rgb(var(--p)); color: #fff; }
.seg.flow button .bar { display: block; height: 4px; border-radius: 2px; margin: 5px auto 0; background: rgb(var(--p)); }
.seg.flow button[aria-pressed="true"] .bar { background: #fff; }
.seg .sub { display: block; font-size: 11px; opacity: .8; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 8px 11px; border-radius: 999px; display: inline-flex; gap: 6px; align-items: center; }
.chip .pips { display: inline-flex; gap: 2px; }
.chip .pips i { width: 5px; height: 12px; border-radius: 2px; background: currentColor; opacity: .25; display: block; }
.chip .pips i.on { opacity: 1; }
.chip.on.mind { background: color-mix(in srgb, var(--mind) 16%, var(--card)); border-color: var(--mind); }
.chip.on.body { background: color-mix(in srgb, var(--body) 16%, var(--card)); border-color: var(--body); }
.chip.on.plain { background: var(--soft); border-color: var(--ink); }
.chip.add { border-style: dashed; color: var(--muted); }

.period-q { background: var(--soft); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
textarea.input { min-height: 80px; resize: vertical; }
details.more { border-top: 1px solid var(--line); padding-top: 12px; margin-bottom: 18px; }
details.more summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.more summary::after { content: "Show"; color: var(--accent); font-weight: 500; font-size: 14px; }
details.more[open] summary::after { content: "Hide"; }
details.more[open] summary { margin-bottom: 12px; }

/* ---------- insights ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile .v { font-size: 22px; font-weight: 700; }
.tile .l { font-size: 13px; color: var(--muted); }
.strip { display: grid; gap: 5px; }
.strip-row { display: grid; grid-template-columns: 54px 1fr; gap: 8px; align-items: center; }
.strip-label { font-size: 12px; color: var(--muted); line-height: 1.15; }
.strip-label b { color: var(--ink); font-size: 13px; }
.strip-cells { display: grid; gap: 1px; height: 18px; }
.strip-cells i { display: block; background: var(--soft); border-radius: 2px; position: relative; }
.strip-cells i.f1 { background: rgb(var(--p) / .25); }
.strip-cells i.f2 { background: rgb(var(--p) / .4); }
.strip-cells i.f3 { background: rgb(var(--p) / .62); }
.strip-cells i.f4 { background: rgb(var(--p) / .82); }
.strip-cells i.f5 { background: rgb(var(--p)); }
.strip-cells i.ov { background: rgb(var(--f)); }
.strip-cells i.hl::after { content: ""; position: absolute; left: 0; right: 0; bottom: -4px; height: 3px; border-radius: 2px; background: var(--body); }
.strip-cells i.hl.mindhl::after { background: var(--mind); }
.strip-axis { display: grid; grid-template-columns: 54px 1fr; gap: 8px; font-size: 11px; color: var(--muted); }
.strip-axis div:last-child { display: flex; justify-content: space-between; }

.heat { display: grid; gap: 3px; overflow-x: auto; }
.heat-row { display: grid; grid-template-columns: 96px repeat(15, minmax(13px, 1fr)); gap: 2px; align-items: center; }
.heat-row .lab { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 4px; }
.heat-row i { display: block; height: 18px; border-radius: 3px; background: var(--soft); }
.heat-row.axis span { font-size: 10.5px; color: var(--muted); text-align: center; }
.heat-row.axis span.zero { color: rgb(var(--p)); font-weight: 700; }

table.hist { width: 100%; border-collapse: collapse; font-size: 14px; }
table.hist th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 4px 6px; }
table.hist td { padding: 7px 4px; border-top: 1px solid var(--line); }

/* ---------- settings ---------- */
.list { display: grid; gap: 0; }
.list > * { padding: 12px 0; border-top: 1px solid var(--line); }
.list > *:first-child { border-top: 0; }
.colours { display: flex; gap: 8px; }
.colours button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.colours button[aria-pressed="true"] { border-color: var(--ink); }
.num-input { width: 80px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; font-size: 14px;
  max-width: calc(100% - 32px);
}
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; display: inline-block; animation: spin .8s linear infinite; vertical-align: -4px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
