/* Period. System fonts only (New York + San Francisco on iPhone): no third-party font requests. */
:root {
  --bg: #f4f3f9; --card: #ffffff; --ink: #221e31; --soft: #6d6880; --line: #e3e0ee;
  --period: #d4415a; --period-soft: #f8dde2; --fertile: #23897d; --fertile-soft: #d6efeb;
  --pms: #b07a1f; --pms-soft: #f5ead2; --accent: #5d4596; --accent-soft: #e8e2f6; --on-accent: #ffffff;
  --err: #b3261e; --err-soft: #fbe3e1;
  --display: ui-serif, "New York", Georgia, serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131c; --card: #1f1c29; --ink: #efedf6; --soft: #a7a2b9; --line: #322e40;
    --period: #ef6d84; --period-soft: #4a2230; --fertile: #4fc2b3; --fertile-soft: #173a36;
    --pms: #e0a94c; --pms-soft: #3d3020; --accent: #b39cf0; --accent-soft: #2e2645; --on-accent: #15131c;
    --err: #ffb4ab; --err-soft: #4a1f1c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); -webkit-text-size-adjust: 100%; }
body { padding-top: env(safe-area-inset-top, 0px); }
button, input, textarea { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.loading { padding: 40px 20px; color: var(--soft); text-align: center; }

header.top { padding: 18px 20px 6px; }
header.top h1 { font: 400 1.7rem var(--display); margin: 0; }
main { padding: 6px 16px calc(96px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; min-width: 0; }
.card.highlight { border-color: var(--accent); background: var(--accent-soft); }
.card h2 { font: 600 .78rem var(--body); letter-spacing: .08em; text-transform: uppercase; color: var(--soft); margin: 0 0 10px; }
.card p { margin: 0 0 8px; line-height: 1.45; }
.sub { color: var(--soft); font-size: .92rem; }
.disclaim { font-size: .76rem; color: var(--soft); margin-top: 8px !important; }
.tagnote { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--accent); }
.ring { display: grid; place-items: center; }
.ring svg { width: 230px; height: 230px; max-width: 100%; }
.ring .sub { font-size: 1rem; color: var(--ink); }
.ring-num { font: 400 46px var(--display); fill: var(--ink); }
.ring-sub { font: 500 13px var(--body); fill: var(--soft); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions button, .filebtn, .inline button, .pinform button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 16px; font-weight: 600; min-height: 44px; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.filebtn { display: inline-flex; align-items: center; margin-top: 6px; position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 9px 13px; font-size: .9rem; min-height: 40px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: .95rem; }
.row:first-of-type { border-top: 0; }
.rowctl { display: flex; align-items: center; gap: 6px; }
.pill { font-size: .78rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.p-period { background: var(--period-soft); color: var(--period); }
.p-fertile { background: var(--fertile-soft); color: var(--fertile); }
.p-pms { background: var(--pms-soft); color: var(--pms); }

.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-head h2 { margin: 0; }
.icon { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; width: 44px; height: 44px; font-size: 1.4rem; line-height: 1; }
.icon.small { width: 34px; height: 34px; font-size: 1rem; }
.icon:disabled { opacity: .35; cursor: default; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-variant-numeric: tabular-nums; }
.cal .dow { font-size: .72rem; color: var(--soft); padding-bottom: 4px; }
.cal .d { aspect-ratio: 1; border: 0; background: transparent; border-radius: 50%; font-size: .92rem; position: relative; padding: 0; max-width: 100%; }
.cal .period { background: var(--period); color: var(--on-accent); font-weight: 600; }
.cal .predicted { box-shadow: inset 0 0 0 2px var(--period); color: var(--period); }
.cal .fertile { background: var(--fertile-soft); color: var(--fertile); font-weight: 600; }
.cal .ovulation { background: var(--fertile); color: var(--on-accent); }
.cal .pms { background: var(--pms-soft); color: var(--pms); }
.cal .today { outline: 2px solid var(--ink); outline-offset: 1px; }
.cal .logged::after { content: ""; position: absolute; bottom: 4px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .76rem; color: var(--soft); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.k-period { background: var(--period); } .k-pred { box-shadow: inset 0 0 0 2px var(--period); } .k-fertile { background: var(--fertile-soft); }
.k-ovu { background: var(--fertile); } .k-pms { background: var(--pms-soft); box-shadow: inset 0 0 0 1px var(--pms); } .k-logged { background: var(--accent); width: 6px !important; height: 6px !important; }

.field { display: flex; align-items: center; gap: 8px; }
.field input, .inline input, .pinform input, textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 12px; font-size: 16px; width: 100%; min-width: 0; }
.field span { color: var(--soft); }
textarea { resize: vertical; display: block; }
.inline { display: flex; gap: 8px; margin-top: 10px; }
.pinform { display: grid; gap: 8px; margin-top: 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font: 400 1.5rem var(--display); }
.stat span { font-size: .74rem; color: var(--soft); }
.bars { display: grid; gap: 4px; }
.bar { display: grid; grid-template-columns: 82px 1fr 74px; align-items: center; gap: 8px; font-size: .82rem; font-variant-numeric: tabular-nums;
  border: 0; background: transparent; padding: 6px 0; text-align: left; }
.bar .track { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar.hidden { opacity: .45; }
.bar.hidden .fill { background: var(--soft); }

.switch { width: 48px; height: 30px; border-radius: 999px; border: 0; background: var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--card); transition: transform .18s; }
.switch[aria-checked="true"] { background: var(--fertile); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch:disabled { opacity: .5; }

.toast { margin: 4px 16px 0; padding: 10px 14px; border-radius: 12px; background: var(--fertile-soft); color: var(--ink); font-size: .9rem; user-select: text; -webkit-user-select: text; }
.toast.error, .err { background: var(--err-soft); color: var(--err); border-radius: 12px; padding: 10px 14px; user-select: text; -webkit-user-select: text; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px)); max-width: 560px; margin: 0 auto; }
.tabbar button { border: 0; background: transparent; color: var(--soft); font-size: .7rem; font-weight: 600; display: grid; justify-items: center; gap: 3px; padding: 4px 0; min-height: 48px; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; }

.lockscreen { min-height: 80vh; display: grid; place-content: center; gap: 18px; padding: 24px; text-align: center; }
.lockscreen h1 { font: 400 2.2rem var(--display); margin: 0; }
.lockscreen form { display: grid; gap: 10px; width: 240px; }
.lockscreen input { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 14px; font-size: 22px; text-align: center; letter-spacing: .3em; }
.lockscreen button { border: 0; border-radius: 14px; padding: 14px; font-weight: 600; }

@media (prefers-reduced-motion: reduce) { .switch::after { transition: none; } }
