:root {
  --bg: #ffffff;
  --bg-alt: #f5f7f8;
  --bg-raised: #ffffff;
  --text: #181c1f;
  --text-muted: #5c6c74;
  --line: #e5ebee;
  --hover: #f2f4f5;
  --pill: #eaedef;
  --pill-hover: #dde2e4;
  --accent: #0045ac;
  --accent-soft: #e4ecf9;
  --brand: #ff4500;
  --upvote: #d93a00;
  --downvote: #6a5cff;
  --scrim: rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 24px rgba(24, 28, 31, 0.12);
}

html[data-theme='dark'] {
  --bg: #0e1113;
  --bg-alt: #14181b;
  --bg-raised: #181c1f;
  --text: #eef1f3;
  --text-muted: #8ba2ad;
  --line: #2a3236;
  --hover: #181c1f;
  --pill: #222a2e;
  --pill-hover: #2e373c;
  --accent: #8cb4ff;
  --accent-soft: #1b2a45;
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }

/* ---------- navbar ---------- */

.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text);
  flex: none;
}
.icon-btn:hover { background: var(--hover); }

.burger { display: none; }

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.logo-text {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--brand);
}

.searchbox {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  height: 40px;
  padding: 0 16px;
  background: var(--pill);
  border-radius: 999px;
}
.searchbox:focus-within { background: var(--bg-raised); box-shadow: 0 0 0 1px var(--accent); }
.search-ic { color: var(--text-muted); flex: none; }
.searchbox input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
}
.searchbox input::placeholder { color: var(--text-muted); }

.search-drop {
  position: absolute;
  top: 46px;
  left: 0;
  right: 0;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 420px;
  overflow-y: auto;
}
.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
}
.search-row:hover { background: var(--hover); }
.search-row .sub { color: var(--text-muted); font-size: 12px; }
.search-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-head {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  margin-left: auto;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
}
.pill-btn:hover { background: var(--hover); }

