* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #fafaf8;
  color: #1a1a1a;
  line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  body { background: #14141a; color: #e8e8ea; }
}

a, a:visited { color: #b4552f; }
a:hover { color: #d4713f; }
@media (prefers-color-scheme: dark) {
  a, a:visited { color: #d4855f; }
  a:hover { color: #e8a077; }
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(128,128,128,0.2);
}
.brand, .brand:visited { font-weight: 700; text-decoration: none; color: inherit; }
.site-header nav a { margin-left: 1rem; color: inherit; text-decoration: none; }
.nav-logout-form { display: inline; margin-left: 1rem; }
.nav-logout-form button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
}
.nav-logout-form button:hover { opacity: 1; text-decoration: underline; }

main { flex: 1 0 auto; width: 100%; max-width: 680px; margin: 0 auto; padding: 1.5rem; }

.hero-gif {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 2rem;
}

.now-playing {
  margin: -1.3rem 0 1.6rem;
  font-size: 0.82rem;
  opacity: 0.85;
}
.np-top { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.now-playing img { width: 28px; height: 28px; border-radius: 3px; }
.np-text { display: flex; flex-direction: column; line-height: 1.25; }
.np-artist { opacity: 0.6; font-size: 0.78rem; }

.np-scrub { padding-left: 2px; }
.np-track-bar {
  position: relative;
  height: 3px;
  border-radius: 2px;
  background: rgba(128,128,128,0.25);
}
.np-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  border-radius: 2px;
  background: currentColor;
}
.np-knob {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}
.np-times {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 0.3rem;
  font-variant-numeric: tabular-nums;
}

/* --- writing activity monitor --- */
.activity { margin-bottom: 2rem; }
.activity-details { margin-top: 0.4rem; text-align: right; }
.activity-details summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.75rem;
  opacity: 0.45;
  display: inline-block;
}
.activity-details summary::-webkit-details-marker { display: none; }
.activity-details summary:hover { opacity: 0.8; }
.activity-details .activity-stats { text-align: right; }
.hm-grid {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  width: 100%;
  height: 84px;
}
.hm-cell {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background: rgba(128,128,128,0.12);
}
.hm-future { background: transparent; }
.hm-level-1 { background: rgba(255,255,255,0.3); }
.hm-level-2 { background: rgba(255,255,255,0.5); }
.hm-level-3 { background: rgba(255,255,255,0.75); }
.hm-level-4 { background: #ffffff; }
@media (prefers-color-scheme: light) {
  .hm-cell { background: rgba(0,0,0,0.08); }
  .hm-level-1 { background: rgba(0,0,0,0.3); }
  .hm-level-2 { background: rgba(0,0,0,0.5); }
  .hm-level-3 { background: rgba(0,0,0,0.75); }
  .hm-level-4 { background: #000000; }
}
.activity-stats { font-size: 0.85rem; opacity: 0.6; margin-top: 0.6rem; }

.project-list { list-style: none; padding: 0; }
.project-card {
  border: 1px solid transparent;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.project-card:hover {
  background: rgba(128,128,128,0.08);
  border-color: rgba(128,128,128,0.25);
}
.project-card a { display: block; padding: 1rem; text-decoration: none; color: inherit; cursor: pointer; }
.project-card h3 { margin: 0 0 0.3rem; }
.project-card p { margin: 0 0 0.4rem; opacity: 0.75; }
.chapter-count { font-size: 0.8rem; opacity: 0.6; }

#chapter-search {
  width: 100%;
  padding: 0.6rem;
  margin: 1rem 0;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 4px;
  background: transparent;
  color: inherit;
}

.chapter-list { list-style: none; padding: 0; }
.chapter-row { border-bottom: 1px solid rgba(128,128,128,0.15); }
.chapter-row a {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 0.2rem;
  text-decoration: none;
  color: inherit;
}
.chapter-num { opacity: 0.5; min-width: 2.5em; }

.chapter-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  font-family: monospace;
  font-size: 1.1rem;
}
.chapter-nav a, .chapter-nav .current, .chapter-nav .disabled { color: inherit; text-decoration: none; }
.chapter-nav .current { font-weight: 700; }
.chapter-nav .disabled { opacity: 0.3; }
.chapter-nav .edge { opacity: 0.5; }

.breadcrumb a { color: inherit; text-decoration: none; opacity: 0.7; }

.chapter-content { margin: 1.5rem 0; }
.chapter-content p { margin: 0 0 1rem; }

.reactions { margin: 1.5rem 0 2rem; }
.reaction-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.reaction-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgba(128,128,128,0.25);
  background: transparent;
  border-radius: 4px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  color: inherit;
  font-size: 0.9rem;
}
.reaction-pill:hover { border-color: rgba(128,128,128,0.6); }
.reaction-pill img { height: 32px; width: auto; display: block; }
.reaction-pill.reacted {
  border-color: var(--reaction-accent, #b4552f);
  background: rgba(180,85,47,0.12);
}

.reaction-add { position: relative; max-width: 260px; }
#emote-search {
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
}
.emote-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  background: #1a1a1a;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 6px;
  margin-top: 0.3rem;
  max-height: 220px;
  overflow-y: auto;
}
@media (prefers-color-scheme: light) {
  .emote-results { background: #fff; }
}
.emote-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
}
.emote-option:hover { background: rgba(128,128,128,0.15); }
.emote-option img { height: 30px; width: auto; }
.emote-empty { display: block; padding: 0.5rem 0.6rem; opacity: 0.6; font-size: 0.85rem; }

.emote-results-floating {
  position: fixed;
  right: auto;
  margin-top: 0;
  z-index: 50;
}

/* honeypot field — off-screen rather than display:none, since some bots
   specifically skip display:none/hidden fields but still fill in anything
   merely positioned off-canvas */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.comment-error {
  font-size: 0.85rem;
  color: #e05a5a;
  margin: -0.4rem 0 1rem;
}

.comments { margin: 1.5rem 0; }
.comments h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.6; margin-bottom: 0.8rem; }
.comment-form, .reply-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}
.reply-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0 0 0 1rem;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}
.reply-form.open {
  max-height: 220px;
  opacity: 1;
  margin: 0.6rem 0 0.6rem 1rem;
}
.comment-form input, .comment-form textarea,
.reply-form input, .reply-form textarea {
  padding: 0.5rem 0.7rem;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.9rem;
}
.comment-form textarea, .reply-form textarea { min-height: 70px; resize: vertical; }
.comment-form button, .reply-form button {
  align-self: flex-start;
  padding: 0.4rem 1rem;
  border: 1px solid rgba(128,128,128,0.4);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
}
.comment-form button:hover, .reply-form button:hover { border-color: rgba(128,128,128,0.8); }

