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

:root {
  --bg: #fdf0f5;
  --surface: #ffffff;
  --border: #e8e0d8;
  --text: #2d1f1a;
  --muted: #9b8882;
  --accent: #9b6b52;
  --accent-light: #f5ede8;

  /* point level colours */
  --pt-none: #d6e8f5;
  --pt0: #e74c3c;
  --pt1: #e67e22;
  --pt2: #f1c40f;
  --pt3: #27ae60;
  --pt3-fg: #ffffff;

  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
}

.hidden { display: none !important; }

/* ── PIN Screen ──────────────────────────────── */

#pin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
}

.pin-card {
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.pin-heart {
  font-size: 52px;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 14px;
}

.pin-card h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.pin-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 30px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 6px;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.15s;
}

.dot.filled { background: var(--accent); }

.pin-error {
  color: #c0392b;
  font-size: 13px;
  min-height: 22px;
  margin-bottom: 18px;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.num-btn {
  height: 66px;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 22px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: background 0.1s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.num-btn:active {
  transform: scale(0.94);
  background: var(--border);
}

.num-back { color: var(--muted); font-size: 20px; }

.num-go {
  background: var(--accent);
  color: white;
}

.num-go:active { background: #7a5240; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-7px); }
  40%       { transform: translateX(7px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}

/* ── App Shell ───────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}

.app-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.4px;
}

.streak-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 5px 13px;
  border-radius: 20px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-btn {
  border: none;
  background: var(--accent-light);
  color: var(--accent);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.guide-btn:active { background: var(--border); }

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 14px;
  flex-shrink: 0;
}

.month-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.month-nav h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.today-btn {
  border: none;
  background: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.today-btn:active { background: var(--accent-light); }
.today-btn.hidden-btn { visibility: hidden; }

.nav-btn {
  border: none;
  background: none;
  font-size: 26px;
  color: var(--accent);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.nav-btn:active { background: var(--accent-light); }

.month-stats {
  padding: 4px 20px 10px;
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Calendar ────────────────────────────────── */

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 0 12px 20px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}

.weekday {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 0;
}

.day-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  font-size: 15px;
  font-weight: 500;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s, border-color 0.15s;
  position: relative;
}

.day-cell:active { transform: scale(0.92); }

.day-cell[data-pts="none"] { background: var(--pt-none); color: var(--text); }
.day-cell[data-pts="0"] { background: var(--pt0); color: white; }
.day-cell[data-pts="1"] { background: var(--pt1); color: white; }
.day-cell[data-pts="2"] { background: var(--pt2); color: var(--text); }
.day-cell[data-pts="3"] { background: var(--pt3); color: var(--pt3-fg); }

.day-cell.today {
  border-color: var(--accent);
  font-weight: 700;
}

.day-cell.future {
  background: transparent !important;
  color: var(--border);
  cursor: default;
}

.day-cell.empty {
  background: transparent !important;
  cursor: default;
  pointer-events: none;
}

.day-note-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  margin-top: 2px;
}

.day-cell[data-pts="2"] .day-note-dot { background: rgba(0,0,0,0.3); }
.day-cell:not([data-pts="2"]) .day-note-dot { background: rgba(255,255,255,0.7); }

/* ── Bottom Sheet ────────────────────────────── */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 12px 20px calc(var(--safe-bottom) + 28px);
  max-height: 92vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 18px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.sheet-header h3 {
  font-size: 18px;
  font-weight: 600;
}

#sheet-close {
  border: none;
  background: var(--border);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Anchor buttons ──────────────────────────── */

.anchors {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.anchor {
  flex: 1;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 6px;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}

.anchor:active { transform: scale(0.95); }

.anchor.on {
  border-color: var(--accent);
  background: var(--accent-light);
}

.anchor-icon { font-size: 24px; margin-bottom: 5px; }
.anchor-name { font-size: 12px; font-weight: 600; color: var(--text); }
.anchor-desc { font-size: 10px; color: var(--muted); margin-top: 2px; line-height: 1.3; }

/* ── Tab bar ─────────────────────────────────── */

.tab-bar {
  display: flex;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 0 calc(var(--safe-bottom) + 12px);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.tab-btn.tab-active {
  color: var(--accent);
  font-weight: 700;
}

.tab-view {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Stats view ──────────────────────────────── */

.stats-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 24px;
}

.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
}

/* ── Heatmap ─────────────────────────────────── */

.heatmap-wrap {
  overflow-x: auto;
  margin-bottom: 6px;
}

.heatmap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: fit-content;
}

.heatmap-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.heatmap-month {
  width: 26px;
  font-size: 9px;
  color: var(--muted);
  text-align: right;
  padding-right: 4px;
  flex-shrink: 0;
}

.heatmap-cell {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

.heatmap-empty { background: transparent; }
.hm-future     { background: var(--border); opacity: 0.4; }
.hm-none       { background: var(--pt-none); }
.hm-0          { background: var(--pt0); }
.hm-1          { background: var(--pt1); }
.hm-2          { background: var(--pt2); }
.hm-3          { background: var(--pt3); }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 20px;
}

.leg-cell {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.leg-label {
  font-size: 10px;
  color: var(--muted);
  margin-left: 4px;
}

/* ── Anchor breakdown ────────────────────────── */

.breakdown {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.breakdown-icon { font-size: 18px; flex-shrink: 0; }

.breakdown-bar-wrap {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  border-radius: 5px;
  width: 0%;
  transition: width 0.6s ease;
}

.bar-morning { background: var(--pt1); }
.bar-love    { background: var(--pt2); }
.bar-evening { background: var(--pt3); }

.breakdown-pct {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  width: 34px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Gemini reflection ───────────────────────── */

.reflect-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.reflect-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  height: 50px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  margin-bottom: 14px;
}

.reflect-btn:active { background: #7a5240; }
.reflect-btn:disabled { background: var(--border); color: var(--muted); cursor: default; }

.reflect-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border-left: 3px solid var(--accent);
}

.reflect-card p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* ── Guide sheet ─────────────────────────────── */

.guide-section {
  margin-bottom: 22px;
}

.guide-anchor-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
}

.guide-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

.guide-prompts-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.guide-prompts {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guide-prompts li {
  font-size: 14px;
  color: var(--text);
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 10px;
  line-height: 1.4;
}

.guide-prompts li::before {
  content: '– ';
  color: var(--muted);
}

.guide-rules {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.guide-rules summary {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  list-style: none;
}

.guide-rules summary::-webkit-details-marker { display: none; }
.guide-rules summary::before { content: '▸ '; }
details[open] .guide-rules summary::before { content: '▾ '; }

.guide-rules ol {
  margin-top: 12px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-rules li {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

/* ── Love acts checklist ─────────────────────── */

.love-acts {
  background: var(--accent-light);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.love-acts-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
}

.love-acts-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.love-act-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.love-act-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.love-act-item span {
  font-size: 14px;
  color: var(--text);
}

/* ── Points row ──────────────────────────────── */

.points-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 15px;
  font-weight: 600;
}

.golden-badge {
  font-size: 12px;
  font-weight: 600;
  background: var(--pt3);
  color: white;
  padding: 3px 11px;
  border-radius: 20px;
}

/* ── Notes ───────────────────────────────────── */

.notes-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  resize: none;
  outline: none;
  min-height: 90px;
  margin-bottom: 18px;
}

textarea:focus { border-color: var(--accent); }

/* ── Save button ─────────────────────────────── */

.save-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  height: 54px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.08s;
}

.save-btn:active {
  background: #7a5240;
  transform: scale(0.98);
}

.save-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: default;
  transform: none;
}
