:root {
  --bg: #faf6f1;
  --card: #ffffff;
  --text: #2b2420;
  --muted: #8a7f77;
  --line: #ece4dc;
  --accent: #e76f51;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok-bg: #e6f4ec; --ok-ink: #1e6b43;
  --err-bg: #fbe9e6; --err-ink: #9b2c1c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f; --card: #221d18; --text: #f1ebe4; --muted: #a39789; --line: #352d26;
    --ok-bg: #173226; --ok-ink: #8fd8b0; --err-bg: #3a1d17; --err-ink: #f2a596;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem;
              max-width: 560px; margin: 0 auto; padding: .55rem 16px; }
.brand { font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em; color: var(--accent); white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: .8rem; }
.me { display: flex; }
.tabs { display: flex; gap: 1.4rem; max-width: 560px; margin: 0 auto; padding: 0 16px; font-weight: 600; font-size: .92rem; }
.tabs a { padding: .35rem 0 .55rem; color: var(--muted); border-bottom: 2.5px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }

.bell { position: relative; display: flex; color: var(--text); padding: .2rem; }
.bell:hover { text-decoration: none; color: var(--accent); }
.badge { position: absolute; top: -4px; right: -7px; min-width: 19px; height: 19px; padding: 0 5px;
         border-radius: 999px; background: var(--accent); color: #fff; font-size: .7rem; font-weight: 700;
         display: flex; align-items: center; justify-content: center; border: 2px solid var(--card); }

.wrap { max-width: 560px; margin: 0 auto; padding: 1rem 16px 4rem; }

/* ---- cards & controls ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
        box-shadow: var(--shadow); margin-bottom: 1rem; padding: 1rem; overflow: hidden; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-wide { width: 100%; margin-top: .4rem; }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }
.topbar .btn { padding: .4rem .85rem; white-space: nowrap; }

.row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .9rem; padding: .2rem .4rem; }

.flash { padding: .7rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 500; word-break: break-word; }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error, .flash-message { background: var(--err-bg); color: var(--err-ink); }

/* ---- forms ---- */
.form label { display: block; font-weight: 600; font-size: .9rem; margin: .8rem 0; }
.form input:not([type=checkbox]):not([type=file]), .form textarea, .comment-form input {
  display: block; width: 100%; margin-top: .3rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem;
}
.form input:focus, .form textarea:focus, .comment-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form input[type=file] { display: block; margin-top: .3rem; max-width: 100%; font-size: .9rem; }
.form .check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.narrow { max-width: 400px; margin: 2rem auto; }
.avatar-row { display: flex; align-items: center; gap: 1rem; }
.grow { flex: 1; min-width: 0; }

