/* CMS chrome. Reuses the site's tokens so the editor feels like the site. */
.admin-body { padding-bottom: 5rem; }
.admin-grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 40rem) { .admin-grid-2 { grid-template-columns: 1fr 1fr; } }

.admin-error { color: var(--danger); }
.admin-check { display: inline-flex; align-items: center; gap: .5rem; font-family: var(--font-meta); font-size: var(--s-2); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--fg-2); }

.admin-more { border-top: 1px solid var(--rule); padding-top: 1rem; }
.admin-more > summary { cursor: pointer; font-family: var(--font-meta); font-size: var(--s-2); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--muted); }
.admin-more > summary:hover { color: var(--fg); }
.admin-more-in { display: grid; gap: 1.2rem; padding-top: 1.4rem; }

.admin-linkbtn { font: inherit; color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; text-transform: uppercase; letter-spacing: var(--meta-tracking); font-size: var(--s-2); font-family: var(--font-meta); }
.admin-linkbtn:hover { color: var(--fg); }

.admin-danger { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); }
.admin-del-btn { font-family: var(--font-meta); font-size: var(--s-2); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--danger); background: none; border: 1px solid var(--danger); padding: .6rem 1.1rem; cursor: pointer; }
.admin-del-btn:hover { background: #C8322B; color: #fff; }

/* Media page. The drop zone is a <label> around a visually hidden file input,
   so click, keyboard (Tab then Enter/Space) and drag all reach the same input. */
.media-upload { display: grid; gap: .9rem; max-width: var(--measure); }
.media-drop {
  position: relative;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .6rem 1rem;
  padding: 2rem 1.25rem;
  border: 2px dashed var(--rule-strong);
  border-radius: 4px;
  background: var(--bg-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.media-drop:hover, .media-drop.is-over { border-color: var(--accent); }
.media-drop.is-over { background: color-mix(in srgb, var(--accent) 8%, var(--bg-2)); }
.media-drop:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
.media-drop.is-busy { opacity: .7; pointer-events: none; }
.media-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.media-drop-title { flex-basis: 100%; font-size: var(--s1); color: var(--fg); font-weight: var(--strong-weight); }
.media-drop-or { font-size: var(--s-1); color: var(--muted); }
/* A phone has nothing to drag: the zone is simply one big Choose button. */
@media (hover: none) and (pointer: coarse) {
  .media-drop-title, .media-drop-or { display: none; }
}
.media-upload .admin-help { margin: 0; }
.media-upload .media-submit { justify-self: start; }
.media-upload.is-js .media-submit { display: none; }
.media-progress { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.media-progress > span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .15s linear; }
.media-status { margin: 0; font-size: var(--s-1); color: var(--fg-2); overflow-wrap: anywhere; }
.media-status:empty { display: none; }
.media-status.is-ok { color: var(--fg); }
.media-status.is-error { color: var(--danger); }
.admin-notice.admin-notice--error { border-left-color: var(--danger); }

.media-grid { display: grid; gap: 1.25rem 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 12rem), 1fr)); margin-top: 2rem; }
.media-item { margin: 0; min-width: 0; }
.media-item.is-new img { border-color: var(--accent); }
.media-item img { display: block; width: 100%; height: auto; aspect-ratio: 4/3; object-fit: cover; border: 1px solid var(--rule); border-radius: 3px; background: var(--bg-2); }
.media-item figcaption { display: grid; gap: .35rem; margin-top: .5rem; }
.media-path { font-family: var(--font-code); font-size: .6875rem; color: var(--fg-2); overflow-wrap: anywhere; user-select: all; }
.media-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.media-actions form { margin: 0; }
.media-copy, .media-del {
  font-family: var(--font-meta); font-size: var(--s-2); letter-spacing: var(--meta-tracking); text-transform: uppercase;
  padding: .35rem .6rem; border-radius: 3px; cursor: pointer; background: transparent;
}
.media-copy { color: var(--fg); border: 1px solid var(--rule-strong); }
.media-copy:hover { border-color: var(--accent); color: var(--accent); }
.media-copy.is-done { border-color: var(--accent); color: var(--accent); }
.media-del { color: var(--danger); border: 1px solid transparent; }
.media-del:hover { border-color: var(--danger); }
.media-uses { font-size: var(--s-1); line-height: 1.45; color: var(--muted); }
.media-uses a { color: var(--fg-2); }

/* Toast UI sits on the page's own surface rather than its default white. */
.toastui-editor-defaultUI { border-color: var(--rule) !important; border-radius: 3px; }

