:root {
  --bg: #faf7f4;
  --card: #ffffff;
  --text: #1d1a17;
  --muted: #8a827a;
  --line: rgba(29, 26, 23, 0.08);
  --accent: #e8576b;
  --accent-soft: rgba(232, 87, 107, 0.12);
  --sheet: #ffffff;
  --field: #f2eee9;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --card: #1e1a17;
    --text: #f3eee9;
    --muted: #9b928a;
    --line: rgba(255, 255, 255, 0.08);
    --sheet: #221d1a;
    --field: #2c2622;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.center { min-height: 100dvh; display: grid; place-items: center; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon { width: 24px; height: 24px; display: block; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); flex: none; }
.brand img { width: 38px; height: 38px; display: block; }
.brand span { font-size: 21px; font-weight: 800; letter-spacing: -0.03em; color: var(--accent); }
button.brand:active { opacity: 0.7; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }
.pill { height: 40px; padding: 0 16px; border-radius: 99px; background: var(--field); font-weight: 650; font-size: 15px; }
.pill.accent { background: var(--accent); color: #fff; }
.pill.small { height: 32px; padding: 0 12px; font-size: 14px; }
.pill:active { transform: scale(0.96); }
.counters { flex: 1; display: flex; justify-content: center; gap: 14px; min-width: 0; }
.count { display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.count b { font-size: 21px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.count span { font-size: 10px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
@media (max-width: 360px) { .brand span { display: none; } }
@media (min-width: 640px) { .counters { gap: 28px; } .count b { font-size: 26px; } .top { padding-left: 20px; padding-right: 20px; } }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text); }
.icon-btn:active { background: var(--line); }
.me-btn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--accent);
}
.me-btn:active { transform: scale(0.92); }

/* ---- signed out ---- */
.landing { min-height: calc(100dvh - 80px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; text-align: center; }
.landing img { width: 150px; height: 150px; }
.landing h1 { margin: 6px 0 0; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.waiting h1 { font-size: 22px; font-weight: 700; color: var(--muted); }
.big-icon { width: 56px; height: 56px; color: var(--accent); }
.auth { display: flex; flex-direction: column; }
.auth.page { width: 100%; max-width: 420px; text-align: left; }
.auth h2 { font-size: 24px; margin: 0 0 4px; text-align: center; }
.row.field { cursor: text; }
.flabel { width: 92px; flex: none; color: var(--text); }
.row.field input { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 15px 0; text-align: left; }
.cta { height: 52px; border-radius: 16px; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; margin-top: 6px; display: grid; place-items: center; }
.cta:disabled { opacity: 0.6; }
.center-link { align-self: center; margin-top: 10px; }
.form-error { color: #e0473d; font-size: 14px; margin: 2px 6px 6px; min-height: 0; }
.spinner.small { width: 20px; height: 20px; border-color: rgba(255, 255, 255, 0.4); border-top-color: #fff; }

/* ---- timeline: one masonry of photos, a small label where each day starts ---- */
.feed { max-width: 3000px; margin: 0 auto; padding-bottom: calc(var(--safe-bottom) + 110px); }
.timeline { display: flex; flex-direction: column; }
.band { display: flex; align-items: flex-start; }
.dayseg { flex: none; min-width: 0; }
.dayseg-cols { display: flex; align-items: flex-start; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.day { padding: 8px 4px 8px; box-sizing: border-box; }
.day.more-of { padding: 8px 4px 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.day-date { font-size: 15px; font-weight: 750; letter-spacing: -0.01em; }
.day-age { font-size: 13px; font-weight: 650; color: var(--accent); }
.day .note { margin-top: 4px; }
.day .note h3 { margin: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.day .note p { margin: 0; font-size: 13px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.day.editable { cursor: pointer; border-radius: 12px; transition: background 0.15s; }
.day.editable:hover, .day.editable:active { background: var(--field); }
.day-edit { width: 13px; height: 13px; margin-left: 6px; vertical-align: -1px; color: var(--muted); opacity: 0.7; }
.row-thumb { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; flex: none; }
.info-title { margin: 8px 0 0; font-size: 17px; font-weight: 700; }
.tile { position: relative; flex: none; border-radius: 14px; overflow: hidden; background: var(--field); cursor: pointer; }
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.35s; }
.tile img.in { opacity: 1; }
.tile:active { filter: brightness(0.92); }
.tile::after { content: ""; position: absolute; inset: auto 0 0; height: 44px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.3)); pointer-events: none; }
.tile-heart {
  position: absolute; left: 3px; bottom: 3px; z-index: 1; display: flex; align-items: center; gap: 3px;
  padding: 6px; color: #fff; font-size: 12px; font-weight: 700; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}
.tile-heart .icon { width: 18px; height: 18px; }
.tile-heart.on { color: #ff4d67; }
.tile-heart.on span { color: #fff; }
.tile-heart.pop svg, .v-heart.pop svg { animation: pop 0.35s ease; }
@keyframes pop { 40% { transform: scale(1.3); } }
.empty { text-align: center; color: var(--muted); padding: 90px 20px; }
.empty svg { width: 54px; height: 54px; margin: 0 auto 10px; opacity: 0.5; display: block; }
.more { display: grid; place-items: center; padding: 26px; }
@media (min-width: 640px) {
  .viewer img { border-radius: 18px; }
  .viewer .info { width: 100%; max-width: 640px; margin: 0 auto; text-align: center; }
  .info-row { flex-direction: column; gap: 4px; }
  .info-row .grow { flex: none; }
}

/* ---- floating add button ---- */
.fab {
  position: fixed; z-index: 20; right: 18px;
  bottom: calc(var(--safe-bottom) + 20px);
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(232, 87, 107, 0.4);
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab .icon { width: 28px; height: 28px; }

/* ---- sheets ---- */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.35); animation: fade 0.2s; display: flex; align-items: flex-end; justify-content: center; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--sheet); border-radius: 26px 26px 0 0;
  padding: 8px 18px calc(var(--safe-bottom) + 20px);
  animation: up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@media (min-width: 640px) { .scrim { align-items: center; } .sheet { border-radius: 26px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; min-height: 44px; margin-bottom: 6px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; text-align: center; }
.sheet-head .side { width: 70px; display: flex; }
.sheet-head .side.end { justify-content: flex-end; }
.link-btn { color: var(--accent); font-weight: 600; padding: 8px 2px; }
.link-btn[disabled] { opacity: 0.4; }

.group { background: var(--field); border-radius: 16px; overflow: hidden; margin: 12px 0; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .sub { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .value { color: var(--muted); }
.row.danger { color: #e0473d; justify-content: center; font-weight: 600; }
.row.accent { color: var(--accent); justify-content: center; font-weight: 600; }
.row input[type=text], .row input[type=date], .row input[type=datetime-local] {
  border: 0; background: none; outline: none; text-align: right; flex: 1; min-width: 0; padding: 14px 0;
}
.row input::placeholder { color: var(--muted); }
.chev { color: var(--muted); width: 18px; height: 18px; }
.label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 6px -4px; }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: rgba(120, 120, 128, 0.32); transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.switch input:checked + span { background: #34c759; }
.switch input:checked + span::after { transform: translateX(20px); }

.seg { display: flex; background: var(--line); border-radius: 10px; padding: 2px; }
.seg button { flex: 1; padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--sheet); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* ---- compose ---- */
.picks { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.picks div { position: relative; flex: none; }
.picks img { width: 92px; height: 92px; object-fit: cover; border-radius: 14px; display: block; background: var(--field); }
.picks div button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 0, 0, 0.55); color: #fff; display: grid; place-items: center; font-size: 14px; line-height: 1; }
.picks .add { width: 92px; height: 92px; border-radius: 14px; background: var(--field); display: grid; place-items: center; color: var(--muted); }
input.title-in {
  width: 100%; border: 0; outline: none; background: var(--field); border-radius: 16px;
  padding: 14px 16px; margin-top: 6px; font-weight: 650;
}
input.title-in::placeholder, textarea.caption-in::placeholder { color: var(--muted); }
.picks.single img { width: 120px; height: 120px; }
textarea.caption-in {
  width: 100%; border: 0; outline: none; background: var(--field); border-radius: 16px;
  padding: 14px 16px; min-height: 96px; resize: none; margin-top: 6px;
}
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 14px 0 0; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.25s; }

/* ---- viewer ---- */
.viewer { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; animation: fade 0.2s; color: #fff; }
.viewer .bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(var(--safe-top) + 6px) 8px 6px; z-index: 2; }
.viewer .bar .icon-btn { color: #fff; }
.viewer .bar-end { display: flex; gap: 4px; }
.viewer .counter { font-size: 13px; color: rgba(255, 255, 255, 0.7); font-variant-numeric: tabular-nums; }
.viewer .track { flex: 1; min-height: 0; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.viewer .track::-webkit-scrollbar { display: none; }
.viewer .slide { position: relative; flex: 0 0 100%; width: 100%; height: 100%; overflow: hidden; scroll-snap-align: center; }
/* sized and placed by the viewer (slide.fit) to the picture's own box, never past the screen */
.viewer img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: contain; border-radius: 14px; transform-origin: center; user-select: none; -webkit-user-drag: none; }
.viewer .info { padding: 14px 18px calc(var(--safe-bottom) + 18px); }
.info-row { display: flex; align-items: center; gap: 12px; }
.info-date { font-weight: 650; font-size: 16px; }
.info-age { color: rgba(255, 255, 255, 0.6); font-size: 14px; }
.info-caption { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; }
.info-meta { color: rgba(255, 255, 255, 0.55); font-size: 13px; margin-top: 8px; }
.v-heart { width: 44px; height: 44px; display: grid; place-items: center; color: #fff; }
.v-heart .icon { width: 28px; height: 28px; }
.v-heart.on { color: #ff4d67; }

/* ---- small things ---- */
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(var(--safe-bottom) + 100px); transform: translateX(-50%); background: rgba(30, 26, 23, 0.92); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; font-weight: 500; animation: fade 0.2s; white-space: nowrap; }
.locked { min-height: 100dvh; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.locked svg { width: 64px; height: 64px; margin: 0 auto 12px; display: block; color: var(--accent); }
.steps { display: grid; gap: 10px; margin: 8px 0 4px; }
.step { display: flex; align-items: center; gap: 14px; background: var(--field); border-radius: 16px; padding: 14px 16px; }
.step b { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; font-size: 14px; }
.step svg { width: 22px; height: 22px; color: #0a84ff; flex: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.tag { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 99px; }
.share-link { font-size: 13px; color: var(--muted); word-break: break-all; padding: 12px 16px; }
.grow { flex: 1; min-width: 0; }
.profile { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: -6px 0 6px; }
.profile b { font-size: 20px; margin-top: 8px; }
.profile span:last-child { color: var(--muted); font-size: 14px; }
.profile.small .me-big { width: 56px; height: 56px; font-size: 20px; margin-bottom: 4px; }
.me-big { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 26px; font-weight: 700; }
.form-page { justify-content: flex-start; padding-top: 40px; }
.row[hidden] { display: none; }

/* ---- timeline bar ---- */
.scrubber { position: fixed; right: 0; top: calc(var(--safe-top) + 64px); bottom: calc(var(--safe-bottom) + 8px); width: 34px; z-index: 15; touch-action: none; cursor: grab; opacity: 0; transition: opacity 0.25s; }
.scrubber.on, .scrubber:hover { opacity: 1; }
.scrubber.none { display: none; }
.scrubber.drag { cursor: grabbing; }
.scrub-thumb { position: absolute; top: 8px; right: 6px; width: 6px; height: 44px; border-radius: 6px; background: var(--muted); opacity: 0.75; }
.scrubber.drag .scrub-thumb { background: var(--accent); opacity: 1; width: 8px; right: 5px; }
.scrub-bubble {
  position: absolute; top: 8px; right: 26px; white-space: nowrap; pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-end; padding: 7px 12px; border-radius: 14px;
  background: var(--sheet); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.16); opacity: 0; transition: opacity 0.2s;
}
.scrubber.on .scrub-bubble { opacity: 1; }
.scrub-bubble b { font-size: 15px; font-weight: 750; color: var(--accent); }
.scrub-bubble span { font-size: 12px; color: var(--muted); }
@media (min-width: 640px) { .scrubber { top: 70px; } }
.row input[type=datetime-local] { flex: none; width: auto; max-width: 62%; }

/* ---- comments ---- */
.tile-comments {
  position: absolute; right: 4px; bottom: 4px; z-index: 1; display: flex; align-items: center; gap: 3px; padding: 6px;
  color: #fff; font-size: 12px; font-weight: 700; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45)); pointer-events: none;
}
.tile-comments .icon { width: 17px; height: 17px; }
.viewer .info { max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; }
.comments { margin-top: 12px; text-align: left; }
.comments ul { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 10px; }
.comments li { display: flex; gap: 10px; align-items: flex-start; }
.comments .avatar.small { width: 30px; height: 30px; font-size: 12px; background: rgba(255, 255, 255, 0.14); color: #fff; flex: none; }
.c-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.c-head span { color: rgba(255, 255, 255, 0.5); font-size: 12px; }
.comments p { margin: 1px 0 0; font-size: 15px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-del { color: rgba(255, 255, 255, 0.45); padding: 4px; }
.c-del .icon { width: 16px; height: 16px; }
.comment-form { display: flex; gap: 8px; align-items: center; }
.comment-in { flex: 1; min-width: 0; height: 42px; border: 0; outline: none; border-radius: 21px; padding: 0 16px; background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 16px; }
.comment-in::placeholder { color: rgba(255, 255, 255, 0.5); }
.comment-send { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; flex: none; }
.comment-send .icon { width: 19px; height: 19px; }
.comment-send:disabled { opacity: 0.5; }

/* ---- arranging (admins: hold a photo, then drag) ---- */
.tile { transform-origin: 0 0; }
body.admin .tile { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
body.admin .tile img { -webkit-user-drag: none; }
.tile.pressing { transform: scale(0.96); transition: transform 0.38s ease; }
.tile.dragging { background: var(--accent-soft); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.tile.dragging > * { visibility: hidden; }
body.drag-active, body.drag-active * { cursor: grabbing !important; }
body.drag-active .tile { pointer-events: auto; }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 90; border-radius: 12px; overflow: hidden; pointer-events: none; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28); }
.drag-ghost img { display: block; width: 100%; height: 100%; object-fit: cover; }
