/* MyCycle v3 — styles */

:root,
:root[data-theme="rose"] {
  --bg: #fbf7f8;
  --surface: #ffffff;
  --surface-soft: #f8edf1;
  --ink: #33252d;
  --muted: #76666e;
  --primary: #9d3f68;
  --primary-dark: #74304e;
  --primary-soft: #efd3df;
  --accent: #d88aaa;
  --line: #eadde2;
  --focus: #4f6fc7;
  --on-primary: #ffffff;
  --danger: #b3261e;
  --stage: #eee7eb;
}

:root[data-theme="sage"] {
  --bg: #f7faf5;
  --surface: #ffffff;
  --surface-soft: #eaf3e9;
  --ink: #26332b;
  --muted: #5e6c63;
  --primary: #527a62;
  --primary-dark: #365441;
  --primary-soft: #cfe2d3;
  --accent: #8bb49a;
  --line: #dce9df;
  --focus: #325fc3;
  --stage: #e8eee7;
}

:root[data-theme="midnight"] {
  --bg: #17182a;
  --surface: #22233a;
  --surface-soft: #2d2c48;
  --ink: #f6f1ff;
  --muted: #b5b0c8;
  --primary: #a78ad8;
  --primary-dark: #cdb8ee;
  --primary-soft: #423b61;
  --accent: #7f77b8;
  --line: #393a54;
  --focus: #dbbdff;
  --on-primary: #17182a;
  --danger: #ff8a80;
  --stage: #10111f;
  color-scheme: dark;
}

:root[data-theme="sunset"] {
  --bg: #fff8f3;
  --surface: #ffffff;
  --surface-soft: #ffeadf;
  --ink: #432923;
  --muted: #7c645d;
  --primary: #c35d4d;
  --primary-dark: #8f4137;
  --primary-soft: #f5cec1;
  --accent: #ea9277;
  --line: #f1ddd6;
  --focus: #305fc5;
  --stage: #f5ebe5;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

h1, h2, h3, p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.serif { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }

/* ---------- Layout ---------- */

.shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  position: relative;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 18px) 22px 14px;
}

.topbar h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.eyebrow {
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 17px;
  display: grid;
  place-items: center;
}

.avatar svg { width: 22px; height: 22px; }

.content {
  padding: 0 16px calc(env(safe-area-inset-bottom) + 104px);
  display: grid;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px;
}

.card-soft { background: var(--surface-soft); }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 { font-size: 18px; letter-spacing: -0.01em; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }

/* ---------- Hero ---------- */

.hero {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 16px;
  align-items: center;
  background:
    radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--primary-soft) 70%, transparent), transparent 55%),
    var(--surface);
}

.ring {
  --p: 50;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--primary-soft) 0);
  position: relative;
}

.ring::after {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 50%;
  background: var(--surface);
}

.ring > div {
  position: relative;
  z-index: 1;
  display: grid;
  text-align: center;
}

.ring span { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.14em; }
.ring strong { color: var(--primary-dark); font-family: Georgia, serif; font-weight: 500; font-size: 44px; line-height: 1; }
.ring small { color: var(--muted); font-size: 11px; margin-top: 3px; }

.pill {
  display: inline-block;
  background: var(--surface-soft);
  color: var(--primary-dark);
  border-radius: 99px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 9px;
}

.hero h2 { font-size: 16px; }
.hero .big {
  font-family: Georgia, serif;
  color: var(--primary-dark);
  font-size: 30px;
  line-height: 1.1;
  margin: 3px 0 4px;
}

/* ---------- Buttons ---------- */

.btn {
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 800;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.btn-primary {
  width: 100%;
  min-height: 60px;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--primary) 26%, transparent);
  font-size: 16px;
}

.btn-primary:disabled { opacity: .45; box-shadow: none; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-soft);
  color: var(--primary-dark);
  border: 1px solid var(--line);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  min-height: 44px;
  padding: 8px 10px;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
}

.btn-danger.solid { background: var(--danger); color: #fff; border: 0; }

.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 0; }

.dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--on-primary) 70%, transparent);
}

.link {
  border: 0; background: none; padding: 6px 0;
  color: var(--primary); font-weight: 800; font-size: 13px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 0 10px;
  line-height: 1.45;
}

/* ---------- Chips ---------- */

.chip-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  margin: 14px 0 8px;
}
.chip-label:first-child { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--bg);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
}

.chip[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.chip[aria-pressed="true"]::before { content: "✓ "; }

.chip.flow[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }

/* ---------- Fields ---------- */

.field { display: grid; gap: 6px; margin-top: 14px; }
.field > span { font-size: 13px; font-weight: 800; color: var(--muted); }

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  padding: 12px 14px;
  font-size: 16px; /* 16px stops iPhone zooming in */
  -webkit-appearance: none;
  appearance: none;
}

.field input[type="date"] { display: block; min-width: 0; text-align: left; }
.field input[type="date"]::-webkit-date-and-time-value { text-align: left; }

