:root {
  --bg: #fbeee6;
  --card: #fffaf6;
  --ink: #3b2a2f;
  --muted: #8a7479;
  --accent: #e2557a;
  --accent-ink: #fff;
  --soft: #f6dcd6;
  --line: #efd9d1;
  --danger: #c0392b;
  --ok: #3f9d6a;
  --hero-a: #f7a1b5;
  --hero-b: #f6c28b;
  --paper: #fffaf0;
  --shadow: 0 6px 20px rgba(120, 60, 60, 0.08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1517;
    --card: #2a2023;
    --ink: #f6e9e6;
    --muted: #b49ca1;
    --accent: #f06b8f;
    --soft: #3a2b2f;
    --line: #3b2d31;
    --danger: #ff7a6b;
    --ok: #6fd39b;
    --hero-a: #8a3550;
    --hero-b: #8a5a2f;
    --paper: #2f2629;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 17px/1.4 ui-rounded, -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  overflow-x: hidden;
}
main {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 28px);
}
[hidden] { display: none !important; }
h1 { font-size: 28px; margin: 2px 0; line-height: 1.15; }
h2 { font-size: 22px; margin: 6px 0; }
h2.section { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 10px 4px -4px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.accent { color: var(--accent); font-weight: 600; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }

/* ---------- Pages ---------- */
.page { display: flex; flex-direction: column; gap: 14px; }
.page.enter { animation: slide-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } }
.center-page { min-height: 80dvh; justify-content: center; }
.hero-emoji { font-size: 60px; text-align: center; }
.small-hero { font-size: 44px; text-align: left; }
.page-head { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 4px; min-height: 48px; }
.page-head h1 { font-size: 24px; text-align: center; }
.page-head .head-right { min-width: 44px; display: flex; justify-content: flex-end; }
.back { background: transparent; color: var(--accent); font-size: 36px; line-height: 1; padding: 0 8px 4px 0; font-weight: 400; }
.empty { text-align: center; padding: 30px 10px; }
.empty-card { text-align: center; color: var(--muted); font-weight: 600; padding: 26px 18px; }

/* ---------- Cards & controls ---------- */
.card {
  background: var(--card);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
  color: inherit;
  text-align: left;
  width: 100%;
}
button.card { font-weight: inherit; display: block; }
button.card:active, .tile:active, .mood-chip:active, .hero-card:active, .row:active, .letter-row:active, .visit-row:active { transform: scale(0.98); }
.notice { border: 1.5px dashed var(--accent); }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
input[type='checkbox'] { width: 22px; height: 22px; padding: 0; border-radius: 6px; -webkit-appearance: checkbox; appearance: auto; accent-color: var(--accent); }
.check-row { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }

