:root {
  --bg: #f2f3f5;
  --card: #fff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e5e8;
  --soft: #f6f7f8;
  --accent: #2563eb;
  --accent-text: #fff;
  --like: #e11d48;
  --error: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaed;
    --muted: #9aa0a9;
    --border: #2a2e36;
    --soft: #1f232a;
    --accent: #4f8cff;
    --like: #fb7185;
    --error: #f87171;
  }
}

/* Pink mode (Settings → Appearance). Set as <html data-theme="pink"> by theme.js; a darker pink when the device is in dark mode. */
/* Hot pink: the accent is as vivid as it can be while still readable as text on white (4.5:1). */
:root[data-theme="pink"] {
  --bg: #ffdcef;
  --card: #fff;
  --text: #4a0027;
  --muted: #a8336d;
  --border: #ffb1d8;
  --soft: #ffeef7;
  --accent: #e6007e;
  --accent-text: #fff;
  --like: #d4003c;
  --error: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="pink"] {
    --bg: #200011;
    --card: #33071f;
    --text: #ffe6f3;
    --muted: #ff8cc8;
    --border: #66124a;
    --soft: #45102f;
    --accent: #ff3ea5;
    --accent-text: #2a0016;
    --like: #ff5d8f;
    --error: #ff8a8a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { margin: 0 0 4px; font-size: 1.25rem; }
p { margin: 0; }

/* ---- controls ---- */
input, textarea, button { font: inherit; color: inherit; max-width: 100%; }
input:not([type=file]), textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
button {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); cursor: pointer;
}
button:hover { background: var(--soft); }
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.linklike { padding: 0; border: 0; border-radius: 0; background: none; color: var(--accent); }
button.linklike:hover { text-decoration: underline; background: none; }
label { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label.toggle { display: flex; align-items: center; gap: 10px; font-size: 1rem; color: var(--text); cursor: pointer; justify-self: start; }
/* Settings switches: a checkbox drawn as an on/off slider (still a real checkbox for keyboards and screen readers). */
label.toggle input {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 44px; height: 26px; margin: 0; padding: 0;
  border: 0; border-radius: 13px; background: var(--border); cursor: pointer; transition: background .2s;
}
label.toggle input::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .2s;
}
label.toggle input:checked { background: var(--accent); }
label.toggle input:checked::before { transform: translateX(18px); }
label.toggle input:focus { outline: none; }
label.toggle input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.toggle input:disabled { opacity: .5; cursor: default; }
@media (prefers-reduced-motion: reduce) { label.toggle input, label.toggle input::before { transition: none; } }
.small { font-size: 0.85rem; }
.muted, button.linklike.muted { color: var(--muted); }
.error { color: var(--error); }
.center { text-align: center; }
p:empty { display: none; }

