:root {
  --bg: #f3ede1;
  --surface: #fbf8f1;
  --text: #17181c;
  --text-muted: #6b6558;
  --border: #e2d9c6;
  --primary: #2d3e8f;
  --primary-dark: #1f2c68;
  --primary-light: #dde2f4;
  --accent: #6b6558;
  --flare: #b1512e;
  --flare-bg: #f2e0d3;
  --ok: #5f7a4c;
  --period: #c26b83;
  --period-light: #f2dbe2;
  --ovulation: #d98a3d;
  --fertile: #f0c896;
  --radius: 14px;
  --radius-sm: 8px;
  --gap: 16px;
  --max-width: 480px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

#app {
  width: 100%;
  max-width: var(--max-width);
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: 72px; /* space for bottom nav */
}

.screen { display: none; flex: 1; padding: 20px 18px 24px; }
.screen.active { display: flex; flex-direction: column; }

h1 { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; letter-spacing: -0.01em; margin: 0 0 4px; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; margin: 0 0 10px; }
p { line-height: 1.4; }
.muted { color: var(--text-muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary-light);
  color: var(--primary-dark);
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-flare { background: var(--flare-bg); color: var(--flare); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; width: auto; }
.btn-danger { background: #f5ddd3; color: #963319; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
}
.chip.selected { background: var(--primary); border-color: var(--primary); color: #fff; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}
.toggle-row.flare-on { background: var(--flare-bg); border-color: var(--flare); }

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.switch input:checked + .track { background: var(--flare); }
.switch input:checked + .track + .thumb { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Keyboard/switch-device focus indicator — the app has no other :focus styling,
   so without this, focus on a borderless .btn or a pill-shaped .chip is either
   invisible or relies on inconsistent browser defaults. */
.btn:focus-visible,
.chip:focus-visible,
.nav-btn:focus-visible,
.mood-btn:focus-visible,
.cycle-day-cell:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Slider component */
.scale-slider label { font-weight: 600; font-size: 0.95rem; display: block; margin-bottom: 6px; }
.scale-slider input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}
.scale-slider .scale-value { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

/* Body map */
.body-map { display: flex; justify-content: center; padding: 6px 0; }
.body-map svg { width: 170px; height: auto; }
.body-map path, .body-map ellipse, .body-map rect, .body-map circle {
  fill: var(--primary-light);
  stroke: var(--border);
  stroke-width: 1.5;
  cursor: pointer;
  transition: fill 0.12s, stroke 0.12s;
}
.body-map [data-region].selected {
  fill: var(--primary);
}
.body-map .widespread {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}
.body-map .widespread.selected {
  stroke: var(--primary);
  fill: rgba(45, 62, 143, 0.08);
}
.body-map-legend-chips { margin-top: 8px; justify-content: center; }
.body-map-legend { text-align: center; margin-top: 4px; }

/* Mood picker */
.mood-picker { display: flex; justify-content: space-between; gap: 6px; }
.mood-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  font-size: 1.4rem;
  cursor: pointer;
}
.mood-btn.selected { border-color: var(--primary); background: var(--primary-light); }
.mood-btn .mood-label { display: block; font-size: 0.65rem; margin-top: 2px; color: var(--text-muted); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}
.bottom-nav.hidden { display: none; }
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 4px;
  cursor: pointer;
}
.nav-btn .nav-icon { font-size: 1.25rem; }
.nav-btn.active { color: var(--primary); font-weight: 600; }

/* Sticky save bar */
.sticky-save {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: 14px 0 6px;
  margin-top: auto;
}

/* Correlation heatmap */
.heatmap-scroll { overflow-x: auto; padding-bottom: 4px; opacity: 1; transition: opacity 0.2s; }
.heatmap-scroll.dim { opacity: 0.45; }
.heatmap-inner { display: flex; flex-direction: column; gap: 3px; width: max-content; }
.heatmap-row { display: flex; align-items: center; gap: 2px; }
.heatmap-row-label {
  flex: 0 0 82px;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding-right: 6px;
}
.heatmap-cell {
  flex: 0 0 22px;
  width: 22px; height: 22px;
  border-radius: 4px;
  background: var(--border);
}
.heatmap-daynum {
  flex: 0 0 22px;
  width: 22px;
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: center;
}
.phase-strip { display: flex; align-items: center; margin-bottom: 2px; }
.phase-seg {
  font-size: 0.55rem;
  color: var(--text-muted);
  text-align: center;
  border-bottom: 2px solid var(--border);
  padding-bottom: 2px;
}

.insight-item {
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.progress-note {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.dot-strip { display: flex; gap: 6px; margin-top: 6px; }
.dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem;
  color: var(--text-muted);
}
.dot.flare { background: var(--flare); color: #fff; }
.dot.logged { background: var(--ok); color: #fff; }

.disclaimer-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.step-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 14px; }
.step-dots .dot-step { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.step-dots .dot-step.active { background: var(--primary); }

.toast {
  position: fixed;
  bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

/* Desktop/laptop layout: the bottom tab bar becomes a left sidebar and the
   content column gets more breathing room. Bottom-nav positioning already
   relies on fixed positioning (independent of its place in the DOM), so it
   can be re-anchored to the left edge here without moving any markup — only
   `body`'s centering offset needs to shift to make room for it. */
@media (min-width: 860px) {
  :root { --max-width: 640px; }

  body { padding-left: 208px; }
  #app { padding-bottom: 24px; }
  .card { padding: 20px; }
  .body-map svg { width: 210px; }

  .bottom-nav {
    left: 0;
    top: 0;
    bottom: 0;
    transform: none;
    width: 208px;
    max-width: 208px;
    height: 100vh;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 2px;
    padding: 32px 16px;
    border-top: none;
    border-right: none;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
  }
  .nav-btn {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 0.9rem;
    transition: background 0.15s ease, color 0.15s ease;
  }
  .nav-btn:hover { background: var(--bg); }
  .nav-btn.active { background: var(--primary-light); }
  .nav-btn .nav-icon { font-size: 1.05rem; }

  .toast { left: calc(50% + 104px); bottom: 32px; }
}

@media (min-width: 1200px) {
  :root { --max-width: 720px; }
}

/* Cycle ring visualization */
.cycle-ring-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 10px auto 6px;
}
.cycle-ring-svg { width: 100%; height: 100%; }
.cycle-ring-daynum {
  font-size: 13px;
  font-weight: 700;
  fill: #fff;
  font-family: var(--font-body);
}
.cycle-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 34px;
  pointer-events: none;
}
.cycle-ring-phase {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 8px;
}
.cycle-ring-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cycle-ring-days {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.15;
  margin: 2px 0;
}
.cycle-ring-date { font-size: 0.75rem; color: var(--text-muted); }

/* Cycle calendar */
.cycle-weekday-row { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.cycle-weekday { text-align: center; font-size: 0.7rem; color: var(--text-muted); }
.cycle-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cycle-day-cell {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.cycle-day-cell.empty { background: transparent; cursor: default; }
.cycle-day-cell.today { box-shadow: inset 0 0 0 2px var(--primary); font-weight: 700; }
.cycle-day-cell.selected { outline: 2px solid var(--primary); outline-offset: 2px; }
/* White text fails WCAG AA contrast on both --period (~3.7:1) and --ovulation
   (~2.75:1) — dark text clears 4.5:1 comfortably against either. */
.cycle-day-cell.period-logged { background: var(--period); color: var(--text); }
.cycle-day-cell.period-predicted { background: var(--period-light); color: var(--period); }
.cycle-day-cell.ovulation-predicted { background: var(--ovulation); color: var(--text); }
.cycle-day-cell.fertile-predicted { background: var(--fertile); color: var(--text); }

.cycle-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 0.75rem; color: var(--text-muted); align-items: center; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
.legend-dot.period-logged { background: var(--period); }
.legend-dot.ovulation-predicted { background: var(--ovulation); }
.legend-dot.fertile-predicted { background: var(--fertile); }

@media print {
  body { display: block; }
  #app { max-width: 100%; padding-bottom: 0; }
  .bottom-nav, .toast, .no-print { display: none !important; }
  .export-report .card { border: none; box-shadow: none; padding: 0; margin-bottom: 18px; break-inside: avoid; }
  .heatmap-scroll { overflow: visible; }
  .heatmap-scroll.dim { opacity: 1; }
}
