:root {
  --paper: #F7F3FC;     /* lilac paper: page background */
  --surface: #FFFFFF;
  --lilac: #D9CCF2;     /* theme light purple */
  --lilac-soft: #EDE6F8;
  --violet: #6E4FB0;    /* actions, focus, today */
  --violet-deep: #563C8E;
  --plum: #2B1A40;      /* ink */
  --plum-muted: #6A5A80;
  --berry: #B23A62;     /* period days only */
  --berry-soft: #F3D9E3;
  --rule: #E2D8F1;

  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 14px;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17111F;
    --surface: #211A2C;
    --lilac: #4A3B66;
    --lilac-soft: #2C2340;
    --violet: #B9A2EE;
    --violet-deep: #D3C4F7;
    --plum: #F1EBFA;
    --plum-muted: #B5A8C9;
    --berry: #E57399;
    --berry-soft: #4A2234;
    --rule: #3A2F4C;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--plum);
  font: 400 1rem/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); margin: 0; }
p { margin: 0; }

:focus-visible {
  outline: 3px solid var(--violet);
  outline-offset: 2px;
  border-radius: 6px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute; left: 16px; top: -48px;
  background: var(--violet); color: #fff;
  padding: 8px 14px; border-radius: 8px;
  z-index: 10;
}
.skip:focus { top: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  font: 700 0.95rem/1 var(--body);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--violet); color: #fff; }
.btn-primary:hover { background: var(--violet-deep); }
@media (prefers-color-scheme: dark) {
  .btn-primary { color: #1B1326; }
}
.btn-quiet { background: transparent; color: var(--plum); border-color: var(--rule); }
.btn-quiet:hover { border-color: var(--violet); }
.btn-danger { color: var(--berry); }

.icon-btn {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--plum);
  font: 400 1.6rem/1 var(--display);
  cursor: pointer;
}
.icon-btn:hover { background: var(--lilac-soft); }

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1120px; margin: 0 auto;
  padding: 20px var(--gutter);
}
.wordmark { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.wordmark-name {
  font: 800 1.75rem/1 var(--display);
  font-variation-settings: "wdth" 75;
  letter-spacing: -0.01em;
  color: var(--violet);
}
.wordmark-note { font: 400 0.75rem/1 var(--mono); color: var(--plum-muted); letter-spacing: 0.02em; }

main { max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- Hero: dial + status ---------- */
.hero {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 1fr;
  align-items: center;
  gap: clamp(24px, 5vw, 72px);
  padding: clamp(8px, 3vw, 32px) 0 clamp(32px, 5vw, 56px);
}
.dial-wrap { position: relative; }
.dial { width: 100%; height: auto; display: block; overflow: visible; }

.dial-face { fill: var(--lilac-soft); }
.tick {
  stroke: var(--lilac);
  stroke-width: 3;
  stroke-linecap: round;
  animation: tick-in 0.5s ease-out both;
}
.tick-past { stroke: var(--plum-muted); opacity: 0.55; }
.tick-period { stroke: var(--berry); stroke-width: 5; opacity: 1; }
.tick-today { stroke: var(--violet); stroke-width: 5; opacity: 1; }
.tick-period.tick-today { stroke: var(--berry); }
.today-dot { fill: var(--violet); }
.dial-window {
  fill: none;
  stroke: var(--berry);
  stroke-width: 3;
  stroke-dasharray: 2 7;
  stroke-linecap: round;
}
.dial-eyebrow {
  font: 500 13px var(--mono);
  fill: var(--plum-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.dial-day {
  font-family: var(--display);
  font-size: 96px;
  font-weight: 800;
  font-variation-settings: "wdth" 75, "opsz" 96;
  fill: var(--plum);
}
.dial-sub { font: 400 15px var(--body); fill: var(--plum-muted); }

@keyframes tick-in {
  from { opacity: 0; }
}

.status { display: grid; gap: 14px; justify-items: start; max-width: 34rem; }
.eyebrow {
  font: 500 0.8rem/1 var(--mono);
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--berry);
}
.headline {
  font-size: clamp(2.4rem, 6vw, 4.5rem);
  font-weight: 700;
  font-variation-settings: "wdth" 80, "opsz" 96;
  line-height: 0.98;
  letter-spacing: -0.02em;
}
.lede { font-size: 1.125rem; color: var(--plum); max-width: 30rem; }
.basis { font-size: 0.95rem; color: var(--plum-muted); }

/* ---------- Panels ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 28px);
}
.panel-title {
  font-size: 1.35rem; font-weight: 700;
  font-variation-settings: "wdth" 85;
  margin-bottom: 16px;
}

/* ---------- Calendar ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-label {
  font: 700 1.35rem/1 var(--display);
  font-variation-settings: "wdth" 85;
}
.weekdays, .week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekdays span {
  text-align: center;
  font: 500 0.7rem/2 var(--mono);
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--plum-muted);
}
.days { display: grid; gap: 4px; }

.day {
  position: relative;
  aspect-ratio: 1;
  min-height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--plum);
  font: 500 0.95rem/1 var(--mono);
  cursor: pointer;
  display: grid; place-items: center;
}
.day:hover:not(:disabled) { background: var(--lilac-soft); }
.day:disabled { cursor: default; }
.day.is-outside .num { opacity: 0.35; }
.day:disabled .num { opacity: 0.55; }

.day.is-period { background: var(--berry); color: #fff; }
.day.is-period:hover:not(:disabled) { background: var(--berry); filter: brightness(1.08); }
.day.flow-light { background: color-mix(in srgb, var(--berry) 55%, var(--surface)); }
.day.flow-gap { background: var(--berry-soft); color: var(--plum); }
.day.is-spotting::after {
  content: ""; position: absolute; bottom: 18%;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--berry);
}
.day.is-predicted {
  box-shadow: inset 0 0 0 2px var(--berry);
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--berry-soft) 4px 6px);
}
.day.is-predicted .num { opacity: 1; }
.day.is-today { box-shadow: inset 0 0 0 2.5px var(--violet); font-weight: 700; }
.day.is-today.is-period { box-shadow: inset 0 0 0 2.5px var(--violet), inset 0 0 0 5px var(--surface); }
.day .mark {
  position: absolute; top: 14%; right: 18%;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--violet);
}
.day.is-period .mark { background: #fff; }

.legend {
  list-style: none; padding: 0; margin: 16px 0 0;
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  font-size: 0.85rem; color: var(--plum-muted);
}
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.key { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.key-period { background: var(--berry); }
.key-predicted { box-shadow: inset 0 0 0 2px var(--berry); background: repeating-linear-gradient(135deg, transparent 0 3px, var(--berry-soft) 3px 5px); }
.key-spotting { width: 6px; height: 6px; margin: 0 4px; background: var(--berry); }
.key-today { box-shadow: inset 0 0 0 2.5px var(--violet); }
.hint { margin-top: 10px; font-size: 0.85rem; color: var(--plum-muted); }

/* ---------- Guidance ---------- */
.guidance { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.guide {
  padding: 16px 18px;
  border-radius: 10px;
  background: var(--lilac-soft);
  display: grid; gap: 6px;
}
.guide h3 { font-size: 1.05rem; font-weight: 700; font-variation-settings: "wdth" 90; }
.guide p { font-size: 0.95rem; }
.guide-flag { background: var(--surface); border: 1.5px solid var(--berry); }
.guide-tag {
  font: 500 0.7rem/1.2 var(--mono) !important;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--berry);
}
.source {
  justify-self: start;
  font: 400 0.78rem/1.4 var(--mono);
  color: var(--violet);
  text-underline-offset: 3px;
}

/* ---------- History ---------- */
.history-panel { margin-top: 24px; }
.history-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 24px; margin-bottom: 8px; }
.history-head .panel-title { margin-bottom: 0; }
.history-key { display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--plum-muted); }
.band-swatch { width: 22px; height: 10px; border-radius: 3px; background: var(--lilac); }

.history { list-style: none; margin: 0; padding: 0; }
.cycle-row {
  display: grid;
  grid-template-columns: 9rem 5.5rem 1fr 8rem;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--rule);
}
.cycle-row:first-child { border-top: 0; }
.cycle-date, .cycle-bleed { font: 400 0.85rem/1.3 var(--mono); color: var(--plum-muted); }
.cycle-len { font: 700 1.05rem/1 var(--display); font-variation-settings: "wdth" 85; }
.cycle-len.is-out { color: var(--berry); }
.bar { position: relative; height: 12px; border-radius: 6px; background: var(--lilac-soft); overflow: hidden; }
.bar-band { position: absolute; top: 0; bottom: 0; background: var(--lilac); }
.bar-fill { position: absolute; left: 0; top: 4px; bottom: 4px; border-radius: 3px; background: var(--plum); opacity: 0.8; }
.bar-bleed { position: absolute; left: 0; top: 2px; bottom: 2px; border-radius: 4px; background: var(--berry); }
.history-empty { color: var(--plum-muted); padding: 8px 0; }

