:root {
  --bg: #0d0d0d;
  --bg-side: #000;
  --fg: #fff;
  --fg-muted: #71767b;
  --accent: #e67e22;
  --border: #2f3336;
  --code-bg: #1a1a2e;
  --dropdown-bg: #1a1a1a;
  --dropdown-hover: #2a2a2a;
  --hover-overlay: rgba(255, 255, 255, 0.03);
  --accent-overlay: rgba(230, 126, 34, 0.1);
  --shadow: rgba(0, 0, 0, 0.5);
  --icon-bg: #1a1a2e;
  --max-width: 600px;
  --avatar-size: 40px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fff;
    --bg-side: #f0f2f5;
    --fg: #0f1419;
    --fg-muted: #536471;
    --accent: #c0611f;
    --border: #eff3f4;
    --code-bg: #f0f0f8;
    --dropdown-bg: #fff;
    --dropdown-hover: #f7f7f7;
    --hover-overlay: rgba(0, 0, 0, 0.03);
    --accent-overlay: rgba(192, 97, 31, 0.1);
    --shadow: rgba(0, 0, 0, 0.12);
    --icon-bg: #dfe1e5;
  }
}

html[data-theme="light"] {
  --bg: #fff;
  --bg-side: #f0f2f5;
  --fg: #0f1419;
  --fg-muted: #536471;
  --accent: #c0611f;
  --border: #eff3f4;
  --code-bg: #f0f0f8;
  --dropdown-bg: #fff;
  --dropdown-hover: #f7f7f7;
  --hover-overlay: rgba(0, 0, 0, 0.03);
  --accent-overlay: rgba(192, 97, 31, 0.1);
  --shadow: rgba(0, 0, 0, 0.12);
  --icon-bg: #dfe1e5;
}

html[data-theme="dark"] {
  --bg: #0d0d0d;
  --bg-side: #000;
  --fg: #fff;
  --fg-muted: #71767b;
  --accent: #e67e22;
  --border: #2f3336;
  --code-bg: #1a1a2e;
  --dropdown-bg: #1a1a1a;
  --dropdown-hover: #2a2a2a;
  --hover-overlay: rgba(255, 255, 255, 0.03);
  --accent-overlay: rgba(230, 126, 34, 0.1);
  --shadow: rgba(0, 0, 0, 0.5);
  --icon-bg: #1a1a2e;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; }

body {
  background: var(--bg-side);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 12rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Thread page header */
.thread-header {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
}

.thread-meta {
  color: var(--fg-muted);
  font-size: 0.8125rem;
  padding-bottom: 0.75rem;
}

/* Thread body */
.thread-body {
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--bg);
}

/* Individual post — avatar left, content right */
.thread-post {
  display: grid;
  grid-template-columns: var(--avatar-size) 1fr;
  gap: 0 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.thread-post:last-child {
  border-bottom: none;
}

/* Remove border between reply posts for continuous connector */
.thread-post:not(.post-first) {
  border-bottom: none;
}

/* First post — prominent style, no grid, full-width */
.thread-post.post-first {
  display: block;
  padding: 1rem;
  padding-bottom: 0.75rem;
}

.thread-post.post-first .post-avatar-col {
  display: none;
}

.thread-post.post-first .post-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.thread-post.post-first .post-header .first-post-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.thread-post.post-first .post-header-text .post-author {
  font-size: 1rem;
}

.thread-post.post-first .post-header-text .post-handle {
  font-size: 0.8125rem;
}

.thread-post.post-first .post-text {
  font-size: 1.0625rem;
  line-height: 1.6;
}

.thread-post.post-first .post-text p {
  font-size: 1.0625rem;
}

/* Standalone date row on first post */
.post-timestamp {
  display: flex;
  gap: 0.5rem;
  color: var(--fg-muted);
  font-size: 0.8125rem;
  padding: 0.75rem 0;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.post-timestamp a {
  color: var(--fg-muted);
  text-decoration: none;
}

.post-timestamp a:hover {
  text-decoration: underline;
}

/* Avatar column */
.post-avatar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.post-avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* Vertical connector line between posts */
.post-connector {
  width: 2px;
  flex: 1;
  background: var(--border);
  margin-top: 0;
  margin-bottom: -1rem;
  min-height: 8px;
}

/* Top connector segment bridging padding gap between consecutive replies */
.thread-post:not(.post-first) + .thread-post:not(.post-first) .post-avatar-col::before {
  content: '';
  width: 2px;
  background: var(--border);
  margin-top: -1rem;
  min-height: 1rem;
}

/* Content column */
.post-content {
  min-width: 0;
}

/* Post header: name, handle, date */
.post-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.post-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.post-name-row {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}

.post-author {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--fg);
  text-decoration: none;
}

.post-handle {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  color: var(--fg-muted);
  font-size: 0.8125rem;
  text-decoration: none;
}

.post-handle:hover {
  text-decoration: underline;
}

.post-handle svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.post-handles {
  display: inline-flex;
  gap: 1rem;
}

a.post-date,
.post-date {
  color: var(--fg-muted);
  font-size: 0.8125rem;
  text-decoration: none;
}

a.post-date:hover {
  text-decoration: underline;
}

.post-date::before {
  content: '\00b7';
  margin-right: 0.25rem;
}

/* Post text content */
.post-text p {
  margin-bottom: 1rem;
  font-size: 0.9375rem;
}

.post-text p:last-child {
  margin-bottom: 0;
}

.post-text img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.post-text .link-card img,
.tp-text .link-card img {
  margin: 0;
  cursor: pointer;
  border: none;
}

.post-text code {
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.875em;
}

.post-text pre {
  background: var(--code-bg);
  padding: 0.75rem;
  border-radius: 12px;
  overflow-x: auto;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}

.post-text pre code {
  background: none;
  padding: 0;
}

/* Action bar under each post */
.post-actions {
  display: flex;
  gap: 0;
  margin-top: 0.5rem;
  margin-left: -0.375rem;
  max-width: 240px;
  justify-content: space-between;
}

.post-actions a,
.post-actions button {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--fg-muted);
  font-size: 0.8125rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  transition: color 0.15s, background 0.15s;
}

.post-actions a:hover,
.post-actions button:hover {
  color: var(--accent);
  background: var(--accent-overlay);
  text-decoration: none;
}

.post-actions svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Share dropdown */
.share-dropdown {
  position: relative;
  display: inline-block;
}

.share-dropdown details {
  display: inline-block;
}

.share-dropdown summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--fg-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  transition: color 0.15s, background 0.15s;
}

