:root {
  --bg: #F8EFE9;
  --surface: #FFFDFB;
  --surface-alt: #FBF1EC;
  --border: #EAD6CE;
  --text: #3A2227;
  --text-soft: #8A6267;
  --text-faint: #B99A9D;
  --accent: #8C2F3F;
  --accent-light: #C2484F;
  --accent-contrast: #FFFFFF;
  --sex-color: #8C2F3F;
  --solo-color: #B5703A;
  --danger: #B23A3A;
  --shadow: 0 8px 24px rgba(92, 22, 38, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Libre Franklin", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
}

.brand-title, .screen-title {
  font-family: "Playfair Display", serif;
  font-weight: 700;
}

.hidden { display: none !important; }

.screen { display: none; padding: 16px 16px 32px; }
.screen.active { display: block; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 12px;
}
.app-header .brand-title { font-size: 26px; margin: 0; color: var(--accent); }
.app-header .screen-title { font-size: 20px; margin: 0; flex: 1; text-align: center; }
.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--accent);
  font-size: 22px; cursor: pointer; border-radius: 50%;
}
.icon-btn:active { background: var(--surface-alt); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn-spacer { width: 40px; display: inline-block; }

/* ---------- Welcome ---------- */
.welcome-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px 24px 24px;
}
.welcome-center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.welcome-hero { width: 96px; height: 96px; margin-bottom: 8px; }
.welcome-title { font-size: 30px; color: var(--accent); margin: 0; }
.welcome-copy { color: var(--text-soft); font-size: 15px; line-height: 1.5; max-width: 320px; margin: 0; }
.welcome-callout {
  margin-top: 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  max-width: 320px;
}
.welcome-callout-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 14px; color: var(--accent);
}
.welcome-callout-title svg { width: 18px; height: 18px; }
.welcome-callout-copy { font-size: 13px; color: var(--text-soft); margin: 6px 0 0; }
.ios-add-steps { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--text-soft); }
.ios-add-step { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ios-add-step svg { width: 20px; height: 20px; color: var(--accent); }
.ios-add-arrow { color: var(--text-faint); }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  border-radius: 999px;
  border: none;
  padding: 13px 20px;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-small { padding: 9px 14px; font-size: 13px; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-secondary { background: var(--surface-alt); color: var(--accent); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(178, 58, 58, 0.35); }

/* ---------- Month nav / calendar ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.month-label { font-weight: 600; font-size: 16px; }
.month-totals { text-align: center; color: var(--text-soft); font-size: 13px; margin: 4px 0 14px; }
.month-totals .count-sex { color: var(--sex-color); font-weight: 600; }
.month-totals .count-solo { color: var(--solo-color); font-weight: 600; }

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-tile {
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  position: relative;
  font-size: 13px;
}
.cal-tile.empty { background: none; border: none; cursor: default; }
.cal-tile.future { opacity: 0.4; cursor: default; }
.cal-tile.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-tile-num { font-weight: 600; }
.cal-tile-dots { display: flex; gap: 3px; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; }
.cal-dot-sex { background: var(--sex-color); }
.cal-dot-solo { background: var(--solo-color); }

.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: calc(50% - 240px + 20px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 28px;
  border: none;
  box-shadow: var(--shadow);
  cursor: pointer;
}
@media (max-width: 519px) {
  .fab { right: 20px; }
}

/* ---------- Day screen ---------- */
.entry-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.entry-card-top { display: flex; align-items: center; justify-content: space-between; }
.entry-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; color: #fff;
}
.entry-badge.sex { background: var(--sex-color); }
.entry-badge.solo { background: var(--solo-color); }
.entry-time { font-weight: 600; color: var(--text); }
.entry-duration { color: var(--text-soft); font-size: 13px; }
.entry-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.entry-tag { font-size: 11px; background: var(--surface-alt); color: var(--text-soft); padding: 3px 8px; border-radius: 999px; }
.entry-note { margin-top: 6px; font-size: 13px; color: var(--text-soft); font-style: italic; }
.entry-empty { text-align: center; color: var(--text-faint); margin-top: 48px; font-size: 14px; }
.btn-add-entry { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 16px; right: 16px; max-width: 448px; margin: 0 auto; }

/* ---------- Settings ---------- */
.settings-body { display: flex; flex-direction: column; gap: 24px; margin-top: 8px; }
.settings-group { display: flex; flex-direction: column; gap: 10px; }
.settings-group-title { font-size: 14px; color: var(--text-soft); margin: 0; text-transform: uppercase; letter-spacing: 0.04em; }
.settings-hint { font-size: 13px; color: var(--text-faint); margin: 0; }
.settings-about { font-size: 12.5px; color: var(--text-faint); line-height: 1.5; text-align: center; margin-top: 8px; }
.custom-position-list { display: flex; flex-wrap: wrap; gap: 6px; }
.custom-position-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 6px 5px 12px;
}
.custom-position-item button { border: none; background: none; color: var(--text-faint); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(58, 34, 39, 0.4);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal-sheet {
  background: var(--surface);
  width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-sheet-center { border-radius: 20px; margin: auto 16px; max-width: 400px; }
.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 999px; margin: 6px auto 0; }
.modal-title { font-size: 19px; margin: 0; }
.modal-copy { font-size: 14px; color: var(--text-soft); line-height: 1.5; margin: 0; }

.field-group { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field-input {
  font-family: inherit; font-size: 15px; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-alt);
  color: var(--text); width: 100%;
}
.field-input-inline { margin-top: 2px; }
.field-textarea { resize: vertical; min-height: 44px; }

.pill-toggle { display: flex; background: var(--surface-alt); border-radius: 999px; padding: 4px; gap: 4px; }
.pill-option {
  flex: 1; border: none; background: none; padding: 10px; border-radius: 999px;
  font-family: inherit; font-weight: 600; font-size: 14px; color: var(--text-soft); cursor: pointer;
}
.pill-option.active { background: var(--accent); color: #fff; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-alt); color: var(--text-soft);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-family: inherit; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.add-custom-row { display: flex; gap: 8px; }
.add-custom-row .field-input { flex: 1; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.modal-actions .btn { flex: 1; }
.modal-actions .btn-danger { flex: 0 0 auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; font-size: 13.5px;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
  z-index: 100; max-width: 90%; text-align: center;
}
