/* Jaunder — base stylesheet (structure + layout only, no theme-specific colors or fonts).
 * Every color/typography choice is a CSS variable; themes set those variables and nothing else.
 */

:root {
  /* surfaces */
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-alt: #f5f5f3;

  /* text */
  --ink: #1a1a19;
  --ink-soft: #3d3d3b;
  --muted: #6e6e6a;
  --muted-soft: #9a9a96;

  /* lines */
  --line: #ebebe8;
  --line-soft: #f2f2ef;

  /* accent + state */
  --accent: #5b4df0;
  --accent-ink: #5b4df0;
  --accent-soft: #eeecff;
  --on-accent: #ffffff;
  --ok: #2f9c5b;
  --warn: #c88a2a;
  --err: #dc2626;

  /* per-protocol color hints (themes may override these too) */
  --c-local: #6b7a8f;
  --c-activitypub: #7b5cd6;
  --c-atproto: #3b82f6;
  --c-rss: #e8833a;
  --c-atom: #14a085;
  --c-jsonfeed: #c5a028;

  /* typography */
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-display: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --font-meta: var(--font-body);

  /* shape / scale */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --pill: 999px;
  --fs-body: 14px;
  --fs-meta: 12px;
  --fs-head: 28px;
  --tracking-head: -0.4px;
  --lh-body: 1.55;

  /* density-driven (tweakable) */
  --post-pad-y: 18px;
  --post-pad-x: 28px;
  --post-gap: 14px;
  --avatar-sz: 38px;
  --fs-post: 14.5px;

  /* stylistic flags (themes set to 'normal' or 'italic') */
  --source-style: normal;
  --source-weight: 400;
  --brand-weight: 600;
  --brand-tracking: -0.3px;

  /* effect hooks — themes opt in by redefining these */
  --chrome-accent: 0;
  /* 0 = plain border; themes can set to use accent underline */
  --border-style: solid;
  /* 'solid' | 'dashed' */
  --card-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

/* ─── reset ─── */
.j-root {
  all: initial;
}

.j-root,
.j-root * {
  box-sizing: border-box;
  font-family: var(--font-body);
  color: var(--ink);
}

.j-root {
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
}

.j-root button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.j-root em {
  font-style: italic;
}

.j-contents {
  display: contents;
}

.j-theme-clip {
  position: relative;
  z-index: 0;
  flex: 1;
  min-width: 0;
  min-height: 0;
  contain: paint;
  isolation: isolate;
}

[data-jaunder-theme-surface] {
  background: var(--bg);
  color: var(--ink);
}

.j-root[data-theme="custom"] .j-sidebar,
.j-root[data-theme="custom"] .j-scroll {
  background: transparent;
}

.j-trusted-post-actions {
  display: contents;
  pointer-events: none;
}

.j-trusted-chrome {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  display: none;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 28px;
  background: var(--surface);
  border-bottom: 1px var(--border-style) var(--line);
  pointer-events: none;
}

/* ─── layout shell ─── */
.j-shell {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.j-main-region {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.j-sidebar {
  width: 232px;
  flex-shrink: 0;
  border-right: 1px var(--border-style) var(--line);
  background: var(--surface);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.j-main {
  container-type: inline-size;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.j-warn-banner {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 28px;
  background: #facc15;
  color: #2d2100;
  border-bottom: 1px solid #a16207;
  font-size: var(--fs-small);
  font-weight: 600;
}

.j-trusted-chrome:has(.j-warn-banner) {
  display: flex;
}

.j-trusted-chrome:has(.j-warn-banner) {
  left: 0;
}

.j-trusted-chrome > * {
  pointer-events: auto;
}

.j-trusted-chrome .j-warn-banner {
  flex: 1 1 100%;
}

.j-topbar {
  padding: 14px 28px;
  border-bottom: 1px var(--border-style) var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg);
  flex-shrink: 0;
}

.j-site-identity {
  display: none;
  color: var(--muted);
  font-size: var(--fs-meta);
}

.j-topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: var(--brand-weight);
  letter-spacing: var(--brand-tracking);
}

.j-topbar .j-sub {
  font-size: var(--fs-meta);
  color: var(--muted);
  margin-top: 2px;
}

.j-topbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.j-scroll {
  flex: 1;
  overflow: auto;
  background: var(--surface);
}

/* Home keeps its publishing chrome available while the browser owns one
   continuous scroll through the User's Posts. Other timelines retain the
   fixed-shell scroll region above. */
.j-root[data-home="true"] {
  height: auto;
  min-height: 100dvh;
  overflow: visible;
}

.j-root[data-home="true"] .j-shell,
.j-root[data-home="true"] .j-main-region {
  height: auto;
  min-height: 100dvh;
}

.j-root[data-home="true"] .j-sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100dvh;
}

.j-root[data-home="true"] .j-main {
  overflow: visible;
}

.j-root[data-home="true"] .j-scroll {
  flex: none;
  overflow: visible;
}

.j-home-chrome {
  position: sticky;
  z-index: 10;
  top: 0;
  background: var(--surface);
}

/* Expanded fields and operational warnings need the document flow's full height.
   Yield stickiness rather than introducing a second vertical scrollbar or
   allowing sticky surfaces to overlap. */
.j-home-chrome:has(.j-composer-control-summary[aria-expanded="true"]),
.j-main-region:has(> .j-warn-banner) .j-home-chrome {
  position: static;
}

.j-root[data-home="true"] .j-composer {
  flex: none;
  min-height: 0;
  overflow: visible;
}

.j-timeline-order {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 28px;
  border-bottom: 1px var(--border-style) var(--line);
}

.j-timeline-order .j-timeline-order-button {
  width: 34px;
  height: 34px;
  justify-content: center;
  color: var(--ink-soft);
  background: var(--surface-alt);
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
}

.j-timeline-order .j-timeline-order-button:hover {
  color: var(--ink);
  background: var(--accent-soft);
}

.j-timeline-order .j-timeline-order-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.j-page {
  padding: 16px 32px;
}

.j-page-narrow {
  padding: 28px 32px;
  max-width: 480px;
  margin: 0 auto;
}

/* ─── brand / logo ─── */
.j-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 2px;
}

.j-brand-mark {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--surface);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -1px;
}