/* ---- layout ---- */
header { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--border); }
.header-inner {
  max-width: 640px; margin: 0 auto; padding: 10px 16px;
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "brand nav" "search search"; gap: 8px 16px; align-items: center;
}
.brand { grid-area: brand; font-weight: 700; color: var(--text); }
#nav { grid-area: nav; display: flex; gap: 14px; justify-content: flex-end; flex-wrap: wrap; font-size: 0.95rem; }
#search-form { grid-area: search; }
#search-input { padding: 6px 12px; border-radius: 999px; background: var(--soft); }
@media (min-width: 640px) {
  .header-inner { grid-template-columns: auto 1fr auto; grid-template-areas: "brand search nav"; }
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.stack button.primary { justify-self: start; }

/* ---- avatars & people ---- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--border); flex-shrink: 0; }
.avatar.big { width: 88px; height: 88px; }
.comment .avatar { width: 28px; height: 28px; }
.person { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
.person + .person { border-top: 1px solid var(--border); }
.profile-head { display: flex; gap: 16px; align-items: center; }
.bio { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }

/* ---- posts ---- */
.post-head { display: flex; gap: 10px; align-items: center; }
.who { min-width: 0; flex: 1; line-height: 1.25; }
.who strong a { color: var(--text); }
.delete-post { align-self: flex-start; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 10px; }
.post img.content { display: block; max-width: 100%; max-height: 520px; margin-top: 10px; border-radius: 8px; }
.post a.link { overflow-wrap: anywhere; }
.post > p:has(a.link) { margin-top: 10px; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
button.like.on { color: var(--like); border-color: var(--like); }
.like-text { font-size: 0.9rem; color: var(--muted); text-align: left; }

.comments { margin-top: 12px; padding: 10px 12px; background: var(--soft); border-radius: 10px; display: grid; gap: 8px; }
.comments > button { justify-self: start; }
.comment-list { display: grid; gap: 8px; }
.comment { display: flex; gap: 8px; align-items: flex-start; }
.comment a { font-weight: 600; color: var(--text); }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment .small button { margin-left: 10px; }
.comment-form { display: flex; gap: 8px; }
.comment-form input { padding: 6px 10px; border-radius: 999px; }

.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 12px; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
button.more { display: block; margin: 8px auto 0; }

/* ---- likers pop-up ---- */
dialog.likers {
  padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--card); color: var(--text);
  width: min(360px, calc(100vw - 32px)); max-height: 70vh;
}
dialog.likers::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-body { padding: 14px 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

/* ---- friends, rows, image preview ---- */
.row { display: flex; gap: 10px 14px; align-items: center; flex-wrap: wrap; }
.profile-info { min-width: 0; flex: 1; }
.profile-info .row { margin-top: 8px; }
.person-name { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.person-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
button.mutual-link { text-decoration: underline; text-underline-offset: 2px; }
#nav a.dot::after {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 4px; vertical-align: super;
  border-radius: 50%; background: var(--like);
}
.photo-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.photo-preview { position: relative; aspect-ratio: 1; }
.photo-preview img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.remove-image {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; padding: 0; border-radius: 50%;
  background: rgb(0 0 0 / 0.65); color: #fff; border: 0; font-size: 0.8rem;
}
.remove-image:hover { background: rgb(0 0 0 / 0.85); }

/* ---- multi-photo carousel ---- */
.carousel { position: relative; margin-top: 10px; }
.carousel-track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  border-radius: 8px; background: var(--soft);
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track img { flex: 0 0 100%; width: 100%; height: min(75vw, 460px); object-fit: contain; scroll-snap-align: center; }
.carousel-arrow {
  position: absolute; top: calc(50% - 14px); transform: translateY(-50%); width: 34px; height: 34px; padding: 0;
  border-radius: 50%; border: 0; background: rgb(0 0 0 / 0.5); color: #fff; font-size: 1.4rem; line-height: 1;
}
.carousel-arrow:hover { background: rgb(0 0 0 / 0.7); }
.carousel-arrow.prev { left: 8px; }
.carousel-arrow.next { right: 8px; }
@media (hover: none) { .carousel-arrow { display: none; } } /* phones: just swipe */
.carousel-dots { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.carousel-dot { width: 7px; height: 7px; padding: 0; border: 0; border-radius: 50%; background: var(--border); }
.carousel-dot:hover { background: var(--muted); }
.carousel-dot.on { background: var(--accent); }

/* ---- notifications & live updates ---- */
#nav a.bell, #nav a.icon { text-decoration: none; }
.notification { display: flex; gap: 10px; align-items: flex-start; padding: 10px 8px; margin: 0 -8px; border-radius: 8px; color: var(--text); }
.notification:hover { background: var(--soft); text-decoration: none; }
.notification + .notification { margin-top: 2px; }
.notification.unread { background: rgb(37 99 235 / 0.1); background: color-mix(in srgb, var(--accent) 10%, transparent); }
button.new-posts {
  position: fixed; top: 120px; left: 50%; transform: translateX(-50%); z-index: 5;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
}

/* red count bubble on the bell */
#nav a.bell { position: relative; }
.bell .badge {
  position: absolute; top: -7px; right: -9px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--like); color: #fff;
  font-size: 0.7rem; line-height: 17px; font-weight: 700; text-align: center;
}


/* comment likes */
.comment-main { min-width: 0; flex: 1; }
.comment-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.comment-meta .comment-like.on { color: var(--like); }
.comment-liked-by { text-align: left; }

/* @mentions of tagged friends inside post and comment text */
.post-text a.mention, .comment-text a.mention { font-weight: 600; color: var(--accent); }

/* @mention suggestions and highlighting while typing (mentionField in app.js). The field's own text is
   transparent; .mention-backdrop draws the same text underneath, with friends' @mentions colored.
   The backdrop copies the field's padding, borders and font in JS, so the two line up exactly. */
.mention-field { position: relative; min-width: 0; }
.comment-form .mention-field { flex: 1; }
.mention-field .mention-input { position: relative; display: block; color: transparent; caret-color: var(--text); background: transparent; }
.mention-field .mention-input::placeholder { color: var(--muted); opacity: 1; }
.mention-field .mention-input::selection { color: transparent; background: rgb(37 99 235 / 0.25); background: color-mix(in srgb, var(--accent) 28%, transparent); }
.compose-box .mention-input { overflow: hidden; } /* it grows with the text instead of scrolling */
.mention-backdrop {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  border-style: solid; border-color: transparent; color: var(--text);
}
.comment-form .mention-backdrop { background: var(--card); }
.mention-backdrop-text { white-space: pre; }
.mention-field.multiline .mention-backdrop-text { white-space: pre-wrap; overflow-wrap: break-word; }
.mention-draft { color: var(--accent); background: rgb(37 99 235 / 0.1); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 3px; }
.mention-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; padding: 4px;
  max-height: 248px; overflow-y: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.mention-option { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--text); }
.mention-option[aria-selected="true"] { background: var(--soft); }
.mention-option .avatar { width: 28px; height: 28px; }
.mention-option-name { font-weight: 600; }

/* ---- composer: text, photo previews and + button in one box ---- */
.compose-box {
  display: grid; gap: 8px; padding: 8px 10px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--card);
}
.compose-box:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.compose-box textarea { border: 0; padding: 2px 0; background: transparent; min-height: 64px; resize: none; }
.compose-box textarea:focus { outline: none; }
.compose-tools { display: flex; justify-content: flex-end; }
button.add-photo {
  width: 32px; height: 32px; padding: 0; border-radius: 8px; border: 1px solid var(--border);
  background: var(--soft); color: var(--muted); font-size: 1.35rem; line-height: 1; font-weight: 300;
}
button.add-photo:hover:not(:disabled) { color: var(--text); border-color: var(--muted); background: var(--soft); }

/* Local test panel (public/dev.js, localhost only) */
.dev-toggle { position: fixed; left: 12px; bottom: 12px; z-index: 50; width: 44px; height: 44px; border-radius: 50%; font-size: 1.3rem; padding: 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); }
.dev-panel { position: fixed; left: 12px; bottom: 64px; z-index: 50; width: min(320px, calc(100vw - 24px)); max-height: calc(100vh - 80px); overflow: auto; margin: 0; box-shadow: 0 4px 20px rgba(0, 0, 0, .25); }
.dev-panel h2 { margin: 0; font-size: 1rem; }
.dev-users { flex-wrap: wrap; gap: 6px; }
.dev-actions { display: grid; gap: 6px; }
.dev-actions button { text-align: left; }