/* Phones: grid items default to min-width:auto, so the editor toolbar's
   min-content width pushed the whole form (and page) past 390px. Let every
   form column shrink, and let the toolbar wrap instead of widening it. */
.admin-editor > *, .admin-grid-2 > *, .admin-more-in > *, .admin-field > * { min-width: 0; }
.admin-field input, .admin-field textarea { max-width: 100%; }
#editor, .toastui-editor-defaultUI { width: 100%; max-width: 100%; }
.toastui-editor-defaultUI-toolbar { flex-wrap: wrap; height: auto; }
.toastui-editor-toolbar { height: auto; }

/* Stat line editor - a row of value/label pairs, not hand-written JSON. */
.facts-rows { display: grid; gap: .5rem; margin-bottom: .6rem; }
.facts-row { display: grid; grid-template-columns: 7rem 1fr auto; gap: .5rem; align-items: center; }
.facts-row input {
  font-family: var(--font-body); font-size: var(--s0); color: var(--fg);
  background: var(--bg); border: 0; border-bottom: 1px solid var(--rule-strong);
  padding: .4rem 0;
}
.facts-row input:focus { outline: none; border-bottom-color: var(--accent); }
.facts-remove {
  font: inherit; font-size: 1.1rem; line-height: 1; color: var(--muted);
  background: none; border: 0; padding: 0 .3rem; cursor: pointer;
}
.facts-remove:hover { color: var(--danger); }

/* Field help. Inline rather than hover-only: a tooltip nobody hovers is not
   documentation. `title` attributes are still set for pointer users. */
.admin-help {
  display: block;
  margin-top: .45rem;
  max-width: 46rem;
  font-family: var(--font-body);
  font-size: var(--s-1);
  line-height: 1.5;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.admin-help code {
  font-family: var(--font-code);
  font-size: .92em;
  background: var(--bg-2);
  padding: .05em .3em;
  border-radius: 2px;
}
.admin-help strong { color: var(--fg-2); font-weight: 600; }
.admin-help a { color: var(--accent); }
.admin-help--block { margin: 1rem 0 0; }

/* Required / optional markers riding on the field label. */
.label .req,
.label .opt {
  margin-left: .5rem;
  font-style: normal;
  font-size: .9em;
  letter-spacing: .08em;
}
.label .req { color: var(--danger); }
.label .opt { color: var(--muted); opacity: .8; }

/* The label is a flex row so the marker sits on the baseline. */
.admin-field > .label { display: inline-flex; align-items: baseline; }

/* ------------------------------------------------------------ posts list --
   Content first: title and New post, one status line, then the posts. The
   site's .intro spacing is for a landing page, far too tall for a work list. */
.admin-notice { margin: 0 0 1rem; padding: .75rem 1rem; border-left: 3px solid var(--accent); background: var(--bg-2); font-size: var(--s-1); }

.posts-top { padding-block: clamp(1.75rem, 5vw, 2.75rem) 1rem; }
.posts-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.posts-title h1 { margin: 0; font-size: var(--s4); line-height: 1.1; letter-spacing: var(--name-tracking); }
.posts-new { padding: .7rem 1.25rem; text-decoration: none; white-space: nowrap; }
.posts-new:hover { text-decoration: none; }
.posts-lede { margin: .5rem 0 0; font-size: var(--s-1); color: var(--fg-2); }

/* Small secondary button: Rebuild, Backup, Clear. Outlined so the one filled
   button on the page stays New post. */
.posts-sbtn {
  font-family: var(--font-meta); font-size: .6875rem; font-weight: var(--meta-weight);
  letter-spacing: var(--meta-tracking); text-transform: uppercase;
  color: var(--fg); background: transparent; border: 1px solid var(--rule-strong);
  padding: .4rem .7rem; cursor: pointer; white-space: nowrap;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}
.posts-sbtn:hover { border-color: var(--fg); }
.posts-sbtn--primary { color: var(--bg); background: var(--fg); border-color: var(--fg); }
.posts-sbtn--primary:hover { color: var(--fg); background: transparent; }

.posts-status {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .5rem 1rem; margin: 0 0 1.5rem; padding: .6rem .85rem;
  border: 1px solid var(--rule); border-radius: 3px;
  font-size: var(--s-1); color: var(--fg-2);
}
.posts-status-state { display: inline-flex; align-items: center; gap: .5rem; cursor: help; }
.posts-status-state strong { color: var(--fg); font-weight: var(--strong-weight); }
.posts-dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--accent); flex: none; }
.posts-status-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.posts-status-actions form { margin: 0; }
.posts-status-note { font-size: var(--s-2); color: var(--muted); cursor: help; }