.comment {
  padding: 0.7rem 0;
}
.comment-list > .comment {
  border-top: 1px solid rgba(128,128,128,0.15);
}
.comment-list > .comment:first-child { border-top: none; }
.comment-replies {
  margin: 0.3rem 0 0 0;
  padding-left: 1rem;
}
/* each reply gets its own elbow connector (short stub + notch into its
   name) regardless of position. the continuation line down to a *next*
   sibling only exists on comments that actually have one — a leaf reply
   or the last one in a group gets no trailing line past its own notch */
.comment-replies > .comment {
  position: relative;
  padding-left: 1rem;
}
.comment-replies > .comment::before {
  content: '';
  position: absolute;
  top: 0;
  left: -1rem;
  width: 2rem;
  height: 1.3rem;
  border-left: 1px solid rgba(128,128,128,0.32);
  border-bottom: 1px solid rgba(128,128,128,0.32);
}
.comment-replies > .comment:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 1.3rem;
  bottom: 0;
  left: -1rem;
  border-left: 1px solid rgba(128,128,128,0.32);
}

.comment-meta { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.2rem; }
.comment-author { font-weight: 600; font-size: 0.85rem; }
a.comment-author { color: inherit; text-decoration: none; }
a.comment-author:hover { text-decoration: underline; }
.profile-bio { opacity: 0.8; margin: 0.5rem 0 1.5rem; }
.comment-actions { display: flex; align-items: center; gap: 0.9rem; margin: 0.3rem 0 0.1rem; }
.reply-toggle {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0;
}
.reply-toggle:hover { opacity: 0.9; }
.comment-body { margin: 0.2rem 0; font-size: 0.92rem; white-space: pre-wrap; }
.comment-empty { opacity: 0.6; font-size: 0.9rem; }
.inline-emote { height: 2.3em; width: auto; vertical-align: middle; margin: 0 0.15em; }

