@import url('https://fonts.googleapis.com/css2?family=Lora:wght@400;600&family=Nunito:wght@400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-head: 'Lora', Georgia, serif;
  --font-body: 'Nunito', system-ui, sans-serif;
  --purple: #7a6a9a;
  --purple-light: #ede9f5;
  --purple-dark: #5a4a7a;
  --period-red: #c0392b;
  --predicted: #f5c0bb;
  --predicted-dark: #a03020;
  --fertile: #c8e6d4;
  --fertile-dark: #3a7a48;
  --sage: #7a9e8a;
  --sage-light: #e8f0eb;
  --warm-bg: #f5f4f8;
  --card-bg: #ffffff;
  --text: #1e1a2e;
  --text-2: #5a5270;
  --text-3: #9a90b0;
  --border: #e2deed;
  --radius: 16px;
  --radius-sm: 10px;
  --tab-h: 50px;
}

body.dark {
  --warm-bg: #15121e;
  --card-bg: #1e1a2a;
  --text: #ede8f5;
  --text-2: #b0a8c8;
  --text-3: #6a6080;
  --border: #2e2840;
  --purple-light: #2a2040;
  --sage-light: #1e2e26;
  --predicted: #5a2020;
  --predicted-dark: #f5c0bb;
}

html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--warm-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; padding-bottom: 80px; }

/* Hero */
.hero {
  text-align: center; padding: 28px 16px 20px;
  background: var(--card-bg); border-bottom: 1px solid var(--border);
}
.hero-icon { font-size: 32px; margin-bottom: 6px; }
.hero-title {
  font-family: var(--font-head);
  font-size: 30px; font-weight: 400; letter-spacing: 1px;
  color: var(--purple-dark);
}
.hero-sub { font-family: var(--font-body); font-size: 10px; letter-spacing: 3px; color: var(--text-3); margin-top: 4px; text-transform: uppercase; }

/* Tabs */
.tab-bar {
  display: flex; background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 90;
}
.tab {
  flex: 1; height: var(--tab-h); border: none; background: none;
  font-family: var(--font-body); font-size: 14px; color: var(--text-3);
  cursor: pointer; font-weight: 600; position: relative;
}
.tab.active { color: var(--purple); }
.tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 20%; right: 20%;
  height: 2px; background: var(--purple); border-radius: 2px 2px 0 0;
}

.tab-content { display: none; flex-direction: column; gap: 14px; padding: 16px; }
.tab-content.active { display: flex; }

/* Glance */
.glance-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; border: 1px solid var(--border);
}
.glance-title {
  font-family: var(--font-body); font-size: 10px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px;
}
.glance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.glance-item {
  background: var(--warm-bg); border-radius: var(--radius-sm); padding: 12px; text-align: center;
}
.glance-val { font-family: var(--font-head); font-size: 22px; font-weight: 600; color: var(--purple-dark); }
.glance-label { font-family: var(--font-body); font-size: 11px; color: var(--text-3); margin-top: 3px; }

/* Phase card */
.phase-card {
  background: var(--purple-light); border-radius: var(--radius);
  padding: 16px 18px; display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border);
}
.phase-icon { font-size: 28px; flex-shrink: 0; }
.phase-title { font-family: var(--font-head); font-size: 15px; font-weight: 600; color: var(--text); }
.phase-sub { font-family: var(--font-body); font-size: 13px; color: var(--text-2); margin-top: 3px; }

/* Calendar */
.cal-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; border: 1px solid var(--border);
}
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-nav {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 18px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cal-nav:active { background: var(--purple-light); }
.cal-month { font-family: var(--font-head); font-size: 17px; font-weight: 600; color: var(--text); }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; margin-bottom: 6px; }
.cal-dow span { font-family: var(--font-body); font-size: 11px; color: var(--text-3); font-weight: 600; padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; position: relative;
  font-family: var(--font-body); font-size: 13px; color: var(--text-2); font-weight: 500;
}
.cal-day.other-month { color: var(--text-3); opacity: 0.35; pointer-events: none; }
.cal-day.today { font-weight: 700; color: var(--purple); }
.cal-day.today::before {
  content: ''; position: absolute; inset: 1px;
  border: 2px solid var(--purple); border-radius: 50%;
}
.cal-day.period { background: var(--period-red); color: white; font-weight: 700; }
.cal-day.period.today::before { border-color: rgba(255,255,255,0.6); }
.cal-day.predicted { background: var(--predicted); color: var(--predicted-dark); }
.cal-day.fertile { background: var(--fertile); color: var(--fertile-dark); }
.cal-day.has-log::after {
  content: ''; position: absolute; bottom: 3px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--sage);
}
.cal-day.period.has-log::after { background: rgba(255,255,255,0.7); }
.cal-day:not(.other-month):active { opacity: 0.7; }