/* A failed publish is the one thing on this page that needs you, so it takes
   the site's alert red (as Delete does) instead of blending into the chrome. */
.posts-status--attention { border-color: var(--danger); border-left-width: 3px; background: var(--bg-2); }
.posts-status--attention .posts-dot { background: var(--danger); }
.posts-pending { flex-basis: 100%; color: var(--fg-2); }
.posts-pending p { margin: 0; }
.posts-pending strong { color: var(--fg); }
.posts-pending ul { margin: .35rem 0 0; padding-left: 1.1rem; color: var(--fg); }

.posts-pill {
  display: inline-block; padding: .1rem .45rem; border: 1px solid var(--rule-strong); border-radius: 999px;
  font-family: var(--font-meta); font-size: .625rem; font-weight: var(--meta-weight);
  letter-spacing: var(--meta-tracking); text-transform: uppercase; line-height: 1.5;
  color: var(--fg-2); white-space: nowrap;
}
.posts-pill--live { color: var(--accent); border-color: var(--accent); }
.posts-pill--draft { color: var(--fg-2); background: var(--bg-2); border-style: dashed; }

/* Tabs + search on one line; search drops under the tabs on a phone. */
.posts-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--fg); }
.posts-tools[hidden] { display: none; }
.posts-tabs { display: flex; flex-wrap: wrap; gap: .25rem; }
.posts-tabs button {
  font-family: var(--font-meta); font-size: .6875rem; font-weight: var(--meta-weight);
  letter-spacing: var(--meta-tracking); text-transform: uppercase;
  color: var(--fg-2); background: none; border: 1px solid transparent; border-radius: 999px;
  padding: .35rem .7rem; cursor: pointer;
}
.posts-tabs button:hover { color: var(--fg); border-color: var(--rule-strong); }
.posts-tabs button[aria-pressed="true"] { color: var(--bg); background: var(--fg); border-color: var(--fg); }
.posts-count { margin-left: .2rem; opacity: .7; font-variant-numeric: tabular-nums; }
.posts-search {
  flex: 1 1 12rem; max-width: 18rem; min-width: 0;
  font: inherit; font-size: var(--s-1); color: var(--fg); background: var(--bg);
  border: 0; border-bottom: 1px solid var(--rule-strong); padding: .4rem 0;
}
.posts-search::placeholder { color: var(--muted); }
.posts-search:focus { outline: none; border-bottom-color: var(--accent); }
@media (max-width: 34rem) { .posts-search { max-width: none; flex-basis: 100%; } }

/* Rows: title on top, pills + dates underneath, View on the right. Pills live
   on the meta line so a long title never strands a badge on its own line.
   The title link is stretched over the row, so the whole row opens the
   editor, while View stays a separate link above it. */
.posts-list { list-style: none; margin: 0; padding: 0; }
.posts-tools[hidden] + .posts-list { border-top: 1px solid var(--fg); }
.prow {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1rem; row-gap: .4rem; align-items: center;
  padding-block: 1rem; border-bottom: 1px solid var(--rule);
}
.prow[hidden] { display: none; }
.prow-title {
  grid-column: 1; min-width: 0; overflow-wrap: anywhere;
  font-family: var(--font-display); font-size: var(--s2); font-weight: var(--display-weight);
  letter-spacing: var(--display-tracking); line-height: 1.25;
  color: var(--fg); text-decoration: none; transition: color .18s ease;
}
.prow-title::after { content: ""; position: absolute; inset: 0; }
.prow:hover .prow-title { color: var(--accent); }
.prow-title:focus-visible { outline: none; }
.prow:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.prow[data-status="draft"] .prow-title { color: var(--fg-2); }
.prow[data-status="draft"]:hover .prow-title { color: var(--accent); }
.prow-meta {
  grid-column: 1; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem;
  font-family: var(--font-meta); font-size: var(--s-2); color: var(--muted); font-variant-numeric: tabular-nums;
}
.prow-dates { white-space: nowrap; }
.prow-date { color: var(--fg-2); }
.prow-view {
  grid-column: 2; grid-row: 1 / span 2; position: relative; z-index: 1;
  font-family: var(--font-meta); font-size: .6875rem; font-weight: var(--meta-weight);
  letter-spacing: var(--meta-tracking); text-transform: uppercase;
  color: var(--fg-2); text-decoration: none; padding: .4rem .2rem; white-space: nowrap;
}
.prow-view:hover { color: var(--accent); }
/* Phone: the title gets the full width; View moves onto the meta line. */
@media (max-width: 34rem) {
  .prow-title { grid-column: 1 / -1; }
  .prow-view { grid-column: 2; grid-row: 2; align-self: end; padding-block: .1rem; }
}