.j-brand-text {
  font-family: var(--font-display);
  font-weight: var(--brand-weight);
  letter-spacing: var(--brand-tracking);
  font-size: 15px;
}

/* ─── search ─── */
.j-search {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--muted-soft);
}

.j-search .j-kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ─── sidebar sections ─── */
.j-sb-head {
  padding: 0 10px 6px;
  font-family: var(--font-meta);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
}

.j-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.j-nav-item {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--ink-soft);
  cursor: default;
}

.j-nav-item.is-active {
  background: var(--surface-alt);
  color: var(--ink);
  font-weight: 500;
}

.j-nav-item .j-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ─── sidebar footer ─── */
.j-sb-foot {
  margin-top: auto;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.j-sb-foot-body {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.j-sb-foot-name {
  font-weight: 500;
}

.j-sign-out {
  color: var(--muted);
  font-size: 11px;
}

/* ─── chips / filter bar ─── */
.j-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--pill);
  font-size: 12px;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px var(--border-style) var(--line);
}

.j-chip.is-active {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

.j-chip .j-dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
}

.j-chip .j-n {
  color: var(--muted-soft);
  font-variant-numeric: tabular-nums;
}

.j-chip.is-active .j-n {
  color: rgba(255, 255, 255, 0.6);
}

/* ─── avatar ─── */
.j-av {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  letter-spacing: -0.4px;
  font-family: var(--font-body);
  border-radius: 50%;
}

/* ─── composer ─── */
.j-composer {
  container-type: inline-size;
  flex: 0 1 50%;
  min-height: 260px;
  overflow: auto;
  padding: 0;
  border-bottom: 1px var(--border-style) var(--line);
  background: var(--surface);
}

.j-composer-details {
  display: flex;
  flex-direction: column;
  gap: 17px;
}

.j-composer-summary textarea {
  height: 44px;
  min-height: 44px;
  overflow: hidden;
  resize: vertical;
}

.j-composer-summary textarea:focus,
.j-composer-summary textarea:not(:placeholder-shown) {
  height: auto;
  min-height: 96px;
  overflow: auto;
}

.j-composer-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 8px;
}

