/* A commentable document on Pagelove.
   No inline styles anywhere: the page ships a strict CSP (style-src 'self'),
   which also neutralizes any style attribute in a visitor-posted comment. */

:root {
  color-scheme: light dark;
  --bg: #fbfaf8;
  --paper: #ffffff;
  --ink: #1a1c22;
  --ink-soft: #585d66;
  --rule: #e5e2db;
  --rail-bg: #f3f1ed;
  --accent: #2563eb;
  --focus-ring: #2563eb;
  --danger: #c62828;
  --mark: #fff3bf;
  --mark-active: #ffe066;
  --shadow: 0 1px 2px rgba(20, 22, 30, 0.07), 0 2px 10px rgba(20, 22, 30, 0.05);
  --toast-bg: #24262c;
  --toast-ink: #f3f2ee;

  /* Commenter colours. Enumerated here and in the page's ShapeConstraint, so
     the palette is closed on both sides. */
  --c1:  #d94f4f;
  --c2:  #d97706;
  --c3:  #b8860b;
  --c4:  #2f9e44;
  --c5:  #0ca678;
  --c6:  #1098ad;
  --c7:  #2563eb;
  --c8:  #6741d9;
  --c9:  #ae3ec9;
  --c10: #e64980;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --paper: #1b1d23;
    --ink: #e9e7e1;
    --ink-soft: #9aa0ab;
    --rule: #2b2e37;
    --rail-bg: #1a1c22;
    --accent: #60a5fa;
    --focus-ring: #60a5fa;
    --danger: #f87171;
    --mark: #4a3f1a;
    --mark-active: #6b5a1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.3);
    --toast-bg: #e9e7e1;
    --toast-ink: #1a1c22;

    --c1:  #ff8787;
    --c2:  #ffa94d;
    --c3:  #ffd43b;
    --c4:  #69db7c;
    --c5:  #38d9a9;
    --c6:  #3bc9db;
    --c7:  #74c0fc;
    --c8:  #9775fa;
    --c9:  #da77f2;
    --c10: #f783ac;
  }
}

* { box-sizing: border-box; }

/* A class setting `display` outranks the user-agent rule for [hidden], which
   would otherwise leave elements toggled with .hidden visibly rendered. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.titles h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.identity {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.identity-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.2rem 0.7rem 0.2rem 0.25rem;
  cursor: pointer;
}

.identity-chip:hover { border-color: var(--accent); }
.identity-chip:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.identity-form { display: flex; align-items: center; gap: 0.35rem; }

.identity-input {
  font: inherit;
  font-size: 0.85rem;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  width: 9rem;
}

.identity-input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

.identity-save {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
}

.identity-cancel {
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
}

.identity-cancel:hover { color: var(--ink); }
.identity-save:focus-visible,
.identity-cancel:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

@media (prefers-color-scheme: dark) {
  .identity-save { color: #16181d; }
}

.edit-form { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.3rem 0; }
.edit-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.4rem; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-soft); }
.status[data-state="live"] .status-dot { background: #2f9e44; }
.status[data-state="preview"] .status-dot { background: var(--ink-soft); }

/* ---------- Avatars ---------- */

.avatar {
  display: inline-grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 0.85rem;
  line-height: 1;
  color: #fff;
  background: var(--ink-soft);
}

.avatar[data-color="c1"]  { background: var(--c1); }
.avatar[data-color="c2"]  { background: var(--c2); }
.avatar[data-color="c3"]  { background: var(--c3); }
.avatar[data-color="c4"]  { background: var(--c4); }
.avatar[data-color="c5"]  { background: var(--c5); }
.avatar[data-color="c6"]  { background: var(--c6); }
.avatar[data-color="c7"]  { background: var(--c7); }
.avatar[data-color="c8"]  { background: var(--c8); }
.avatar[data-color="c9"]  { background: var(--c9); }
.avatar[data-color="c10"] { background: var(--c10); }

@media (prefers-color-scheme: dark) {
  .avatar { color: #16181d; }
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  gap: 2rem;
  align-items: start;
  max-width: 74rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

#pl-doc {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 2.25rem 2.5rem 1.5rem;
  box-shadow: var(--shadow);
}

#pl-doc article > h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 2rem 0 0.5rem;
}

#pl-doc article > h2:first-child { margin-top: 0; }

#pl-doc p {
  margin: 0 0 1.1rem;
  font-size: 1.02rem;
  line-height: 1.72;
}

.colophon {
  margin-top: 2rem !important;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem !important;
  color: var(--ink-soft);
  line-height: 1.6 !important;
}

