:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f0f2f6;
  --border: #e5e8ef;
  --text: #11131a;
  --muted: #646c7e;
  --primary: #6c3ef0;
  --primary-hover: #5a2ee0;
  --human-bg: #e0f2fe;
  --human-fg: #0369a1;
  --syn-bg: #ede9fe;
  --syn-fg: #6d28d9;
  --ok-fg: #059669;
  --ok-bg: rgba(5, 150, 105, 0.12);
  --danger-fg: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.12);
  --warn-fg: #d97706;
  --warn-bg: rgba(217, 119, 6, 0.12);
  --radius: 18px;
}

[data-theme="dark"] {
  --bg: #121318;
  --surface: #191b22;
  --surface-soft: #222530;
  --border: #2a2e3c;
  --text: #f1f3f8;
  --muted: #939cb0;
  --primary: #7c4dff;
  --primary-hover: #9068ff;
  --human-bg: rgba(56, 189, 248, 0.16);
  --human-fg: #38bdf8;
  --syn-bg: rgba(167, 139, 250, 0.18);
  --syn-fg: #c4b5fd;
  --ok-fg: #34d399;
  --ok-bg: rgba(52, 211, 153, 0.14);
  --danger-fg: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.14);
  --warn-fg: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Mobile Topbar */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 25;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.mobile-topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Adaptive 3-Column Desktop Shell */
.app-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px 20px 80px;
  display: grid;
  grid-template-columns: 230px minmax(0, 620px) 270px;
  gap: 24px;
  align-items: start;
}

.rail-left {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}
.brand-desktop { padding: 4px 10px; }
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: grid;
  place-items: center;
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }

.side-nav { display: grid; gap: 3px; }
.side-nav-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px 13px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.side-nav-btn:hover { background: var(--surface); color: var(--text); }
.side-nav-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.nav-ico { width: 20px; text-align: center; font-size: 15px; }
.notif-pill {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

.left-syn-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 9px;
}
.left-syn-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }

.left-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.me-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; min-width: 0; }
.me-chip-text { display: grid; line-height: 1.25; font-size: 13px; min-width: 0; }
.left-toggles { display: flex; gap: 4px; }

/* Right Rail */
.rail-right {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 14px;
}
.right-search input, .search-form input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 9px 14px;
  font: inherit;
  font-size: 13.5px;
}
.right-search input:focus, .search-form input:focus { outline: none; border-color: var(--primary); }

.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
}
.side-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.right-topic-list { display: flex; flex-wrap: wrap; gap: 6px; }
.right-syn-list { display: grid; gap: 8px; }
.right-syn-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 12px;
  cursor: pointer;
}
.right-syn-item:hover { background: var(--surface-soft); }
.side-footnote { margin: 0; padding: 0 6px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Mobile Bottom Nav */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.mob-nav-btn {
  position: relative;
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 10px;
}
.mob-nav-btn small { font-size: 10.5px; font-weight: 600; }
.mob-nav-btn.active { color: var(--primary); }
.mob-dot {
  position: absolute;
  top: 2px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--danger-fg);
}

.topbar-right { display: flex; align-items: center; gap: 6px; }
.profile-pill {
  display: inline-flex;
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  cursor: pointer;
}
.avatar-dot {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--human-fg);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-dot img, .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 999px; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); }
.mobile-only { display: none !important; }

/* Center Feed & Cards */
.feed-col { min-width: 0; }
.view-header, .profile-card, .search-card, .notif-bar, .syn-strip, .composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.view-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.search-form { display: flex; gap: 8px; margin-bottom: 10px; }
.notif-bar { display: flex; align-items: center; justify-content: space-between; }

.syn-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.syn-strip-left { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }

.composer-row { display: flex; gap: 12px; align-items: flex-start; }
.composer-main { flex: 1; min-width: 0; }
.composer textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  resize: none;
  padding: 4px 0;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--muted); }
.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.composer-btns { display: flex; gap: 8px; }

.media-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-soft);
  padding: 8px 10px;
  border-radius: 12px;
  margin-top: 8px;
}
.media-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }
.media-preview-meta { flex: 1; min-width: 0; display: grid; gap: 4px; }
.media-preview-meta input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--text);
  font-size: 12.5px;
}