.j-composer-control {
  min-width: 0;
  overflow: hidden;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.j-composer-control.is-wide {
  grid-column: 1 / -1;
}

.j-composer-control-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 12px;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 44px;
  padding: 0 8px;
  color: var(--ink);
  text-align: left;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.j-composer-control-summary[aria-expanded="true"] {
  box-shadow: inset 0 0 0 1px var(--ink);
}

.j-composer-control-label {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.j-composer-control-value {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.j-composer-control-chevron {
  color: var(--muted);
  font-size: 16px;
  text-align: center;
  transition: transform 120ms ease;
}

.j-composer-control-summary[aria-expanded="true"] .j-composer-control-chevron {
  transform: rotate(180deg);
}

.j-composer-control-body {
  padding: 0 10px 10px;
}

.j-composer-control-body > .j-form-field > .j-form-label,
.j-composer-control-body > fieldset > .j-form-label {
  display: none;
}

.j-composer-media {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.j-media-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.j-composer-media > .j-media-upload-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 8px;
}

.j-composer-media > .j-media-upload-actions > .j-btn {
  width: 100%;
}

.j-composer-media-heading,
.j-composer-media-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.j-composer-media-heading .j-btn.is-icon,
.j-composer-media-row .j-btn.is-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
}

.j-composer-media-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.j-composer-media-row {
  min-width: 0;
}

.j-composer-media-thumbnail {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}

.j-composer-media-filename {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.j-publication-time {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.j-publication-time > span {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.j-btn.is-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
}

.j-button-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  z-index: 20;
  padding: 4px 7px;
  color: var(--surface);
  font-size: 11px;
  font-family: var(--font-meta);
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  visibility: hidden;
  background: var(--ink);
  border-radius: var(--radius-sm);
  opacity: 0;
  transform: translateX(-50%);
}

.j-btn.is-icon:hover .j-button-tooltip,
.j-btn.is-icon:focus .j-button-tooltip {
  visibility: visible;
  opacity: 1;
}

.j-composer-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.j-composer-toolbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding-top: 17px;
  border-top: 1px var(--border-style) var(--line);
}

.j-composer-toolbar .j-btn {
  width: 100%;
}

.j-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-alt);
  border-radius: var(--pill);
  font-size: 12px;
  color: var(--muted);
  border: 1px var(--border-style) transparent;
}

.j-tag.is-accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 500;
}

.j-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted-soft);
  font-variant-numeric: tabular-nums;
}

/* ─── buttons ─── */
.j-btn {
  background: var(--surface);
  color: var(--ink);
  border: 1px var(--border-style) var(--line);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.j-btn.is-primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
  font-weight: 500;
}

.j-btn.is-accent {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: 500;
}

.j-btn.is-danger {
  background: var(--err);
  color: var(--on-accent);
  border-color: var(--err);
  font-weight: 500;
}

.j-btn.is-danger:hover {
  background: color-mix(in srgb, var(--err) 88%, black);
  border-color: color-mix(in srgb, var(--err) 88%, black);
}

.j-btn.is-active {
  background: var(--surface-alt);
  font-weight: 500;
}

/* ─── segmented control (format selector) ─── */
.j-seg {
  display: flex;
  width: 100%;
}

.j-seg .j-btn {
  flex: 1;
  border-radius: 0;
  margin-left: -1px;
}

.j-seg .j-btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  margin-left: 0;
}

.j-seg .j-btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.j-seg .j-btn.is-selected {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
  z-index: 1;
}

/* ─── post ─── */
.j-post {
  padding: var(--post-pad-y) var(--post-pad-x);
  border-bottom: 1px var(--border-style) var(--line-soft);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--post-gap);
}

.j-post-layout,
.j-post-content {
  min-width: 0;
}

.j-post-layout {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.j-post-content {
  flex: 1;
}

.j-post-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.j-post-name {
  font-weight: 600;
  font-size: var(--fs-post);
}

.j-post-handle {
  color: var(--muted);
  font-size: 13px;
}

.j-post-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-meta);
  font-style: var(--source-style);
  font-weight: var(--source-weight);
}

.j-post-source .j-dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
}

.j-post-time {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.j-post-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.3px;
  margin: 2px 0 6px;
  color: var(--ink);
  text-wrap: balance;
}

.j-post-body {
  font-size: var(--fs-post);
  line-height: 1.55;
  color: var(--ink);
  text-wrap: pretty;
  margin: 0;
}

.j-provider-embed {
  margin: 1rem 0;
  max-width: 100%;
}

.j-provider-embed-frame {
  aspect-ratio: 16 / 9;
  max-width: 100%;
}

.j-provider-embed-frame iframe {
  border: 0;
  display: block;
  height: 100%;
  max-width: 100%;
  width: 100%;
}

