/* ---------- tokens ---------- */
:root {
  --bg: #fff7ef;
  --blob-1: #ffe3d8;
  --blob-2: #e4f1ff;
  --card: #ffffff;
  --ink: #3b2a3d;
  --muted: #76627a;
  --line: #f1e2d9;
  --accent: #f6a28f;
  --accent-soft: #ffe6de;
  --accent-ink: #a2402f;
  --on-accent: #2b1b2d;
  --danger: #c8424a;
  --warn-bg: #fff3cd;
  --warn-ink: #7a5a00;
  --shadow: 0 10px 28px -12px rgba(122, 64, 52, 0.28), 0 2px 6px rgba(122, 64, 52, 0.08);
  --radius: 24px;
  color-scheme: light dark;
}

[data-theme="boy"] { --accent: #7cc4ef; --accent-soft: #e0f1ff; --accent-ink: #1d6293; }
[data-theme="girl"] { --accent: #f59ac0; --accent-soft: #ffe3ef; --accent-ink: #a32a62; }
[data-theme="neutral"] { --accent: #7fd6a4; --accent-soft: #fff4c7; --accent-ink: #2f7350; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1620;
    --blob-1: #3a2330;
    --blob-2: #1f2c3d;
    --card: #2a2130;
    --ink: #f7ebf2;
    --muted: #b9a5b5;
    --line: #3d3244;
    --accent-soft: #46302c;
    --accent-ink: #ffc2b4;
    --danger: #ff7a82;
    --warn-bg: #3d3214;
    --warn-ink: #ffe08a;
    --shadow: 0 10px 28px -12px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.3);
  }
  [data-theme="boy"] { --accent-soft: #1d3346; --accent-ink: #a9dcff; }
  [data-theme="girl"] { --accent-soft: #45253a; --accent-ink: #ffb6d4; }
  [data-theme="neutral"] { --accent-soft: #3b3820; --accent-ink: #a8ecc4; }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 0% 0%, var(--blob-1), transparent 45vmax),
    radial-gradient(circle at 100% 20%, var(--blob-2), transparent 40vmax),
    var(--bg);
  color: var(--ink);
  font-family: "Baloo Bhaijaan 2", system-ui, sans-serif;
  font-size: 1.05rem;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; overflow-wrap: break-word; }
h1 { font-size: clamp(1.7rem, 7vw, 2.3rem); font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0 0 6px; }
img { max-width: 100%; }
a { color: var(--accent-ink); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.loading { text-align: center; padding: 64px 0; color: var(--muted); font-size: 1.2rem; }

/* ---------- cards ---------- */
.card {
  display: block;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
  animation: pop-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
}

.empty { text-align: center; padding: 32px 18px; }
.empty-icon { font-size: 3.2rem; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 16px -8px var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 2px currentColor; }
.btn.small { padding: 6px 14px; font-size: 0.95rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- forms ---------- */
.field { display: grid; gap: 4px; margin-bottom: 12px; font-weight: 600; }
.field > span { font-size: 0.95rem; }
input {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--ink);
}
input:focus { border-color: var(--accent); }
input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
input[dir="ltr"] { text-align: left; font-size: 0.9rem; }
.form-error { color: var(--danger); min-height: 0; }
.form-error:empty { display: none; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.link-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 8px; }
.link-row .field { flex: 1; min-width: 0; margin-bottom: 0; }
.link-row .btn { flex-shrink: 0; margin-bottom: 4px; }

.warning {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 16px;
  padding: 10px 14px;
  margin: 12px 0;
  font-weight: 700;
}

.themes { border: 0; padding: 0; margin: 0 0 8px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.themes legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; padding: 0; }
.theme-choice { position: relative; }
.theme-choice input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.theme-choice span {
  display: block;
  text-align: center;
  padding: 10px 4px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow 0.15s, transform 0.15s;
}
.theme-choice input:checked + span { box-shadow: inset 0 0 0 3px var(--accent); transform: scale(1.04); }
.theme-choice input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

dialog {
  border: 0;
  border-radius: 28px;
  padding: 22px 18px;
  width: min(440px, calc(100vw - 32px));
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  animation: pop-in 0.3s both;
}
dialog::backdrop { background: rgba(40, 20, 40, 0.45); backdrop-filter: blur(3px); }

/* ---------- home ---------- */
.hero { text-align: center; padding: 24px 0 18px; }
.hero-icon { font-size: 3.4rem; margin: 0; animation: float 4s ease-in-out infinite; }
.hero .muted { max-width: 34ch; margin-inline: auto; }
@keyframes float { 50% { transform: translateY(-8px); } }
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent li { display: flex; align-items: center; gap: 8px; }
.recent a {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  text-decoration: none;
  overflow-wrap: break-word;
}
.recent .muted { margin: 10px 0 0; }

/* ---------- family page: edit link, collapsed ---------- */
.key-box summary { cursor: pointer; font-weight: 700; }
.key-box[open] summary { margin-bottom: 12px; }
.key-box .warning { margin-bottom: 0; }

/* ---------- family page ---------- */
.family-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.family-head h1 { margin: 0; }
.share-box { background: var(--accent-soft); box-shadow: none; }
.children { display: grid; gap: 14px; margin-bottom: 14px; }
.children .card { margin-bottom: 0; }
.add-child { width: 100%; padding: 14px; font-size: 1.15rem; }

.child-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  color: inherit;
  text-decoration: none;
  border-inline-start: 6px solid var(--accent);
  transition: transform 0.2s;
}
.child-card:hover { transform: translateY(-2px); }
.child-info { flex: 1; min-width: 0; }
.child-info h2 { margin-bottom: 2px; }
.age { font-size: 1.15rem; font-weight: 700; color: var(--accent-ink); margin-bottom: 8px; }

.avatar {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.9rem;
  font-weight: 800;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.9rem;
  color: var(--muted);
}
.chip strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); }
  80%, 100% { box-shadow: 0 0 0 8px transparent; }
}