.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.field textarea { min-height: 84px; resize: vertical; line-height: 1.4; }

.error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
}

.saved { font-size: 12px; color: var(--muted); margin-top: 8px; min-height: 16px; }

/* ---------- Quick date choice ---------- */

.quick-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-dates .btn { min-height: 64px; flex-direction: column; gap: 2px; }
.quick-dates .btn small { font-weight: 600; font-size: 12px; opacity: .8; }

.or {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 12px; font-weight: 700;
  margin: 16px 0 0;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Week strip ---------- */

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.week button {
  border: 0; background: transparent; border-radius: 14px;
  min-width: 0; height: 64px;
  display: grid; place-items: center; align-content: center; gap: 2px;
}
.week span { font-size: 11px; color: var(--muted); }
.week strong { font-size: 16px; }
.week .is-predicted { background: var(--surface-soft); color: var(--primary-dark); border: 1px dashed var(--primary); }
.week .is-period { background: var(--primary); color: var(--on-primary); }
.week .is-period span { color: inherit; opacity: .8; }
.week .is-today { box-shadow: inset 0 0 0 2px var(--ink); }

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

.cal-head {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  margin-bottom: 14px;
}
.cal-head h2 { text-align: center; font-family: Georgia, serif; font-weight: 500; font-size: 22px; }
.round {
  width: 46px; height: 46px; border: 0; border-radius: 50%;
  background: var(--surface-soft); color: var(--primary-dark);
  display: grid; place-items: center;
}
.round svg { width: 20px; height: 20px; }

.grid7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekdays { margin-bottom: 6px; }
.weekdays span { text-align: center; color: var(--muted); font-size: 11px; font-weight: 800; }

.day {
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  font-size: 15px;
  position: relative;
  padding: 0;
}
.day.outside { opacity: .35; }
.day.is-period { background: var(--primary); color: var(--on-primary); font-weight: 800; }
.day.is-estimated { background: var(--primary-soft); color: var(--primary-dark); border-color: color-mix(in srgb, var(--primary) 50%, transparent); }
.day.is-predicted { background: var(--surface-soft); color: var(--primary-dark); border: 1px dashed var(--primary); }
.day.is-today { box-shadow: inset 0 0 0 2px var(--ink); font-weight: 900; }
.day.is-selected { outline: 3px solid var(--focus); outline-offset: 1px; }
.day .log-dot {
  position: absolute; left: calc(50% - 3px); bottom: 5px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--primary);
}
.day.is-period .log-dot { background: var(--on-primary); }
.day .flow-mark {
  position: absolute; top: 3px; right: 5px; font-size: 9px; font-weight: 900; letter-spacing: -1px;
}

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 5px; display: inline-block; }
.lg-period { background: var(--primary); }
.lg-est { background: var(--primary-soft); border: 1px solid var(--primary); }
.lg-pred { background: var(--surface-soft); border: 1px dashed var(--primary); }
.lg-today { box-shadow: inset 0 0 0 2px var(--ink); }
.lg-log { width: 8px !important; height: 8px !important; border-radius: 50% !important; background: var(--primary); }

/* ---------- Insights ---------- */

.intro {
  background: linear-gradient(140deg, color-mix(in srgb, var(--primary-soft) 75%, transparent), transparent), var(--surface);
}
.intro h2 { font-family: Georgia, serif; font-weight: 500; font-size: 26px; margin-bottom: 6px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 14px; }
.stat span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.stat strong { font-family: Georgia, serif; font-weight: 500; font-size: 34px; color: var(--primary-dark); line-height: 1; }
.stat small { color: var(--muted); font-size: 12px; margin-left: 3px; }

.bars {
  height: 170px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 0 4px;
}
.bar-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; min-width: 0; }
.bar-col b { font-size: 13px; color: var(--ink); }
.bar { width: min(34px, 100%); border-radius: 9px 9px 3px 3px; background: var(--primary); }
.bar.forecast { background: repeating-linear-gradient(-45deg, var(--primary-soft), var(--primary-soft) 5px, var(--accent) 5px, var(--accent) 8px); }
.bar-labels { display: flex; gap: 8px; padding: 6px 4px 0; }
.bar-labels span { flex: 1 1 0; text-align: center; font-size: 11px; color: var(--muted); min-width: 0; }

.list { display: grid; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 2px;
  border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; width: 100%;
}
.row:last-child { border-bottom: 0; }
.row strong { display: block; font-size: 15px; }
.row small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.row .chev { color: var(--muted); flex: 0 0 auto; }
.row .badge {
  font-size: 11px; font-weight: 800; color: var(--primary-dark);
  background: var(--surface-soft); border-radius: 99px; padding: 3px 8px; margin-left: 6px;
}

.feel-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.feel-row:last-child { border-bottom: 0; }
.feel-row span:last-child { color: var(--muted); text-align: right; }

