:root {
  color-scheme: light dark;
  --bg: #f6f2f0;
  --card: #ffffff;
  --text: #1f1a1d;
  --muted: #6f656b;
  --line: #ebe4e1;
  --field: #f6f2f0;
  --accent: #c23b63;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 30, 40, 0.05), 0 8px 24px rgba(60, 30, 40, 0.05);

  --ph-menstrual: #cf3f66;
  --ph-follicular: #4f9e55;
  --ph-fertile: #1290a4;
  --ph-luteal: #6769cf;
  --ph-pms: #cf8215;
  --ph-late: #8b8490;
  --ph-unknown: #b5adb3;
  --ph: var(--accent);

  --radius: 22px;
  --tabs-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141216;
    --card: #1f1c22;
    --text: #f3eef1;
    --muted: #a69da4;
    --line: #2f2b33;
    --field: #29252d;
    --accent: #ee7396;
    --accent-ink: #2a0a14;
    --danger: #ff8a80;
    --shadow: none;

    --ph-menstrual: #f0708f;
    --ph-follicular: #7cc47f;
    --ph-fertile: #4fc3d6;
    --ph-luteal: #9a9cf0;
    --ph-pms: #f0b04f;
    --ph-late: #a9a2ae;
    --ph-unknown: #6f6873;
  }
}

[data-phase='menstrual'] { --ph: var(--ph-menstrual); }
[data-phase='follicular'] { --ph: var(--ph-follicular); }
[data-phase='fertile'] { --ph: var(--ph-fertile); }
[data-phase='luteal'] { --ph: var(--ph-luteal); }
[data-phase='pms'] { --ph: var(--ph-pms); }
[data-phase='late'] { --ph: var(--ph-late); }
[data-phase='unknown'] { --ph: var(--ph-unknown); }

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body.sheet-open { overflow: hidden; }

#main {
  max-width: 540px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + var(--tabs-h) + 28px);
}

h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

.top { padding: 4px 4px 14px; }
.top h1 { font-size: 30px; line-height: 1.15; letter-spacing: -0.02em; font-weight: 750; }
.eyebrow { color: var(--muted); font-size: 14px; font-weight: 600; margin-bottom: 2px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card > * + * { margin-top: 12px; }
.card-title {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.card h3 { font-size: 15px; font-weight: 700; margin-top: 18px; }
.card h3 + * { margin-top: 6px; }
.section-title { font-size: 20px; font-weight: 750; letter-spacing: -0.01em; margin: 22px 4px 12px; }

.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.center { text-align: center; padding: 6px 12px; }
.stack > * + * { margin-top: 12px; }

.card ul:not([class]) li,
.ticks li {
  position: relative;
  padding-left: 22px;
}
.card ul:not([class]) li + li,
.ticks li + li { margin-top: 7px; }
.card ul:not([class]) li::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ph);
}
.ticks li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0.36em;
  width: 9px;
  height: 5px;
  border-left: 2px solid var(--ph);
  border-bottom: 2px solid var(--ph);
  transform: rotate(-45deg);
}

.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ph);
}

/* ---------- buttons and fields ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 50px;
  padding: 12px 18px;
  border: 0;
  border-radius: 15px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { opacity: 0.7; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--danger); }
.actions { display: grid; gap: 10px; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.sheet:focus { outline: none; }

.field { display: block; }
.field > span { display: block; font-size: 14px; font-weight: 650; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
input[type='date'],
input[type='number'],
input[type='text'],
select,
textarea {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1.5px solid transparent;
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
}
.toggle span { font-weight: 600; }
.toggle small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.toggle input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.18s;
}
.toggle input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s;
}
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }

.error { color: var(--danger); font-size: 14px; font-weight: 600; }
.error:empty { display: none; }

.plain li { padding: 9px 0; border-top: 1px solid var(--line); font-size: 15px; }
.plain li:last-child { border-bottom: 1px solid var(--line); }

/* ---------- Today ---------- */

.hero { text-align: center; padding-top: 22px; }
.ring { display: block; width: min(64vw, 236px); height: auto; margin: 0 auto; }
.ring .arc { fill: none; stroke: var(--ph); stroke-width: 15; }
.ring.is-late .arc { opacity: 0.35; }
.ring .marker { fill: var(--card); stroke: var(--text); stroke-width: 4; }
.ring text { text-anchor: middle; fill: var(--text); }
.ring-small { font-size: 13px; font-weight: 600; fill: var(--muted) !important; }
.ring-day { font-size: 46px; font-weight: 750; letter-spacing: -0.03em; }

.pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ph) 16%, transparent);
  color: color-mix(in srgb, var(--ph) 78%, var(--text));
  font-weight: 700;
  font-size: 15px;
}
.hero-next .label { color: var(--muted); font-size: 13px; font-weight: 650; }
.hero-next .big { font-size: 22px; font-weight: 750; letter-spacing: -0.01em; }
.hero-next .big span { color: var(--muted); font-weight: 600; font-size: 17px; }
.hero-next .muted { font-size: 13.5px; line-height: 1.45; margin-top: 4px; }
.hero .actions { margin-top: 16px; }

.phase-name { font-size: 22px; font-weight: 750; letter-spacing: -0.01em; line-height: 1.2; }
.phase-name span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-top: 2px; }

.meters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.meter { background: var(--field); border-radius: 14px; padding: 10px 6px; text-align: center; }
.meter-label { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); }
.pips { display: flex; justify-content: center; gap: 4px; margin: 7px 0 5px; }
.pips i { width: 16px; height: 6px; border-radius: 3px; background: var(--line); }
.pips i.on { background: var(--ph); }
.meter-word { display: block; font-size: 13.5px; font-weight: 650; }