.posts-empty-state { padding: 3rem 1rem; text-align: center; border: 1px dashed var(--rule-strong); border-radius: 3px; margin-top: 1rem; }
.posts-empty-state[hidden] { display: none; }
.posts-empty-title { margin: 0 0 .75rem; font-family: var(--font-display); font-size: var(--s2); font-weight: var(--display-weight); color: var(--fg); }
.posts-empty-state .posts-lede { margin: 0 0 1.25rem; }
.posts-empty-state .admin-btn { display: inline-block; text-decoration: none; }

/* Help sits between the label and the field, so it is read before typing
   rather than discovered afterwards, and in a colour that is readable
   rather than decorative. */
.admin-field > * { order: 2; }
.admin-field > .label { order: 0; }
.admin-field > .admin-help { order: 1; margin-top: -.15rem; color: var(--fg-2); }
.label .opt { color: var(--fg-2); opacity: 1; }
/* Side-by-side fields: the help row takes up the slack so both inputs sit on
   the same line even when one explanation is longer. */
.admin-grid-2 > .admin-field { grid-template-rows: auto 1fr auto; }
.admin-help { color: var(--fg-2); }

/* ---------------------------------------------------- admin spacing ------ */
/* The public .intro leaves ~130px above a page title, which suits a landing
   page but pushes every admin form down. Half of that inside the admin. */
.admin-body .intro { padding-top: clamp(2rem, 6vw, 4rem); }

/* ----------------------------------------------------- danger colour ----- */
/* A token rather than a fixed red, so errors stay readable in dark mode. */
.admin-error,
.label .req { color: var(--danger); }
.admin-del-btn { color: var(--danger); border-color: var(--danger); }
.facts-remove:hover,
.admin-del:hover { color: var(--danger); }

/* ------------------------------------------------------ a11y: focus ------ */
/* Underlined text fields keep their look, but the focused line thickens so
   focus reads as more than a change of hue. Textareas get a 2px accent edge. */
.admin-field input:focus { box-shadow: 0 1px 0 var(--accent); }
.facts-row input:focus { box-shadow: 0 2px 0 var(--accent); }
.admin-field textarea:focus { box-shadow: 0 0 0 1px var(--accent); }
.admin-field input[type="file"]:focus,
.admin-field input[type="checkbox"]:focus { box-shadow: none; }

/* Text-style buttons have no border to recolour, so they get the full ring. */
.admin-linkbtn:focus-visible,
.admin-linkish:focus-visible,
.media-copy:focus-visible,
.facts-remove:focus-visible,
.admin-del:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ------------------------------------------------ a11y: touch targets ---- */
/* Phones: pad small text controls to a ~44px tap area. */
@media (pointer: coarse), (max-width: 40rem) {
  .admin-check { min-height: 2.75rem; }
  .admin-check input[type="checkbox"] { width: 1.25rem; height: 1.25rem; margin: 0; }
  .admin-more > summary { padding-block: .7rem; }
  .admin-linkbtn { padding-block: .75rem; }
  .facts-remove { min-width: 2.75rem; min-height: 2.75rem; }
  .media-copy { padding-block: .85rem; margin-top: -.45rem; }
  .admin-del-btn { padding-block: .8rem; }
  .admin-links a,
  .admin-actions a,
  .intro .label a { display: inline-block; padding-block: .75rem; margin-block: -.75rem; }
}

/* Sign-in: the form sits right under the heading, not a section-gap below. */
.admin-login h1 { margin-bottom: 1.5rem; }
.admin-login .admin-new { gap: 1.1rem; }

/* ============================================================ post editor ==
   Everything below styles the edit/new page only. The page is wider than the
   reading column so the body and its settings can sit side by side. */
main.page:has(> .ed-form),
body:has(.ed-form) .site-head > .page { max-width: 80rem; }
.intro--editor { padding-block: clamp(2rem, 6vw, 3.5rem) 1rem; }
.intro--editor h1 { margin-top: .4rem; }
/* A phone on its side has ~390px: the page heading gives most of it back to
   the title field. */
@media (max-height: 32rem) {
  .intro--editor { padding-block: 1rem .5rem; }
  .intro--editor h1 { font-size: var(--s3); margin-bottom: .5rem; }
}

.ed-form.admin-editor { max-width: none; display: block; }
.ed-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2.5rem; }
.ed-main, .ed-side { display: grid; gap: 1.4rem; align-content: start; min-width: 0; }
@media (min-width: 64rem) {
  .ed-layout { grid-template-columns: minmax(0, 1fr) minmax(18rem, 23rem); gap: 3rem; }
}
.admin-field input.ed-title { font-family: var(--font-display); font-size: var(--s3); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); }