button {
  font: inherit; border: 0; border-radius: 14px; padding: 13px 16px; cursor: pointer; font-weight: 600;
  color: inherit; background: none; transition: transform 0.12s ease;
}
button:disabled { opacity: 0.55; }
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.ghost { background: transparent; color: var(--muted); }
.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.big { padding: 20px; font-size: 20px; }
.small-btn { white-space: nowrap; padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.icon-btn { background: transparent; color: var(--muted); font-size: 24px; padding: 6px 4px 6px 12px; }
.row-btns { display: flex; gap: 10px; }
.row-btns > * { flex: 1; }
.load-more { width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px;
  z-index: 10; animation: toast-in 0.25s ease; transition: opacity 0.3s; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.out { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.pill { display: inline-block; margin-top: 10px; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--soft); }
.pill.hot { background: var(--accent); color: var(--accent-ink); }
.pill.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }

.badge {
  position: absolute; top: 10px; right: 10px; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 800; display: grid; place-items: center;
}

/* ---------- Home ---------- */
.home-head { display: flex; justify-content: space-between; align-items: flex-start; padding-top: 4px; }

.moods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mood-chip {
  background: var(--card); box-shadow: var(--shadow); border-radius: 20px; padding: 12px; display: flex; gap: 10px;
  align-items: center; text-align: left; font-weight: 400; min-width: 0;
}
.mood-emoji { font-size: 30px; line-height: 1; }
.mood-emoji.faded { opacity: 0.45; }
.mood-emoji.huge { font-size: 56px; }
.mood-text { display: flex; flex-direction: column; min-width: 0; }
.mood-text > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mood-big { display: flex; gap: 16px; align-items: center; }

.hero-card {
  display: block; width: 100%; text-align: left; border-radius: 26px; padding: 22px 20px; color: #3b1f28;
  background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); box-shadow: 0 10px 30px rgba(226, 85, 122, 0.25);
}
@media (prefers-color-scheme: dark) { .hero-card { color: #fff3f5; } }
.label.on-hero { color: inherit; opacity: 0.75; }
.hero-big { font-size: 38px; font-weight: 800; margin: 4px 0; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.hero-big small { font-size: 16px; font-weight: 700; opacity: 0.75; margin: 0 7px 0 2px; }
.hero-sub { font-weight: 600; opacity: 0.85; }
.progress { margin-top: 14px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.4); overflow: hidden; }
.progress > div { height: 100%; border-radius: inherit; background: rgba(255, 255, 255, 0.95); }

.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.clocks .span { grid-column: 1 / -1; }
.time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

.heart-card { overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.heart {
  font-size: 60px; line-height: 1; background: var(--soft); width: 116px; height: 116px;
  border-radius: 50%; padding: 0; margin: 2px auto 8px; display: grid; place-items: center;
}
.heart:active { transform: scale(0.9); }
.pop { animation: pop 0.45s ease; }
@keyframes pop { 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
.nudges { display: flex; gap: 8px; overflow-x: auto; width: calc(100% + 36px); margin: 12px -18px -4px; padding: 2px 18px 4px; scrollbar-width: none; }
.nudges::-webkit-scrollbar { display: none; }
.nudge { flex: none; background: var(--bg); border-radius: 999px; padding: 8px 14px; font-size: 14px; display: flex; gap: 6px; align-items: center; }
.nudge span { font-size: 18px; }
.floaties { position: absolute; inset: 0; pointer-events: none; }
.floaties span { position: absolute; top: 70px; font-size: 26px; animation: float 1.6s ease-out forwards; }
@keyframes float {
  from { transform: translate(0, 0) scale(0.6); opacity: 1; }
  to { transform: translate(var(--dx), -140px) scale(1.25); opacity: 0; }
}

.question { font-size: 19px; font-weight: 700; margin: 6px 0 0; }
.big-q { font-size: 22px; }
.answer { background: var(--bg); border-radius: 14px; padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer .who { font-size: 13px; font-weight: 700; color: var(--accent); display: block; margin-bottom: 2px; }
.answer.locked { color: var(--muted); font-style: italic; }

.tiles, .list-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--card); box-shadow: var(--shadow); border-radius: 22px; padding: 16px; text-align: left;
  display: flex; flex-direction: column; gap: 2px; position: relative; font-weight: 400; min-height: 112px;
}
.tile-emoji { font-size: 30px; margin-bottom: 6px; }

/* ---------- Lists of rows ---------- */
.list-card { padding: 4px 0; }
.row, .letter-row, .visit-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 18px; text-align: left; border-radius: 0;
  font-weight: 500; justify-content: space-between;
}
.list-card > * + * { border-top: 1px solid var(--line); }
.chev { color: var(--muted); font-size: 22px; }
.letter-icon { font-size: 26px; }
.letter-meta, .visit-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 1px; }
.letter-row.unread strong { color: var(--accent); }
.visit-date {
  display: flex; flex-direction: column; align-items: center; min-width: 46px; padding: 6px 0;
  background: var(--soft); border-radius: 12px; line-height: 1.1;
}
.visit-date strong { font-size: 20px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border-radius: 14px; padding: 4px; }
.segmented button { padding: 9px; border-radius: 10px; font-size: 15px; color: var(--muted); }
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 500; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); box-shadow: var(--shadow); border-radius: 18px; padding: 14px 10px; text-align: center; display: flex; flex-direction: column; }
.stat strong { font-size: 26px; }

a.link-btn { display: block; text-align: center; text-decoration: none; padding: 13px 16px; border-radius: 14px; font-weight: 600; }
.tag { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--soft); font-size: 11px; font-weight: 700; color: var(--muted); vertical-align: 2px; }

/* ---------- Letters ---------- */
.paper {
  background: var(--paper); border-radius: 6px 6px 22px 22px; padding: 26px 22px; box-shadow: var(--shadow);
  background-image: repeating-linear-gradient(transparent 0 31px, var(--line) 31px 32px);
  background-position: 0 70px;
}
.paper-title { font-size: 22px; font-weight: 800; margin-bottom: 20px; }
.paper-body { white-space: pre-wrap; line-height: 32px; overflow-wrap: anywhere; }
.paper-sign { margin-top: 24px; text-align: right; font-weight: 700; display: flex; flex-direction: column; align-items: flex-end; }
.letter-input { line-height: 1.5; }

/* ---------- Lists ---------- */
.add-row { display: flex; gap: 8px; }
.add-row button { flex: none; width: 52px; font-size: 22px; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--accent); padding: 0;
  color: var(--accent-ink); font-size: 15px; display: grid; place-items: center;
}
.item.done .check { background: var(--accent); }
.item-text { flex: 1; overflow-wrap: anywhere; }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.x { flex: none; color: var(--muted); font-size: 22px; padding: 2px 8px; }
.done-box summary { padding: 6px 4px 10px; cursor: pointer; }

/* ---------- Doodles ---------- */
.doodle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.doodle-thumb {
  position: relative; padding: 0; border-radius: 18px; overflow: hidden; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; font-weight: 500;
}
.doodle-thumb img { width: 100%; aspect-ratio: 1; display: block; object-fit: cover; }
.doodle-thumb .tiny { padding: 8px 10px; text-align: left; color: var(--muted); }
.doodle-full img { width: 100%; border-radius: 22px; display: block; box-shadow: var(--shadow); }
.doodle-caption { font-size: 19px; font-weight: 700; text-align: center; }
.pad-wrap { border-radius: 22px; overflow: hidden; box-shadow: var(--shadow); line-height: 0; }
.pad { width: 100%; aspect-ratio: 1; touch-action: none; display: block; }
.tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; padding: 0; border: 3px solid transparent; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); font-size: 14px; color: #8a7479; }
.swatch.on { border-color: var(--ink); }
.brushes { display: flex; gap: 6px; }
.brush { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; border-radius: 12px; background: var(--card); }
.brush span { background: var(--ink); border-radius: 50%; display: block; }
.brush.on { outline: 2px solid var(--accent); }