/* ---------- Settings ---------- */

.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme {
  min-height: 60px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--bg); padding: 10px 12px;
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 10px;
  text-align: left; font-weight: 800; font-size: 14px;
}
.theme[aria-pressed="true"] { border: 2px solid var(--primary); }
.theme i { width: 26px; height: 26px; border-radius: 50%; box-shadow: inset -8px -5px rgba(255,255,255,.4); }
.theme b { color: var(--primary); }

.steps { margin: 10px 0 0; padding-left: 22px; display: grid; gap: 8px; font-size: 14px; }
.steps li::marker { color: var(--primary); font-weight: 800; }
.share-icon { display: inline-block; vertical-align: -3px; width: 18px; height: 18px; color: var(--primary); }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface-soft); border: 1px solid var(--line);
  border-radius: 20px; padding: 14px 16px;
}
.notice .ico {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 12px;
  background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center;
}
.notice .ico svg { width: 20px; height: 20px; }
.notice h3 { font-size: 15px; margin-bottom: 3px; }
.notice p { font-size: 13px; color: var(--muted); }
.notice .btn-row { margin-top: 10px; }
.notice .btn { min-height: 42px; font-size: 14px; padding: 8px 14px; }

/* ---------- Bottom nav ---------- */

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.nav button {
  min-height: 56px; border: 0; background: transparent; border-radius: 14px;
  color: var(--muted); display: grid; place-items: center; align-content: center; gap: 3px;
  font-size: 11px; font-weight: 800;
}
.nav svg { width: 22px; height: 22px; }
.nav button[aria-current="page"] { background: var(--surface-soft); color: var(--primary-dark); }

/* ---------- Sheet ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 12, 18, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out;
}
.sheet {
  width: 100%; max-width: 480px;
  max-height: 92vh; max-height: 92dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 22px);
  animation: rise .22s ease-out;
}
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { font-family: Georgia, serif; font-weight: 500; font-size: 24px; line-height: 1.2; }
.close {
  width: 40px; height: 40px; flex: 0 0 40px; border: 0; border-radius: 50%;
  background: var(--surface-soft); color: var(--ink); display: grid; place-items: center;
}
.close svg { width: 18px; height: 18px; }
.sheet .card { margin-bottom: 12px; }
.sheet .btn-primary { margin-top: 16px; }

.period-box {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
}
.period-box h3 { font-size: 16px; margin-bottom: 2px; }
.period-box p { font-size: 13px; color: var(--muted); }
.period-box .btn-row { margin-top: 12px; }
.period-box .btn { min-height: 46px; font-size: 14px; }

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

/* ---------- Toast ---------- */

.toast {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  width: calc(100% - 32px); max-width: 440px;
  background: var(--ink); color: var(--bg);
  border-radius: 16px; padding: 12px 12px 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
  animation: rise .2s ease-out;
}
.toast button {
  border: 0; background: transparent; color: var(--accent);
  font-weight: 900; padding: 8px 10px; min-height: 40px;
}

/* ---------- Onboarding ---------- */

.welcome {
  min-height: 100vh; min-height: 100dvh;
  max-width: 480px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 36px) 20px calc(env(safe-area-inset-bottom) + 28px);
  display: flex; flex-direction: column; justify-content: center;
  background:
    radial-gradient(circle at 85% 8%, var(--primary-soft), transparent 34%),
    radial-gradient(circle at 8% 94%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 34%),
    var(--bg);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand img { width: 72px; height: 72px; border-radius: 20px; margin-bottom: 12px; box-shadow: 0 10px 26px color-mix(in srgb, var(--primary) 25%, transparent); }
.brand h1 { font-family: Georgia, serif; font-weight: 500; font-size: 44px; color: var(--primary-dark); }
.brand p { color: var(--muted); margin-top: 4px; }
.welcome .card { padding: 22px; box-shadow: 0 18px 50px color-mix(in srgb, var(--primary) 12%, transparent); }
.welcome .card > h2 { font-family: Georgia, serif; font-weight: 500; font-size: 25px; margin: 6px 0; }
.step-dots { display: flex; gap: 6px; }
.step-dots i { width: 22px; height: 5px; border-radius: 9px; background: var(--line); }
.step-dots i.on { background: var(--primary); }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mt-s { margin-top: 8px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.seg button {
  min-height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); font-weight: 800; font-size: 14px;
}
.seg button[aria-pressed="true"] { border: 2px solid var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- Desktop preview ---------- */

@media (min-width: 560px) {
  html, body { background: var(--stage); }
  .shell { box-shadow: 0 0 60px rgba(40, 20, 30, .08); }
}

@media (max-width: 360px) {
  .hero { grid-template-columns: 108px 1fr; gap: 12px; }
  .ring { width: 104px; height: 104px; }
  .ring strong { font-size: 36px; }
  .hero .big { font-size: 25px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .themes { grid-template-columns: 1fr; }
}

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