.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0;
}
.badge.big { font-size: 1.2rem; padding: 8px 18px; margin: 6px 0; }
.wobble { animation: wobble 4s ease-in-out infinite; transform-origin: center; }
@keyframes wobble {
  0%, 82%, 100% { transform: rotate(0); }
  86% { transform: rotate(-3deg) scale(1.03); }
  90% { transform: rotate(3deg) scale(1.03); }
  94% { transform: rotate(-2deg); }
}

/* ---------- child page ---------- */
.back { display: inline-block; margin-bottom: 10px; font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.child-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, var(--accent-soft), var(--card) 70%);
}
.child-head h1 { margin: 0; }
.child-head .child-info { flex: 1 1 0; }
/* Narrow screens: buttons drop to their own row so the name keeps the full width. */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-basis: 100%; }
@media (min-width: 520px) { .head-actions { flex-basis: auto; } }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--card);
  border-radius: 20px;
  padding: 5px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.tabs button {
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.2;
  border: 0;
  border-radius: 16px;
  padding: 9px 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }

.age-card { text-align: center; }
.big-age { font-size: clamp(1.7rem, 8vw, 2.6rem); font-weight: 800; color: var(--accent-ink); line-height: 1.25; margin: 4px 0 8px; }

.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.totals .card { margin: 0; text-align: center; padding: 14px 8px; position: relative; }
.total strong {
  display: block;
  font-size: clamp(1.25rem, 5.5vw, 1.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.total span { color: var(--muted); }
.total.live { background: var(--accent-soft); }
.total .live-dot { position: absolute; top: 12px; inset-inline-end: 12px; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.fact { margin: 0; text-align: center; display: grid; gap: 2px; justify-items: center; }
.fact-icon { font-size: 2.2rem; }
.fact strong { font-size: 1.4rem; font-weight: 800; color: var(--accent-ink); white-space: nowrap; }

.next-ms { text-align: center; background: linear-gradient(135deg, var(--accent-soft), var(--card)); }
.ms-list { list-style: none; padding: 0; margin: 0; }
.ms-list li { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.ms-list li:last-child { border-bottom: 0; }
.ms-label { flex: 1; font-weight: 600; min-width: 0; }
.mark { width: 1.6em; text-align: center; flex-shrink: 0; }
.done .mark { color: var(--accent-ink); font-weight: 800; }

/* ---------- celebration ---------- */
.celebrate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
  background: rgba(40, 20, 45, 0.4);
  animation: fade-in 0.3s both;
  cursor: pointer;
}
@keyframes fade-in { from { opacity: 0; } }

.celebrate-card {
  position: relative;
  z-index: 1;
  background: var(--card);
  color: var(--ink);
  border-radius: 32px;
  padding: 28px 22px 22px;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: bounce-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
.celebrate-card p { font-size: clamp(1.4rem, 6.5vw, 2rem); font-weight: 800; line-height: 1.3; margin-bottom: 16px; }
@keyframes bounce-in { from { opacity: 0; transform: scale(0.6); } }

.confetti, .balloon { position: absolute; z-index: 2; pointer-events: none; left: var(--x); }
.confetti {
  top: -4vh;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  background: var(--color);
  animation: fall var(--dur) cubic-bezier(0.3, 0.5, 0.6, 1) var(--delay) both;
}
.confetti:nth-child(3n) { border-radius: 50%; width: 10px; height: 10px; }
@keyframes fall { to { transform: translate(var(--drift), 112vh) rotate(var(--spin)); } }

.balloon {
  bottom: -110px;
  width: 54px;
  height: 68px;
  border-radius: 50% 50% 48% 52% / 58% 58% 42% 42%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.7), transparent 28%), var(--color);
  animation: rise var(--dur) ease-in var(--delay) both;
}
.balloon::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 1.5px;
  height: 64px;
  background: rgba(120, 100, 110, 0.5);
}
@keyframes rise { to { transform: translate(var(--drift), -135vh) rotate(var(--spin)); } }

/* ---------- album ---------- */
.album-actions { margin-bottom: 14px; }
.upload { position: relative; width: 100%; padding: 14px; font-size: 1.15rem; cursor: pointer; }
.upload input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.upload:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.upload:has(input:disabled) { opacity: 0.6; cursor: wait; }
.upload-status { text-align: center; margin: 8px 0 0; }
.upload-status:empty { display: none; }
.upload-errors { list-style: none; padding: 0; margin: 8px 0 14px; color: var(--danger); font-weight: 600; overflow-wrap: anywhere; }
.upload-errors:empty { display: none; }

/* Vertical timeline: a soft line on the inline-start edge, a dot per photo, month pills on the line. */
.timeline { position: relative; padding-inline-start: 26px; }
.timeline::before {
  content: "";
  position: absolute;
  inset-block: 14px 0;
  inset-inline-start: 8px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(var(--accent), var(--accent-soft) 85%, transparent);
}
.month-pill {
  position: relative;
  display: inline-block;
  margin: 4px 0 12px;
  margin-inline-start: -26px;
  padding: 4px 16px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 1rem;
  box-shadow: 0 0 0 4px var(--bg);
}
.tl-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 14px; }
.tl-item { position: relative; padding: 0; margin: 0; }
.tl-item::before {
  content: "";
  position: absolute;
  top: 22px;
  inset-inline-start: -22px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 0 0 3px var(--accent);
}
.tl-photo {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  background: var(--accent-soft);
  cursor: zoom-in;
}
.tl-photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; transition: transform 0.4s; }
.tl-photo:hover img { transform: scale(1.03); }
.tl-body { padding: 12px 16px 16px; }
.tl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.tl-star { color: var(--accent-ink); font-weight: 700; }
.tl-caption { font-weight: 600; margin: 8px 0 0; overflow-wrap: anywhere; }
.tl-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tl-edit { margin-top: 4px; }
@media (min-width: 600px) {
  .tl-list { grid-template-columns: 1fr 1fr; }
  .tl-list > li:nth-child(even)::before { display: none; }
}