/* ---------- Moods ---------- */
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-btn { font-size: 26px; padding: 6px 0; border-radius: 12px; }
.emoji-btn.on { background: var(--soft); outline: 2px solid var(--accent); }

/* ---------- Photos ---------- */
.photo-card {
  position: relative; border-radius: 26px; overflow: hidden; aspect-ratio: 1; background: var(--soft);
  box-shadow: 0 10px 30px rgba(60, 20, 30, 0.18); cursor: pointer;
}
.photo-card > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-card .badge { top: 14px; right: 14px; }
.photo-overlay {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 18px 16px; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55)); display: flex; flex-direction: column;
}
.photo-overlay span { font-size: 13px; opacity: 0.85; }
.photo-cap { font-size: 19px; font-weight: 700; margin-bottom: 6px; padding-right: 60px; }
.photo-cap:empty { display: none; }
.cam-fab {
  position: absolute; right: 14px; bottom: 14px; width: 52px; height: 52px; border-radius: 50%; padding: 0;
  background: rgba(255, 255, 255, 0.92); font-size: 24px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.empty-photo { aspect-ratio: auto; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 28px 18px; text-align: center; }
.empty-photo .hero-emoji { font-size: 44px; }

.cam-view { position: relative; border-radius: 28px; overflow: hidden; aspect-ratio: 1; background: #000; }
.cam-view video, .cam-preview { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-view video.mirror { transform: scaleX(-1); }
.cam-caption { text-align: center; font-weight: 600; }
.cam-controls { display: flex; align-items: center; justify-content: space-around; gap: 12px; padding: 6px 0; }
.cam-controls > .primary, .cam-controls > .secondary { flex: 1; }
.shutter {
  width: 78px; height: 78px; border-radius: 50%; padding: 0; background: var(--accent);
  box-shadow: 0 0 0 5px var(--bg), 0 0 0 8px var(--accent);
}
.shutter:active { transform: scale(0.92); }
.cam-btn { width: 54px; height: 54px; border-radius: 50%; padding: 0; background: var(--card); font-size: 24px; box-shadow: var(--shadow); }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-thumb { position: relative; padding: 0; border-radius: 14px; overflow: hidden; aspect-ratio: 1; background: var(--soft); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .badge { top: 6px; right: 6px; }
.photo-by { position: absolute; left: 6px; bottom: 6px; font-size: 11px; color: #fff; background: rgba(0, 0, 0, 0.45); padding: 2px 7px; border-radius: 999px; }
.photo-full { position: relative; border-radius: 26px; overflow: hidden; box-shadow: var(--shadow); }
.photo-full img { width: 100%; display: block; }
.photo-caption {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: 86%;
  background: rgba(0, 0, 0, 0.5); color: #fff; padding: 8px 16px; border-radius: 999px; font-weight: 700; text-align: center;
}
.reaction-bar { display: flex; flex-direction: column; gap: 10px; }
.reactions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.react { font-size: 28px; padding: 6px 10px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.react.on { outline: 2px solid var(--accent); background: var(--soft); }

/* ---------- Calendar ---------- */
.cal { padding: 14px 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px; }
.cal-head .icon-btn { font-size: 28px; color: var(--accent); padding: 0 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day {
  padding: 6px 0 4px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-weight: 600; font-size: 15px; min-height: 46px;
}
.cal-day.other { color: var(--muted); opacity: 0.45; }
.cal-day.today > span:first-child { color: var(--accent); font-weight: 800; }
.cal-day.sel { background: var(--accent); color: var(--accent-ink); }
.cal-day.sel > span:first-child { color: inherit; }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; font-style: normal; }
.dot.event { background: #e2557a; }
.dot.trip { background: #3d8bd9; }
.dot.visit { background: #3fae6a; }
.dot.anniv { background: #f4c430; }
.cal-day.sel .dot { box-shadow: 0 0 0 1.5px #fff; }
.cal-legend { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding-top: 10px; }
.cal-legend span { display: flex; align-items: center; gap: 5px; }
.cal-group { font-size: 13px; font-weight: 700; color: var(--muted); margin: 4px 6px -6px; }
.cal-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px; text-align: left; border-radius: 0; font-weight: 500; }
.cal-item:disabled { opacity: 1; }
.cal-emoji { font-size: 24px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; background: var(--soft); flex: none; }
.cal-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.emoji-chip { font-size: 20px; padding: 6px 10px; }
.chip.on { background: var(--soft); outline: 2px solid var(--accent); }

@media (max-width: 360px) {
  .emoji-grid { grid-template-columns: repeat(6, 1fr); }
  .hero-big { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .pop, .floaties span, .page.enter { animation: none; }
}
