/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #ffffff;
  --bg-hover:      #f7f9fa;
  --border:        #eff3f4;
  --text:          #0f1419;
  --text-muted:    #536471;
  --thread-line:   #cfd9de;
  --like-active:   #f91880;
  --accent:        #1d9bf0;
  --tooltip-bg:    #ffffff;
  --tooltip-shadow: 0 8px 32px rgba(0,0,0,0.18);

  --avatar-lg: 40px;
  --avatar-sm: 32px;
  --gutter:    16px;
  /* left edge of thread line = gutter + half of large avatar */
  --line-x:    36px;
  /* top of thread line = gutter-top(12) + avatar(40) + gap(4) */
  --line-top:  56px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --max-width: 600px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ============================================================
   Site header
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px var(--gutter);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.header-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.header-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.handle-link {
  color: var(--accent);
  cursor: pointer;
}

/* ============================================================
   Thread container
   ============================================================ */
#thread-container {
  max-width: var(--max-width);
  margin: 0 auto;
}

.status-msg {
  padding: 24px var(--gutter);
  color: var(--text-muted);
  text-align: center;
}

.error-msg {
  padding: 24px var(--gutter);
  color: #c00;
  font-size: 14px;
  line-height: 1.6;
}

.error-msg code {
  background: #f5f5f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

/* ============================================================
   Post wrapper  (contains one post row + its replies area)
   ============================================================ */
.post-wrapper {
  position: relative;
  border-bottom: 1px solid var(--border);
}

/* Thread line: runs from below the avatar to the bottom of the wrapper,
   including any expanded replies inside it */
.post-wrapper.in-thread::after {
  content: '';
  position: absolute;
  left: var(--line-x);
  top: var(--line-top);
  bottom: 0;
  width: 2px;
  background: var(--thread-line);
  pointer-events: none;
}

/* ============================================================
   Post row
   ============================================================ */
.post-row {
  display: flex;
  gap: 12px;
  padding: 12px var(--gutter) 0;
  cursor: default;
  transition: background 0.1s;
}

.post-row:hover { background: var(--bg-hover); }

/* ============================================================
   Avatar
   ============================================================ */
.avatar {
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ============================================================
   Post body
   ============================================================ */
.post-body {
  flex: 1;
  min-width: 0;
  padding-bottom: 12px;
}

.post-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 3px;
  line-height: 1.3;
}

.post-name {
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.post-name:hover { text-decoration: underline; }

.post-handle {
  font-size: 14px;
  color: var(--text-muted);
}

.post-ts {
  font-size: 14px;
  color: var(--text-muted);
}
.post-ts::before { content: '·'; margin: 0 3px; }

.post-content {
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 10px;
}

/* ============================================================
   Actions bar (likes + reply toggle)
   ============================================================ */
.post-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 4px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: color 0.1s;
}

.action-btn:hover { color: var(--accent); }

.action-icon {
  font-size: 15px;
  line-height: 1;
}

/* @mention */
.mention {
  color: var(--accent);
  cursor: pointer;
}
.mention:hover { text-decoration: underline; }

/* Like button */
.like-btn { position: relative; }
.like-btn:hover { color: var(--like-active); }

.like-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,20,25,0.9);
  color: #fff;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 30;
}

.like-btn:hover .like-tooltip { display: block; }

/* ============================================================
   Replies area  (inside post-wrapper, below post-row)
   ============================================================ */
.replies-area {
  display: none;
}
.replies-area.open {
  display: block;
}

/* ============================================================
   Reply row  (same structure as post-row but indented)
   ============================================================ */
.reply-row {
  display: flex;
  gap: 10px;
  /* padding-left is set inline by app.js based on nesting depth */
  padding: 10px var(--gutter) 0 0;
  transition: background 0.1s;
}

.reply-row:hover { background: var(--bg-hover); }

.reply-body {
  flex: 1;
  min-width: 0;
  padding-bottom: 10px;
}

/* ============================================================
   Repost row  (same indent as reply, distinct visual treatment)
   ============================================================ */
.repost-row {
  display: flex;
  gap: 10px;
  /* padding-left is set inline by app.js based on nesting depth */
  padding: 8px var(--gutter) 0 0;
  transition: background 0.1s;
}

.repost-row:hover { background: var(--bg-hover); }

.repost-body {
  flex: 1;
  min-width: 0;
  padding-bottom: 8px;
}

.repost-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 3px;
  font-size: 14px;
  line-height: 1.3;
}

.repost-icon {
  color: var(--text-muted);
  font-style: normal;
}

/* Name inside a repost header is slightly smaller than in a full reply */
.repost-name {
  font-size: 14px !important;
}

.repost-verb {
  color: var(--text-muted);
  font-size: 14px;
}

/* Quote-repost comment text (shown when <comment> is present) */
.repost-comment {
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 4px !important;
}

/* Children of a reply/repost — always visible once their parent's replies-area opens */
.child-replies-area { display: block; }

/* ============================================================
   Link card  (WikipediaBot / external link preview)
   ============================================================ */
.link-card {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-top: 8px;
  margin-bottom: 4px;
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}
.link-card:hover { background: var(--bg-hover); }

.link-card-thumb {
  flex-shrink: 0;
  width: 100px;
  object-fit: cover;
  object-position: center;
  border-right: 1px solid var(--border);
}

.link-card-body {
  padding: 10px 12px;
  min-width: 0;
}

.link-card-domain {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.link-card-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  margin-bottom: 3px;
}

.link-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.link-card-verse {
  font-size: 14px;
  line-height: 1.55;
  font-style: italic;
  color: var(--text);
}

/* ============================================================
   Quote box  (quote-tweet)
   ============================================================ */
.quote-box {
  border: 1px solid var(--thread-line);
  border-radius: 12px;
  background: var(--bg-hover);
  padding: 10px 12px;
  margin-top: 8px;
  margin-bottom: 4px;
  cursor: default;
}

.quote-attribution {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.3;
}

.quote-attribution .avatar { align-self: center; }

.quote-name {
  font-weight: 700;
  cursor: pointer;
}
.quote-name:hover { text-decoration: underline; }

.quote-handle {
  font-size: 13px;
  color: var(--text-muted);
}

.quote-ts {
  font-size: 13px;
  color: var(--text-muted);
}
.quote-ts::before { content: '·'; margin: 0 3px; }

.quote-source {
  display: flex;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-muted);
}
.quote-source::before { content: '·'; margin: 0 3px; flex-shrink: 0; }

.quote-content {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ============================================================
   Profile tooltip
   ============================================================ */
.profile-tooltip {
  position: fixed;
  width: 300px;
  background: var(--tooltip-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--tooltip-shadow);
  z-index: 100;
  pointer-events: none;
}

.profile-tooltip[hidden] { display: none !important; }

.tt-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  margin-bottom: 10px;
  overflow: hidden;
}

.tt-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.tt-name {
  font-weight: 800;
  font-size: 16px;
  line-height: 1.2;
}

.tt-handle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.tt-bio {
  font-size: 14px;
  line-height: 1.45;
  margin-bottom: 6px;
}

.tt-years {
  font-size: 13px;
  color: var(--text-muted);
}

/* ============================================================
   Legend / editorial footer
   ============================================================ */
#legend {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px var(--gutter) 36px;
  border-top: 1px solid var(--border);
}

#legend p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

#legend p + p {
  margin-top: 10px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 480px) {
  :root { --gutter: 12px; }
  .reply-row  { padding-left: 44px; }
  .sub-reply-row { padding-left: 72px; }
}
