:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #1f1c19;
  --ink-soft: #6b6560;
  --line: #e8e2d9;
  --accent: #c2394f;
  --accent-soft: #f7e3e6;
  --ok: #2e7d4f;
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }
img { display: block; }

.app { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; background: var(--bg); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(250,247,242,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.wordmark { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; color: var(--accent); }
.topbar-actions { display: flex; gap: 6px; }
.iconbtn {
  position: relative; border: none; background: none; padding: 8px;
  font-size: 22px; line-height: 1; color: var(--ink);
}
.dot {
  position: absolute; top: 4px; right: 4px; width: 9px; height: 9px;
  background: var(--accent); border-radius: 50%; border: 2px solid var(--bg);
}

/* ---------- bottom nav ---------- */
.bottomnav {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; border-top: 1px solid var(--line);
  background: rgba(250,247,242,.95); backdrop-filter: blur(8px);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav button {
  flex: 1; border: none; background: none; padding: 10px 0 12px;
  font-size: 24px; color: var(--ink-soft);
}
.bottomnav button.active { color: var(--accent); }

/* ---------- generic ---------- */
.view { flex: 1; padding: 16px; }
.view.flush { padding: 0; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

.btn {
  display: inline-block; border: none; border-radius: 12px;
  padding: 12px 18px; font-weight: 600; font-size: 15px;
  background: var(--accent); color: #fff; text-align: center;
}
.btn:disabled { opacity: .5; }
.btn.block { display: block; width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: #f0ebe3; color: var(--ink); }
.btn.danger { background: #8f1d2c; }
.btn.sm { padding: 8px 14px; font-size: 14px; border-radius: 10px; }

.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; background: #fff; color: var(--ink);
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.notice { border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.notice.error { background: #fbe6e9; color: #8f1d2c; }
.notice.info { background: #e7f2ec; color: var(--ok); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
  background: #efe9e0; flex: none;
}
.avatar.lg { width: 84px; height: 84px; }
.avatar.sm { width: 34px; height: 34px; }
.avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-weight: 700; background: #efe9e0;
}

/* ---------- posts ---------- */
.post { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 16px; overflow: hidden; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.post-img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #efe9e0; }
.post-actions { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0; }
.post-actions .iconbtn { font-size: 24px; }
.post-actions .liked { color: var(--accent); }
.post-body { padding: 0 14px 14px; }
.post-body .caption { margin-top: 4px; }
.post-body .time { margin-top: 6px; font-size: 12px; color: var(--ink-soft); }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.grid .cell { aspect-ratio: 1; background: #efe9e0; overflow: hidden; border: none; padding: 0; }
.grid .cell img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- profile ---------- */
.profile-head { display: flex; gap: 18px; align-items: center; }
.stats { display: flex; gap: 18px; }
.stats div { text-align: center; }
.stats b { display: block; font-size: 17px; }
.lockbox { text-align: center; padding: 36px 16px; color: var(--ink-soft); }
.lockbox .big { font-size: 32px; margin-bottom: 8px; }

/* ---------- messages ---------- */
.convo { display: flex; gap: 12px; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--card); border: none; width: 100%; text-align: left; }
.convo .snippet { color: var(--ink-soft); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 999px; min-width: 20px; height: 20px; display: inline-flex;
  align-items: center; justify-content: center; padding: 0 6px; }

.thread { flex: 1; display: flex; flex-direction: column; }
.thread-list { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 18px; font-size: 15px;
  white-space: pre-wrap; word-break: break-word; }
.bubble.mine { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.bubble.theirs { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble-time { font-size: 11px; color: var(--ink-soft); align-self: flex-end; }
.composer { display: flex; gap: 8px; padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg); position: sticky; bottom: 0; }
.composer input { flex: 1; border: 1px solid var(--line); border-radius: 999px; padding: 11px 16px; }
.composer button { border: none; border-radius: 999px; padding: 0 18px;
  background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- auth ---------- */
.auth-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.auth-wrap .wordmark { font-size: 40px; text-align: center; margin-bottom: 4px; }
.auth-tag { text-align: center; color: var(--ink-soft); margin-bottom: 24px; }

.menu-list { list-style: none; }
.menu-list li { border-bottom: 1px solid var(--line); }
.menu-list button, .menu-list a {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  background: none; border: none; padding: 14px 4px; font-size: 15px; color: var(--ink);
  text-decoration: none;
}
.menu-list .danger { color: var(--accent); }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: var(--ink-soft); margin: 18px 0 8px; }

.chip { display: inline-flex; align-items: center; gap: 6px; background: #f0ebe3;
  border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--ink-soft); }

.empty { text-align: center; color: var(--ink-soft); padding: 48px 24px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }

.spinner { text-align: center; padding: 40px; color: var(--ink-soft); }

.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(31,28,25,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.dialog {
  background: var(--card); border-radius: 18px 18px 0 0; width: 100%; max-width: 520px;
  padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.dialog h3 { margin-bottom: 12px; }