.j-provider-embed figcaption {
  margin-top: 0.5rem;
}

.j-post-foot {
  margin-top: 12px;
  display: flex;
  gap: 22px;
  color: var(--muted);
  font-size: 12px;
  align-items: center;
  font-family: var(--font-meta);
}

.j-post-foot .j-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.j-post-foot .j-stat strong {
  font-weight: 500;
  color: var(--ink);
}

/* ─── tag chips (display) ─── */
.j-tag-list {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

.j-tag-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.j-tag {
  background: var(--surface-alt);
  color: var(--accent-ink);
  border: 1px var(--border-style) var(--line);
  border-radius: var(--pill);
  padding: 2px 9px;
  font-size: 12px;
  font-family: var(--font-meta);
  text-decoration: none;
  line-height: 1.4;
}

.j-tag:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.j-tag-here {
  color: var(--muted-soft);
  font-size: 11px;
  font-family: var(--font-meta);
  text-decoration: none;
}

.j-tag-here:hover {
  color: var(--accent);
}

/* ─── tag input (editable chips + autocomplete) ─── */
.j-tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  position: relative;
  padding: 4px 6px;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: text;
}

.j-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  border: 1px var(--border-style) var(--accent);
  border-radius: var(--pill);
  padding: 2px 6px 2px 9px;
  font-size: 12px;
  font-family: var(--font-meta);
  color: var(--accent-ink);
}

.j-tag-chip-label {
  line-height: 1.4;
}

.j-tag-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted-soft);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}

.j-tag-chip-remove:hover {
  color: var(--ink);
}

.j-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted-soft);
  padding: 0;
  display: inline-flex;
  align-items: center;
}

.j-icon-btn:hover {
  color: var(--ink);
}

.j-card-head .j-icon-btn {
  margin-left: auto;
}

.j-tag-text {
  flex: 1;
  min-width: 120px;
  border: none;
  background: transparent;
  outline: none;
  padding: 2px 0;
  font-size: inherit;
  color: inherit;
}

.j-tag-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--c-danger);
}

.j-tag-suggest {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px var(--border-style) var(--line);
  border-radius: 6px;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  max-height: 220px;
  overflow-y: auto;
}

.j-tag-suggest-item {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-meta);
  color: var(--ink);
}

.j-tag-suggest-item:hover,
.j-tag-suggest-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ─── trusted Post Actions disclosures ─── */

.j-post-action-control {
  position: absolute;
  z-index: 1;
  top: anchor(top);
  left: anchor(left);
  width: 72px;
  height: 32px;
  pointer-events: auto;
}

.j-post-action-trigger {
  width: 100%;
  height: 100%;
}

.j-post-action-popover {
  pointer-events: auto;
  position: fixed;
  /* Native popovers default every inset to zero; release the unused axes so the
    viewport-relative anchor placement wins over the conflicting defaults. */
  top: anchor(bottom);
  right: max(8px, anchor(right));
  bottom: auto;
  left: auto;
  margin: 4px 0 0;
  inline-size: max-content;
  max-inline-size: calc(100vw - 16px);
  max-block-size: calc(100dvh - 16px);
  overflow: auto;
  overflow-wrap: anywhere;
  padding: 6px;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
}