/* Settings panels: quiet boxes that read as "about the post", not content. */
.ed-panel { display: grid; gap: 1.25rem; align-content: start; padding: 1.25rem; border: 1px solid var(--rule-strong); border-radius: 3px; min-width: 0; }
.ed-panel[hidden] { display: none; }
.ed-panel-h { margin: 0; padding-bottom: .6rem; border-bottom: 1px solid var(--rule); font-family: var(--font-meta); font-size: var(--s-2); font-weight: var(--meta-weight); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--fg); }
.ed-panel .admin-field input[type=text],
.ed-panel .admin-field input[type=url],
.ed-panel .admin-field input[type=date] { font-size: var(--s0); }
.ed-panel .admin-notice { margin: 0; }
.ed-panel > .admin-help { margin: 0; }
.admin-field > .ed-state-line { order: 0; margin: 0; font-size: var(--s0); color: var(--fg); }
.ed-state-line a { color: var(--accent); overflow-wrap: anywhere; }
.ed-state-when { font-size: var(--s-1); color: var(--fg-2); }

/* The body: a heading row carrying the Visual / Markdown switch. */
.admin-field > .ed-body-head { order: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; }
.ed-mode { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 3px; overflow: hidden; }
.ed-mode button { font-family: var(--font-meta); font-size: var(--s-2); font-weight: var(--meta-weight); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--fg-2); background: var(--bg); border: 0; padding: .45rem .9rem; cursor: pointer; }
.ed-mode button + button { border-left: 1px solid var(--rule-strong); }
.ed-mode button[aria-pressed="true"] { color: var(--bg); background: var(--fg); }
.ed-mode button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#editor { min-width: 0; }
/* The toolbar stays reachable while the body grows under a long post. The
   sticky box is the toolbar's wrapper: the inner bar's own parent is only
   as tall as the bar itself, so sticking that never did anything. Above the
   text (Toast UI puts it at z-index 20) and the Save bar (70), so its menus
   are not cut off by the bar; below the site header (80). */
.ed-body .toastui-editor-toolbar { position: sticky; top: var(--ed-head-h, 4.6rem); z-index: 75; background: var(--bg-2); border-radius: 3px 3px 0 0; }

/* Help: one line visible; the rest behind an accessible More button. */
.help-more { font-family: var(--font-meta); font-size: .6875rem; font-weight: var(--meta-weight); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--accent); background: none; border: 0; padding: 0 .1rem; cursor: pointer; }
.help-more:hover { text-decoration: underline; }
.admin-help-more { padding: .6rem .8rem; background: var(--bg-2); border-radius: 2px; }
.admin-help-more p { margin: 0; }
.admin-help-more p + p { margin-top: .5rem; }
.admin-help-more[hidden] { display: none; }

.admin-warn,
.admin-contrast { margin: 0; font-size: var(--s-1); line-height: 1.5; color: var(--fg-2); }
.admin-warn { padding: .6rem .8rem; border-left: 3px solid var(--danger); background: var(--bg-2); color: var(--fg); }
.admin-warn[hidden], .admin-contrast[hidden] { display: none; }
.admin-contrast.is-bad { color: var(--danger); font-weight: 600; }

/* Summary: a live count and what a search result would show. */
.ed-count { margin: 0; font-family: var(--font-meta); font-size: var(--s-2); letter-spacing: .04em; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.ed-count.is-over { color: var(--danger); font-weight: 600; }
.serp { padding: .75rem .9rem; border: 1px solid var(--rule); border-radius: 3px; background: var(--bg-2); min-width: 0; }
.serp p { margin: 0; overflow-wrap: anywhere; }
.serp .serp-label { margin-bottom: .35rem; font-family: var(--font-meta); font-size: .625rem; letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--fg-2); }
.serp-title { font-size: var(--s1); line-height: 1.3; color: var(--accent); }
.serp-url { font-family: var(--font-code); font-size: .6875rem; color: var(--fg-2); }
.serp .serp-desc { margin-top: .2rem; font-size: var(--s-1); line-height: 1.45; color: var(--fg); }
.serp .serp-desc.is-empty { color: var(--muted); font-style: italic; }

/* Image path + preview + picker button on one line. */
.img-field { display: grid; grid-template-columns: 3rem minmax(0, 1fr) auto; gap: .75rem; align-items: center; }
.img-thumb { width: 3rem; height: 3rem; border: 1px solid var(--rule); border-radius: 3px; background: var(--bg-2); overflow: hidden; }
.img-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.img-thumb img[hidden] { display: none; }
.img-pick { color: var(--accent); }

