:root {
  --bg: #f5f3fa; --card: #ffffff; --ink: #1d1a2b; --muted: #6c6782; --line: #e3dfee;
  --accent: #6b4fc8; --accent-ink: #ffffff; --bar: #241b46; --bar-ink: #f4f1ff;
  --rose: #c2366b; --rose-bg: #fde7ef; --good: #237a4b; --good-bg: #e1f4e8; --warn: #8a5a00; --warn-bg: #fff1d1;
  --grey-bg: #ece9f3; --gold: #b7791f; --sleep: #7d8fd6; --sleep-short: #e0a24c;
  --foll: #d9f0e3; --ovu: #fff0bf; --lut: #ece3fb; --pre: #e3e6f3;
  --radius: 16px; --shadow: 0 1px 3px rgba(30,20,60,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110e1c; --card: #1b1729; --ink: #ece9f6; --muted: #a29cba; --line: #2c2740;
    --accent: #a993ff; --accent-ink: #160f2c; --bar: #0b0815; --bar-ink: #ece9f6;
    --rose: #ff86b0; --rose-bg: #3d1627; --good: #85d6a2; --good-bg: #15301f; --warn: #f2c063; --warn-bg: #3a2c0d;
    --grey-bg: #262137; --gold: #f0c36a; --sleep: #7d8fd6; --sleep-short: #e0a24c;
    --foll: #173226; --ovu: #3a3214; --lut: #2b2340; --pre: #222638; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.center { text-align: center; padding: 40px 16px; }
.center-text { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok { color: var(--good); font-weight: 600; }
[hidden] { display: none !important; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
code { font-size: 13px; background: var(--grey-bg); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }

/* top bar and tabs */
.bar { position: sticky; top: 0; z-index: 10; background: var(--bar); color: var(--bar-ink);
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px; display: flex; align-items: center; gap: 4px; }
.bar h1 { font-size: 19px; margin: 0 8px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar button { background: transparent; border: 0; color: var(--bar-ink); padding: 6px 12px; font-size: 24px;
  border-radius: 10px; min-height: 42px; min-width: 42px; cursor: pointer; }
.bar button:disabled { opacity: .25; }
.wrap { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0 6px;
  font-size: 11px; color: var(--muted); text-decoration: none; }
.tabs a span { font-size: 21px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--accent); font-weight: 700; }
.tabs a.on span { filter: none; opacity: 1; }

/* login */
.login { max-width: 360px; margin: 10vh auto 0; padding: 0 16px; text-align: center; }
.login .logo { font-size: 56px; }
.login h1 { font-size: 28px; margin: 4px 0; }
.login form { text-align: left; margin-top: 14px; }

/* cards */
.card { display: block; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px; color: inherit; text-decoration: none; }
.card h2 { font-size: 15px; margin: 0 0 10px; font-weight: 700; }
.hero { background: linear-gradient(135deg, var(--card), var(--lut)); }
.hero-txt { display: flex; flex-direction: column; gap: 3px; }
.hero-txt b { font-size: 20px; }
.saved { color: var(--muted); min-height: 1em; }
.bday { background: linear-gradient(135deg, var(--warn-bg), var(--rose-bg)); }

/* inputs */
label.f, div.f { display: block; margin: 0 0 12px; }
label.f > span, .lbl { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px; }
.lbl b { color: var(--ink); }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; font-size: 16px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin: 8px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--card); border-radius: 12px; padding: 10px 14px; min-height: 46px; cursor: pointer; text-decoration: none; color: inherit; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(.97); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.btnrow .btn { flex: 1; }
.link { border: 0; background: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 2px 4px; }
.x { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 6px 8px; cursor: pointer; border-radius: 8px; }

/* scales and chips */
.scale { margin-bottom: 12px; }
.scale-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.sc { border: 1px solid var(--line); background: var(--card); border-radius: 12px; font-size: 26px; min-height: 52px; cursor: pointer; }
.sc.on { background: var(--lut); border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 2px 0 10px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chip.big { padding: 10px 14px; font-size: 15px; }
.moments { border-top: 1px solid var(--line); margin-top: 4px; }
.mo { display: grid; grid-template-columns: 132px 1fr auto; gap: 6px 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mo input[type=time] { min-height: 38px; padding: 4px 6px; }
.mo input[type=text] { grid-column: 1 / 3; min-height: 38px; font-size: 15px; }
.mo .x { grid-row: 1; grid-column: 3; }

/* sleep, movement */
.big-num { font-size: 26px; font-weight: 800; margin-bottom: 6px; }
.big-num span { font-weight: 400; }
.stagebar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; margin: 6px 0 4px; background: var(--grey-bg); }
.st-deep { background: #3d3a9e; } .st-rem { background: #8c6cf0; } .st-light { background: #a9c4f5; } .st-awake { background: #f0b36d; }
.vitals { margin: 10px 0 12px; font-size: 14px; }
.inline { max-width: 220px; }
.act { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.effort { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.effort select { width: auto; min-height: 36px; padding: 4px 8px; font-size: 14px; }
details.add { margin-top: 10px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; padding: 4px 0; }
.stars-mini { background: linear-gradient(135deg, var(--card), var(--lut)); }
.stars-mini b, .stars-mini span { display: block; }
.stars-mini span { margin-top: 3px; }

/* cycle */
.cyc-hero { display: flex; gap: 14px; align-items: center; background: linear-gradient(135deg, var(--card), var(--rose-bg)); }
.cyc-hero > div:last-child { display: flex; flex-direction: column; gap: 3px; }
.ring { width: 78px; height: 78px; flex: none; }
.ring-bg { fill: none; stroke: var(--grey-bg); stroke-width: 7; }
.ring-fg { fill: none; stroke: var(--rose); stroke-width: 7; stroke-linecap: round; }
.ring text { font-size: 20px; font-weight: 800; fill: var(--ink); }
.ring .ring-sub { font-size: 10px; font-weight: 500; fill: var(--muted); }
.calhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); }
.cal .day { position: relative; aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--grey-bg); font-size: 14px; cursor: pointer; padding: 0; }
.cal .day:disabled { opacity: .45; cursor: default; }
.cal .day.bleed { background: var(--rose); color: #fff; font-weight: 700; }
.cal .day.spot { box-shadow: inset 0 0 0 2px var(--rose); }
.cal .day.pred { background: var(--rose-bg); box-shadow: inset 0 0 0 2px var(--rose); opacity: 1; border: 0; }
.cal .day.ph-foll { background: var(--foll); }
.cal .day.ph-ovu { background: var(--ovu); }
.cal .day.ph-lut { background: var(--lut); }
.cal .day.ph-pre { background: var(--pre); }
.cal .day.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal .md { position: absolute; left: 50%; bottom: 4px; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; }
.md.m1 { background: #c0392b; } .md.m2 { background: #e67e22; } .md.m3 { background: #b9b4c9; } .md.m4 { background: #5cb85c; } .md.m5 { background: #1e8449; }
.cal em { position: absolute; top: 0; right: 2px; font-size: 9px; font-style: normal; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; color: var(--muted); margin: 8px 0 4px; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.lg.bleed { background: var(--rose); } .lg.pred { background: var(--rose-bg); box-shadow: inset 0 0 0 2px var(--rose); }
.lg.ph-ovu { background: var(--ovu); } .lg.ph-pre { background: var(--pre); } .lg.sleepbar { background: var(--sleep); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; padding: 0 6px 6px 0; }
.tbl td { padding: 7px 6px 7px 0; border-top: 1px solid var(--line); vertical-align: top; }
.tbl td.up { color: var(--good); font-weight: 700; } .tbl td.down { color: var(--rose); font-weight: 700; }

/* patterns */
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 12px; background: var(--card); }
.seg button { flex: 1; border: 0; background: transparent; padding: 10px 4px; min-height: 42px; cursor: pointer; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chart { width: 100%; height: auto; display: block; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-lbl { fill: var(--muted); font-size: 10px; }
.c-bleed { fill: var(--rose); opacity: .14; }
.c-sleep { fill: var(--sleep); opacity: .7; } .c-sleep.short { fill: var(--sleep-short); }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.c-dot { fill: var(--accent); }
.c-cry { font-size: 9px; }
.ins-h { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ins-h b { flex: 1; min-width: 150px; }
.ins-i { font-size: 22px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--grey-bg); color: var(--muted); }
.pill.strong { background: var(--accent); color: var(--accent-ink); }
.pill.maybe { background: var(--lut); color: var(--accent); }
.ins.na { opacity: .85; }
.ins p { margin: 6px 0; }
.care { background: var(--rose-bg); }

/* stars */
.sign { display: flex; gap: 14px; align-items: center; background: linear-gradient(135deg, var(--bar), #4b2f8f); color: #f4f1ff; }
.sign .muted { color: #cfc6f3; }
.glyph { font-size: 52px; line-height: 1; width: 70px; text-align: center; }
.h-big { font-size: 20px !important; margin: 2px 0 6px !important; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv span { color: var(--muted); }
.kv b { text-align: right; }
.wk { padding-left: 18px; margin: 6px 0; font-size: 14px; }
.wk li { margin-bottom: 4px; }

/* settings */
.ed { margin-bottom: 8px; }
.edrow { display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; padding: 5px 0; align-items: center; }
.edrow .ic { text-align: center; padding: 8px 4px; }
.steps { padding-left: 20px; margin: 8px 0; }
.steps li { margin-bottom: 10px; }
.steps input { margin: 6px 0; }
.copyrow { display: flex; gap: 8px; align-items: center; margin: 4px 0 8px; }
.copyrow code { flex: 1; padding: 8px; }
.qr img { width: 200px; height: 200px; background: #fff; padding: 6px; border-radius: 8px; margin: 6px 0; }
.log { padding-left: 4px; list-style: none; font-size: 13px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: 90vw; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