.share-dropdown summary::-webkit-details-marker { display: none; }

.share-dropdown summary:hover {
  color: var(--accent);
  background: var(--accent-overlay);
}

.share-dropdown .share-options {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: var(--dropdown-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.25rem 0;
  min-width: 180px;
  z-index: 10;
  box-shadow: 0 0 12px var(--shadow);
}

.share-dropdown .share-options a {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--fg);
  font-size: 0.875rem;
  border-radius: 0;
}

.share-dropdown .share-options a:hover {
  background: var(--dropdown-hover);
  text-decoration: none;
}

/* Thread index */
.thread-list {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
}

.thread-list h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.thread-list-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.thread-list-item:last-child {
  border-bottom: none;
}

.thread-list-item a {
  font-size: 1rem;
  font-weight: 600;
}

.thread-list-item .thread-list-date {
  color: var(--fg-muted);
  font-size: 0.8125rem;
  margin-top: 0.15rem;
}

.thread-list-item .thread-list-desc {
  color: var(--fg-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* Profile page */
.profile-header {
  max-width: var(--max-width);
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.profile-banner {
  height: 150px;
  background: var(--accent);
  border-radius: 0;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 12px;
}

.profile-info {
  padding: 0 1rem 1rem;
  position: relative;
  z-index: 1;
}

.profile-avatar-wrap {
  display: inline-block;
  margin-top: -45px;
  margin-bottom: 0.75rem;
}

.profile-avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--bg);
}

.profile-name {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.profile-name a {
  color: var(--fg);
  text-decoration: none;
}

.profile-handle {
  color: var(--fg-muted);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.profile-socials {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.profile-socials a {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--fg-muted);
  font-size: 0.8125rem;
  text-decoration: none;
}

.profile-socials a:hover {
  color: var(--accent);
  text-decoration: none;
}

.profile-socials svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Pinned tags */
.pinned-tags {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
  display: flex;
  gap: 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  overflow-x: auto;
}

.pinned-tag {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--fg-muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  flex-shrink: 0;
}

.pinned-tag:hover {
  color: var(--accent);
  text-decoration: none;
}

.pinned-tag-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--border);
  transition: border-color 0.15s;
}

.pinned-tag:hover .pinned-tag-icon {
  border-color: var(--accent);
}

.pinned-tag-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pinned-tag-icon .icon-bg {
  fill: var(--icon-bg);
}

/* Thread feed */
.thread-feed {
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--bg);
}

.thread-empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

.thread-preview {
  display: block;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  text-decoration: none;
  transition: background 0.15s;
}

.thread-preview:hover {
  background: var(--hover-overlay);
  text-decoration: none;
}

/* Thread preview rows — avatar | content grid */
a.tp-row {
  color: var(--fg);
  text-decoration: none;
}

a.tp-row:hover {
  text-decoration: none;
}

.tp-row {
  display: grid;
  grid-template-columns: var(--avatar-size) 1fr;
  gap: 0 0.75rem;
}

