:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #1c1b19;
  --muted: #78736b;
  --line: #e3dfd7;
  --accent: #b8500f;
  --accent-soft: #fbe8dc;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191817;
    --card: #23211f;
    --text: #ece9e4;
    --muted: #9b958c;
    --line: #383530;
    --accent: #f08b4b;
    --accent-soft: #3a2a1f;
  }
}

* { box-sizing: border-box; }

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

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

main { max-width: 640px; margin: 0 auto; padding: 1rem 1rem 4rem; }

/* top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 640px; margin: 0 auto; padding: 0.8rem 1rem;
}
.topbar .brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; gap: 0.9rem; align-items: center; }
.inline { display: inline; }
.linkish {
  background: none; border: none; padding: 0; font: inherit;
  color: var(--accent); cursor: pointer;
}
.linkish:hover { text-decoration: underline; }

/* cards */
.card, .post {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

/* compose */
.compose { display: flex; flex-direction: column; gap: 0.5rem; }
.compose-title, .compose-body, .reply-form textarea, .settings-form input,
.settings-form textarea, .login input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}
.compose-body, .reply-form textarea, .settings-form textarea { resize: vertical; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; }
.hint { color: var(--muted); font-size: 0.85rem; }

button[type="submit"], .button-link {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
}
button[type="submit"]:hover, .button-link:hover { filter: brightness(1.08); text-decoration: none; }
button.danger { background: #a83232; }

/* posts */
.post-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.post-byline { display: flex; flex-direction: column; line-height: 1.25; }
.author { font-weight: 650; color: var(--text); }
.stamp, .reply-head time { color: var(--muted); font-size: 0.8rem; }
.post-title { margin: 0.3rem 0 0; font-size: 1.15rem; }
.post-title a { color: var(--text); }
.post-body { overflow-wrap: break-word; }
.post-body img { max-width: 100%; border-radius: 8px; }
.post-body pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.7rem; overflow-x: auto; font-size: 0.85rem;
}
.post-body code { background: var(--bg); padding: 0.1em 0.3em; border-radius: 4px; font-size: 0.9em; }
.post-body pre code { background: none; padding: 0; }
.post-body blockquote { border-left: 3px solid var(--line); margin: 0.5rem 0; padding-left: 0.8rem; color: var(--muted); }

/* avatars */
.avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.8rem; }
.avatar-fallback { color: #fff; font-weight: 700; }
.hue-0 { background: #b8500f; } .hue-1 { background: #2f6f4f; }
.hue-2 { background: #4f5d9e; } .hue-3 { background: #9e4f77; }
.hue-4 { background: #6f5a2f; } .hue-5 { background: #47707e; }

/* reactions */
.post-actions { display: flex; align-items: center; gap: 0.35rem; margin-top: 0.6rem; flex-wrap: wrap; }
.react {
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.15rem 0.55rem; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.react .count { margin-left: 0.3rem; font-size: 0.8rem; color: var(--muted); }
.react.mine { background: var(--accent-soft); border-color: var(--accent); }
.react.mine .count { color: var(--accent); font-weight: 650; }
.react.zero { opacity: 0.55; }
.react:hover { opacity: 1; border-color: var(--accent); }
.replies-link { margin-left: auto; color: var(--muted); font-size: 0.9rem; }

/* replies */
.replies h3, .section-head { font-size: 1rem; margin: 1.4rem 0 0.7rem; }
.reply { display: flex; gap: 0.6rem; margin-bottom: 0.9rem; }
.reply-main { flex: 1; min-width: 0; }
/* wraps rather than squeezing the name when the tools are present */
.reply-head { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
.reply-body { overflow-wrap: break-word; }
.reply-body p { margin: 0.2rem 0; }
.reply-form { display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-end; }

/* edit + delete controls, on your own posts and replies only */
.tools {
  margin-left: auto;
  display: flex;
  gap: 0.7rem;
  align-items: center;
  font-size: 0.8rem;
  line-height: 1;
}
.tools a, .tools summary { color: var(--muted); }
.tools a:hover { color: var(--accent); }
.tools details { position: relative; }
.tools summary { list-style: none; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary:hover { color: #a83232; }

/* the delete confirmation, floated so it never stretches the byline row */
.confirm {
  position: absolute;
  right: 0;
  top: 1.5rem;
  z-index: 5;
  margin-top: 0;
  width: 15rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.confirm p { margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--muted); }
.confirm button { width: 100%; }

/* editing a post or reply in place */
.edit-form { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.5rem 0; }
.edit-form input, .edit-form textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}
.edit-form textarea { resize: vertical; }
.edit-foot { display: flex; justify-content: flex-end; align-items: center; gap: 0.9rem; }
.edit-foot a { color: var(--muted); font-size: 0.85rem; }

/* threads inline on the feed */
.post-replies {
  border-top: 1px solid var(--line);
  margin-top: 0.9rem;
  padding-top: 0.9rem;
}
.post-replies .reply:last-of-type { margin-bottom: 1rem; }

/* nesting: the model caps `indent` at 3, so this ladder has a last rung */
.indent-1 { margin-left: 1.6rem; }
.indent-2 { margin-left: 3.2rem; }
.indent-3 { margin-left: 4.8rem; }
.indent-1, .indent-2, .indent-3 {
  border-left: 2px solid var(--line);
  padding-left: 0.7rem;
}
.reply-nested { display: block; }

@media (max-width: 480px) {
  .indent-1 { margin-left: 0.7rem; }
  .indent-2 { margin-left: 1.4rem; }
  .indent-3 { margin-left: 2.1rem; }
}

.reply-link {
  font-size: 0.8rem;
  color: var(--muted);
}
.reply-link:hover { color: var(--accent); }
.reply-form { display: flex; flex-direction: column; gap: 0.5rem; }
.reply-foot { display: flex; justify-content: flex-end; align-items: center; gap: 0.9rem; }
.reply-foot a { color: var(--muted); font-size: 0.85rem; }

/* what a deleted post or reply leaves behind */
.tombstone {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}
.post-deleted { background: none; border-style: dashed; }
/* the reply count doubles as the way through to the surviving permalink */
.post-tombstone { display: flex; align-items: center; gap: 0.6rem; }
.post-tombstone .replies-link { margin-left: auto; }

/* profile */
.profile { display: flex; gap: 1.1rem; align-items: flex-start; }
.profile-main h1 { margin: 0; font-size: 1.3rem; }
.handle { color: var(--muted); margin: 0.1rem 0 0.5rem; }
.bio { white-space: pre-wrap; margin: 0.4rem 0; }

/* settings */
.settings-form { display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-start; }
.settings-form label { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }
.settings-form button { margin-top: 0.8rem; }
.token-reveal { border-color: var(--accent); }
.token { display: inline-block; word-break: break-all; background: var(--bg); padding: 0.3rem 0.5rem; border-radius: 6px; }
details summary { cursor: pointer; color: var(--accent); }
details form { margin-top: 0.6rem; }

/* login */
.login { max-width: 420px; margin: 3rem auto; text-align: center; }
.login form { display: flex; flex-direction: column; gap: 0.6rem; margin: 1rem 0; }
.login label { text-align: left; font-size: 0.85rem; color: var(--muted); }
.error { color: #a83232; font-weight: 600; }

.empty { color: var(--muted); text-align: center; margin: 2rem 0; }