.drop { position: relative; display: flex !important; align-items: center; justify-content: center;
        min-height: 220px; border: 2px dashed var(--line); border-radius: var(--radius);
        background: var(--bg); cursor: pointer; overflow: hidden; color: var(--muted); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img { width: 100%; max-height: 420px; object-fit: contain; }

/* ---- avatars ---- */
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none;
          border-radius: 50%; object-fit: cover; color: #fff; font-weight: 700; }

/* ---- posts ---- */
.post { padding: 0; }
.post-head { padding: .75rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.who { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.who span, .people span { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.who small, .people small { color: var(--muted); font-size: .8rem; }
.post-img-link { display: block; background: var(--bg); }
.post-img { display: block; width: 100%; max-height: 80vh; object-fit: contain; }
.post-body { padding: .7rem 1rem 1rem; }
.actions { display: flex; gap: .5rem; margin-bottom: .4rem; }
.pill { display: inline-flex; align-items: center; gap: .3rem; font: inherit; font-weight: 600; font-size: .9rem;
        padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
        color: var(--text); cursor: pointer; }
.pill:hover { text-decoration: none; }
.like .heart { font-size: 1.05rem; }
.like.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.caption, .comment-text p, .bio { white-space: pre-wrap; overflow-wrap: anywhere; }

.comments { list-style: none; margin: .4rem 0 0; padding: 0; }
.comments.compact li { margin: .2rem 0; overflow-wrap: anywhere; }
.comment { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem 0; border-top: 1px solid var(--line); }
.comment:first-child { border-top: 0; }
.comment-text { flex: 1; min-width: 0; }
.comment-form { display: flex; gap: .5rem; margin-top: .7rem; }
.comment-form input { margin: 0; border-radius: 999px; padding: .5rem .9rem; }
.back { display: inline-block; margin-bottom: .7rem; }

/* ---- profile ---- */
.profile-head { display: flex; gap: 1rem; align-items: flex-start; }
.profile-head > div { min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; border-radius: var(--radius); overflow: hidden; }
.tile { position: relative; aspect-ratio: 1; background: var(--line); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-stats { position: absolute; left: 0; right: 0; bottom: 0; padding: .3rem .4rem; font-size: .72rem; font-weight: 600;
              color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55)); opacity: 0; transition: opacity .15s; }
.tile:hover .tile-stats { opacity: 1; }

/* ---- lists ---- */
.people, .admin-users { list-style: none; margin: 0; padding: 0; }
.people li a { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; }
.people li + li, .admin-users li + li { border-top: 1px solid var(--line); }
.admin-users li { padding: .75rem 0; }
.code { font: 700 1.5rem/1 ui-monospace, Consolas, monospace; letter-spacing: .05em; padding: .8rem 1rem;
        background: var(--bg); border-radius: 12px; margin: .6rem 0; text-align: center; user-select: all; }
.empty { text-align: center; padding: 2.5rem 1rem; }

@media (max-width: 420px) {
  .top-actions { gap: .6rem; }
  .profile-head { flex-direction: column; align-items: center; text-align: center; }
  .profile-head .row { justify-content: center; }
}

/* ---- groups ---- */
.group-badge { display: inline-flex; align-items: center; justify-content: center; flex: none;
               border-radius: 28%; color: #fff; font-weight: 800; }
.group-chip { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
              font-size: .78rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px;
              background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.group-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.group-list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 0; }
.group-list li + li { border-top: 1px solid var(--line); }
.group-status { display: flex; align-items: center; gap: .4rem; flex: none; }
.tag { font-size: .78rem; font-weight: 600; padding: .25rem .65rem; border-radius: 999px;
       background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.tag-alert { background: var(--accent); color: #fff; border-color: transparent; }
.group-head { display: flex; gap: 1rem; align-items: flex-start; }
.avatars { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: .6rem; }
.admin-users li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.manage summary { cursor: pointer; font-weight: 700; }
.manage h4 { margin: 1.2rem 0 .3rem; }
.form select, .manage select {
  display: block; width: 100%; margin-top: .3rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem;
}

/* ---- notifications ---- */
.notifs { list-style: none; margin: 0 -1rem -1rem; padding: 0; }
.notifs li a { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--line); }
.notifs li a:hover { text-decoration: none; background: var(--bg); }
.notifs li.unread a { background: color-mix(in srgb, var(--accent) 9%, var(--card)); }
.notif-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.notif-text small { display: block; margin-top: .1rem; }
.notif-text q { color: var(--muted); }
.notif-thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex: none; }
.group-list .who { flex: 1; }
.group-list .who small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-status { flex-direction: column; align-items: flex-end; }

/* ---- events ---- */
.tabs { overflow-x: auto; scrollbar-width: none; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.section-head h2, .section-head h3 { margin: 0; }
#photos > .section-head { margin: 1.4rem 0 .8rem; }
.event-row { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.section-head + .event-row, h3 + .event-row, .past-events > .event-row:first-child { border-top: 0; }
.event-row:hover { text-decoration: none; }
.event-row:hover strong { text-decoration: underline; }
.event-row .tag { flex: none; }
.event-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.event-row-text small { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date-block { flex: none; width: 48px; height: 52px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line);
              display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.date-block small { font-size: .65rem; font-weight: 800; color: var(--accent); letter-spacing: .06em; }
.date-block b { font-size: 1.35rem; margin-top: .15rem; }
.date-block.big { width: 58px; height: 64px; }
.date-block.big b { font-size: 1.7rem; }
.coming-up { padding-bottom: .4rem; }
.past-events { margin-top: .5rem; }

.event-card { padding: 0; }
.event-cover { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.event-main { padding: 1rem; }
.event-title-row { display: flex; gap: .9rem; align-items: center; margin-bottom: .6rem; }
.event-title-row h2 { margin: 0 0 .25rem; overflow-wrap: anywhere; }
.event-facts { list-style: none; margin: .4rem 0 .8rem; padding: 0; }
.event-facts li { display: flex; gap: .6rem; align-items: flex-start; padding: .3rem 0; overflow-wrap: anywhere; }
.event-facts .ico { width: 22px; flex: none; text-align: center; display: flex; justify-content: center; }
.event-facts a.small { margin-left: .3rem; color: var(--accent); font-weight: 600; }
.event-details { border-top: 1px solid var(--line); padding-top: .7rem; margin-bottom: .8rem; }
.event-details h4 { margin: 0 0 .3rem; }

.rsvp-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .6rem; }
.rsvp-buttons .btn { padding: .6rem .4rem; white-space: nowrap; }
.rsvp-going.on { background: #2a9d8f; border-color: #2a9d8f; color: #fff; }
.rsvp-maybe.on { background: #e9c46a; border-color: #e9c46a; color: #3a2e05; }
.rsvp-no.on { background: var(--muted); border-color: var(--muted); color: #fff; }
.rsvp-group h4 { margin: .8rem 0 .4rem; font-size: .9rem; }
.rsvp-people { display: flex; flex-wrap: wrap; gap: .4rem; }
.rsvp-person { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem .2rem .2rem;
               border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: .85rem; font-weight: 600; }
.rsvp-person:hover { text-decoration: none; border-color: var(--accent); }
.tag-host { font-size: .68rem; padding: .1rem .45rem; background: var(--accent); color: #fff; border-color: transparent; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.two-col label { min-width: 0; }
@media (max-width: 420px) { .two-col { grid-template-columns: 1fr; } }
