:root {
  font: -apple-system-body;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #252a73;
  background: #eee9fd;
  color-scheme: light;
  --muted: #575778;
  --button: #333781;
}

* { box-sizing: border-box; }
[hidden], .symbols { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% 42%, #fffafb 0%, #f5f0fd 39%, transparent 74%),
    linear-gradient(145deg, #e7e5fc, #eee9fd 58%, #e7e5fb);
}
h1, p { margin: 0; }
button, input { font: inherit; }
button, summary { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid #5549aa; outline-offset: 4px; }
h1[tabindex="-1"]:focus { outline: none; }
.page {
  --view-space: clamp(2rem, 7vh, 5.5rem);
  position: relative;
  z-index: 1;
  display: grid;
  /* Equal tracks above and below the view keep it centered. */
  grid-template-rows: auto minmax(var(--view-space), 1fr) auto auto minmax(var(--view-space), 1fr) 2.75rem;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100svh;
  padding: max(1.65rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(.85rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.brand {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .46rem;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -.035em;
}
.settings-cog, .nav-back {
  position: absolute;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--button);
}
.settings-cog { inset-inline-end: 0; }
.brand:has(.nav-back:not([hidden])) { min-height: 44px; }
.nav-back {
  inset-inline-start: 0;
  background: #faf8ff;
  box-shadow: 0 1px 4px rgb(37 42 115 / 12%);
}
.nav-back:dir(rtl) svg { transform: scaleX(-1); }
.settings-cog:hover, .nav-back:hover { background: #e3ddf6; }
.brand-ring {
  width: 1.22em;
  height: 1.22em;
  border-radius: 50%;
  background: conic-gradient(#9969fe, #506dfd 52%, #5fbdfe 95%, #a7a0f9);
  -webkit-mask: radial-gradient(circle closest-side, transparent 61%, #000 67%);
  mask: radial-gradient(circle closest-side, transparent 61%, #000 67%);
}
main {
  grid-row: 3;
  display: grid;
  justify-items: center;
  width: 100%;
}
.waves {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  height: clamp(6.5rem, 22vh, 15rem);
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .waves path {
    transform-origin: center bottom;
    animation: wave-drift 18s ease-in-out -7s infinite alternate;
  }
  .waves path:last-child {
    animation-duration: 24s;
    animation-delay: -9s;
    animation-direction: alternate-reverse;
  }
}
@keyframes wave-drift {
  from { transform: translateX(-7%) scale(1.16, .87); }
  to { transform: translateX(7%) scale(1.16, 1.09); }
}

/* Place the text over the ring at common phone widths. */
#forecast-view { width: min(calc(100% + .75rem), 33rem); }
.forecast-panel {
  container-type: inline-size;
  display: grid;
  justify-items: center;
}
.dial {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  text-align: center;
}
.ring, .ring-copy { grid-area: 1 / 1; }
.ring {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}
.ring-track { stroke: #dcd8f3; }
.ring-track, #ring-progress { stroke-width: 15; }
#ring-progress {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  filter: drop-shadow(0 1px 2px rgb(121 110 236 / 28%));
  transition: stroke-dashoffset .24s ease-out;
}
.ring-outline { visibility: hidden; stroke: #68639e; stroke-width: 2; stroke-dasharray: 3 5; }
[data-state="overdue"] .ring-outline { visibility: visible; }
.ring-copy {
  width: 78%;
  min-height: 54cqi;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  justify-items: center;
}
.cycle-length {
  align-self: start;
  display: inline-block;
  max-width: 89%;
  padding: .22em .8em;
  border-radius: 1.4em;
  background: #e6e1f9;
  font-size: clamp(.83rem, 3.6cqi, 1.06rem);
  font-weight: 500;
  line-height: 1.38;
}
#countdown {
  font-size: clamp(2.75rem, 15.7cqi, 4.9rem);
  line-height: 1.04;
  font-weight: 600;
  letter-spacing: -.05em;
  text-wrap: balance;
}
[data-state="started"] #countdown, [data-state="due"] #countdown {
  font-size: clamp(2rem, 9.9cqi, 3.35rem);
  line-height: 1.06;
}
[data-state="overdue"] #countdown { font-size: clamp(2rem, 12.5cqi, 4rem); }
#countdown-past { color: #634677; }
.forecast-notes {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: clamp(.4rem, 1.8cqi, .65rem);
}
.detail {
  color: #595983;
  font-size: clamp(1rem, 4.8cqi, 1.44rem);
  line-height: 1.26;
  letter-spacing: -.018em;
}
.detail:empty { display: none; }
.date-line {
  margin-top: .35rem;
  font-size: clamp(.82rem, 3.5cqi, 1.04rem);
  line-height: 1.35;
  color: var(--muted);
  text-wrap: balance;
}
.date-line time { color: #444572; font-weight: 550; }
.day-line {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .62em;
  margin-top: auto;
  min-height: 1.85em;
  font-size: clamp(.88rem, 3.65cqi, 1.07rem);
  font-weight: 550;
}
.detail:not([hidden]) ~ .day-line, .date-line:not([hidden]) + .day-line { padding-top: .4em; }
.day-line::before, .day-line::after {
  content: "";
  width: 1.7em;
  height: 1px;
  background: #b7b1d7;
}
.primary, .secondary {
  min-height: 2.85rem;
  border: 0;
  border-radius: 2rem;
  padding: .65em 1.55em;
  font-weight: 600;
  line-height: 1.3;
}
.primary { background: var(--button); color: #fff; }
.primary:hover { background: #282c71; }
.primary:active { background: #20245e; }
.secondary { background: transparent; color: var(--button); }
.secondary:hover { background: #e8e4fa; }
#log-start {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .48em;
  max-width: 82%;
  margin-top: 1.5rem;
  font-size: clamp(1rem, 4.2cqi, 1.26rem);
}
.drop {
  flex: none;
  width: 1.16em;
  height: 1.16em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linejoin: round;
}

/* Let enlarged text use the full width when it cannot fit in the circle. */
@container (max-width: 16rem) {
  .ring { width: 5.5rem; max-width: 100%; }
  .ring-copy { grid-area: 2 / 1; width: 100%; min-height: 0; margin-top: .5rem; grid-template-rows: auto auto auto; }
  .cycle-length { margin-bottom: .6rem; }
  #log-start { max-width: 100%; }
}

/* The two date forms use the same native input and confirmation button. */
#date-view, .form-card { width: min(100%, 27rem); }
.form-card {
  margin-inline: auto;
  border: 1px solid rgb(100 85 165 / 13%);
  border-radius: 1.8rem;
  padding: clamp(1.45rem, 6vw, 2.3rem);
  background: rgb(255 253 255 / 80%);
  box-shadow: 0 .65rem 2.8rem rgb(82 60 133 / 6%);
}
.form-mark {
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 3.2rem;
  margin-bottom: 1.3rem;
  border: 1px solid #d6cff3;
  border-radius: 50%;
  background: #eae5fa;
  color: #554b9c;
  font-size: 1.4rem;
}
.form-card h1 {
  font-size: clamp(1.75rem, 6.6vw, 2.28rem);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -.045em;
  text-wrap: balance;
}
#start-form { display: grid; grid-template-columns: minmax(0, 1fr); margin-top: 1.65rem; }
#start-form label { font-weight: 550; margin-bottom: .46rem; }
.date-field {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  min-height: 3rem;
  color: #252a73;
  background: #fff;
  border: 1px solid #9b95b5;
  border-radius: .7rem;
}
#start-date {
  appearance: none;
  -webkit-appearance: none;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 0 .9rem;
  border: 0;
  border-radius: inherit;
  color: inherit;
  background: transparent;
}
#date-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding-inline: .9rem;
  border-radius: inherit;
  background: white;
  color: var(--muted);
  pointer-events: none;
}
.date-field:focus-within #date-hint { visibility: hidden; }
#confirm-start { margin-top: 1.1rem; }
#cancel-start { margin-top: .3rem; }
.error { margin-top: .65rem; color: #922443; line-height: 1.45; }
#settings-view { display: grid; gap: .75rem; }
#update-status { display: grid; text-align: center; color: var(--muted); line-height: 1.45; }
#update-status span { grid-area: 1 / 1; align-self: center; }
#update-status [aria-hidden="true"] { visibility: hidden; }
#delete-data { margin-top: .65rem; border: 1px solid #cda8b4; }
.secondary.danger-action { color: #922443; }
.primary.danger-action { background: #922443; }
.confirm-dialog {
  width: min(calc(100% - 2rem), 27rem);
  color: inherit;
  background: #fffdff;
}
.confirm-dialog::backdrop { background: rgb(36 29 66 / 38%); }
.confirm-dialog h2 { margin: 0 0 .75rem; }
.confirm-dialog p { line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
.storage-help { margin: 1rem 0 1.3rem; line-height: 1.5; }
.install-icon {
  display: block;
  margin-bottom: 1.25rem;
  border-radius: .9rem;
}
#install-view ol {
  display: grid;
  gap: .65rem;
  margin: 1.25rem 0;
  padding-inline-start: 1.5rem;
  line-height: 1.5;
}
#install-view li::marker { font-weight: 600; }
#install-view p { color: var(--muted); line-height: 1.5; }
.offline-error, footer details {
  width: min(100%, 25rem);
  margin-inline: auto;
  font-size: .9rem;
  line-height: 1.55;
  color: var(--muted);
}
.offline-error { grid-row: 4; padding-block: 1rem; text-align: center; }
footer {
  grid-row: 5 / 7;
  display: flex;
  flex-direction: column;
  contain: size;
  padding-top: .5rem;
  text-align: center;
}
/* Use the gap below the view first. On short screens the page can scroll. */
footer details { flex: none; margin-top: auto; }
footer details[open] { padding-bottom: env(safe-area-inset-bottom); }
footer summary {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  gap: .5em;
  list-style: none;
  font-weight: 550;
}
footer summary::-webkit-details-marker { display: none; }
footer summary::after {
  content: "";
  width: .43em;
  height: .43em;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-.12em) rotate(45deg);
}
footer details[open] summary::after { transform: translateY(.12em) rotate(225deg); }
footer details p { text-align: left; margin: .5rem 0; }
@media (prefers-reduced-motion: reduce) {
  #ring-progress { transition: none; }
}

#open-history {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  margin-top: .5rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #655e9a;
}
#open-history:hover { background: #e8e4fa; }
.page:has(#history-view:not([hidden])) { --view-space: 1.25rem; }
#history-view {
  width: min(100%, 29rem);
  min-width: 0;
  padding: clamp(.85rem, 3vw, 1.5rem);
  border: 1px solid #dfdbef;
  border-radius: 1.65rem;
  background: #fcfaff;
  box-shadow: 0 .65rem 2.8rem rgb(82 60 133 / 6%);
}
#history-title { font-size: clamp(1.45rem, 5vw, 1.9rem); letter-spacing: -.04em; }
#history-today { padding-inline: .7rem; }
.history-switch {
  display: flex;
  margin-block: .85rem .45rem;
  padding: .22rem;
  border-radius: 1rem;
  background: #eeebf7;
}
.history-switch button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: .8rem;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.history-switch [aria-pressed="true"] {
  color: var(--button);
  background: white;
  box-shadow: 0 1px 5px rgb(49 41 97 / 13%);
}
.calendar-tools, .legend { display: flex; align-items: center; flex-wrap: wrap; }
.calendar-tools { justify-content: space-between; gap: 0 .4rem; }
.legend { gap: .35rem 1rem; color: var(--muted); font-size: .85rem; }
.legend span { display: inline-flex; align-items: center; gap: .35em; }
.legend span::before {
  content: "";
  box-sizing: border-box;
  width: 1em;
  height: 1em;
  border-radius: .3em;
}
.history-scroll {
  position: relative;
  height: clamp(14rem, 45svh, 23rem);
  overflow: auto;
  overscroll-behavior-y: contain;
  overflow-anchor: none;
  border-block: 1px solid #e4dfef;
}
#history-months section { min-height: 100%; padding: .8rem .2rem; }
.history-scroll h2 { font-size: 1.25rem; margin: .25rem 0 .7rem; letter-spacing: -.025em; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; }
.weekday { color: var(--muted); font-size: .78rem; margin-bottom: .35rem; }
.month-grid button {
  position: relative;
  min-height: max(44px, 2.75em);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: .75rem;
  color: inherit;
  font-variant-numeric: tabular-nums;
}
.month-grid button:not(:disabled):not(.saved-marker):hover, #history-list button:hover { background: #eeebf7; }
.month-grid button:focus-visible, #history-list button:focus-visible { outline-offset: -3px; }
.month-grid button:disabled { cursor: default; color: var(--muted); }
.legend .saved-marker::before, .month-grid button.saved-marker {
  background: #514785;
  color: white;
}
.legend .estimate-marker::before, .month-grid button.estimate-marker {
  background: #f2edff;
  border: 2px dashed #79699f;
  color: #44396f;
}
.month-grid button.saved-marker:hover { background: #413771; }
.month-grid .saved-marker, .month-grid .estimate-marker { font-weight: 650; }
.month-grid button[aria-current="date"] {
  text-decoration: underline;
  text-underline-offset: .2em;
  font-weight: 700;
}
.history-content { position: relative; }
#calendar-panel[inert] { visibility: hidden; }
#history-list { position: absolute; inset: 0; height: auto; padding: .75rem .2rem; }
#history-list h2:not(:first-child) { margin-top: 1.3rem; }
#history-list button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: .7rem .5rem;
  text-align: left;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #e4dfef;
}
#history-add { display: block; width: 100%; margin-top: 1rem; }
