/* Soft and warm by day, calm dusk when the phone is in dark mode. */
:root {
  --bg: #FBF6F1;
  --card: #FFFFFF;
  --ink: #4A3530;
  --ink-2: #9A8478;
  --rose: #C46A7E;
  --rose-fill: #F3E3E2;
  --water: #8FB5B0;
  --lavender: #8E5A66;
  --line: rgba(74, 53, 48, 0.1);
  --on-rose: #FFFFFF;
  --serif: ui-serif, "New York", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --tab-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #2A2233;
    --card: #3A3045;
    --ink: #F1E8F3;
    --ink-2: #A89BB5;
    --rose: #D99AB0;
    --rose-fill: #4A3346;
    --water: #8FC3C9;
    --lavender: #C9B3E0;
    --line: rgba(241, 232, 243, 0.1);
    --on-rose: #2A2233;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body.hidden-app #app, body.hidden-app #tabs { filter: blur(24px); }

#app {
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.caption { font-size: 12px; color: var(--ink-2); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; }
.row > .grow { flex: 1; min-width: 0; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 16px; }
.topbar .back { font-size: 16px; }

.card {
  background: var(--card);
  border-radius: 22px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card.tint { background: var(--rose-fill); }
button.card, a.card { text-align: left; border: 0; color: inherit; font: inherit; width: 100%; cursor: pointer; text-decoration: none; }

button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  background: var(--rose-fill);
  color: var(--rose);
  font-weight: 600;
}
.btn.primary { background: var(--rose); color: var(--on-rose); }
.btn.block { width: 100%; padding: 15px 16px; font-size: 17px; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 12px; }
.btn.danger { background: transparent; color: #C0392B; }
.btn:disabled { opacity: 0.45; }
.link { background: none; border: 0; color: var(--rose); padding: 0; font-weight: 500; }
.icon-btn { background: none; border: 0; color: var(--ink-2); padding: 6px; font-size: 22px; line-height: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0;
  border-radius: 999px;
  padding: 8px 13px;
  background: var(--rose-fill);
  color: var(--ink);
  font-size: 15px;
}
.chip.on { background: var(--rose); color: var(--on-rose); }

.seg { display: flex; background: var(--rose-fill); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 7px 4px;
  font-size: 14px;
  color: var(--ink);
}
.seg button.on { background: var(--card); color: var(--rose); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.section-title { font-size: 13px; color: var(--ink-2); text-transform: none; margin: 8px 4px -4px; }

.list { background: var(--card); border-radius: 22px; overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  color: inherit;
  font: inherit;
}
.list-row .grow { flex: 1; min-width: 0; }
.chev { color: var(--ink-2); }

input[type=text], input[type=tel], input[type=number], input[type=password], textarea, select {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
}
textarea { min-height: 96px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--ink-2); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--rose-fill); border-radius: 30px; transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.switch input:checked + span { background: var(--rose); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Hero ring */
.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 4px 0 6px; }
.ring { position: relative; width: 196px; height: 196px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .big { font-family: var(--serif); font-size: 34px; font-weight: 600; line-height: 1.1; }
.phase { color: var(--lavender); font-weight: 600; font-size: 15px; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--card);
  border: 0;
  border-radius: 20px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 500;
}
.tile .ico { font-size: 20px; color: var(--rose); }

.meals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.meal {
  border: 0;
  background: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-2);
}
.meal .box {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--rose-fill);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 13px;
}
.meal .box.done { color: var(--rose); font-size: 20px; }
.meal .box img { width: 100%; height: 100%; object-fit: cover; }

.mini-ring { width: 46px; height: 46px; flex: none; }

.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: var(--rose-fill); }
.photo { width: 100%; border-radius: 14px; display: block; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px 2px; text-align: center; }
.cal-grid .dow { font-size: 12px; color: var(--ink-2); font-weight: 600; padding-bottom: 4px; }
.day {
  border: 0;
  background: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 15px;
  color: var(--ink);
}
.day .num { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.day.period .num { background: var(--rose); color: var(--on-rose); }
.day.spot .num { box-shadow: inset 0 0 0 2px var(--rose); }
.day.predicted .num { outline: 1.5px dashed var(--rose); outline-offset: -2px; }
.day.fertile .num { background: color-mix(in srgb, var(--water) 30%, transparent); }
.day.ovulation .num { background: color-mix(in srgb, var(--water) 65%, transparent); }
.day.today .num { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.day .dot { width: 4px; height: 4px; border-radius: 50%; background: transparent; }
.day.has .dot { background: var(--ink-2); }
.day:disabled { opacity: 0.55; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); justify-content: center; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 56px; gap: 8px; align-items: center; font-size: 14px; }
.bar { height: 10px; border-radius: 6px; background: var(--rose); }
.bar.water { background: var(--water); }
.vbars { display: flex; align-items: flex-end; gap: 8px; height: 120px; }
.vbars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; font-size: 11px; color: var(--ink-2); }
.vbars .fill { width: 100%; border-radius: 6px 6px 3px 3px; background: var(--water); min-height: 3px; }
.vbars .fill.dim { opacity: 0.45; }

/* Tabs */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabs button {
  flex: 1;
  height: var(--tab-h);
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--ink-2);
}
.tabs button .ico { font-size: 21px; line-height: 1; }
.tabs button.on { color: var(--rose); }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 20, 25, 0.35);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.2s ease;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.25s ease;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 14px;
  z-index: 50;
  max-width: 90vw;
}

/* Lock */
.lock {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
}
.pin-dots { display: flex; gap: 14px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--rose); }
.pin-dots i.on { background: var(--rose); }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; }
.keypad button { height: 72px; border-radius: 50%; border: 0; background: var(--card); font-size: 26px; font-family: var(--serif); }
.keypad button.blank { background: none; }
.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* Breathing */
.breath { position: relative; width: 190px; height: 190px; margin: 0 auto; }
.breath .base, .breath .pulse { position: absolute; inset: 0; border-radius: 50%; }
.breath .base { background: var(--rose-fill); }
.breath .pulse { background: color-mix(in srgb, var(--rose) 35%, transparent); transform: scale(0.45); }
.breath .label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: var(--serif); font-size: 18px; }

.note-quote { font-family: var(--serif); font-size: 17px; }
.banner { background: var(--rose-fill); color: var(--rose); border-radius: 16px; padding: 12px 14px; font-size: 14px; }

/* Doctor report (also used for printing) */
.report { background: #fff; color: #222; font: 12px/1.45 var(--sans); padding: 20px; border-radius: 12px; }
.report h1 { font-size: 20px; color: #222; }
.report h2 { font-size: 15px; color: #A04A5E; border-bottom: 1px solid #E5C9CF; padding-bottom: 3px; margin: 18px 0 8px; }
.report table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.report th, .report td { text-align: left; padding: 4px 6px; vertical-align: top; }
.report th { font-weight: 600; border-bottom: 1px solid #ddd; }
.report tr:nth-child(even) td { background: #F7F5F3; }
.report tr.flag td { background: #FBEAED; }
.report ul { margin: 4px 0 8px; padding-left: 18px; }
.report .rbar { display: inline-block; height: 8px; background: #C46A7E; border-radius: 4px; vertical-align: middle; }
.report .photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.report .photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.report .disclaimer { font-style: italic; color: #666; }

@media print {
  body { background: #fff; }
  #tabs, #sheet-root, .toast, .no-print { display: none !important; }
  #app { padding: 0; max-width: none; }
  .report { padding: 0; border-radius: 0; }
  .report h2 { break-after: avoid; }
  .report tr, .report .photos img { break-inside: avoid; }
}