.callout {
  background: color-mix(in srgb, var(--ph) 11%, transparent);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14.5px;
}
.callout b, .callout span { display: block; }

.upcoming li { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.upcoming li + li { border-top: 1px solid var(--line); }
.up-main { flex: 1; min-width: 0; }
.up-main b { display: block; font-weight: 650; }
.up-main span { display: block; color: var(--muted); font-size: 14px; }
.up-when { color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; }

.note-scores { font-weight: 650; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.notice { border: 1.5px solid var(--accent); }

/* ---------- chips and scales ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none;
  min-height: 40px;
  padding: 8px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}
.chip[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.chip.static { min-height: 0; padding: 4px 11px; font-size: 13.5px; cursor: default; display: inline-block; }

.scale-label { display: block; font-size: 14px; font-weight: 650; margin-bottom: 6px; }
.scale-buttons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale-buttons button {
  appearance: none;
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
.scale-buttons button[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
.scale-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* ---------- Calendar ---------- */

.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-title {
  appearance: none;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 19px;
  font-weight: 750;
  min-height: 44px;
  padding: 0 12px;
  cursor: pointer;
}
.icon-btn {
  appearance: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 24px;
  line-height: 1;
  padding-bottom: 3px;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:disabled { opacity: 0.3; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-week span { text-align: center; color: var(--muted); font-size: 12px; font-weight: 650; padding: 4px 0; }
.cal-day {
  appearance: none;
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
}
.cal-day.period { background: var(--ph-menstrual); color: #fff; font-weight: 700; }
.cal-day.period-predicted { border: 2px dashed var(--ph-menstrual); }
.cal-day.fertile { background: color-mix(in srgb, var(--ph-fertile) 20%, transparent); }
.cal-day.ovulation { border-color: var(--ph-fertile); font-weight: 700; }
.cal-day.pms { background: color-mix(in srgb, var(--ph-pms) 22%, transparent); }
.cal-day.today { font-weight: 800; }
.cal-day.today span { border-bottom: 2.5px solid currentColor; padding-bottom: 1px; }
.cal-day.noted::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 11%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.75;
}

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; font-size: 13.5px; color: var(--muted); padding-top: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.key { flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; position: relative; }
.key.period { background: var(--ph-menstrual); }
.key.period-predicted { border: 2px dashed var(--ph-menstrual); }
.key.fertile { background: color-mix(in srgb, var(--ph-fertile) 20%, transparent); }
.key.ovulation { border-color: var(--ph-fertile); }
.key.pms { background: color-mix(in srgb, var(--ph-pms) 22%, transparent); }
.key.noted::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0.75;
}

/* ---------- Cycles ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats > div { background: var(--field); border-radius: 16px; padding: 14px 6px 12px; }
.stats b { display: block; font-size: 26px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.stats span { display: block; font-size: 13.5px; font-weight: 650; }
.stats small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.3; margin-top: 3px; }

.rows li + li { border-top: 1px solid var(--line); }
.row {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 10px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; font-weight: 650; }
.row-main span { display: block; color: var(--muted); font-size: 14px; }
.row-side { color: var(--muted); font-size: 13.5px; text-align: right; }
.chev { color: var(--muted); font-size: 22px; line-height: 1; }

.pattern { width: 100%; border-collapse: collapse; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.pattern th, .pattern td { padding: 9px 4px; text-align: right; border-top: 1px solid var(--line); }
.pattern thead th { border-top: 0; color: var(--muted); font-size: 12.5px; font-weight: 650; }
.pattern th:first-child { text-align: left; font-weight: 600; }
.pattern tbody th .dot { margin-right: 8px; }

/* ---------- Guide ---------- */

details.phase { padding: 0; }
details.phase > * { margin-left: 18px; margin-right: 18px; }
details.phase > :last-child { margin-bottom: 18px; }
details.phase summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  margin: 0;
  padding: 12px 18px;
  list-style: none;
  cursor: pointer;
}
details.phase summary::-webkit-details-marker { display: none; }
details.phase summary::after {
  content: '›';
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  transition: transform 0.18s;
}
details.phase[open] summary::after { transform: rotate(90deg); }
.sum-main { flex: 1; min-width: 0; }
.sum-main b { display: block; font-size: 17px; font-weight: 700; }
.sum-main span { display: block; color: var(--muted); font-size: 13.5px; line-height: 1.35; }
.now {
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ph) 16%, transparent);
  color: color-mix(in srgb, var(--ph) 78%, var(--text));
  font-size: 12.5px;
  font-weight: 700;
}

/* ---------- tab bar ---------- */

#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 0 6px env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
#tabs button {
  appearance: none;
  flex: 1;
  max-width: 108px;
  height: var(--tabs-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
#tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#tabs button[aria-current='page'] { color: var(--accent); }

/* ---------- sheets and toast ---------- */

#sheet-root { display: none; }
#sheet-root.open { display: block; }
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(15, 8, 12, 0.5); animation: fade 0.2s ease-out; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-width: 540px;
  max-height: 90dvh;
  margin: 0 auto;
  padding: 26px 20px calc(env(safe-area-inset-bottom) + 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border-radius: 26px 26px 0 0;
  animation: rise 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet h2 { font-size: 22px; font-weight: 750; letter-spacing: -0.01em; line-height: 1.2; }
.sheet h3 { font-size: 15px; font-weight: 700; margin-top: 20px; }
.sheet .muted .dot { margin-right: 4px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + var(--tabs-h) + 14px);
  z-index: 30;
  width: max-content;
  max-width: min(88vw, 440px);
  padding: 12px 18px;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