/* ---------- Footer ---------- */
.foot {
  max-width: 1120px; margin: 40px auto 0;
  padding: 24px var(--gutter) 48px;
  border-top: 1px solid var(--rule);
  display: grid; gap: 16px;
}
.disclaimer { font-size: 0.9rem; color: var(--plum-muted); max-width: 46rem; }
.data-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.data-controls label.btn:focus-within { outline: 3px solid var(--violet); outline-offset: 2px; }

/* ---------- Dialog ---------- */
.day-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border: 0; border-radius: 18px;
  padding: 0;
  background: var(--surface); color: var(--plum);
  box-shadow: 0 24px 60px -20px rgba(43, 26, 64, 0.45);
}
.day-dialog::backdrop { background: rgba(43, 26, 64, 0.35); }
.day-dialog form { padding: 20px 24px 24px; display: grid; gap: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-size: 1.4rem; font-weight: 700; font-variation-settings: "wdth" 85; }

fieldset { border: 0; padding: 0; margin: 0; }
legend {
  font: 500 0.72rem/1 var(--mono);
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--plum-muted);
  margin-bottom: 10px;
}
.choices, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.choices legend, .chips legend { width: 100%; }
.choices label, .chips label { position: relative; }
.choices input, .chips input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choices span, .chips span {
  display: inline-flex; align-items: center;
  min-height: 40px; padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--rule);
  font-size: 0.92rem;
}
.choices input:checked + span { background: var(--violet); border-color: var(--violet); color: #fff; }
fieldset:first-of-type input:checked + span { background: var(--berry); border-color: var(--berry); }
fieldset:first-of-type input[value="none"]:checked + span { background: var(--plum-muted); border-color: var(--plum-muted); }
.chips input:checked + span { background: var(--lilac); border-color: var(--lilac); color: var(--plum); }
.choices input:focus-visible + span, .chips input:focus-visible + span { outline: 3px solid var(--violet); outline-offset: 2px; }
@media (prefers-color-scheme: dark) {
  .choices input:checked + span { color: #1B1326; }
}

.checks { display: grid; gap: 8px; }
.checks label { display: flex; gap: 10px; align-items: center; font-size: 0.95rem; }
.checks input { width: 20px; height: 20px; accent-color: var(--violet); }

.note { display: grid; gap: 8px; font: 500 0.72rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--plum-muted); }
.note textarea {
  font: 400 1rem/1.4 var(--body); text-transform: none; letter-spacing: 0;
  color: var(--plum); background: var(--paper);
  border: 1.5px solid var(--rule); border-radius: 10px;
  padding: 10px 12px; resize: vertical;
}
.dialog-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Sync ---------- */
.top-actions { display: flex; align-items: center; gap: 10px; }
.sync-chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1.5px solid var(--rule); border-radius: 999px;
  background: var(--surface); color: var(--plum);
  font: 500 0.8rem/1 var(--mono);
  cursor: pointer;
}
.sync-chip:hover { border-color: var(--violet); }
.sync-chip::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--plum-muted); opacity: 0.5;
}
.sync-chip[data-state="synced"]::before, .sync-chip[data-state="idle"]::before { background: var(--violet); opacity: 1; }
.sync-chip[data-state="syncing"]::before { background: var(--violet); opacity: 1; animation: pulse 1s ease-in-out infinite alternate; }
.sync-chip[data-state="locked"]::before, .sync-chip[data-state="error"]::before { background: var(--berry); opacity: 1; }
@keyframes pulse { to { opacity: 0.3; } }

