:root {
  --bg: #FFF6F0;
  --card: #FFFFFF;
  --ink: #4A3835;
  --muted: #9A8580;
  --line: #F1E2DA;
  --coral: #E8736C;
  --coral-soft: #F9D3CE;
  --rose: #FBE9E5;
  --mint: #8FCBB8;
  --mint-soft: #DDF1EA;
  --mint-dark: #4E9E86;
  --radius: 20px;
  --shadow: 0 4px 18px rgba(170, 100, 85, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-user-select: none; user-select: none;
}
textarea, input { -webkit-user-select: text; user-select: text; font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 10px;
  background: linear-gradient(var(--bg) 75%, rgba(255,246,240,0));
}
.topbar h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -.5px; }

main { padding: 4px 16px 16px; max-width: 560px; margin: 0 auto; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 17px; font-weight: 700; }
.card p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 16px; padding: 15px 16px;
  font: inherit; font-weight: 700; cursor: pointer; margin-top: 10px;
  background: var(--coral); color: #fff;
}
.btn:active { transform: scale(.98); }
.btn.soft { background: var(--rose); color: var(--coral); }
.btn.mint { background: var(--mint-soft); color: var(--mint-dark); }
.btn.ghost { background: transparent; color: var(--coral); padding: 10px; }
.btn.danger { background: #FCE4E1; color: #C0453C; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Ring */
.ring-wrap { display: flex; flex-direction: column; align-items: center; padding: 8px 0 4px; }
.ring { width: 240px; height: 240px; position: relative; }
.ring svg { width: 100%; height: 100%; }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring-center .label { font-size: 14px; color: var(--muted); }
.ring-center .big { font-size: 46px; font-weight: 800; line-height: 1.05; }
.ring-center .phase { margin-top: 4px; font-weight: 700; color: var(--coral); font-size: 15px; padding: 0 30px; }

.stats-row { display: flex; gap: 10px; margin-bottom: 14px; }
.tile { flex: 1; background: var(--card); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.tile .v { font-size: 24px; font-weight: 800; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile.coral .v { color: var(--coral); }
.tile.mint .v { color: var(--mint-dark); }

.banner {
  background: var(--coral-soft); color: #8E3B34; border-radius: 16px;
  padding: 12px 14px; margin-bottom: 14px; font-weight: 600;
}
.banner.mint { background: var(--mint-soft); color: var(--mint-dark); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 13px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink);
}
.chip.on { background: var(--coral); border-color: var(--coral); color: #fff; }
.chip.on.m { background: var(--mint-dark); border-color: var(--mint-dark); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 16px 0 8px; }

.summary-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.summary-chips span { background: var(--rose); color: var(--coral); border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 600; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { margin: 0; text-transform: capitalize; }
.cal-head button { border: 0; background: var(--rose); color: var(--coral); width: 40px; height: 40px; border-radius: 50%; font-size: 20px; font-weight: 700; cursor: pointer; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; padding-bottom: 4px; }
.day {
  aspect-ratio: 1; border: 0; background: transparent; border-radius: 50%;
  font: inherit; font-size: 15px; color: var(--ink); position: relative; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.day.out { visibility: hidden; }
.day.period { background: var(--coral); color: #fff; font-weight: 700; }
.day.pred { box-shadow: inset 0 0 0 2px var(--coral); border-style: dashed; color: var(--coral); background: repeating-linear-gradient(45deg, #fff, #fff 4px, var(--rose) 4px, var(--rose) 8px); }
.day.fertile { background: var(--mint-soft); color: var(--mint-dark); }
.day.ovu { background: var(--mint); color: #fff; font-weight: 700; }
.day.today { outline: 2.5px solid var(--ink); outline-offset: 1px; font-weight: 800; }
.day.log::after {
  content: ""; position: absolute; bottom: 4px; left: 50%; width: 5px; height: 5px;
  margin-left: -2.5px; border-radius: 50%; background: var(--ink); opacity: .55;
}
.day.period.log::after { background: #fff; opacity: .9; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 5px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.list li:last-child { border-bottom: 0; }
.list li[data-action] { cursor: pointer; }
.sheet input[type=date] + .section-title { margin-top: 18px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; }
.bar-row .name { width: 130px; flex: none; }
.bar-row .bar { flex: 1; height: 10px; background: var(--rose); border-radius: 6px; overflow: hidden; }
.bar-row .bar b { display: block; height: 100%; background: var(--coral); border-radius: 6px; }
.bar-row .n { width: 26px; text-align: right; color: var(--muted); }

/* Settings */
.field { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.field:last-child { border-bottom: 0; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--rose); color: var(--coral); font-size: 20px; font-weight: 700; cursor: pointer; }
.stepper output { min-width: 32px; text-align: center; font-weight: 700; }
input[type=date] {
  width: 100%; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px; background: #fff;
  -webkit-appearance: none; appearance: none; min-height: 48px;
}
textarea {
  width: 100%; min-height: 80px; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px;
  background: #fff; resize: vertical;
}

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: rgba(255,255,255,.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; border: 0; background: none; font: inherit; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer;
}
.tabbar button span { font-size: 22px; filter: grayscale(1); opacity: .6; }
.tabbar button.active { color: var(--coral); font-weight: 700; }
.tabbar button.active span { filter: none; opacity: 1; }

/* Bottom sheet */
.backdrop { position: fixed; inset: 0; background: rgba(74,56,53,.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 10px 18px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; animation: up .22s ease-out;
  -webkit-overflow-scrolling: touch;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 20px; text-transform: capitalize; }
.sheet-head button { border: 0; background: var(--rose); color: var(--coral); border-radius: 999px; padding: 8px 14px; font: inherit; font-weight: 700; cursor: pointer; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 30;
  font-size: 14px; font-weight: 600; max-width: 90vw; text-align: center;
}
.chart { width: 100%; height: auto; display: block; }
