:root {
  --bg: #0c0b10;
  --bg-2: #14121b;
  --surface: #1a1722;
  --surface-2: #221e2e;
  --line: #2a2636;
  --text: #f1eef7;
  --muted: #9a93ad;
  --accent: #7c5cff;
  --accent-2: #a98bff;
  --danger: #ff5c7a;
  --max: 600px;
  --tabbar-h: 58px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent-2); text-decoration: none; }

/* ---------------------------------------------------------- auth screen */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(124,92,255,.18), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px;
}
.brand {
  font-family: 'Sora', sans-serif;
  font-weight: 700; font-size: 26px;
  letter-spacing: -.02em;
  display: flex; align-items: center; gap: 8px;
}
.brand-mark { color: var(--accent); transform: translateY(1px); }
.auth-tag { color: var(--muted); margin: 6px 0 22px; }
.seg {
  display: flex; gap: 4px; background: var(--bg-2);
  border-radius: 12px; padding: 4px; margin-bottom: 16px;
}
.seg-btn {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 9px; border-radius: 9px; font-weight: 600; font-size: 14px;
}
.seg-btn.active { background: var(--surface-2); color: var(--text); }
.field {
  width: 100%; margin-bottom: 11px; padding: 13px 14px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--text); font-size: 15px;
}
.field:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn-primary {
  width: 100%; padding: 13px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
}
.btn-primary:active { background: var(--accent-2); }
.btn-sm { width: auto; padding: 8px 16px; border-radius: 10px; font-size: 14px; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ----------------------------------------------------------- app shell */
.app { max-width: var(--max); margin: 0 auto; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  background: rgba(12,11,16,.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title {
  font-family: 'Sora', sans-serif; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; gap: 7px; letter-spacing: -.01em;
}
.icon-btn {
  background: transparent; border: 0; color: var(--text);
  font-size: 22px; width: 38px; height: 38px; border-radius: 10px;
}
.icon-btn:active { background: var(--surface); }

.view {
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
  min-height: calc(100dvh - var(--topbar-h));
}

/* ------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
  width: 100%; max-width: var(--max);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(12,11,16,.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 30;
}
.tab {
  background: transparent; border: 0; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; flex: 1; padding: 6px 0;
}
.tab-ico { font-size: 19px; line-height: 1; }
.tab.active { color: var(--text); }
.tab-compose {
  flex: 0 0 auto; width: 46px; height: 38px; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 24px; font-weight: 400;
  margin: 0 4px; display: grid; place-items: center;
}

/* -------------------------------------------------------------- posts */
.post {
  display: flex; gap: 11px; padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.post-tap { cursor: pointer; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 42px;
  object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 600; color: var(--accent-2);
  border: 1px solid var(--line); overflow: hidden;
}
.avatar.lg { width: 76px; height: 76px; flex-basis: 76px; font-size: 28px; }
.post-main { flex: 1; min-width: 0; }
.post-head { display: flex; align-items: baseline; gap: 6px; }
.post-name { font-weight: 600; }
.post-handle, .post-time { color: var(--muted); font-size: 13px; }
.post-body { margin: 3px 0 0; white-space: pre-wrap; word-wrap: break-word; }
.post-media { margin-top: 9px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.post-media img, .post-media video { display: block; width: 100%; max-height: 520px; object-fit: cover; background: #000; }
.post-actions { display: flex; gap: 18px; margin-top: 9px; color: var(--muted); font-size: 13px; }
.act { display: inline-flex; align-items: center; gap: 5px; background: transparent; border: 0; color: var(--muted); font-size: 13px; padding: 2px; }
.media-note {
  margin-top: 9px; padding: 22px 14px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--bg-2); color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 9px; font-size: 14px;
}
.media-note.processing { color: var(--accent-2); }
.spinner.sm { width: 15px; height: 15px; border-width: 2px; margin: 0; display: inline-block; vertical-align: middle; }
.act.liked { color: var(--danger); }
.act:active { opacity: .6; }

/* ------------------------------------------------------------ profile */
.profile-head { padding: 18px 16px; border-bottom: 1px solid var(--line); }
.profile-top { display: flex; gap: 16px; align-items: center; }
.profile-meta { flex: 1; min-width: 0; }
.profile-name { font-family: 'Sora', sans-serif; font-size: 20px; font-weight: 700; }
.profile-handle { color: var(--muted); font-size: 14px; }
.profile-bio { margin: 12px 0 4px; }
.profile-stats { display: flex; gap: 18px; color: var(--muted); font-size: 14px; margin-top: 6px; }
.profile-stats b { color: var(--text); }
.profile-actions { margin-top: 14px; display: flex; gap: 8px; }
.btn-outline {
  padding: 9px 18px; border-radius: 11px; background: transparent;
  border: 1px solid var(--line); color: var(--text); font-weight: 600; font-size: 14px;
}
.btn-outline.active { background: var(--surface-2); }

/* -------------------------------------------------------------- reels */
.reels {
  height: calc(100dvh - var(--topbar-h) - var(--tabbar-h));
  overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none;
}
.reels::-webkit-scrollbar { display: none; }
.reel {
  position: relative; height: 100%; scroll-snap-align: start;
  display: grid; place-items: center; background: #000;
}
.reel video { width: 100%; height: 100%; object-fit: contain; }
.reel-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 16px 22px;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
}
.reel-author { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.reel-body { margin-top: 4px; }
.reel-side {
  position: absolute; right: 12px; bottom: 80px;
  display: flex; flex-direction: column; gap: 18px; align-items: center;
}
.reel-side .act { flex-direction: column; color: #fff; font-size: 12px; gap: 3px; }

/* --------------------------------------------------------- misc states */
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty-emoji { font-size: 40px; display: block; margin-bottom: 10px; }
.loader { text-align: center; color: var(--muted); padding: 26px; }
.spinner {
  width: 22px; height: 22px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------- compose sheet */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
  width: 100%; max-width: var(--max);
  background: var(--surface); border-radius: 20px 20px 0 0;
  border: 1px solid var(--line); border-bottom: 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.link-btn { background: transparent; border: 0; color: var(--muted); font-size: 15px; }
.compose-body {
  width: 100%; min-height: 110px; resize: none; border: 0; outline: 0;
  background: transparent; color: var(--text); font-size: 17px; font-family: inherit;
}
.compose-preview img, .compose-preview video {
  width: 100%; border-radius: 12px; margin-top: 6px; max-height: 280px; object-fit: cover;
}
.sheet-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.chip {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 13px; border-radius: 999px; font-size: 13px; font-weight: 500;
}
.chip:active { background: var(--surface-2); }
.count { margin-left: auto; color: var(--muted); font-size: 13px; }

/* --------------------------------------------------- edit profile sheet */
.ep-avatar-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0 18px; }
.ep-avatar {
  width: 92px; height: 92px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--accent-2); font-size: 34px; font-weight: 600;
  display: grid; place-items: center; overflow: hidden; cursor: pointer; padding: 0;
  position: relative;
}
.ep-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ep-avatar::after {
  content: '📷'; position: absolute; right: -2px; bottom: -2px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); display: grid; place-items: center; font-size: 14px;
  border: 3px solid var(--surface);
}
.ep-change { background: transparent; border: 0; color: var(--accent-2); font-weight: 600; font-size: 14px; }
.ep-label { display: block; color: var(--muted); font-size: 13px; margin: 10px 2px 5px; }
.ep-bio { width: 100%; min-height: 70px; resize: none; font-family: inherit; }
.ep-count { text-align: right; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 999px; z-index: 80; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

/* tablet/desktop niceties */
@media (min-width: 640px) {
  .tab-lbl { display: inline; }
  .tabbar { border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
