:root {
  --paper: #f5eedf;
  --card: #fbf7ee;
  --ink: #3b2a1e;
  --ink-soft: #7a6652;
  --line: #e3d8c3;
  --sage: #6b8467;
  --sage-deep: #4f6a4c;
  --gold: #b8903f;
  --wine: #8b2e3a;
  --display: 'Young Serif', Georgia, 'Times New Roman', serif;
  --body: 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; line-height: 1.2; margin: 0; }
a { color: var(--sage-deep); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

#app { min-height: 100dvh; max-width: 560px; margin: 0 auto; position: relative; }

/* ---------- Top bar and tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 18px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 24px; letter-spacing: 0.2px; }
.top .who { border: 0; background: none; padding: 0; border-radius: 50%; }

main { padding: 18px 16px calc(var(--tab-h) + var(--safe-b) + 90px); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs-inner { display: flex; width: 100%; max-width: 560px; }
.tab {
  flex: 1; height: var(--tab-h); border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  position: relative;
}
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--sage-deep); }
.tab[aria-current="page"]::after {
  content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--gold);
}

/* ---------- Buttons and fields ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; min-height: 46px;
  background: var(--sage-deep); color: var(--paper); font-weight: 700;
}
.btn:active { background: var(--sage); }
.btn.quiet { background: transparent; color: var(--sage-deep); border: 1.5px solid var(--sage); }
.btn.danger { background: transparent; color: var(--wine); border: 1.5px solid var(--wine); }
.btn.small { min-height: 38px; padding: 7px 16px; font-size: 15px; }
.btn[disabled] { opacity: 0.55; }
.linkbtn { border: 0; background: none; padding: 6px 0; color: var(--ink-soft); font-size: 15px; font-weight: 600; }
.linkbtn.wine { color: var(--wine); }

label { display: block; font-weight: 700; font-size: 15px; margin: 14px 0 5px; }
input[type=text], input[type=password], input[type=tel], input[type=datetime-local], textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card);
}
input:focus, textarea:focus, select:focus { border-color: var(--sage); outline: none; box-shadow: 0 0 0 3px rgba(107, 132, 103, 0.25); }
textarea { resize: vertical; min-height: 96px; }
.hint { color: var(--ink-soft); font-size: 15px; margin: 4px 0 0; }
.error { color: var(--wine); font-weight: 600; margin: 12px 0 0; min-height: 1.2em; }

/* ---------- Avatars ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover;
  display: inline-grid; place-items: center;
  font-family: var(--display); font-size: 18px; color: var(--paper);
  border: 2px solid var(--card);
  box-shadow: 0 0 0 1.5px var(--line);
}
.avatar.big { width: 96px; height: 96px; font-size: 40px; }
.avatar.small { width: 30px; height: 30px; font-size: 13px; border-width: 1.5px; }

/* ---------- Sign in ---------- */
.gate { padding: 12vh 24px 40px; }
.gate .mark { width: 76px; height: 76px; border-radius: 20px; display: block; margin-bottom: 22px; }
.gate h1 { font-size: 36px; margin-bottom: 8px; }
.gate p { color: var(--ink-soft); margin: 0 0 8px; }
.gate .btn { width: 100%; margin-top: 22px; }

/* ---------- Feed: photos are mounted like prints in a family album ---------- */
.post { margin: 0 0 30px; }
.post-head { display: flex; align-items: center; gap: 11px; margin: 0 4px 10px; }
.post-head .names { flex: 1; min-width: 0; }
.post-head strong { display: block; font-weight: 700; line-height: 1.2; }
.post-head time { color: var(--ink-soft); font-size: 14px; }

.print {
  position: relative; background: var(--card);
  padding: 12px 12px 14px;
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px -8px rgba(59, 42, 30, 0.35);
  transform: rotate(-0.5deg);
}
.post:nth-child(even) .print { transform: rotate(0.5deg); }
.print .mount { position: relative; display: block; background: var(--line); }
.print .mount img { display: block; width: 100%; max-height: 78vh; object-fit: cover; }
.print .mount::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(135deg, var(--wine) 50%, transparent 50%) top left / 20px 20px no-repeat,
    linear-gradient(225deg, var(--wine) 50%, transparent 50%) top right / 20px 20px no-repeat,
    linear-gradient(45deg, var(--wine) 50%, transparent 50%) bottom left / 20px 20px no-repeat,
    linear-gradient(315deg, var(--wine) 50%, transparent 50%) bottom right / 20px 20px no-repeat;
}
.print .cap { margin: 12px 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.print.textonly { transform: none; padding: 16px 18px; }
.print.textonly .cap { margin: 0; }

.actions { display: flex; align-items: center; gap: 18px; margin: 12px 6px 0; }
.act { border: 0; background: none; padding: 6px 2px; display: inline-flex; gap: 7px; align-items: center; font-weight: 700; color: var(--ink-soft); }
.act svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.act.on { color: var(--wine); }
.act.on svg { fill: var(--wine); }
.act.del { margin-left: auto; font-weight: 600; font-size: 15px; }
.likedby { margin: 2px 6px 0; font-size: 15px; color: var(--ink-soft); }

.comments { margin: 10px 4px 0; }
.comment { display: flex; gap: 9px; margin: 9px 0; align-items: flex-start; }
.comment .bubble { flex: 1; min-width: 0; background: rgba(227, 216, 195, 0.45); padding: 8px 12px; border-radius: 4px 16px 16px 16px; }
.comment strong { display: block; font-weight: 700; font-size: 14px; line-height: 1.3; color: var(--ink-soft); }
.comment .txt { overflow-wrap: anywhere; white-space: pre-wrap; }
.comment .x { border: 0; background: none; color: var(--ink-soft); font-size: 13px; padding: 0 0 0 6px; }
.comment-form { display: flex; gap: 8px; margin-top: 10px; }
.comment-form input { flex: 1; border-radius: 999px; padding: 10px 16px; }

.empty { text-align: center; padding: 56px 24px; color: var(--ink-soft); }
.empty h2 { color: var(--ink); font-size: 22px; margin-bottom: 8px; }

.fab {
  position: fixed; z-index: 7;
  right: max(16px, calc(50% - 280px + 16px));
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  height: 56px; padding: 0 22px 0 18px; border-radius: 999px; border: 0;
  background: var(--gold); color: #2d2014; font-weight: 800;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 8px 20px -6px rgba(59, 42, 30, 0.55);
}
.fab svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; }

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(59, 42, 30, 0.5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + var(--safe-b));
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h2 { font-size: 24px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.row .btn { flex: 1; }
.photo-pick { margin-top: 12px; }
.photo-pick img { width: 100%; max-height: 260px; object-fit: cover; border-radius: 10px; margin-top: 10px; }

/* ---------- Events ---------- */
.day { margin: 26px 0 10px; font-size: 20px; }
.day:first-child { margin-top: 0; }
.event { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--sage); border-radius: 6px 16px 16px 6px; padding: 14px 16px; margin-bottom: 12px; }
.event h3 { font-family: var(--body); font-weight: 700; font-size: 18px; }
.event .when { color: var(--sage-deep); font-weight: 700; }
.event .meta { color: var(--ink-soft); font-size: 15px; margin-top: 2px; overflow-wrap: anywhere; }
.rsvp { display: flex; gap: 8px; margin-top: 12px; }
.rsvp button { flex: 1; min-height: 42px; border-radius: 999px; border: 1.5px solid var(--line); background: transparent; font-weight: 700; font-size: 15px; }
.rsvp button[aria-pressed="true"].going { background: var(--sage-deep); color: var(--paper); border-color: var(--sage-deep); }
.rsvp button[aria-pressed="true"].maybe { background: var(--gold); color: #2d2014; border-color: var(--gold); }
.rsvp button[aria-pressed="true"].no { background: var(--wine); color: var(--paper); border-color: var(--wine); }
.who-list { margin: 10px 0 0; font-size: 15px; color: var(--ink-soft); }
.who-list b { color: var(--ink); }

/* ---------- Chat ---------- */
.thread { display: flex; gap: 13px; align-items: center; width: 100%; text-align: left; padding: 12px 4px; border: 0; background: none; border-bottom: 1px solid var(--line); }
.thread .t { flex: 1; min-width: 0; }
.thread strong { display: block; }
.thread .last { color: var(--ink-soft); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { display: flex; flex-direction: column; min-height: calc(100dvh - 82px - env(safe-area-inset-top, 0px) - var(--tab-h) - var(--safe-b) - 78px); }
main.chat-on { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 78px); }
.chat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.chat-head h2 { font-size: 22px; }
.msgs { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; padding-bottom: 12px; }
.msg { max-width: 82%; padding: 9px 14px; border-radius: 18px 18px 18px 4px; background: var(--card); border: 1px solid var(--line); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg .from { display: block; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.msg.mine { align-self: flex-end; background: var(--sage-deep); border-color: var(--sage-deep); color: var(--paper); border-radius: 18px 18px 4px 18px; }
.composer {
  position: fixed; left: 0; right: 0; z-index: 6; display: flex; justify-content: center;
  bottom: calc(var(--tab-h) + var(--safe-b)); background: var(--paper); border-top: 1px solid var(--line);
}
.composer form { display: flex; gap: 8px; width: 100%; max-width: 560px; padding: 10px 14px; }
.composer input { flex: 1; border-radius: 999px; padding: 11px 18px; }

/* ---------- Family ---------- */
.people { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.person { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px 10px 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.person .avatar { width: 76px; height: 76px; font-size: 32px; }
.person strong { line-height: 1.2; }
.person small { color: var(--ink-soft); }
.profile { text-align: center; }
.profile .avatar { margin: 4px auto 10px; }
.profile h2 { font-size: 28px; }
.profile .bio { color: var(--ink-soft); margin: 8px 0 0; white-space: pre-wrap; }
.section-title { font-size: 20px; margin: 30px 0 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(var(--tab-h) + var(--safe-b) + 84px);
  background: var(--ink); color: var(--paper); padding: 11px 20px; border-radius: 999px; font-weight: 600; width: max-content; max-width: 90vw; text-align: center;
}

@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
