:root {
  --ink: #30282a;
  --muted: #7d7073;
  --paper: #fff8f5;
  --card: #fffdfb;
  --rose: #bd4663;
  --rose-dark: #97364f;
  --rose-soft: #f8dce2;
  --rose-pale: #fff0f2;
  --sage: #577568;
  --sage-soft: #e4eee8;
  --line: #eddfdc;
  --shadow: 0 14px 40px rgba(91, 52, 61, 0.09);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { background: #eee6e3; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% -5%, rgba(244, 183, 195, .38), transparent 34%),
    var(--paper);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px calc(112px + env(safe-area-inset-bottom));
}

.topbar, .section-heading, .calendar-heading, .dialog-heading,
.summary-foot, .settings-title, .button-row, .dialog-actions, .joined-field {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; margin-bottom: 24px; }

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.privacy-dot, .status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #5a8d75;
  box-shadow: 0 0 0 4px var(--sage-soft);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: 39px; line-height: .95; letter-spacing: -.045em; }
h1 span { color: var(--rose); }
h2 { margin-bottom: 0; font-family: Georgia, serif; font-size: 23px; letter-spacing: -.025em; }
h3 { margin-bottom: 6px; font-size: 15px; }

.icon-button {
  display: grid;
  width: 45px;
  height: 45px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--rose-dark);
  background: rgba(255, 253, 251, .84);
}
.icon-button:active { transform: scale(.96); }
.icon-button svg { width: 21px; fill: currentColor; }
.icon-button.small { width: 34px; height: 34px; border: 0; background: var(--rose-pale); font-size: 25px; line-height: 1; }

.install-note {
  align-items: flex-start;
  gap: 10px;
  margin: -4px 0 18px;
  padding: 12px 12px 12px 14px;
  border: 1px solid #d9e5de;
  border-radius: 15px;
  background: #f0f6f2;
  color: #3e5c4f;
}
.install-note:not([hidden]) { display: flex; }
.install-note div { flex: 1; }
.install-note strong, .install-note span { display: block; }
.install-note strong { margin-bottom: 3px; font-size: 13px; }
.install-note span { font-size: 12px; line-height: 1.45; }