.avatar-btn { border-radius: 50%; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  flex: none;
  user-select: none;
}

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: 48px;
  right: 0;
  min-width: 220px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  font-size: 14px;
}
.menu-item:hover { background: var(--hover); }
.menu-item .sub { display: block; font-size: 12px; color: var(--text-muted); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ---------- layout ---------- */

.shell { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
  width: 270px;
  flex: none;
  border-right: 1px solid var(--line);
  padding: 16px 12px 32px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  background: var(--bg);
}

.side-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
}
.side-item:hover { background: var(--hover); }
.side-item.active { background: var(--pill); font-weight: 600; }
.side-item .cicon { flex: none; }
.side-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-head {
  padding: 16px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.side-sep { height: 1px; background: var(--line); margin: 12px 4px; }

.scrim {
  position: fixed;
  inset: 0;
  top: 56px;
  background: var(--scrim);
  z-index: 40;
}

main { flex: 1; min-width: 0; }

.content-grid {
  display: flex;
  gap: 24px;
  max-width: 1096px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}
.feed-col { flex: 1; min-width: 0; max-width: 756px; margin: 0 auto; }
.rail { width: 316px; flex: none; }
.rail-sticky { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 16px; }

.rail-card {
  background: var(--bg-alt);
  border-radius: 16px;
  padding: 14px 16px;
}
.rail-card h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.rail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 0;
  text-align: left;
}
.rail-row .grow { flex: 1; min-width: 0; }
.rail-row .name { font-size: 13px; font-weight: 500; }
.rail-row .sub { font-size: 12px; color: var(--text-muted); }
.rail-desc { font-size: 13px; color: var(--text); margin: 0 0 10px; }
.rail-stats { display: flex; gap: 24px; margin: 12px 0; }
.rail-stat .num { font-size: 15px; font-weight: 700; }
.rail-stat .lbl { font-size: 12px; color: var(--text-muted); }
.online-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #46a508;
  margin-right: 5px;
}
.rail-rule {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.rail-rule:first-of-type { border-top: 0; }
.rail-rule .n { color: var(--text-muted); font-weight: 600; margin-right: 8px; }
.rail-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  border: 0;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
html[data-theme='dark'] .btn-primary { color: #0e1113; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { filter: brightness(1.08); }
.btn-outline { background: transparent; border: 1px solid var(--text-muted); color: var(--text); }
.btn-outline:hover { background: var(--hover); }
.btn-ghost { background: var(--pill); color: var(--text); }
.btn-ghost:hover { background: var(--pill-hover); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn[disabled] { opacity: 0.45; cursor: default; pointer-events: none; }

/* ---------- feed ---------- */

.feed-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 10px;
}
.sort-pill {
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.sort-pill:hover { background: var(--hover); }
.sort-pill.active { background: var(--pill); color: var(--text); }

.post-card {
  padding: 10px 12px 6px;
  border-radius: 16px;
  cursor: pointer;
  position: relative;
}
.post-card:hover { background: var(--hover); }
.post-wrap { border-bottom: 1px solid var(--line); padding: 2px 0; }
.post-wrap:last-child { border-bottom: 0; }

.post-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.post-meta a { font-weight: 700; color: var(--text); }
.post-meta a:hover { color: var(--accent); }
.post-meta .dot { opacity: 0.7; }
.post-meta .author-link { font-weight: 400; color: var(--text-muted); }
.post-meta .author-link:hover { color: var(--accent); }

.cicon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex: none;
  user-select: none;
}

.post-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 6px;
}
.post-title-lg { font-size: 21px; font-weight: 700; margin: 2px 0 10px; }

.post-body-preview {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-body-full {
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin: 0 0 10px;
}

.post-image {
  width: 100%;
  max-height: 540px;
  object-fit: cover;
  border-radius: 14px;
  background: var(--bg-alt);
  margin: 2px 0 8px;
  display: block;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 2px 0 8px;
  font-size: 13px;
  color: var(--accent);
  overflow: hidden;
}
.link-card:hover { text-decoration: underline; }
.link-card .domain { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.post-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 6px;
}

.vote-pill {
  display: inline-flex;
  align-items: center;
  background: var(--pill);
  border-radius: 999px;
  height: 32px;
  overflow: hidden;
}
.vote-pill.voted-up { background: var(--upvote); color: #fff; }
.vote-pill.voted-down { background: var(--downvote); color: #fff; }
.vote-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: inherit;
}
.vote-pill:not(.voted-up):not(.voted-down) .vote-btn:hover { background: var(--pill-hover); }
.vote-pill:not(.voted-up):not(.voted-down) .vote-btn.up:hover { color: var(--upvote); }
.vote-pill:not(.voted-up):not(.voted-down) .vote-btn.down:hover { color: var(--downvote); }
.vote-pill.voted-up .vote-btn:hover, .vote-pill.voted-down .vote-btn:hover { background: rgba(255, 255, 255, 0.18); }
.vote-count {
  min-width: 16px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 0 2px;
}
.pop { animation: pop 0.18s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.action-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--pill);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.action-pill:hover { background: var(--pill-hover); }

/* ---------- community banner ---------- */

.comm-banner {
  height: 120px;
  border-radius: 0 0 16px 16px;
  margin: 0 0 0;
}
.comm-head {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  padding: 0 16px;
  margin-top: -28px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.comm-head .cicon { border: 4px solid var(--bg); }
.comm-head-info { flex: 1; min-width: 200px; padding-bottom: 2px; }
.comm-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.5px; }
.comm-head .sub { color: var(--text-muted); font-size: 13px; }
.comm-head-actions { display: flex; gap: 8px; padding-bottom: 4px; }

.page-head { padding: 8px 4px 14px; }
.page-head h1 { margin: 0 0 2px; font-size: 22px; }
.page-head .sub { color: var(--text-muted); font-size: 13px; }

/* ---------- post page ---------- */

.back-row { display: flex; align-items: center; gap: 10px; padding: 4px 0 10px; }
.back-row .ctx { font-size: 12px; color: var(--text-muted); }

/* ---------- comments ---------- */

.composer {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  margin: 6px 0 18px;
  background: var(--bg-raised);
}
.composer:focus-within { border-color: var(--text-muted); }
.composer textarea {
  width: 100%;
  border: 0;
  outline: 0;
  resize: vertical;
  min-height: 22px;
  background: transparent;
  font-size: 14px;
  line-height: 1.5;
  padding: 2px;
}
.composer .composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.composer.collapsed .composer-actions { display: none; }
.composer.collapsed textarea { min-height: 20px; height: 22px; resize: none; }

.comments-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 10px;
}
.comments-toolbar select {
  background: transparent;
  border: 0;
  outline: 0;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
}
.comments-toolbar select option { background: var(--bg-raised); color: var(--text); }

.comment { margin: 2px 0 0; }
.comment-main { display: flex; gap: 8px; }
.comment-body-col { flex: 1; min-width: 0; }
.comment-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.comment-meta .author { font-weight: 700; color: var(--text); }
.comment-meta .author:hover { color: var(--accent); }
.comment-meta .author.op { color: var(--accent); }
.comment-text {
  font-size: 14px;
  margin: 2px 0 4px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.comment-actions { display: flex; align-items: center; gap: 2px; margin-bottom: 4px; }
.comment-actions .mini {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.comment-actions .mini:hover { background: var(--pill); color: var(--text); }
.comment-actions .mini.voted-up { color: var(--upvote); }
.comment-actions .mini.voted-down { color: var(--downvote); }

.comment-children {
  margin-left: 15px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
}
.collapse-line { cursor: pointer; }
.comment-children:hover { border-left-color: var(--text-muted); }
.collapsed-stub {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 999px;
}
.collapsed-stub:hover { background: var(--pill); }
.collapsed-stub .author { font-weight: 700; color: var(--text); }

.reply-composer { margin: 0 0 8px; }

.c-vote { display: inline-flex; align-items: center; }
.c-vote .cnt {
  font-size: 12px;
  font-weight: 700;
  min-width: 16px;
  text-align: center;
  color: var(--text-muted);
}
.c-vote.voted-up .up, .c-vote.voted-up .cnt { color: var(--upvote); }
.c-vote.voted-down .down, .c-vote.voted-down .cnt { color: var(--downvote); }

/* ---------- submit ---------- */

.submit-card { padding: 4px; }
.field-label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin: 14px 0 6px; }
.text-input, .select-input, .area-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-raised);
  padding: 10px 14px;
  outline: 0;
  font-size: 14px;
}
.text-input:focus, .select-input:focus, .area-input:focus { border-color: var(--text-muted); }
.area-input { min-height: 140px; resize: vertical; line-height: 1.5; }
.char-count { font-size: 11px; color: var(--text-muted); text-align: right; margin-top: 4px; }

.type-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 4px; }
.type-tab {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.type-tab.active { color: var(--text); border-bottom-color: var(--brand); }
.submit-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.comm-select-row { display: flex; align-items: center; gap: 10px; }

/* ---------- profile ---------- */

.profile-banner { height: 88px; border-radius: 0 0 16px 16px; background: linear-gradient(120deg, var(--brand), #ff8717); }
.profile-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 12px; }

.mini-comment {
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.mini-comment:hover { background: var(--hover); }
.mini-comment .ctx { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.mini-comment .ctx b { color: var(--text); }
.mini-comment .txt { font-size: 13px; }
.mini-wrap { border-bottom: 1px solid var(--line); }
.mini-wrap:last-child { border-bottom: 0; }

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 400px;
  background: var(--bg-raised);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  position: relative;
}
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.modal .modal-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}
.auth-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--pill); border-radius: 999px; padding: 4px; }
.auth-tab {
  flex: 1;
  height: 32px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-tab.active { background: var(--bg-raised); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.modal .field { margin-bottom: 12px; }
.form-error { color: #d93a00; font-size: 12px; margin: 4px 0 0; min-height: 16px; }
.modal .btn { width: 100%; height: 40px; }
.or-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 11px;
  margin: 14px 0;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.or-row::before, .or-row::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- toast ---------- */

#toast-root {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: #181c1f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
html[data-theme='dark'] .toast { background: #eef1f3; color: #181c1f; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- skeleton ---------- */

.skel {
  border-radius: 10px;
  background: linear-gradient(90deg, var(--pill) 25%, var(--pill-hover) 45%, var(--pill) 65%);
  background-size: 300% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}
.skel-post { padding: 14px 12px; border-bottom: 1px solid var(--line); }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state .big { font-size: 40px; margin-bottom: 8px; }

.load-sentinel { height: 1px; }
.feed-end {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 24px 0 8px;
}

/* ---------- responsive ---------- */

@media (max-width: 1240px) {
  .rail { display: none; }
}

@media (max-width: 1024px) {
  .burger { display: flex; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    height: auto;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
}

@media (max-width: 640px) {
  .logo-text { display: none; }
  .create-btn span { display: none; }
  .content-grid { padding: 8px 8px 64px; }
  .post-title { font-size: 16px; }
  .comm-head h1 { font-size: 20px; }
}