.colophon code {
  font-size: 0.95em;
  background: var(--rail-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* ---------- Sentences ---------- */

.sent {
  cursor: pointer;
  border-radius: 3px;
  padding: 0.05em 0.1em;
  margin: 0 -0.1em;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

.sent:hover { background: var(--mark); }

.sent:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  background: var(--mark);
}

.sent.has-comments {
  background: var(--mark);
  box-shadow: inset 0 -2px 0 var(--c2);
}

.sent.is-active {
  background: var(--mark-active);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.sent.has-comments::after {
  content: attr(data-count);
  display: inline-grid;
  place-items: center;
  min-width: 1.05rem;
  height: 1.05rem;
  margin-left: 0.3em;
  padding: 0 0.25em;
  border-radius: 999px;
  background: var(--c2);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: 0.15em;
}

@media (prefers-color-scheme: dark) {
  .sent.has-comments::after { color: #16181d; }
}

/* ---------- Comment rail ---------- */

#pl-rail {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  background: var(--rail-bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem;
}

.rail-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.rail-head h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0;
}

.rail-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.rail-empty {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0;
}

.threads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; }

.thread {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
}

.thread.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent); }

.thread-excerpt {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-left: 2px solid var(--c2);
  padding: 0 0 0 0.55rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
}

.thread-excerpt:hover { color: var(--ink); }
.thread-excerpt:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.thread-comments { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }

.comment-row { font-size: 0.88rem; }
.comment-row.is-reply { margin-left: 1.1rem; padding-left: 0.7rem; border-left: 2px solid var(--rule); }

.comment-head { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }

.comment-who { font-weight: 600; font-size: 0.82rem; }
.comment-when { font-size: 0.74rem; color: var(--ink-soft); }

.orphan-flag {
  font-size: 0.7rem;
  color: var(--ink-soft);
  font-style: italic;
  width: 100%;
}

.comment-body { margin: 0.3rem 0 0.35rem; overflow-wrap: anywhere; }

.comment-actions { display: flex; gap: 0.15rem; }

.comment-action {
  font: inherit;
  font-size: 0.74rem;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 0.12rem 0.35rem;
  cursor: pointer;
}

.comment-action:hover { background: var(--rail-bg); color: var(--ink); }
.comment-action[data-action="delete"]:hover { color: var(--danger); }
.comment-action:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

.foreign-note {
  margin: 0.25rem 0 0;
  font-size: 0.72rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- Composer ---------- */

.composer {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 0.5rem;
  align-items: start;
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--rule);
}

.composer-input {
  grid-column: 2;
  font: inherit;
  font-size: 0.85rem;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  resize: vertical;
  min-height: 2.6rem;
  width: 100%;
}

.composer-input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

.composer-send {
  grid-column: 2;
  justify-self: end;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}

.composer-send:hover { filter: brightness(1.08); }
.composer-send:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

@media (prefers-color-scheme: dark) {
  .composer-send { color: #16181d; }
}

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 2000;
  pointer-events: none;
  max-width: min(92vw, 34rem);
}

.toast {
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.85rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* ---------- Progressive enhancement ----------
   Without JavaScript the raw comment list is the comments: real, readable
   content rather than an empty rail. */

#pl-comments {
  list-style: none;
  max-width: 74rem;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#pl-comments > li.comment {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.9rem;
}

#pl-comments > li.comment > p { margin: 0 0 0.2rem; }
#pl-comments .comment-avatar { font-size: 1.1rem; }
#pl-comments .comment-author:empty { display: none; }
#pl-comments .comment-time { font-size: 0.75rem; color: var(--ink-soft); }

html.js #pl-comments { display: none; }
html:not(.js) .layout { display: block; }
html:not(.js) #pl-rail { display: none; }
html:not(.js) .sent { cursor: default; }

/* ---------- Small screens ---------- */

@media (max-width: 62rem) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 1rem 1rem 3rem; gap: 1.25rem; }
  #pl-doc { padding: 1.5rem 1.25rem 1rem; }
  #pl-rail { position: static; max-height: none; }
}

@media (max-width: 40rem) {
  .topbar { padding: 0.75rem 1rem; gap: 0.6rem; }
  .identity { margin-left: 0; min-width: 0; flex-wrap: wrap; }
  .identity-label { display: none; }
  .identity-form { flex-wrap: wrap; min-width: 0; }
  .identity-input { width: 100%; min-width: 0; flex: 1 1 7rem; }
  #pl-comments { padding-inline: 1rem; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