.tp-avatar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tp-avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.tp-connector {
  width: 2px;
  flex: 1;
  background: var(--border);
  margin-top: 4px;
  min-height: 8px;
}

.tp-connector-full {
  width: 2px;
  height: 100%;
  background: var(--border);
}

.tp-content {
  min-width: 0;
}

.tp-header {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
}

.tp-author {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--fg);
  text-decoration: none;
}

.tp-handle {
  color: var(--fg-muted);
  font-size: 0.8125rem;
}

.tp-date {
  color: var(--fg-muted);
  font-size: 0.8125rem;
}

.tp-date::before {
  content: '\00b7';
  margin-right: 0.25rem;
  margin-left: 0.15rem;
}

.tp-text {
  font-size: 0.9375rem;
  line-height: 1.5;
}

.tp-text .feed-link {
  color: var(--accent);
}

.tp-text p {
  margin-bottom: 1rem;
}

.tp-text p:last-child {
  margin-bottom: 0;
}

.tp-text img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}

/* Ellipsis / compressed posts row */
.tp-ellipsis-row {
  padding: 0.35rem 0;
}

.tp-ellipsis {
  color: var(--fg-muted);
  font-size: 0.8125rem;
}

/* Last reply row */
.tp-reply {
  color: var(--fg);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.tp-reply p {
  margin-bottom: 0.25rem;
}

.tp-reply p:last-child {
  margin-bottom: 0;
}

.tp-reply img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}

/* Feed action buttons */
.tp-actions-row {
  padding: 0;
}

.tp-actions {
  display: flex;
  gap: 0;
  padding: 0.25rem 0;
  max-width: 240px;
  justify-content: space-between;
}

.tp-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--fg-muted);
  padding: 0.375rem;
  border-radius: 9999px;
  transition: color 0.15s, background 0.15s;
}

.tp-action:hover {
  background: var(--accent-overlay);
  color: var(--accent);
}

.tp-action svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hashtags */
.hashtag {
  color: var(--accent);
  text-decoration: none;
}

.hashtag:hover {
  text-decoration: underline;
}

/* Tag filter header */
.tag-filter {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
}

.tag-filter .tag-name {
  font-weight: 700;
  color: var(--accent);
}

.tag-filter .tag-back {
  color: var(--fg-muted);
  font-size: 0.8125rem;
}

.pinned-tag.active .pinned-tag-icon {
  border-color: var(--accent);
}

.pinned-tag.active {
  color: var(--accent);
}

/* Theme toggle */
.home-toggle,
.rss-toggle,
.notify-toggle {
  position: relative;
  top: auto;
  left: auto;
  background: rgba(0, 0, 0, 0.35);
  border: none;
  border-radius: 9999px;
  padding: 6px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 5;
  text-decoration: none;
}

.home-toggle:hover,
.rss-toggle:hover,
.notify-toggle:hover {
  background: rgba(0, 0, 0, 0.55);
  text-decoration: none;
}

.home-toggle svg,
.rss-toggle svg,
.notify-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notify-toggle { width: 30px; height: 30px; padding: 0; }
.notify-toggle.active { background: rgba(255, 255, 255, 0.15); }
.notify-toggle.active svg { fill: currentColor; }

.theme-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: none;
  border-radius: 9999px;
  padding: 6px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 5;
}

.theme-toggle:hover {
  background: rgba(0, 0, 0, 0.55);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun { display: none; }

html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
  html:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
}

html[data-theme="light"] .theme-toggle .icon-moon { display: block; }
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }

.thread-header .theme-toggle {
  background: var(--hover-overlay);
  color: var(--fg-muted);
}

.thread-header .theme-toggle:hover {
  background: var(--accent-overlay);
  color: var(--accent);
}

/* Parent posts banner for permalink focus */
.thread-parent-banner {
  max-width: var(--max-width);
  padding: 0.75rem 1rem;
  background: var(--bg);
}

.thread-parent-link {
  color: var(--fg-muted);
  font-size: 0.875rem;
  text-decoration: none;
}

.thread-parent-link::before {
  content: '\2191 ';
}

.thread-parent-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Image lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  object-fit: contain;
}

/* Link cards */
.link-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--fg);
  margin-top: 0.75rem;
  transition: background 0.15s;
}

.link-card:hover {
  background: var(--hover-overlay);
  text-decoration: none;
}

.link-card-image {
  width: 100%;
  height: auto;
  max-height: 260px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
}

.link-card-body {
  padding: 0.75rem;
}

.link-card-domain {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-bottom: 0.15rem;
}

.link-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
}

.link-card-description {
  font-size: 0.8125rem;
  color: var(--fg-muted);
  margin-top: 0.15rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