.j-post-acts {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.j-post-acts .j-btn {
  text-decoration: none;
}

.j-post-plink {
  font-size: 12px;
  color: var(--muted-soft);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.j-post-plink:hover {
  color: var(--ink);
}

/* ─── permalink post page ─── */
.j-post-page {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 24px;
  padding: var(--post-pad-y) var(--post-pad-x);
}

/* ─── compose page (grid and aside shared with Post editor) ─── */
.j-compose-header {
  padding: 14px 28px;
  border-bottom: 1px var(--border-style) var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.j-compose-grid,
.j-composer-layout {
  display: grid;
  grid-template-columns: minmax(480px, 1fr) 320px;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.j-composer-layout {
  height: 100%;
}

.j-compose-grid {
  flex: 1;
  overflow: hidden;
}

.j-compose-body {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
  padding: 22px;
  overflow: auto;
  background: var(--surface);
}

.j-compose-aside {
  display: flex;
  flex-direction: column;
  gap: 17px;
  min-width: 0;
  padding: 22px;
  overflow: auto;
  border-left: 1px var(--border-style) var(--line);
  background: var(--bg);
}

@container (max-width: 800px) {
  .j-home-chrome {
    position: static;
  }

  .j-compose-grid,
  .j-composer-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .j-composer-layout {
    height: auto;
  }

  .j-compose-grid {
    overflow: auto;
  }

  .j-compose-body {
    padding: 16px;
    overflow: visible;
  }

  .j-compose-aside {
    border-top: 1px var(--border-style) var(--line);
    border-left: 0;
    overflow: visible;
  }
}

.j-compose-options {
  display: contents;
}

@container (max-width: 360px) {
  .j-composer-controls {
    grid-template-columns: minmax(0, 1fr);
  }
}

.j-compose-editor {
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink);
  min-height: 180px;
  text-wrap: pretty;
  font-family: var(--font-body);
}

.j-caret {
  display: inline-block;
  width: 2px;
  height: 22px;
  background: var(--accent);
  transform: translateY(5px);
  margin-left: 2px;
}

/* destinations list */
.j-dest {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px var(--border-style) var(--line);
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.j-dest:last-of-type {
  border-bottom: 1px var(--border-style) var(--line);
}

.j-dest-body {
  flex: 1;
  min-width: 0;
}

.j-dest-name {
  font-size: 13px;
  font-weight: 500;
}

.j-dest-addr {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.j-dest-vis {
  font-size: 11px;
  color: var(--muted);
}

.j-switch {
  width: 28px;
  height: 16px;
  border-radius: 9px;
  background: var(--line);
  position: relative;
}

.j-switch.is-on {
  background: var(--accent);
}

.j-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 6px;
  background: #fff;
  transition: left 0.15s;
}

.j-switch.is-on .j-switch-knob {
  left: 14px;
}

/* ─── settings ─── */
.j-settings {
  padding: 28px 32px;
  max-width: 720px;
}

.j-card {
  background: var(--surface);
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.j-card-head {
  padding: 14px 18px;
  border-bottom: 1px var(--border-style) var(--line-soft);
  display: flex;
  align-items: center;
}

.j-card-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: var(--brand-tracking);
}

.j-card-head .j-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.j-websub-recovery-guidance,
.j-websub-empty,
.j-websub-redrive-guidance {
  padding: 12px 18px;
  font-size: 13.5px;
  line-height: 1.4;
}

.j-websub-recovery-guidance p,
.j-websub-empty,
.j-websub-redrive-guidance {
  margin: 0;
}

.j-websub-recovery-guidance p + p {
  margin-top: 6px;
  color: var(--muted);
}

.j-websub-redrive-guidance {
  color: var(--muted);
  border-top: 1px var(--border-style) var(--line-soft);
}

.j-field-row {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 16px;
  align-items: center;
  border-top: 1px var(--border-style) var(--line-soft);
}

.j-field-row:first-child {
  border-top: none;
}

.j-field-label {
  font-size: 13px;
  color: var(--ink-soft);
  font-family: var(--font-meta);
}

.j-field-val {
  font-size: 13.5px;
  padding: 7px 10px;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
}

/* ─── generic forms (login, register, settings-style forms) ─── */
.j-form-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.j-form-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.j-form-field.j-form-toggle {
  flex-direction: row;
  align-items: center;
}

.j-form-toggle > input[type="checkbox"] {
  margin: 0;
}

.j-form-label {
  font-family: var(--font-meta);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
}

.j-compose-grid .j-form-label,
.j-composer-layout .j-form-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.j-form-help {
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.4;
}

/* ─── composer form groups ─── */
.j-composer-group {
  margin: 0;
  padding: 0;
  border: 0;
}

.j-composer-group > .j-form-help,
.j-creation-schedule-editor > .j-form-help {
  margin: 0;
}

.j-audience-named,
.j-creation-schedule-editor {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.j-creation-schedule > p {
  margin: 0;
}

.j-form-input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}

.j-form-input:focus {
  border-color: var(--accent);
}

.j-form-actions {
  padding: 14px 18px;
  border-top: 1px var(--border-style) var(--line-soft);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg);
}

/* ─── audience management ─── */
.j-audience-create-form,
.j-audience-summary,
.j-audience-editor,
.j-audience-editor > form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.j-audience-create-form .j-form-input,
.j-audience-editor .j-form-input {
  flex: 1 1 240px;
  min-width: 0;
}

.j-audience-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.j-audience-item {
  border-top: 1px var(--border-style) var(--line-soft);
  padding-top: 14px;
}

.j-audience-item:first-child {
  border-top: none;
  padding-top: 0;
}

.j-audience-name {
  flex: 1;
  margin: 0;
}

.j-audience-head {
  margin-left: auto;
}

.j-audience-head > [hidden] {
  display: none;
}

.j-audience-editor > form {
  flex: 1 1 320px;
}

@media (max-width: 720px) {
  .j-audience-create-form,
  .j-audience-summary,
  .j-audience-editor {
    align-items: stretch;
    flex-direction: column;
  }

  .j-audience-create-form .j-form-input {
    flex-basis: auto;
    width: 100%;
  }

  .j-audience-editor > form {
    flex: none;
    width: 100%;
  }

  .j-audience-head {
    margin-left: 0;
  }
}

/* ─── backup administration ─── */
.j-backup-settings {
  width: min(100%, 760px);
}

.j-backup-form {
  margin-bottom: 0;
}

.j-backup-form-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
}

.j-backup-field-wide {
  grid-column: 1 / -1;
}

.j-settings-loading,
.j-settings-error {
  margin: 0;
}

@media (max-width: 720px) {
  .j-backup-form-body {
    grid-template-columns: 1fr;
  }
}

.j-proto-row {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 14px 1fr auto auto;
  align-items: center;
  gap: 14px;
  border-top: 1px var(--border-style) var(--line-soft);
}

.j-proto-row:first-of-type {
  border-top: none;
}

.j-proto-row .j-dot {
  width: 10px;
  height: 10px;
  border-radius: 5px;
}

.j-proto-name {
  font-size: 14px;
  font-weight: 500;
}

.j-proto-addr {
  font-size: 12px;
  color: var(--muted);
}

.j-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--pill);
  font-weight: 500;
  font-family: var(--font-meta);
}