/* inline mod controls on the public chapter page — only rendered at all
   when the viewer is on the tailnet. no visible affordance is added for
   admins at all; the comment body itself becomes clickable to reveal the
   panel, so mods see literally the same page as everyone else until they
   click a comment */
.mod-clickable:hover { cursor: pointer; background: rgba(128,128,128,0.06); border-radius: 4px; }
.comment-meta .mod-panel {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: flex-start;
  width: 100%;
  margin: 0.4rem 0;
  padding: 0.5rem;
  border: 1px dashed rgba(128,128,128,0.25);
  border-radius: 6px;
}
.mod-edit-form { display: flex; gap: 0.4rem; align-items: flex-start; }
.mod-edit-form textarea {
  font-size: 0.82rem;
  padding: 0.4rem;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  min-width: 200px;
}
.mod-action, .mod-edit-form button {
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(128,128,128,0.35);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.78rem;
}

.admin-note { opacity: 0.6; font-size: 0.9rem; margin-bottom: 1rem; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid rgba(128,128,128,0.15);
  vertical-align: top;
}
.admin-table .admin-body { max-width: 280px; white-space: pre-wrap; }
.admin-table form { margin: 0; }
.admin-table button {
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(200,60,60,0.5);
  background: transparent;
  color: #e05a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
.admin-table button:hover { background: rgba(200,60,60,0.12); }

.admin-stats { display: flex; gap: 1.5rem; margin: 1.2rem 0 2rem; flex-wrap: wrap; }
.admin-stat {
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(128,128,128,0.2);
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  min-width: 140px;
}
.admin-stat-num { font-size: 1.6rem; font-weight: 700; }
.admin-stat span:last-child { font-size: 0.78rem; opacity: 0.6; margin-top: 0.2rem; }

.admin-cols { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: 2rem; }
.admin-cols > div { flex: 1; min-width: 240px; }
.admin-cols h2 { font-size: 0.9rem; opacity: 0.7; margin-bottom: 0.5rem; }
.admin-highlight { font-size: 0.9rem; opacity: 0.85; margin: 0 0 0.4rem; }
.admin-highlight strong { font-weight: 600; }
.admin-details summary {
  cursor: pointer;
  font-size: 0.78rem;
  opacity: 0.5;
  margin-bottom: 0.5rem;
}
.admin-details summary:hover { opacity: 0.85; }
.admin-details[open] summary { margin-bottom: 0.6rem; }

.admin-btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(128,128,128,0.4);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.admin-btn:hover { border-color: rgba(128,128,128,0.8); }
button.admin-btn { background: none; font-family: inherit; cursor: pointer; }

.profile-actions { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; }
.profile-actions form { margin: 0; }
.profile-actions .admin-btn { margin-bottom: 0; }

.admin-project-list { list-style: none; padding: 0; }
.admin-project-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(128,128,128,0.15);
}
.admin-project-row a { color: inherit; }
.admin-dim { opacity: 0.55; font-size: 0.8rem; }

.admin-actions a { margin-right: 0.8rem; font-size: 0.82rem; color: inherit; opacity: 0.75; }
.admin-actions a:hover { opacity: 1; }

.admin-form { display: flex; flex-direction: column; gap: 0.8rem; max-width: 640px; }
.admin-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; opacity: 0.8; }
.admin-form input[type="text"], .admin-form input[type="password"], .admin-form textarea {
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.95rem;
}
/* browsers force their own background/highlight on password fields they're
   tracking for autofill — override it so it matches the rest of the form
   instead of showing a mismatched gray box */