.cal-legend {
  display: flex; gap: 14px; margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.leg-item { display: flex; align-items: center; gap: 5px; font-family: var(--font-body); font-size: 11px; color: var(--text-3); }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; }
.leg-dot.period { background: var(--period-red); }
.leg-dot.predicted { background: var(--predicted); }
.leg-dot.logged { background: var(--sage); }
.cal-hint { font-family: var(--font-body); font-size: 11px; color: var(--text-3); text-align: center; margin-top: 10px; font-style: italic; }

/* Cards */
.section-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; border: 1px solid var(--border);
}
.section-title { font-family: var(--font-head); font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.card-desc { font-family: var(--font-body); font-size: 13px; color: var(--text-3); margin-bottom: 10px; }

/* History */
.history-year { 
  font-family: var(--font-body); font-size: 11px; font-weight: 700;
  color: var(--text-3); text-transform: uppercase; letter-spacing: 1px;
  padding: 8px 0 6px; margin-top: 4px;
}
.history-year:first-child { margin-top: 0; }
.cycle-entry {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--warm-bg);
  border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 6px;
}
.cycle-entry-date { font-family: var(--font-body); font-size: 14px; font-weight: 600; color: var(--text); }
.cycle-entry-meta { font-family: var(--font-body); font-size: 12px; color: var(--text-3); margin-top: 1px; }
.cycle-entry-flow {
  font-family: var(--font-body); font-size: 12px; padding: 3px 10px; border-radius: 12px;
  background: var(--purple-light); color: var(--purple-dark); font-weight: 600;
}
.entry-delete { border: none; background: none; cursor: pointer; color: var(--text-3); font-size: 20px; padding: 0 4px; }
.show-more-btn {
  width: 100%; padding: 10px; border-radius: var(--radius-sm);
  border: 1px dashed var(--border); background: none;
  font-family: var(--font-body); font-size: 13px; color: var(--text-3);
  cursor: pointer; margin-top: 4px;
}
.show-more-btn:active { background: var(--warm-bg); }

/* Day heading */
.day-heading { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px; }
.day-heading-text { font-family: var(--font-head); font-size: 17px; font-weight: 600; color: var(--text); }
.day-badge {
  font-family: var(--font-body); font-size: 12px; padding: 4px 10px; border-radius: 12px;
  background: var(--purple-light); color: var(--purple-dark); font-weight: 600;
}

/* Mood */
.mood-row { display: flex; justify-content: space-between; }
.mood-btn {
  width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid transparent; background: var(--warm-bg); font-size: 26px; cursor: pointer;
}
.mood-btn.active { border-color: var(--purple); transform: scale(1.1); }

/* Sleep */
.rating-row { display: flex; gap: 8px; margin-bottom: 4px; }
.rating-btn {
  flex: 1; height: 42px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-family: var(--font-body); font-size: 15px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.rating-btn.active { background: var(--purple); border-color: var(--purple); color: white; }
.rating-label { font-family: var(--font-body); font-size: 11px; color: var(--text-3); }

/* Chips */
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--warm-bg);
  font-family: var(--font-body); font-size: 13px; color: var(--text-2); cursor: pointer; font-weight: 500;
}
.chip.active { background: var(--purple); border-color: var(--purple); color: white; }

/* Notes grid */
.notes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note-label { display: block; font-family: var(--font-body); font-size: 12px; color: var(--text-3); margin-bottom: 4px; font-weight: 600; }
.note-select {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-family: var(--font-body); font-size: 13px; color: var(--text); appearance: none; -webkit-appearance: none;
}
.notes-text {
  width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--warm-bg); padding: 10px 12px;
  font-family: var(--font-body); font-size: 14px; color: var(--text); resize: none;
}

