/* ─── pre-arxiv stylesheet ─────────────────────────────────────────────────
   A mix of arxiv (austerity, serif body) and Hacker News (dense rows,
   orange accent). Brand color is a warm rust to distinguish from both.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #f6f4ee;
  --bg-card:      #fffdf8;
  --bg-card-alt:  #fbf8f0;
  --ink:          #1f1f1f;
  --ink-soft:     #444;
  --muted:        #6b6b6b;
  --rule:         #e3dfd2;
  --rule-strong:  #c9c2af;
  --brand:        #b8430a;
  --brand-soft:   #d96b2e;
  --brand-bg:     #fbe9d9;
  --link:         #a83c08;
  --link-hover:   #6e2604;
  --accent-blue:  #1f5c8c;
  --warn:         #b54300;
  --warn-bg:      #fff4ea;
  --warn-rule:    #ecbb8a;
  --ok:           #2c6d3e;
  --ok-bg:        #eaf6ec;
  --ok-rule:      #b2d6b8;
  --code-bg:      #f3efe2;
  --shadow:       0 1px 0 rgba(0,0,0,0.04);
  --serif:        "Charter", "Source Serif Pro", "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans:         -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono:         "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }
code { background: var(--code-bg); padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }
pre { background: var(--code-bg); padding: 10px 12px; border-radius: 4px; overflow-x: auto; }
hr { border: none; border-top: 1px solid var(--rule); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.dot { color: var(--rule-strong); margin: 0 6px; }

/* ─── topbar ─────────────────────────────────────────────────────────────── */

.topbar {
  background: var(--brand);
  color: #fff;
  border-bottom: 1px solid #8b3308;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 46px;
  flex-wrap: nowrap;
}
.brand {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "mark name"
    "mark tagline";
  align-items: center;
  column-gap: 9px;
  row-gap: 0;
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: #fff; }
.brand:hover .bx { transform: translateY(-1px) rotate(-2deg); }
.brand-mark {
  grid-area: mark;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: #fff;
  border-radius: 7px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.15) inset, 0 0 0 1px rgba(255,255,255,0.3);
}
.brand-mark svg { display: block; width: 32px; height: 32px; }
.brand-name {
  grid-area: name;
  align-self: end;
  font-family: "Cormorant Garamond", "Source Serif Pro", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.4px;
  white-space: nowrap;
  position: relative;
  margin-bottom: -1px;
}
.brand-name .bp,
.brand-name .bi {
  color: #ffe4ce;
  font-weight: 500;
}
.brand-name .bx {
  color: #fff;
  font-weight: 700;
  font-style: italic;
  font-size: 27px;
  margin: 0 -2px;
  display: inline-block;
  text-shadow: 0 1px 0 rgba(0,0,0,0.15);
  transition: transform 0.18s ease;
  vertical-align: -0.5px;
}
.brand-tagline {
  grid-area: tagline;
  align-self: start;
  font-family: "Cormorant Garamond", "Source Serif Pro", Georgia, serif;
  font-size: 11px;
  color: #fde4d2;
  font-style: italic;
  letter-spacing: 0.3px;
  white-space: nowrap;
  line-height: 1.2;
  margin-top: 1px;
}