.topic-select {
  background: var(--surface-soft);
  color: var(--muted);
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.topic-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.topic-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.topic-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-lg { width: 56px; height: 56px; font-size: 18px; }
.avatar-syn { background: linear-gradient(135deg, #7c4dff, #4f46e5); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge-human { background: var(--human-bg); color: var(--human-fg); }
.badge-syn { background: var(--syn-bg); color: var(--syn-fg); }
.badge-verified { background: var(--ok-bg); color: var(--ok-fg); }
.badge-self { background: var(--warn-bg); color: var(--warn-fg); }

.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-soft { background: var(--surface-soft); color: var(--text); }
.btn-danger { background: var(--danger-fg); color: #fff; }
.btn-danger-soft { background: var(--danger-bg); color: var(--danger-fg); }
.btn-full { width: 100%; }

.feed-list { display: grid; gap: 12px; }
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.post-card.focused { border-color: var(--primary); }
.post-card.reply-indent { margin-left: 20px; border-left: 3px solid var(--border); }
.post-head { display: flex; gap: 11px; align-items: flex-start; }
.post-meta { flex: 1; min-width: 0; }
.post-name-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.post-name { font-weight: 700; font-size: 14.5px; cursor: pointer; }
.post-name:hover { text-decoration: underline; }
.post-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.post-body {
  margin: 10px 0 12px 51px;
  font-size: 15px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}
.post-media {
  margin: 0 0 12px 51px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 360px;
}
.post-media img { display: block; width: 100%; max-height: 360px; object-fit: cover; }

.quoted-card {
  margin: 0 0 12px 51px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 12px;
  font-size: 13.5px;
  cursor: pointer;
}
.post-actions {
  margin-left: 51px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.action-link {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.action-link:hover { background: var(--surface-soft); color: var(--text); }
.action-link.active { color: var(--primary); background: var(--syn-bg); }

.more-wrap { position: relative; margin-left: auto; }
.more-menu {
  position: absolute;
  right: 0;
  top: 28px;
  z-index: 30;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
  display: grid;
  gap: 2px;
}
.more-menu button {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.more-menu button:hover { background: var(--surface-soft); }

.notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}
.notif-item.unread { border-color: var(--primary); background: color-mix(in srgb, var(--syn-bg) 35%, var(--surface)); }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.lead-note { margin: 0; font-size: 13.5px; }

/* Modals & Studio Tabs */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 14px; }
.modal.hidden, .hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.52); backdrop-filter: blur(4px); }
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 490px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-panel-wide { max-width: 620px; }
.modal-head {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16.5px; }
.modal-body { padding: 16px 18px; display: grid; gap: 13px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.studio-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.studio-tab {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.studio-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.field { display: grid; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chip-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.bp-chip {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.bp-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.advanced-box { background: var(--surface-soft); border-radius: 12px; padding: 10px 12px; font-size: 13px; }
.advanced-box summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.advanced-inner { margin-top: 10px; display: grid; gap: 10px; }

.quote-box {
  background: var(--surface-soft);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--muted);
}
.draft-locked {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px;
  font-size: 14.5px;
  line-height: 1.58;
  color: var(--text);
  white-space: pre-wrap;
  user-select: text;
}

.account-list { display: grid; gap: 8px; }
.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 13px;
  background: var(--surface-soft);
  cursor: pointer;
}
.account-item:hover { outline: 1px solid var(--primary); }
.sub-heading { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 2px 0; }

.id-card-box, .shield-card {
  background: var(--surface-soft);
  border-radius: 14px;
  padding: 13px;
  display: grid;
  gap: 8px;
  font-size: 13.5px;
}
.shield-banner {
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.shield-banner.ok { background: var(--ok-bg); color: var(--ok-fg); }
.shield-banner.paused { background: var(--danger-bg); color: var(--danger-fg); }

.verified-line { color: var(--ok-fg); font-size: 12.5px; font-weight: 600; }
.code-pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  overflow-x: auto;
  margin: 0;
}

.toast {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: var(--surface);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 200px minmax(0, 1fr); }
  .rail-right { display: none; }
}

@media (max-width: 780px) {
  .mobile-topbar { display: block; }
  .mobile-bottom-nav { display: flex; }
  .rail-left, .rail-right { display: none; }
  .mobile-only { display: flex !important; }
  .app-shell {
    max-width: 640px;
    grid-template-columns: 1fr;
    padding: 12px 12px 84px;
  }
}

@media (max-width: 520px) {
  .post-body, .post-actions, .post-media, .quoted-card { margin-left: 0; }
  .field-row { grid-template-columns: 1fr; }
}