.j-badge.is-ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

.j-badge.is-warn {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 16%, transparent);
}

.j-code {
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.8;
}

.j-code .k {
  color: var(--muted);
}

/* ─── shared form field chrome ─── */

.j-edit-form-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted-soft);
  font-family: var(--font-meta);
}

.j-edit-form-input {
  width: 100%;
  font-size: 20px;
  font-weight: 600;
  border: none;
  border-bottom: 1px var(--border-style) var(--line);
  outline: none;
  background: transparent;
  color: var(--ink);
  padding: 6px 0;
  font-family: var(--font-body);
}

.j-edit-form-input:focus {
  border-bottom-color: var(--accent);
}

.j-edit-form-textarea {
  width: 100%;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: transparent;
  resize: vertical;
  padding: 10px 12px;
  font-family: var(--font-body);
  min-height: 300px;
}

.j-edit-form-textarea:focus {
  border-color: var(--accent);
}

/* ─── drafts list ─── */
.j-draft-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.j-draft-list > li:last-child .j-draft-row {
  border-bottom: none;
}

.j-draft-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 18px;
  border-bottom: 1px var(--border-style) var(--line-soft);
}

.j-draft-row-content {
  flex: 1;
  min-width: 0;
}

.j-draft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .j-draft-page {
    padding-inline: 4px;
  }

  .j-draft-row {
    flex-direction: column;
    padding-inline: 4px;
  }

  .j-draft-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .j-draft-actions .j-btn {
    padding-inline: 2px;
  }
}

/* ─── tables ─── */
.j-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}

.j-table thead tr {
  text-align: left;
  border-bottom: 1px var(--border-style) var(--line);
}

.j-table tbody tr {
  border-bottom: 1px var(--border-style) var(--line-soft);
}

.j-table tbody tr:last-child {
  border-bottom: none;
}

.j-table th,
.j-table td {
  padding: 8px 10px;
  vertical-align: top;
}