.admin-form input[type="password"]:-webkit-autofill,
.admin-form input[type="password"]:-webkit-autofill:hover,
.admin-form input[type="password"]:-webkit-autofill:focus {
  -webkit-text-fill-color: inherit;
  transition: background-color 9999s ease-in-out 0s;
}
.admin-form textarea#chapter-body { font-family: monospace; font-size: 0.9rem; }
.admin-form button {
  align-self: flex-start;
  padding: 0.5rem 1.2rem;
  border: 1px solid rgba(128,128,128,0.4);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.admin-form button:hover { border-color: rgba(128,128,128,0.8); }

.md-toolbar { display: flex; gap: 0.4rem; margin-bottom: -0.3rem; }
.md-toolbar button {
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.78rem;
}
.md-toolbar button:hover { border-color: rgba(128,128,128,0.7); }

.rte-toolbar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  padding: 0.4rem;
  border: 1px solid rgba(128,128,128,0.25);
  border-radius: 6px 6px 0 0;
  border-bottom: none;
}
.rte-toolbar button {
  padding: 0.3rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  min-width: 1.8rem;
}
.rte-toolbar button:hover { border-color: rgba(128,128,128,0.4); background: rgba(128,128,128,0.08); }
.rte-sep { width: 1px; align-self: stretch; background: rgba(128,128,128,0.2); margin: 0 0.2rem; }

.rte-editor {
  min-height: 400px;
  border: 1px solid rgba(128,128,128,0.25);
  border-radius: 0 0 6px 6px;
  padding: 1rem 1.2rem;
  outline: none;
  margin: 0;
}
.rte-editor:focus { border-color: rgba(128,128,128,0.5); }
.rte-editor h1, .rte-editor h2 { margin-top: 0; }

.comment.is-deleted { opacity: 0.5; }
.comment.is-deleted .comment-body { font-style: italic; }
.mod-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: rgba(128,128,128,0.15);
  opacity: 0.8;
}
.mod-badge-deleted { background: rgba(200,60,60,0.18); color: #e05a5a; }

.mod-original {
  width: 100%;
  margin: 0 0 0.3rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  border-radius: 4px;
  background: rgba(200,60,60,0.08);
  border: 1px solid rgba(200,60,60,0.25);
}
.mod-original span { color: #e05a5a; font-family: monospace; }

.mod-toggle {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  font-size: 0.78rem;
}
.mod-toggle:hover { opacity: 0.9; }
.mod-panel {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin: 0.5rem 0;
  padding: 0.6rem;
  border: 1px dashed rgba(128,128,128,0.25);
  border-radius: 6px;
}
.mod-panel[hidden] { display: none; }
.admin-form-inline { display: flex; gap: 0.4rem; align-items: flex-start; }
.admin-form-inline textarea {
  font-size: 0.82rem;
  padding: 0.4rem;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  min-width: 200px;
}
.mod-panel button {
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(128,128,128,0.35);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.78rem;
}
.admin-danger { border-color: rgba(200,60,60,0.5) !important; color: #e05a5a; }
.admin-danger:hover { background: rgba(200,60,60,0.12); }

.auth-page { max-width: 420px; }
.auth-page img { max-width: 100%; }
.auth-page code {
  font-family: monospace;
  background: rgba(128,128,128,0.15);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  word-break: break-all;
}

.comment-identity { font-size: 0.85rem; opacity: 0.7; margin: 0.2rem 0; }
.comment-identity a { color: inherit; }

.vote-widget {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-variant-numeric: tabular-nums;
}
.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 0.7rem;
  opacity: 0.35;
  color: inherit;
  line-height: 1;
}
.vote-btn:hover { opacity: 0.7; }
.vote-btn.active-up { opacity: 0.85; color: #ff6b35; }
.vote-btn.active-down { opacity: 0.85; color: #5b8dfa; }
.vote-count {
  font-size: 0.68rem;
  font-weight: 400;
  min-width: 0.8em;
  text-align: center;
  opacity: 0.8;
}

.author-badge { height: 1.1em; width: auto; vertical-align: middle; margin-left: -0.2rem; }
.author-tag {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fff;
  background: #c0392b;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  vertical-align: middle;
}

.site-footer {
  text-align: center;
  padding: 2rem;
  font-size: 0.8rem;
  opacity: 0.5;
}