/* Hex field with a native colour well as its swatch. */
.colour-field { display: grid; grid-template-columns: 2.5rem minmax(0, 1fr); gap: .75rem; align-items: center; }
.admin-field .colour-field input[type=color] { width: 2.5rem; height: 2.5rem; padding: 0; border: 1px solid var(--rule-strong); border-radius: 3px; background: var(--bg); cursor: pointer; }
.colour-field input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
.colour-field input[type=color]::-webkit-color-swatch { border: 0; border-radius: 2px; }
/* No colour set yet: an empty, hatched well rather than a fake black. */
.colour-field input[type=color].is-empty::-webkit-color-swatch { background: repeating-linear-gradient(45deg, var(--bg-2) 0 4px, var(--rule-strong) 4px 8px) !important; }
.colour-field input[type=color].is-empty::-moz-color-swatch { background: repeating-linear-gradient(45deg, var(--bg-2) 0 4px, var(--rule-strong) 4px 8px) !important; }

/* Revisions: title, when, and what you can do with it. */
.rev-list { display: grid; }
.rev-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .35rem 1.5rem; align-items: baseline; padding-block: .9rem; border-bottom: 1px solid var(--rule); }
.rev-title { font-family: var(--font-display); font-size: var(--s0); font-weight: var(--display-weight); color: var(--fg); overflow-wrap: anywhere; }
.rev-when { font-family: var(--font-meta); font-size: var(--s-2); letter-spacing: .04em; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.rev-actions { display: inline-flex; gap: 1rem; }
.rev-actions .admin-linkbtn { color: var(--accent); }
@media (max-width: 40rem) {
  .rev-row { grid-template-columns: minmax(0, 1fr) auto; }
  .rev-title { grid-column: 1 / -1; }
}
.ed-revisions .admin-help { margin: .75rem 0 .25rem; }

/* Delete: a second, explicit step in the page's own voice. */
.ed-delete > summary { display: inline-block; list-style: none; }
.ed-delete > summary::-webkit-details-marker { display: none; }
.ed-delete[open] > summary { opacity: .5; }
.ed-delete-confirm { margin-top: 1rem; padding: 1rem 1.1rem; max-width: 36rem; border: 1px solid var(--danger); border-radius: 3px; }
.ed-delete-confirm p { margin: 0 0 1rem; font-size: var(--s-1); line-height: 1.55; color: var(--fg); }
.ed-delete-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; }
.admin-del-btn--solid { background: var(--danger); color: #fff; }
.admin-del-btn--solid:hover { background: transparent; color: var(--danger); }

/* The action bar: sticks to the bottom of the viewport for the whole page. */
.ed-bar { position: sticky; bottom: 0; z-index: 70; margin-top: 2.5rem; margin-inline: calc(var(--pad-l) * -1) calc(var(--pad-r) * -1); padding: .7rem var(--pad-r) max(.7rem, env(safe-area-inset-bottom)) var(--pad-l); border-top: 1px solid var(--rule-strong); background: color-mix(in srgb, var(--bg) 94%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
@supports not (backdrop-filter: blur(1px)) { .ed-bar { background: var(--bg); } }
.ed-bar-in { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.25rem; }
.ed-bar-opts { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.25rem; }
.ed-status { display: flex; align-items: baseline; flex-wrap: wrap; gap: .1rem .5rem; margin: 0 auto 0 0; min-width: 0; }
.ed-status-dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); align-self: center; }
.ed-status-text { font-family: var(--font-meta); font-size: var(--s-2); font-weight: 600; letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--fg); }
.ed-status-sub { font-size: var(--s-1); color: var(--fg-2); }
.ed-status[data-state="live"] .ed-status-dot { background: var(--accent); }
.ed-status[data-state="dirty"] .ed-status-dot { background: var(--danger); }
.ed-status[data-state="dirty"] .ed-status-text { color: var(--danger); }
.ed-bar .admin-check input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--fg); }
.ed-preview { font-family: var(--font-meta); font-size: var(--s-2); font-weight: var(--meta-weight); letter-spacing: var(--meta-tracking); text-transform: uppercase; color: var(--accent); }
.ed-save { padding: .7rem 1.6rem; }
/* Phones: two rows. Status and Save (the thing you came to press), then the
   toggles and Preview. */