.j-table th {
  font-family: var(--font-meta);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

/* ─── save summary card ─── */
.j-save-summary {
  margin: 16px 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.j-save-summary > p {
  margin: 0;
}

.j-save-summary > a {
  align-self: flex-start;
}

/* ─── status messages ─── */
.j-loading {
  color: var(--muted);
  font-size: 13.5px;
  font-family: var(--font-meta);
  margin: 8px 0;
}

.error,
.success,
.draft-banner {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
  font-size: 13.5px;
  line-height: 1.4;
}

.error {
  display: block;
  color: var(--err);
  background: color-mix(in srgb, var(--err) 10%, transparent);
  border: 1px var(--border-style)
    color-mix(in srgb, var(--err) 30%, transparent);
}

.success {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
  border: 1px var(--border-style) color-mix(in srgb, var(--ok) 30%, transparent);
}

.draft-banner {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px var(--border-style)
    color-mix(in srgb, var(--warn) 32%, transparent);
  font-family: var(--font-meta);
  font-size: 12.5px;
}

/* ─── Theme management Studio ─── */
.j-themes-page {
  display: grid;
  gap: 16px;
  max-width: 980px;
}

.j-theme-scope-options,
.j-theme-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.j-theme-catalog {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.j-theme-catalog-item {
  background: var(--surface-raised);
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
  padding: 9px 11px;
  text-align: left;
  width: 100%;
}

.j-theme-catalog-item[aria-pressed="true"],
.j-theme-scope-options [aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.j-theme-editor,
.j-theme-presentation {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.j-theme-presentation {
  border: 1px var(--border-style) var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.j-theme-media-pool {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.j-theme-media-pool > li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px;
  border: 1px var(--border-style) var(--line-soft);
  border-radius: var(--radius-sm);
}

.j-theme-media-pool > li > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.j-theme-code {
  font-family: var(--font-mono);
  min-height: 10rem;
  resize: vertical;
}

.j-theme-status {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px var(--border-style)
    color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm);
  color: var(--ink);
  margin: 0;
  padding: 10px 12px;
}

.j-theme-preview {
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius-sm);
  height: 28rem;
  width: 100%;
}

@media (max-width: 720px) {
  .j-themes-page {
    padding: 12px 16px;
  }

  .j-theme-actions > .j-btn,
  .j-theme-scope-options > .j-btn {
    flex: 1 1 12rem;
  }
}

/* ─── Post Revision history ─── */
.j-history-table-wrap {
  overflow-x: auto;
  border: 1px var(--border-style) var(--line);
  border-radius: var(--radius);
}

.j-history-table-wrap .j-table {
  min-width: 720px;
}

.j-history-load-more {
  margin: 16px 0 0;
}

@media (max-width: 720px) {
  .j-history-summary .j-field-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* ─── narrow application shell ─── */
@media (max-width: 720px) {
  .j-shell {
    flex-direction: column;
  }

  .j-sidebar,
  .j-root[data-home="true"] .j-sidebar {
    box-sizing: border-box;
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px var(--border-style) var(--line);
  }

  .j-sidebar .j-search,
  .j-sidebar .j-sb-head {
    display: none;
  }

  .j-sidebar .j-nav {
    flex-direction: row;
    flex: 0 0 auto;
  }

  .j-sidebar .j-nav-item {
    white-space: nowrap;
  }

  .j-sidebar .j-sb-foot {
    flex: 0 0 auto;
    margin: 0 0 0 auto;
  }

  .j-main-region {
    width: 100%;
    height: auto;
  }

  .j-topbar,
  .j-timeline-order {
    padding-right: 16px;
    padding-left: 16px;
  }
}

/* ─── utilities ─── */
.j-spacer {
  flex: 1;
}

.j-icon {
  flex-shrink: 0;
}

.j-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.j-dot {
  display: inline-block;
}

/* ─── theme-specific structural tweaks (still triggered by variables only) ─── */
.j-root[data-chrome="rule"] .j-topbar {
  border-bottom-width: 1px;
}

/* ─── #181 pre-paint authed layout (ADR-0044 D4/D5) ─────────────
   The pre-paint <head> script sets html.authed BEFORE first paint (from the
   jaunder_auth marker), so these rules adjust the owner's chrome up-front and the
   CSR fill causes no visible reflow:
   - the anon-only Sign in / Register CTA on `/` is hidden for the owner (it never
     paints, so no flash);
   - the authed sidebar footer's height is reserved so the avatar row filling in
     doesn't shift the sidebar.
   The own-post action-column gutter is deliberately NOT reserved here: ownership
   is decided client-side from the marker (unknown at the anonymous projector
   paint), so a per-post reserve can't be pre-painted, and reserving it on every
   post would wrongly gutter non-owner posts. The empirical layout-shift (CLS)
   assertion for that bounded case is the deferred follow-up #202. */
html.authed .j-anon-only {
  display: none;
}

html.authed .j-sb-foot {
  min-height: 44px;
}