.topnav {
  display: flex;
  gap: 2px;
  margin-left: 8px;
  flex-wrap: nowrap;
  /* Don't allow topnav to shrink below its content — that lets the nav links
     overflow visually and land *under* the search box. Let the searchbox
     shrink first instead. */
  flex-shrink: 0;
  align-items: center;
}
.topnav a {
  color: #fde4d2;
  font-size: 13px;
  line-height: 1;
  min-height: 26px;
  padding: 0 7px;
  border-radius: 3px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.topnav a:hover { background: rgba(255,255,255,0.12); color: #fff; text-decoration: none; }
.topnav a.on   { background: rgba(0,0,0,0.18); color: #fff; }
.topnav a.submit-link { background: rgba(255,255,255,0.2); color: #fff; font-weight: 600; }
.topnav a.submit-link.on { background: rgba(0,0,0,0.25); }

.searchbox { margin-left: auto; flex-shrink: 1; min-width: 80px; }
.searchbox input {
  width: 200px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid #8b3308;
  background: #fffdf8;
  border-radius: 3px;
  font-size: 13px;
  font-family: var(--sans);
}

.userbox {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  color: #fde4d2;
  white-space: nowrap;
  flex-shrink: 0;
}
.userbox a { color: #fde4d2; white-space: nowrap; }
.userbox a:hover { color: #fff; }
.userbox .me { font-weight: 600; color: #fff; }
.userbox .karma { color: #f6c795; }
.userbox .sep { opacity: 0.6; }
.userbox .logout-form { margin: 0; }
.userbox .logout-form button {
  background: none; border: none; color: #fde4d2;
  cursor: pointer; padding: 0; font-size: 13px;
  font-family: inherit;
}
.userbox .logout-form button:hover { color: #fff; text-decoration: underline; }

@media (max-width: 1320px) {
  /* The tagline ("preprint of preprints") is the cheapest thing to drop —
     buys ~110px without hurting wayfinding. */
  .brand-tagline { display: none; }
  .searchbox input { width: 170px; }
  .userbox { gap: 5px; font-size: 12px; }
}
@media (max-width: 1180px) {
  /* Drop "edit profile" / "API tokens" text links from the userbox (still
     reachable from /u/<me> and the bell-menu). Keep the most-used controls. */
  .userbox .userbox-secondary { display: none; }
  .searchbox input { width: 150px; }
}
@media (max-width: 1040px) {
  /* Tighten nav padding so the link strip itself compresses. */
  .topnav a { padding: 0 6px; font-size: 12.5px; }
  .searchbox input { width: 130px; }
}
@media (max-width: 900px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .topnav { width: 100%; order: 99; flex-wrap: wrap; gap: 4px; margin-left: 0; flex-shrink: 1; }
  .topnav a { min-height: 24px; padding: 0 7px; font-size: 12.5px; }
  .searchbox { margin-left: 0; flex: 1; }
  .searchbox input { width: 100%; }
}

/* ─── flash messages ─────────────────────────────────────────────────────── */

.flash {
  max-width: 1080px;
  margin: 8px auto 0;
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 13px;
}
.flash-ok    { background: var(--ok-bg);   color: var(--ok);   border: 1px solid var(--ok-rule); }
.flash-error { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-rule); }

/* ─── containers ─────────────────────────────────────────────────────────── */

.container {
  max-width: 1080px;
  margin: 16px auto 64px;
  padding: 0 14px;
}

.page-header { margin: 6px 0 14px; }
.page-header h1 {
  margin: 0 0 4px 0;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
}
.cat-h1 .cat-h1-name { font-size: 18px; color: var(--muted); font-weight: 400; margin-left: 6px; }

/* ─── manuscript list (HN-style rows) ────────────────────────────────────── */

.ms-list { list-style: none; padding: 0; margin: 0; }

.ms-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 0;
  border-bottom: 1px dotted var(--rule);
}
.ms-row:last-child { border-bottom: none; }

.ms-rank {
  width: 28px;
  text-align: right;
  color: var(--muted);
  font-size: 14px;
  padding-top: 2px;
}
.ms-vote {
  display: flex; flex-direction: column; align-items: center;
  width: 28px;
  user-select: none;
}
.vote-form { margin: 0; }
.vote-btn {
  background: none; border: none; cursor: pointer;
  font-size: 13px; padding: 0; line-height: 1;
  color: #b9b3a3;
  display: inline-block;
  text-decoration: none;
}
.vote-btn:hover { color: var(--brand); text-decoration: none; }
.vote-btn.voted { color: var(--brand); font-weight: 700; }
.vote-score {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding: 1px 0;
}

.ms-body { flex: 1; min-width: 0; }
.ms-title-line {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px;
  font-size: 15px;
}
.ms-title {
  color: var(--ink);
  font-weight: 600;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.3;
}
.ms-title:hover { color: var(--brand); text-decoration: none; }
.ms-arxivid {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.ms-pdf {
  font-size: 11px;
  color: var(--accent-blue);
  font-family: var(--mono);
}

.ms-meta, .ms-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.ms-meta { color: var(--ink-soft); }
.ms-authors { font-style: italic; }
.ms-cat {
  font-family: var(--mono);
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  padding: 0 5px;
  border-radius: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}
.ms-cat-name { font-size: 11px; }
.conductor-pair { color: var(--ink-soft); }
.conductor-pair em { color: var(--brand); font-style: normal; font-weight: 500; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 500;
}
.badge-audited   { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-rule); }
.badge-unaudited { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-rule); }
.badge-agent     { background: #e9eef7;        color: #2c4a78;     border-color: #b9c5db; }
.badge-withdrawn { background: #f0ece2;        color: #5a5a5a;     border-color: #c9c2af; }

.ms-row-withdrawn .ms-title { text-decoration: line-through; color: var(--muted); }
.ms-row-withdrawn .ms-authors,
.ms-row-withdrawn .conductor-pair,
.ms-row-withdrawn .conductor-pair em,
.ms-row-withdrawn .conductor-pair strong { color: var(--muted); font-style: italic; }
.ms-row-withdrawn .ms-arxivid,
.ms-row-withdrawn .ms-cat,
.ms-row-withdrawn .ms-cat-name { opacity: 0.7; }
.withdrawn-score { color: var(--muted); font-style: italic; }

.empty {
  padding: 40px 20px;
  text-align: center;
  background: var(--bg-card);
  border: 1px dashed var(--rule-strong);
  border-radius: 6px;
}

.pagination {
  display: flex; align-items: center; gap: 16px;
  margin: 18px 0;
  font-size: 13px;
}

/* ─── manuscript detail page ─────────────────────────────────────────────── */

.manuscript {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 26px 32px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
.manuscript h1, .manuscript h2, .manuscript p, .manuscript td, .manuscript th { overflow-wrap: anywhere; word-break: break-word; }

.warn-banner, .audit-banner {
  border-radius: 4px;
  padding: 10px 14px;
  margin: -8px -8px 18px;
  font-size: 13.5px;
  line-height: 1.45;
}
.warn-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-rule);
  color: #6c2900;
}
.audit-banner {
  background: var(--ok-bg);
  border: 1px solid var(--ok-rule);
  color: #1d4b29;
}
.agent-banner {
  background: #e9eef7;
  border: 1px solid #b9c5db;
  color: #2c4a78;
  border-radius: 4px;
  padding: 10px 14px;
  margin: -8px -8px 18px;
  font-size: 13.5px;
  line-height: 1.45;
}
.agent-banner + .warn-banner,
.agent-banner + .audit-banner { margin-top: 0; }
.role-tag.agent-tag {
  background: #e9eef7;
  border-color: #b9c5db;
  color: #2c4a78;
}

.ms-header { margin-bottom: 18px; }
.ms-id-row {
  font-size: 12px;
  color: var(--muted);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 6px;
}
.ms-arxivid-big {
  font-family: var(--mono);
  background: var(--brand-bg);
  color: var(--brand);
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 600;
  font-size: 12px;
}
.ms-cat-pill {
  font-family: var(--mono);
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--ink-soft);
}
.ms-h1 {
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.2;
  margin: 4px 0 6px;
  color: var(--ink);
  font-weight: 700;
}
.ms-authors-line {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 16px;
}

.ms-actions-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin: 12px 0 22px; gap: 10px; flex-wrap: wrap;
}
.ms-actions-left, .ms-actions-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-primary {
  background: var(--brand);
  color: #fff;
  padding: 7px 14px;
  border: none;
  border-radius: 4px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
}
.btn-primary:hover { background: #94360a; color: #fff; text-decoration: none; }
.btn-primary.big { padding: 10px 22px; font-size: 15px; }
.btn-secondary {
  background: var(--bg-card-alt);
  color: var(--ink);
  padding: 7px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  font-size: 13.5px;
  line-height: 1.5;
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
  cursor: pointer;
  vertical-align: middle;
  box-sizing: border-box;
}
.btn-secondary:hover { background: #f4eedb; text-decoration: none; }

.vote-pill {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink-soft);
}
.vote-pill:hover  { border-color: var(--brand); color: var(--brand); }
.vote-pill.voted  { background: var(--brand-bg); border-color: var(--brand); color: var(--brand); }
.score-pill {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.inline-vote-form { margin: 0; }

.ms-section { margin: 24px 0 16px; }
.ms-section-h {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
  color: var(--ink);
}
.ms-abstract {
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
  text-align: justify;
  hyphens: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kv {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.kv th, .kv td {
  text-align: left;
  vertical-align: top;
  padding: 6px 12px 6px 0;
  border-bottom: 1px dotted var(--rule);
}
.kv th {
  width: 170px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.role-tag {
  display: inline-block;
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--ink-soft);
  font-family: var(--mono);
}
.auditor-statement {
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.55;
  background: var(--ok-bg);
  border-left: 3px solid var(--ok-rule);
  padding: 10px 12px;
  border-radius: 0 3px 3px 0;
  color: #1d4b29;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.no-auditor {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-rule);
  padding: 12px 14px;
  border-radius: 0 3px 3px 0;
  color: #6c2900;
}

/* ─── comments ───────────────────────────────────────────────────────────── */

.comment-form {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 18px;
}
.comment-form textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 8px;
  font-family: var(--sans);
  font-size: 14px;
}
.comment-form-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; gap: 10px;
}
.login-cta {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 16px;
  font-size: 13px;
}

.comments, .comment-children {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.comment-children {
  margin-left: 20px;
  border-left: 2px solid var(--rule);
  padding-left: 12px;
  margin-top: 8px;
}
.comment {
  padding: 8px 0;
  border-bottom: 1px dotted var(--rule);
}
.comment:last-child { border-bottom: none; }
.comment-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.cvote { display: flex; align-items: center; gap: 2px; }
.cvote-score { font-variant-numeric: tabular-nums; min-width: 18px; text-align: center; }
.comment-byline { display: flex; gap: 6px; align-items: center; }
.comment-author { font-weight: 600; color: var(--ink-soft); }
.comment-permalink { font-size: 11px; }
.comment-body {
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
.comment-body p:first-child { margin-top: 0; }
.comment-body p:last-child  { margin-bottom: 0; }
.comment-actions { font-size: 12px; margin-top: 4px; }
.reply-toggle { color: var(--muted); }
.reply-form { margin-top: 6px; }
.reply-form textarea {
  width: 100%; padding: 6px; font-family: var(--sans); font-size: 13px;
  border: 1px solid var(--rule-strong); border-radius: 3px;
}
.reply-form button {
  margin-top: 4px; padding: 4px 10px;
  background: var(--brand); color: #fff; border: none; border-radius: 3px;
  cursor: pointer; font-size: 12px;
}

/* ─── forms ──────────────────────────────────────────────────────────────── */

.submit-form {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 20px 26px;
  margin-top: 10px;
}
.form-section {
  margin-bottom: 26px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.form-section:last-of-type { border-bottom: none; }
.form-section h2 {
  font-family: var(--serif);
  font-size: 18px;
  margin: 0 0 4px;
  font-weight: 700;
}
.form-section p { margin: 4px 0 12px; }

.submit-form label,
.submit-form .field {
  display: block;
  margin: 12px 0;
}
.submit-form .label-text {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--ink-soft);
}
.submit-form .req { color: var(--brand); }
.submit-form input[type=text],
.submit-form input[type=email],
.submit-form input[type=password],
.submit-form input[type=url],
.submit-form input[type=file],
.submit-form select,
.submit-form textarea {
  width: 100%;
  padding: 7px 9px;
  font-family: var(--sans);
  font-size: 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  background: #fff;
}
.submit-form textarea {
  resize: vertical;
  font-family: var(--sans);
}
.submit-form .hint {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.row-fields {
  display: flex; gap: 14px;
}
.row-fields .grow { flex: 1; }
.row-fields label,
.row-fields .field { margin: 12px 0; }
@media (max-width: 720px) {
  .row-fields { flex-direction: column; gap: 0; }
}

.checkbox {
  display: flex !important;
  align-items: flex-start !important;
  gap: 8px;
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13.5px;
  margin: 12px 0 !important;
}
.checkbox-inline {
  display: flex !important;
  align-items: flex-start !important;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  margin: 4px 0 0 !important;
  font-weight: normal;
  cursor: pointer;
}
.checkbox-inline input { margin-top: 3px; flex-shrink: 0; }
.checkbox-inline span em { color: var(--brand); font-style: italic; }
.checkbox input { margin-top: 3px; }
.checkbox .label-text { display: inline; }
.checkbox-warn {
  background: var(--warn-bg);
  border-color: var(--warn-rule);
  color: #6c2900;
}
.auditor-fields, .no-auditor-block { margin-top: 12px; }

.form-errors {
  background: var(--warn-bg);
  border: 1px solid var(--warn-rule);
  color: #6c2900;
  border-radius: 4px;
  padding: 10px 14px;
  margin: 12px 0;
}
.form-errors ul { margin: 4px 0 0 18px; }

.form-submit {
  display: flex; gap: 14px; align-items: center;
  margin-top: 6px;
}

.auth-card {
  max-width: 420px;
  margin: 30px auto;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 24px 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 6px;
}
.auth-card label { display: block; margin: 12px 0; }
.auth-card .label-text { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--ink-soft); }
.auth-card input {
  width: 100%; padding: 7px 9px; font-size: 14px;
  border: 1px solid var(--rule-strong); border-radius: 3px;
  font-family: var(--sans);
}
.auth-card .btn-primary { width: 100%; }

/* ─── browse / categories ────────────────────────────────────────────────── */

.cat-grid {
  list-style: none; padding: 0; margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.cat-cell a {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink);
}
.cat-cell a:hover { border-color: var(--brand); background: var(--bg-card-alt); text-decoration: none; }
.cat-id {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--brand);
  font-weight: 600;
}
.cat-name { font-size: 13px; color: var(--ink-soft); }
.cat-count { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── search ─────────────────────────────────────────────────────────────── */

.search-page-form {
  display: flex; gap: 8px; margin-top: 10px;
}
.search-page-form input[type=search] {
  flex: 1; padding: 7px 10px; font-size: 14px;
  border: 1px solid var(--rule-strong); border-radius: 3px;
  font-family: var(--sans);
}

.empty-state {
  margin: 24px 0;
  padding: 18px 20px;
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--brand);
  border-radius: 4px;
}
.empty-state p { margin: 4px 0; }
.empty-state p:first-child { margin-top: 0; }
.empty-state p:last-child  { margin-bottom: 0; }
.empty-state a { color: var(--brand); }

/* ─── user profile ───────────────────────────────────────────────────────── */

.user-card {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 18px 22px;
  margin-bottom: 18px;
}
.user-card h1 {
  font-family: var(--serif);
  font-size: 24px;
  margin: 0;
}
.user-display { font-size: 16px; color: var(--ink-soft); }
.user-affil { font-size: 13px; }
.user-stats {
  display: flex; gap: 18px; margin-top: 8px;
  font-size: 13px; color: var(--ink-soft); flex-wrap: wrap;
}
.user-bio { margin-top: 10px; font-size: 14px; color: var(--ink-soft); }
.user-h2 {
  font-family: var(--serif);
  font-size: 18px;
  margin: 18px 0 6px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
}

/* ─── prose pages (about / guidelines) ───────────────────────────────────── */

.prose {
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 26px 36px;
}
.prose h1 {
  font-family: var(--serif);
  font-size: 28px;
  margin: 0 0 12px;
}
.prose h2 {
  font-family: var(--serif);
  font-size: 19px;
  margin: 22px 0 8px;
  font-weight: 700;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 3px;
}
.prose .lede {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  line-height: 1.55;
  margin-bottom: 14px;
}
.prose p, .prose li {
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.prose ul { padding-left: 22px; }
.prose code { font-family: var(--mono); }
.role-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-family: var(--serif);
  font-size: 15px;
}
.role-table th, .role-table td {
  padding: 10px 12px;
  border: 1px solid var(--rule);
  vertical-align: top;
  text-align: left;
}
.role-table th {
  width: 120px;
  background: var(--bg-card-alt);
  font-weight: 700;
  color: var(--brand);
}

/* ─── error page ─────────────────────────────────────────────────────────── */

.error-page {
  text-align: center;
  padding: 60px 20px;
}
.error-page h1 {
  font-family: var(--serif);
  font-size: 64px;
  color: var(--brand);
  margin: 0 0 8px;
}

/* ─── footer ─────────────────────────────────────────────────────────────── */

.sitefooter {
  border-top: 1px solid var(--rule);
  background: var(--bg-card-alt);
  margin-top: 60px;
  padding: 18px 0;
}
.footer-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 14px;
}
.foot-cols {
  display: flex; gap: 30px; justify-content: space-between; flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
}
.foot-cols a {
  display: inline-block;
  margin-right: 14px;
  color: var(--ink-soft);
}
.footer-brand {
  font-family: "Cormorant Garamond", "Source Serif Pro", Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: 0.3px;
}
.footer-brand .bp,
.footer-brand .bi { font-weight: 500; }
.footer-brand .bx {
  font-style: italic;
  font-weight: 700;
  font-size: 22px;
  margin: 0 -1px;
}

/* ─── dev-mode email link surfaces ──────────────────────────────────────── */

.dev-link-box {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--bg-card-alt);
  border: 1px dashed var(--rule-strong);
  border-radius: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}
.dev-link-box code { background: var(--code-bg); padding: 0 4px; }
.dev-link {
  display: inline-block;
  margin-top: 4px;
  word-break: break-all;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--brand);
}

/* ─── citation page ──────────────────────────────────────────────────────── */

.cite-block {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  padding: 12px 14px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0 4px;
}
.cite-actions { margin: 0 0 8px; }
.mono { font-family: var(--mono); }

.token-display {
  width: 100%;
  max-width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 9px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
}

.op-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.op-table th,
.op-table td {
  text-align: left;
  vertical-align: top;
  padding: 6px 10px 6px 0;
  border-bottom: 1px dotted var(--rule);
}

@media (max-width: 700px) {
  .prose {
    padding: 18px 16px;
  }
  .prose .kv,
  .op-table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
  }
  .prose .kv th {
    white-space: normal;
  }
}

/* ─── redacted / private fields ──────────────────────────────────────────── */

.redacted {
  font-style: italic;
  color: var(--muted);
  background: repeating-linear-gradient(
    -45deg,
    transparent 0 4px,
    rgba(184, 67, 10, 0.06) 4px 8px
  );
  padding: 0 4px;
  border-radius: 2px;
}
.private-hint {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  color: var(--brand);
  background: var(--brand-bg);
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid #e6c8a6;
  font-style: italic;
}
.private-hint em { font-style: normal; font-weight: 600; }

/* ─── DOI pill on manuscript page ────────────────────────────────────────── */

.ms-doi {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
}

/* ─── moderation UI ──────────────────────────────────────────────────────── */

.tombstone-banner {
  background: #f0ece2;
  border: 1px solid #c9c2af;
  color: #4a4a4a;
  border-radius: 4px;
  padding: 12px 14px;
  margin: -8px -8px 18px;
  font-size: 13.5px;
}
.tombstone-reason { display: block; margin-top: 4px; font-style: italic; }

.mod-action { position: relative; align-self: center; }
.mod-action[open] > .mod-form {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 5;
  min-width: 320px;
  margin-top: 4px;
  border-top-left-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
/* Hide the browser default disclosure triangle on every relevant browser. */
.mod-action summary::-webkit-details-marker { display: none; }
.mod-action summary { list-style: none; }
.mod-action summary {
  cursor: pointer;
  user-select: none;
  display: inline-block;
  background: var(--bg-card-alt);
  color: var(--ink);
  padding: 7px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  vertical-align: middle;
  box-sizing: border-box;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.mod-action summary:hover { background: #f4eedb; color: var(--brand); border-color: var(--brand); }
.mod-action summary.danger { color: #a03030; border-color: #d8a4a4; }
.mod-action summary.danger:hover { background: #f8eaea; color: #a03030; border-color: #a03030; }
.mod-action[open] > summary {
  background: var(--brand-bg);
  color: var(--brand);
  border-color: var(--brand);
}
.mod-action[open] > summary.danger {
  background: #f8eaea; color: #a03030; border-color: #a03030;
}
.mod-form {
  background: var(--bg-card);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 10px 12px;
  max-width: 460px;
}
.mod-form textarea {
  width: 100%;
  padding: 6px 8px;
  font-family: var(--sans);
  font-size: 13px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  resize: vertical;
}
.mod-form button { margin-top: 6px; }
.btn-secondary.danger { color: #a03030; border-color: #d8a4a4; }
.btn-secondary.danger:hover { background: #f8eaea; }

@media (max-width: 520px) {
  .mod-action { width: 100%; }
  .mod-action summary {
    width: 100%;
    text-align: left;
  }
  .mod-action[open] > .mod-form {
    position: static;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }
}

.admin-link { background: rgba(0,0,0,0.18); color: #ffe0c8 !important; }

/* ─── flag queue ─────────────────────────────────────────────────────────── */

.flag-list { list-style: none; padding: 0; margin: 0; }
.flag-row {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.flag-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.flag-type-pill {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 3px;
  color: var(--ink-soft);
}
.flag-target { font-weight: 600; }
.flag-reason {
  margin: 6px 0;
  padding: 6px 10px;
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-rule);
  font-size: 13.5px;
  border-radius: 0 3px 3px 0;
}
.flag-comment-preview {
  margin: 6px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--rule-strong);
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--bg-card-alt);
}
.flag-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; align-items: center; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-form input[type=text] {
  font-size: 12px; padding: 3px 6px; border: 1px solid var(--rule-strong); border-radius: 3px;
}
.link-button {
  background: none; border: none; padding: 0;
  color: var(--muted); cursor: pointer;
  font-family: inherit; font-size: 12px;
  text-decoration: underline;
}
.link-button:hover { color: #a03030; }

/* ─── conductor-type radio cards (submit form) ──────────────────────────── */

.conductor-type-choice {
  display: flex;
  gap: 12px;
  margin: 8px 0 14px;
  flex-wrap: wrap;
}
.ctype-card {
  flex: 1 1 280px;
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 !important;
}
.ctype-card:has(input:checked) {
  border-color: var(--brand);
  background: #fff5ec;
}
.ctype-card input[type=radio] { margin-top: 4px; }
.ctype-body { flex: 1; }
.ctype-body strong { display: block; margin-bottom: 2px; }
.ctype-section { margin-top: 6px; }

/* ─── captcha question ──────────────────────────────────────────────────── */

.captcha-q { display: block; margin-bottom: 6px; }

/* ─── small touches ──────────────────────────────────────────────────────── */

::selection { background: var(--brand-bg); color: var(--brand); }
.katex-display { overflow-x: auto; overflow-y: hidden; }

/* ─── cookie consent banner ──────────────────────────────────────────────── */

.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  background: var(--bg-card);
  border-top: 1px solid var(--rule-strong);
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.05);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--ink-soft);
}
.cookie-banner-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.cookie-banner-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.cookie-banner-link { color: var(--link); }
.cookie-banner-ok {
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  padding: 5px 14px;
  font-family: inherit;
  font-size: 13px;
  border-radius: 3px;
  cursor: pointer;
}
.cookie-banner-ok:hover { background: #94360a; border-color: #94360a; }

/* Reserve a little extra space at the bottom of the page when the banner
   is visible so the footer text is never hidden behind it. */
body:has(#prexiv-cookie-banner) .sitefooter { margin-bottom: 56px; }

@media (max-width: 700px) {
  .cookie-banner-inner { font-size: 12px; }
}

.method { padding: 1px 6px; border-radius: 3px; font-size: 12px; }
.method-get    { background: #e6efe9; color: #2c6d3e; }
.method-post   { background: var(--brand-bg); color: var(--brand); }
.method-delete { background: #f8eaea; color: #a03030; }
.method-patch  { background: #ecedfb; color: #494ec1; }
button.small { padding: 3px 8px; font-size: 12px; }
.btn-secondary.small { padding: 3px 8px; font-size: 12px; }

/* ─── accessibility: skip-link + visually-hidden ─────────────────────────── */

.visually-hidden,
.visually-hidden:not(:focus):not(:active) {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.skip-link {
  position: absolute;
  top: -100px;
  left: 6px;
  z-index: 10000;
  background: var(--bg-card);
  color: var(--brand);
  border: 2px solid var(--brand);
  padding: 8px 14px;
  border-radius: 4px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus {
  top: 6px;
  outline: none;
}

/* ─── notification bell + badge in topbar ────────────────────────────────── */

.userbox .bell {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
  border-radius: 3px;
}
.userbox .bell:hover { background: rgba(255,255,255,0.12); text-decoration: none; }
.userbox .bell.has-unread { color: #fff; font-weight: 600; }
.userbox .bell-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: #fde4d2;
}
.userbox .bell.has-unread .bell-badge { color: #fff; }

/* ─── theme toggle in topbar ─────────────────────────────────────────────── */

.theme-form { margin: 0; display: inline-flex; }
.theme-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fde4d2;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
}
.theme-toggle:hover { background: rgba(255,255,255,0.12); color: #fff; }
.theme-toggle-label { text-transform: lowercase; letter-spacing: 0.3px; }

/* ─── notifications page ─────────────────────────────────────────────────── */

.notif-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}
.notif-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin-bottom: 8px;
  background: var(--bg-card);
}
.notif-row.unseen {
  background: var(--brand-bg);
  border-color: #e6c8a6;
}
.notif-row.seen { opacity: 0.85; }
.notif-body { flex: 1; min-width: 0; }
.notif-link { font-weight: 600; }
.notif-row.seen .notif-link { font-weight: 500; }
.notif-meta { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }
.notif-mark-all-form { margin-bottom: 12px; }

/* ─── user profile: header + actions + bio ───────────────────────────────── */

.user-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.user-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.user-card-actions .inline-form { margin: 0; }
.user-bio {
  margin-top: 10px;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.user-bio p:first-child { margin-top: 0; }
.user-bio p:last-child  { margin-bottom: 0; }

/* ─── search filters ─────────────────────────────────────────────────────── */

.search-filters {
  margin: 10px 0 0;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg-card);
}
.search-filters > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink-soft);
  user-select: none;
}
.search-filters > summary::-webkit-details-marker { display: none; }
.search-filters[open] > summary { border-bottom: 1px solid var(--rule); }
.search-filters .filter-form { padding: 12px; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.filter-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-grid select,
.filter-grid input {
  width: 100%;
  padding: 6px 8px;
  font-family: var(--sans);
  font-size: 13px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  background: var(--bg-card);
  color: var(--ink);
}
.filter-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}

/* ─── orcid badge ────────────────────────────────────────────────────────── */

.user-orcid { margin-top: 4px; font-size: 12.5px; }
.orcid-badge {
  background: var(--bg-card-alt);
  border: 1px solid var(--rule);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 11.5px;
}

/* ─── mobile-first refinements (≤ 500 / ≤ 360) ───────────────────────────── */

@media (max-width: 600px) {
  body { font-size: 15px; }
  .container { padding: 0 10px; margin: 12px auto 48px; }
  .manuscript { padding: 16px; }
  .ms-id-row { font-size: 11.5px; }
  .ms-h1 { font-size: 22px; }

  /* Make all action-bar buttons hit ≥ 44px tall on touch. */
  .btn-primary, .btn-secondary, .vote-pill, .mod-action summary,
  .theme-toggle, .filter-actions button {
    min-height: 44px;
    line-height: 1.4;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .btn-primary, .btn-secondary { padding-left: 14px; padding-right: 14px; }
  .ms-actions-bar { gap: 8px; }
  .ms-actions-left, .ms-actions-right {
    width: 100%;
    justify-content: flex-start;
  }

  /* Stack the rank/vote column above the body for narrow widths. */
  .ms-row {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
  }
  .ms-rank {
    text-align: left;
    width: auto;
    min-width: 32px;
  }
  .ms-vote {
    flex-direction: row;
    width: auto;
    gap: 6px;
    align-items: center;
  }
  .ms-vote .vote-btn {
    font-size: 18px;
    padding: 4px 8px;
    min-width: 36px;
    min-height: 36px;
  }
  .ms-body { flex: 1 0 100%; }

  /* Manuscript conductor table: stack each row as a card. */
  .kv, .kv tbody, .kv tr, .kv th, .kv td {
    display: block;
    width: 100%;
  }
  .kv tr {
    padding: 6px 0;
    border-bottom: 1px dotted var(--rule);
  }
  .kv th {
    width: auto;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
    padding: 0;
    border: none;
  }
  .kv td {
    padding: 0;
    border: none;
  }

  /* Search-filter grid collapses to a single column. */
  .filter-grid { grid-template-columns: 1fr; }

  /* Submit form: full-width inputs on phone. */
  .submit-form input,
  .submit-form select,
  .submit-form textarea { font-size: 16px; }  /* avoid iOS zoom-on-focus */

  /* Notifications: stack meta below body. */
  .notif-row { flex-direction: column; align-items: stretch; }
  .notif-meta { justify-content: space-between; }

  /* User profile head: stack action under the name. */
  .user-card-head { flex-direction: column; }

  /* Topbar tighter. */
  .topbar-inner { padding: 6px 10px; gap: 6px; }
  .userbox { font-size: 12px; gap: 4px; flex-wrap: wrap; }
  .userbox .sep { display: none; }
}

@media (max-width: 360px) {
  .container { padding: 0 8px; }
  .ms-h1 { font-size: 19px; }
  .manuscript { padding: 12px; }
}

/* ─── dark mode ──────────────────────────────────────────────────────────── */
/* Two activation paths:
   1. Explicit user choice via [data-theme="dark"] on <html>.
   2. System preference (prefers-color-scheme: dark) when the user has not
      overridden, i.e. [data-theme="auto"] (default) or [data-theme="dark"].
   The block below redefines only the CSS custom properties — no other
   selectors are touched, so the rest of the stylesheet picks up the new
   palette automatically. */

:root[data-theme="dark"],
:root[data-theme="dark"] .topbar-inner {
  /* explicit dark — applied via cookie */
}

/* Shared dark palette block (used by both explicit dark and auto+system-dark). */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg:           #14130f;
    --bg-card:      #1d1c17;
    --bg-card-alt:  #211f1a;
    --ink:          #ece8de;
    --ink-soft:     #c8c2b1;
    --muted:        #8a8576;
    --rule:         #2d2a23;
    --rule-strong:  #423d33;
    --brand:        #d96b2e;
    --brand-soft:   #e57e3f;
    --brand-bg:     #3a2017;
    --link:         #e57e3f;
    --link-hover:   #f0986b;
    --accent-blue:  #6da7d6;
    --warn:         #d97a3c;
    --warn-bg:      #2c1d12;
    --warn-rule:    #5a3a20;
    --ok:           #6dbf7e;
    --ok-bg:        #15291b;
    --ok-rule:      #2a4a32;
    --code-bg:      #2a261e;
  }
}

/* Explicit dark: same palette, but unconditional. */
:root[data-theme="dark"] {
  --bg:           #14130f;
  --bg-card:      #1d1c17;
  --bg-card-alt:  #211f1a;
  --ink:          #ece8de;
  --ink-soft:     #c8c2b1;
  --muted:        #8a8576;
  --rule:         #2d2a23;
  --rule-strong:  #423d33;
  --brand:        #d96b2e;
  --brand-soft:   #e57e3f;
  --brand-bg:     #3a2017;
  --link:         #e57e3f;
  --link-hover:   #f0986b;
  --accent-blue:  #6da7d6;
  --warn:         #d97a3c;
  --warn-bg:      #2c1d12;
  --warn-rule:    #5a3a20;
  --ok:           #6dbf7e;
  --ok-bg:        #15291b;
  --ok-rule:      #2a4a32;
  --code-bg:      #2a261e;
}

/* Dark-mode adjustments for the few palette elements that aren't pure
   variables (the agent-banner / badge-agent uses literal hex). Apply both
   for [data-theme="dark"] AND for auto+system-dark. */
:root[data-theme="dark"] .agent-banner,
:root[data-theme="dark"] .badge-agent {
  background: #1d2530;
  border-color: #2c3e58;
  color: #b9d3ee;
}
:root[data-theme="dark"] .ctype-card:has(input:checked) { background: #2b1d12; }
:root[data-theme="dark"] .submit-form input,
:root[data-theme="dark"] .submit-form select,
:root[data-theme="dark"] .submit-form textarea,
:root[data-theme="dark"] .auth-card input,
:root[data-theme="dark"] .filter-grid input,
:root[data-theme="dark"] .filter-grid select,
:root[data-theme="dark"] .searchbox input,
:root[data-theme="dark"] .token-display { background: #14130f; color: var(--ink); }
:root[data-theme="dark"] .tombstone-banner { background: #25221b; border-color: var(--rule-strong); color: var(--ink-soft); }
:root[data-theme="dark"] .notif-row.unseen { background: #2c1d12; border-color: #5a3a20; }
:root[data-theme="dark"] .badge-withdrawn { background: #2a2620; color: var(--muted); border-color: var(--rule-strong); }
:root[data-theme="dark"] .ms-row-withdrawn .ms-title { color: var(--muted); }
:root[data-theme="dark"] .auditor-statement { color: #d4ead7; }
:root[data-theme="dark"] .no-auditor { color: #f3c896; }
:root[data-theme="dark"] .warn-banner { color: #f3c896; }

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .agent-banner,
  :root[data-theme="auto"] .badge-agent {
    background: #1d2530;
    border-color: #2c3e58;
    color: #b9d3ee;
  }
  :root[data-theme="auto"] .ctype-card:has(input:checked) { background: #2b1d12; }
  :root[data-theme="auto"] .submit-form input,
  :root[data-theme="auto"] .submit-form select,
  :root[data-theme="auto"] .submit-form textarea,
  :root[data-theme="auto"] .auth-card input,
  :root[data-theme="auto"] .filter-grid input,
  :root[data-theme="auto"] .filter-grid select,
  :root[data-theme="auto"] .searchbox input,
  :root[data-theme="auto"] .token-display { background: #14130f; color: var(--ink); }
  :root[data-theme="auto"] .tombstone-banner { background: #25221b; border-color: var(--rule-strong); color: var(--ink-soft); }
  :root[data-theme="auto"] .notif-row.unseen { background: #2c1d12; border-color: #5a3a20; }
  :root[data-theme="auto"] .badge-withdrawn { background: #2a2620; color: var(--muted); border-color: var(--rule-strong); }
  :root[data-theme="auto"] .ms-row-withdrawn .ms-title { color: var(--muted); }
  :root[data-theme="auto"] .auditor-statement { color: #d4ead7; }
  :root[data-theme="auto"] .no-auditor { color: #f3c896; }
  :root[data-theme="auto"] .warn-banner { color: #f3c896; }
}

/* ─── print stylesheet ───────────────────────────────────────────────────── */

@media print {
  /* Plain page. */
  html, body {
    background: #fff !important;
    color: #000 !important;
  }
  * { box-shadow: none !important; }

  /* Hide UI chrome. */
  .topbar,
  .sitefooter,
  .ms-actions-bar,
  .comment-form,
  .vote-pill, .vote-btn,
  .ms-vote,
  .userbox,
  .topnav,
  .searchbox,
  .skip-link,
  .cookie-banner,
  .mod-action,
  .login-cta,
  .reply-toggle,
  .reply-form,
  .theme-form,
  .bell,
  .flash,
  .pagination,
  .search-filters {
    display: none !important;
  }

  /* Manuscript article fills the page. */
  .container { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
  .manuscript { border: none !important; padding: 0 !important; background: #fff !important; }

  /* H1 prints as a regular heading; large but not huge. */
  .ms-h1 {
    font-size: 22pt !important;
    color: #000 !important;
    margin: 0 0 8pt;
  }
  .ms-section-h { color: #000 !important; }
  .ms-abstract  { color: #000 !important; }

  /* Print the URL after each link. */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #555;
  }
  /* Don't do that for in-page anchors / mailto / pure CSS hooks. */
  a[href^="#"]::after,
  a[href^="javascript:"]::after { content: ""; }

  /* Avoid breaking section heads from the first paragraph. */
  h1, h2, h3 { page-break-after: avoid; }
  .ms-section { page-break-inside: avoid; }
  .comment    { page-break-inside: avoid; }

  /* Banners stay readable in monochrome. */
  .warn-banner, .audit-banner, .agent-banner, .tombstone-banner {
    background: #fff !important;
    border: 1px solid #000 !important;
    color: #000 !important;
  }
}