@media (max-width: 40rem) {
  .ed-bar { padding-top: .5rem; padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }
  .ed-bar-in { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .75rem; }
  .ed-status { margin: 0; }
  .ed-bar-opts { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; gap: .25rem .75rem; }
  .ed-save { grid-column: 2; grid-row: 1; padding: .55rem 1.1rem; }
  .ed-bar .admin-check { gap: .4rem; font-size: .75rem; letter-spacing: .06em; }
  .ed-preview { letter-spacing: .06em; }
  /* "Show" and "page" are dropped visually but stay in the accessible name. */
  .ed-hide-sm { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 22.49rem) {
  .ed-hide-xs { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* Dialogs: picker, revision viewer, leave-without-saving. */
.ed-dialog { width: min(40rem, calc(100vw - 2rem)); max-height: min(44rem, calc(100vh - 2rem)); max-height: min(44rem, calc(100dvh - 2rem)); padding: 1.25rem; color: var(--fg); background: var(--bg); border: 1px solid var(--rule-strong); border-radius: 4px; box-shadow: 0 1rem 3rem rgba(0, 0, 0, .25); }
.ed-dialog--wide { width: min(52rem, calc(100vw - 2rem)); }
.ed-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.ed-dialog h2 { margin: 0; font-family: var(--font-meta); font-size: var(--s-1); font-weight: var(--meta-weight); letter-spacing: var(--meta-tracking); text-transform: uppercase; }
.ed-dialog > p { margin: .75rem 0 0; font-size: var(--s-1); line-height: 1.55; }
.ed-dialog-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--rule); }
.ed-dialog-tools { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem 1rem; padding-block: .9rem; }
.ed-dialog-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; margin-top: 1.25rem; }
.media-upload { position: relative; color: var(--accent); }
.media-upload:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
.visually-hidden-input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.picker-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 6.5rem), 1fr)); font-size: var(--s-1); color: var(--fg-2); }
.picker-item { display: grid; gap: .3rem; padding: .35rem; text-align: left; color: var(--fg-2); background: none; border: 1px solid var(--rule); border-radius: 3px; cursor: pointer; min-width: 0; }
.picker-item:hover, .picker-item:focus-visible { border-color: var(--accent); outline: none; }
.picker-item[aria-pressed="true"] { border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); }
.picker-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--bg-2); border-radius: 2px; }
.picker-item span { font-family: var(--font-code); font-size: .625rem; overflow-wrap: anywhere; }
.ed-dialog .rev-dialog-title { font-family: var(--font-display); font-size: var(--s2); font-weight: var(--display-weight); }
.rev-dialog-body { margin-top: 1rem; padding: 1rem; border: 1px solid var(--rule); border-radius: 3px; overflow: auto; }
.rev-dialog-body pre { margin: 0; white-space: pre-wrap; font-family: var(--font-code); font-size: .8125rem; }

/* ---------------------------------------------------------------- phones -- */
/* iOS Safari zooms the whole page when a field under 16px gets focus, which
   throws the editor off screen. Every place you type is 16px. */
.posts-search,
#editor .toastui-editor-contents,
#editor .ProseMirror { font-size: 1rem; }

@media (pointer: coarse), (max-width: 40rem) {
  /* Nothing a phone has to read below 12px. */
  .posts-pill, .posts-count, .posts-sbtn, .posts-tabs button, .prow-view,
  .help-more, .label .opt, .label .req, .serp .serp-label, .serp-url,
  .ed-bar .admin-check, .media-path, .admin-help code { font-size: .75rem; }
  /* The bar's checkboxes are a tap target of their own, not just the label. */
  .ed-bar .admin-check input { width: 1.5rem; height: 1.5rem; }

  /* ~44px tap areas without moving the layout. */
  .prow-view { display: inline-flex; align-items: center; min-height: 2.75rem; }
  .help-more,
  .media-uses a,
  .ed-state-line a,
  .ed-bar .ed-preview { display: inline-block; padding-block: .9rem; margin-block: -.9rem; }
}

/* ------------------------------------------------------- admin width ---- */
/* The public reading column (47rem) suits an article, not a management
   screen on a wide monitor. Posts and Media use a wider frame (the editor has
   its own 80rem one); sign-in stays narrow. Intro text keeps its measure. */
body.admin-body:not(:has(.admin-login, .ed-form)) main.page,
body.admin-body:not(:has(.admin-login, .ed-form)) .site-head > .page { max-width: 72rem; }
/* Writing-note warning inside the sticky save bar: visible wherever you are. */
.ed-bar .ed-notes { margin: 0 0 .6rem; }

/* ------------------------------------------------ phones: screen edges --- */
/* viewport-fit=cover lets the page run under a notch and the home bar, so
   the side padding and the bottom bar keep clear of them. */
.admin-body {
  --pad-l: max(var(--gutter), env(safe-area-inset-left));
  --pad-r: max(var(--gutter), env(safe-area-inset-right));
}
.admin-body .page { padding-inline: var(--pad-l) var(--pad-r); }