.summary-card {
  position: relative;
  overflow: hidden;
  margin-bottom: 16px;
  padding: 23px 22px 16px;
  border-radius: 25px;
  color: white;
  background: linear-gradient(145deg, #c9516d, #a93956);
  box-shadow: 0 17px 34px rgba(157, 49, 78, .23);
}
.summary-card::after {
  content: "";
  position: absolute;
  top: -57px;
  right: -42px;
  width: 165px;
  height: 165px;
  border: 34px solid rgba(255,255,255,.08);
  border-radius: 50%;
}
.summary-copy { position: relative; z-index: 1; min-height: 85px; }
.summary-copy span, .summary-copy strong { display: block; }
.summary-label { margin-bottom: 6px; color: rgba(255,255,255,.75); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.summary-copy strong { max-width: 78%; font-family: Georgia, serif; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; }
.summary-copy #estimate-detail { margin-top: 5px; color: rgba(255,255,255,.78); font-size: 12px; }
.countdown { position: absolute; z-index: 1; top: 30px; right: 22px; width: 64px; text-align: center; }
.countdown strong, .countdown span { display: block; }
.countdown strong { font: 37px/1 Georgia, serif; }
.countdown span { margin-top: 2px; color: rgba(255,255,255,.7); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.summary-foot { position: relative; z-index: 1; justify-content: space-between; gap: 12px; padding-top: 13px; border-top: 1px solid rgba(255,255,255,.18); color: rgba(255,255,255,.82); font-size: 11px; }
.estimate-caveat { white-space: nowrap; }

.calendar-card {
  margin-bottom: 26px;
  padding: 18px 16px 14px;
  border: 1px solid rgba(237, 223, 220, .8);
  border-radius: 24px;
  background: rgba(255,253,251,.9);
  box-shadow: var(--shadow);
}
.calendar-heading { justify-content: space-between; margin-bottom: 16px; }
.calendar-heading h2 { font-size: 20px; }
.weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays { margin-bottom: 5px; color: #a09294; font-size: 10px; font-weight: 700; text-align: center; text-transform: uppercase; }
.day {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  margin: 2px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #473c3e;
  background: transparent;
  font-size: 13px;
}
.day.outside { color: #c7bdbf; }
.day.today { outline: 1.5px solid var(--rose); outline-offset: -2px; font-weight: 750; }
.day.estimated { border-radius: 11px; background: var(--rose-pale); color: var(--rose-dark); }
.day.period { border-radius: 11px; color: white; background: var(--rose); font-weight: 700; }
.day:active { transform: scale(.92); }
.legend { display: flex; gap: 18px; justify-content: center; margin-top: 12px; color: var(--muted); font-size: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.period-key { background: var(--rose); }
.estimate-key { background: var(--rose-pale); border: 1px solid var(--rose-soft); }

.section-heading { justify-content: space-between; margin-bottom: 12px; }
.section-heading h2 { font-size: 22px; }
.count-chip { min-width: 30px; padding: 6px 9px; border-radius: 99px; color: var(--rose-dark); background: var(--rose-soft); font-size: 12px; font-weight: 750; text-align: center; }
.history-list { display: grid; gap: 9px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--ink);
  background: var(--card);
  text-align: left;
}
.history-item:active { background: var(--rose-pale); }
.history-date { display: grid; width: 45px; height: 45px; place-items: center; border-radius: 14px; color: white; background: var(--rose); }
.history-date strong, .history-date span { display: block; text-align: center; }
.history-date strong { font: 20px/18px Georgia, serif; }
.history-date span { font-size: 9px; font-weight: 750; text-transform: uppercase; }
.history-copy { flex: 1; }
.history-copy strong, .history-copy span { display: block; }
.history-copy strong { margin-bottom: 3px; font-size: 14px; }
.history-copy span { color: var(--muted); font-size: 11px; }
.history-arrow { color: #bcaeb1; font-size: 22px; }
.empty-state { display: grid; padding: 26px 25px; place-items: center; border: 1px dashed #dfcccf; border-radius: 20px; text-align: center; }
.empty-state[hidden] { display: none; }
.empty-icon { display: grid; width: 39px; height: 39px; margin-bottom: 9px; place-items: center; border-radius: 50%; color: var(--rose); background: var(--rose-soft); font-size: 25px; }
.empty-state strong { margin-bottom: 5px; font-size: 14px; }
.empty-state span { max-width: 275px; color: var(--muted); font-size: 12px; line-height: 1.5; }

.bottom-action {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 13px 18px calc(13px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--paper) 25%);
  pointer-events: none;
}
.primary-button {
  display: flex;
  width: min(100%, 484px);
  min-height: 54px;
  margin: 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 17px;
  color: white;
  background: var(--rose);
  box-shadow: 0 12px 25px rgba(157,49,78,.22);
  font-weight: 760;
  pointer-events: auto;
}
.primary-button:active { background: var(--rose-dark); transform: translateY(1px); }
.primary-button span { font-size: 21px; font-weight: 400; }
.primary-button.compact { width: auto; min-width: 145px; min-height: 47px; margin: 0; padding: 0 22px; }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(52,37,41,.4); backdrop-filter: blur(3px); }
.sheet-dialog {
  width: min(calc(100% - 24px), 490px);
  max-height: min(88vh, 720px);
  margin: auto auto 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  overflow: auto;
  border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--card);
  box-shadow: 0 -14px 45px rgba(64,38,45,.18);
}
.sheet-handle { width: 42px; height: 4px; margin: 1px auto 17px; border-radius: 99px; background: #dacdca; }
.dialog-heading { justify-content: space-between; margin-bottom: 20px; }
.date-field, .text-field { display: block; margin-bottom: 13px; }
.date-field > span, .text-field > span { display: block; margin: 0 0 6px 3px; color: var(--muted); font-size: 11px; font-weight: 700; }
.date-field input, .text-field input, .text-field select {
  width: 100%;
  min-height: 49px;
  padding: 0 13px;
  border: 1px solid #decfd0;
  border-radius: 13px;
  color: var(--ink);
  background: white;
  outline: none;
}
.date-field input:focus, .text-field input:focus, .text-field select:focus { border-color: var(--rose); box-shadow: 0 0 0 3px var(--rose-soft); }
.form-error { min-height: 18px; margin: 4px 3px 9px; color: #a32f46; font-size: 12px; }
.dialog-actions { justify-content: flex-end; gap: 10px; }
.danger-button, .secondary-button, .text-button, .joined-field button {
  border: 0;
  color: var(--rose-dark);
  background: transparent;
  font-weight: 700;
}
.danger-button { margin-right: auto; padding: 12px 4px; }
.secondary-button { min-height: 44px; padding: 0 16px; border: 1px solid #ddcccf; border-radius: 13px; background: white; }
.text-button { padding: 2px 3px; font-size: 12px; }
.danger-text { color: #a32f46; }
.reminder-controls { margin-top: 13px; }
.reminder-controls[hidden] { display: none; }

.settings-section { padding: 16px 0; border-top: 1px solid var(--line); }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section p { margin-bottom: 13px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.settings-title { gap: 3px; margin-bottom: 6px; }
.settings-title strong { font-size: 14px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 13px; font-size: 13px; font-weight: 700; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--rose); }
#cycle-length-field[hidden] { display: none; }
.joined-field input { min-width: 0; border-radius: 13px 0 0 13px; font-family: ui-monospace, monospace; font-size: 11px; }
.joined-field button { align-self: stretch; padding: 0 13px; border: 1px solid #decfd0; border-left: 0; border-radius: 0 13px 13px 0; background: var(--rose-pale); }
.button-row { flex-wrap: wrap; gap: 9px; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.backup-status { min-height: 18px; margin: 10px 0 0 !important; color: var(--sage) !important; }
.backup-status.error { color: #a32f46 !important; }
.settings-footer { padding: 10px 0 3px; color: #a09294; font-size: 10px; text-align: center; }

.toast {
  position: fixed;
  z-index: 30;
  right: 20px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  left: 20px;
  max-width: 420px;
  margin: auto;
  padding: 12px 15px;
  border-radius: 13px;
  color: white;
  background: #3f3537;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: .18s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

@media (min-width: 620px) {
  body { padding: 24px 0; }
  .app-shell { min-height: calc(100vh - 48px); border-radius: 32px; background: var(--paper); box-shadow: 0 20px 65px rgba(81,56,62,.13); }
  .bottom-action { background: transparent; }
  .sheet-dialog { margin: auto; border-radius: 26px; }
}

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