:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e2e5ea;
  --line: #d4d9e0;
  --text: #1b1f24;
  --muted: #656d76;
  --accent: #6364ff;
  --op: #fff7e6;
  --op-border: #f0c060;
  --target: #eef0ff;
  --target-border: #6364ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  padding: 24px 16px 8px;
  max-width: 780px;
  margin: 0 auto;
}
.site-header h1 { margin: 0 0 4px; font-size: 22px; }
.tagline { margin: 0; color: var(--muted); }

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 16px 48px;
}

.url-form {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.url-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: var(--card);
  color: var(--text);
}
.url-form button, .load-more {
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.url-form button:hover, .load-more:hover { filter: brightness(1.08); }

.status { min-height: 20px; margin: 8px 0; color: var(--muted); }
.status.error { color: #b4232a; }
.status.loading::after {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-left: 6px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.load-more { display: block; margin: 16px auto; }

/* --- Tree ------------------------------------------------------------- */
.thread { margin-top: 8px; }

.node { position: relative; }

/* connecting line down the left of a subtree — the only indent source,
   so depth never compounds beyond this single step per level. */
.children {
  position: relative;
  border-left: 2px solid var(--line);
  margin-left: 16px;
  padding-left: 4px;
}

.node.collapsed > .children { display: none; }

/* "Continue thread" — Reddit/HN-style depth cap: instead of nesting forever,
   offer to re-root the view at this post. */
.continue-thread {
  display: block;
  margin: 4px 0 12px 16px;
  padding: 6px 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.continue-thread:hover { background: var(--card); border-color: var(--accent); }

/* Breadcrumb shown when focused on a sub-thread via "Continue thread". */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.back-link {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.back-link:hover { text-decoration: underline; }
.breadcrumb-note { color: var(--muted); font-size: 13px; }

/* Reply-to attribution — keeps who-replied-to-whom clear regardless of
   indentation, especially once depth-capping resets it to 0. */
.reply-to {
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 4px;
}
.reply-to:hover { text-decoration: underline; }

.post {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
}
.post.is-op { background: var(--op); border-color: var(--op-border); }
.post.is-target {
  border-color: var(--target-border);
  box-shadow: 0 0 0 2px var(--target-border);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.collapse {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
}
.collapse:hover { background: var(--bg); }

.avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex: none;
}
.who { display: flex; flex-direction: column; min-width: 0; }
.display-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.handle { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.time:hover { text-decoration: underline; }

.post-body { margin-top: 6px; word-wrap: break-word; overflow-wrap: anywhere; }
.post-body :first-child { margin-top: 0; }
.post-body :last-child { margin-bottom: 0; }
.post-body p { margin: 0 0 8px; }
.post-body a { color: var(--accent); }
.emoji { width: 1.2em; height: 1.2em; object-fit: contain; vertical-align: -0.2em; }

.media {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  margin-top: 8px;
}
.media img, .media video {
  width: 100%;
  border-radius: 8px;
  display: block;
}

.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
}
.site-footer a { color: var(--muted); }

@media (max-width: 520px) {
  .children { margin-left: 10px; }
}