/* The admin header was ~140px on a phone and followed you down the page,
   leaving little room to write. Its links wrap as whole words, and on a
   small or short screen it scrolls away with the page. */
.admin-body .head-nav { flex-wrap: wrap; gap: .25rem 1.25rem; }
.admin-body .head-nav a { white-space: nowrap; }
@media (max-width: 40rem), (max-height: 32rem) {
  .admin-body .site-head--sticky { position: relative; }
}

/* ------------------------------------------ phones: on-screen keyboard --- */
/* Fields scrolled into view (Tab, focus, the browser's own nudge) stop above
   the Save bar rather than behind it. --ed-bar-h is measured by admin.js. */
html:has(.ed-bar) { scroll-padding-bottom: calc(var(--ed-bar-h, 4rem) + .75rem); }

/* While the keyboard is up (admin.js sets .kb-open) the screen is ~40% of its
   height, so the bar steps out of the way and every pixel goes to the field.
   It stays where it is in the page, below the form, and comes back when the
   keyboard closes. Nothing above it moves. */
html.kb-open { scroll-padding-bottom: .75rem; }
html.kb-open .ed-bar,
html.kb-open .admin-body .site-head--sticky { position: relative; }
html.kb-open .ed-body .toastui-editor-toolbar { top: 0; }

/* ----------------------------------------------------- phones: dialogs --- */
/* A dialog is never taller than the screen: its header and buttons stay put
   and only the list or text in the middle scrolls, so Close and Restore are
   always in reach, upright or sideways. */
.ed-dialog[open] { display: flex; flex-direction: column; overflow: auto; }
.ed-dialog > * { flex: none; }
.ed-dialog .picker-grid,
.ed-dialog .rev-dialog-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.ed-dialog .picker-grid { align-content: start; padding: 2px; }
@media (max-width: 40rem), (max-height: 32rem) {
  .ed-dialog { padding: .9rem 1rem; }
  .ed-dialog-head { padding-bottom: .4rem; }
  .ed-dialog-tools { padding-block: .4rem; }
  .ed-dialog-foot { margin-top: .75rem; }
  .rev-dialog-body { margin-top: .6rem; padding: .75rem; }
}
@media (max-height: 32rem) {
  .ed-dialog > p { margin-top: .4rem; }
  .ed-dialog .rev-dialog-title { font-size: var(--s1); }
}

/* ------------------------------------------ phones: editor pop-ups ------- */
/* Toast UI places its pop-ups by the button that opened them and sizes them
   for a desktop: on a phone the folded-toolbar menu (539px) and the image
   pop-up (300px) ran off the left edge. Pin them inside the editor, let the
   menu wrap, and keep their text fields at 16px so iOS does not zoom. */
@media (max-width: 40rem) {
  .ed-body .toastui-editor-dropdown-toolbar { left: 0; right: 0 !important; height: auto; flex-wrap: wrap; }
  .ed-body .toastui-editor-popup { left: 0 !important; right: auto; margin-left: 0; width: auto; max-width: 100%; }
  .ed-body .toastui-editor-popup input[type="text"],
  .ed-body .toastui-editor-popup input:not([type]) { font-size: 1rem; }
}
/* Toolbar tooltips are hover help. A tap fires the hover too, and the label
   then sat on top of the menu it had just opened; the icons carry
   aria-labels, so a touch screen loses nothing without them. */
@media (hover: none) {
  .toastui-editor-tooltip { display: none !important; }
}
/* Sign-in is one field and a button: keep it a narrow card whatever the
   public column width is. */
body.admin-body:has(.admin-login) main.page { max-width: 36rem; }

/* Admin nav: five links (Analytics joined) wrap on a 320px phone instead of
   pushing the page sideways. */
.admin-body .head-nav { flex-wrap: wrap; gap: .25rem 1.1rem; }
/* Account: a narrow form; a password field does not need a wide screen. */
.acct { max-width: 36rem; }
.acct-form { display: grid; gap: 1.1rem; }
/* "Log out" is a form (POST + CSRF), dressed as the other header links. */
.nav-form { display: inline; margin: 0; }
.nav-btn {
  font-family: var(--font-meta); font-size: var(--s-2); font-weight: var(--meta-weight);
  letter-spacing: var(--meta-tracking); text-transform: uppercase; white-space: nowrap;
  color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer;
}
.nav-btn:hover { color: var(--fg); }
@media (pointer: coarse), (max-width: 40rem) {
  .nav-btn { padding-block: .75rem; margin-block: -.75rem; }
}