.lightbox {
  width: auto;
  max-width: calc(100vw - 16px);
  padding: 0;
  background: transparent;
  box-shadow: none;
  color: #fff;
  text-align: center;
  overflow: visible;
  cursor: zoom-out;
}
.lightbox::backdrop { background: rgba(12, 6, 14, 0.92); backdrop-filter: none; }
.lightbox figure { margin: 0; }
/* Fixed stage so the sharp copy swapping in for the thumb never shifts the layout. */
.lightbox img { display: block; width: min(calc(100vw - 16px), 960px); height: calc(100vh - 170px); height: calc(100dvh - 170px); object-fit: contain; }
.lightbox figcaption { padding: 12px 16px 0; }
.lb-caption { font-weight: 700; font-size: 1.15rem; overflow-wrap: anywhere; }
.lb-meta { opacity: 0.8; }
.lb-close {
  position: fixed;
  top: 12px;
  inset-inline-end: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

/* ---------- trash ---------- */
.trash-kids { list-style: none; padding: 0; margin: 0; }
.trash-kids li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.trash-kids li:last-child { border-bottom: 0; }
.avatar.small { width: 44px; height: 44px; font-size: 1.3rem; }
.trash-name { flex: 1; min-width: 0; display: grid; font-weight: 700; overflow-wrap: anywhere; }
.trash-photos { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.trash-photos li { display: grid; gap: 6px; justify-items: center; text-align: center; }
.trash-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 16px; background: var(--accent-soft); }

/* ---------- motion & wider screens ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 640px) {
  #app { padding-top: 36px; }
  .avatar { width: 76px; height: 76px; }
}