.sync-dialog > .dialog-head { padding: 16px 16px 0 24px; }
.sync-dialog > .dialog-head form { padding: 0; display: block; }
.sync-body { padding: 14px 24px 24px; display: grid; gap: 14px; }
.sync-dialog .sync-form { display: grid; gap: 14px; padding: 0; }
.sync-body p { font-size: 0.97rem; }
.muted { color: var(--plum-muted); }
.field {
  display: grid; gap: 6px;
  font: 500 0.72rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--plum-muted);
}
.field input {
  font: 400 1rem/1.4 var(--body); text-transform: none; letter-spacing: 0;
  color: var(--plum); background: var(--paper);
  border: 1.5px solid var(--rule); border-radius: 10px;
  min-height: 44px; padding: 8px 12px;
}
.field input:focus-visible { border-color: var(--violet); }
.field-help { font: 400 0.85rem/1.4 var(--body); text-transform: none; letter-spacing: 0; }
.sync-error { color: var(--berry); font-size: 0.92rem; }
.sync-error:empty { display: none; }
.sync-warning {
  padding: 12px 14px; border-radius: 10px;
  background: var(--berry-soft); color: var(--plum);
}
.sync-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sync-actions > :only-child { margin-left: auto; }
.sync-more { border-top: 1px solid var(--rule); padding-top: 12px; }
.sync-more summary { cursor: pointer; color: var(--violet); font-size: 0.92rem; min-height: 32px; }
.sync-more[open] summary { margin-bottom: 12px; }
.sync-actions > .btn-quiet:only-child { margin-left: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; justify-items: center; text-align: left; }
  .dial-wrap { width: min(340px, 86vw); }
  .status { justify-self: stretch; }
  .grid { grid-template-columns: 1fr; }
  .cycle-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .cycle-row .bar { grid-column: 1 / -1; }
  .cycle-bleed { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  .wordmark-note { display: none; }
  .top-actions { gap: 6px; }
  .sync-chip { padding: 0 12px; }
  #log-today { padding: 0 14px; }
  .day { min-height: 36px; font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