/* Buttons */
.primary-btn {
  width: 100%; height: 50px; border-radius: var(--radius); border: none;
  background: var(--purple); color: white;
  font-family: var(--font-body); font-size: 16px; font-weight: 700; cursor: pointer;
}
.primary-btn:active { background: var(--purple-dark); }
.save-status { text-align: center; font-family: var(--font-body); font-size: 13px; color: var(--sage); height: 20px; margin-top: 6px; }
.mt { margin-top: 12px; }
.field-label { display: block; font-family: var(--font-body); font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }

/* Todo */
.todo-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.todo-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--warm-bg);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; font-family: var(--font-body); font-size: 14px; color: var(--text);
}
.todo-item:active { opacity: 0.6; }
.todo-item-del { color: var(--text-3); font-size: 18px; margin-left: 8px; flex-shrink: 0; }
.todo-add-row { display: flex; gap: 8px; }
.todo-input {
  flex: 1; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-family: var(--font-body); font-size: 14px; color: var(--text);
}
.todo-add-btn {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: none; background: var(--purple); color: white; font-size: 24px; cursor: pointer;
}

/* Mini chart */
.mini-chart { display: flex; align-items: flex-end; gap: 4px; height: 64px; }
.mini-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.mini-bar { width: 100%; background: var(--border); border-radius: 3px 3px 0 0; min-height: 4px; }
.mini-bar.filled { background: var(--purple); }
.mini-bar-label { font-family: var(--font-body); font-size: 9px; color: var(--text-3); }

/* Trend */
.trend-list { display: flex; flex-direction: column; gap: 10px; }
.trend-row { display: flex; align-items: center; gap: 10px; }
.trend-name { font-family: var(--font-body); font-size: 13px; color: var(--text-2); min-width: 130px; }
.trend-bar-bg { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.trend-bar-fill { height: 100%; border-radius: 4px; background: var(--purple); }
.trend-pct { font-family: var(--font-body); font-size: 12px; color: var(--text-3); min-width: 32px; text-align: right; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card-bg); border-radius: 20px 20px 0 0;
  padding: 24px 20px 40px; width: 100%; max-width: 480px;
}
.modal-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; margin-bottom: 18px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.cancel-btn {
  flex: 1; height: 48px; border-radius: var(--radius);
  border: 1px solid var(--border); background: none;
  font-family: var(--font-body); font-size: 16px; color: var(--text-2); cursor: pointer;
}
.modal-save { flex: 1; height: 48px; margin-top: 0; }

/* FAB */
.fab {
  position: fixed; bottom: 24px; right: 20px;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--purple); color: white; border: none;
  font-size: 20px; cursor: pointer; z-index: 80;
  box-shadow: 0 4px 16px rgba(122,106,154,0.4);
}

/* Settings */
.settings-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 300; display: flex; align-items: flex-end; justify-content: center;
}
.settings-overlay.hidden { display: none; }
.settings-panel {
  background: var(--card-bg); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; padding-bottom: 40px;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 14px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--card-bg);
}
.settings-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: none; cursor: pointer; font-size: 16px; color: var(--text-2); }
.settings-section { padding: 16px; border-bottom: 1px solid var(--border); }
.settings-group-title { font-family: var(--font-body); font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-3); margin-bottom: 12px; font-weight: 700; }
.settings-row { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.settings-label { font-family: var(--font-body); font-size: 15px; color: var(--text); }
.settings-input-wrap { display: flex; align-items: center; gap: 6px; font-family: var(--font-body); font-size: 14px; color: var(--text-2); }
.settings-input {
  width: 56px; padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-family: var(--font-body); font-size: 15px; color: var(--text); text-align: center;
}
.settings-action-btn {
  width: 100%; padding: 13px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-family: var(--font-body); font-size: 15px; color: var(--text); cursor: pointer; text-align: left; margin-bottom: 8px;
}
.settings-action-btn.danger { color: #c0392b; }
.settings-hint { font-family: var(--font-body); font-size: 12px; color: var(--text-3); line-height: 1.5; margin-top: 4px; }
.toggle-btn {
  width: 48px; height: 28px; border-radius: 14px;
  background: var(--border); border: none; cursor: pointer; position: relative; transition: background 0.2s;
}
.toggle-btn[aria-checked="true"] { background: var(--purple); }
.toggle-knob {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: white; transition: transform 0.2s;
}
.toggle-btn[aria-checked="true"] .toggle-knob { transform: translateX(20px); }

.empty-msg { font-family: var(--font-body); font-size: 13px; color: var(--text-3); font-style: italic; }
