/* ============================================================================
   Artifyde — viewer shell styles (trusted shell only; NOT iframe content).
   Warm "artifyde/paper" palette borrowed from the product proposal: off-white
   paper, ink text, a restrained terracotta accent, serif display headings.
   ========================================================================== */

/* The `hidden` attribute must beat author `display` rules. Without this,
   elements toggled via element.hidden (composer, sign-in CTA, toast) that also
   carry a `display: flex/block` rule never actually hide. */
[hidden] {
  display: none !important;
}

:root {
  --ink: #1a1714;
  --ink-soft: #4a423b;
  --muted: #8b8178;
  --muted-strong: #6b6357; /* AA-passing muted for small secondary text */
  --paper: #f6f1e7;
  --card: #fffdf8;
  --card-2: #fbf6ec;
  --line: #e3dccd;
  --line-soft: #efe8d9;
  --accent: #9a4d2e;
  --accent-soft: #c97a4e;
  --accent-wash: #f7ede2;
  --good: #3f6f4f;
  --good-wash: #e9f1ea;
  --good-border: #d4e3d6;
  --danger: #8a3324;

  /* Semantic surfaces that were once hardcoded inline. Naming them is what lets
     the dark theme below be a pure palette swap instead of a per-selector
     rewrite. */
  --accent-hover: #8a4226;        /* darker accent for :hover on solid buttons */
  --accent-border: #ecd9c8;       /* hairline around accent-wash chips/pills */
  --paper-glow: #fbf6ec;          /* warm radial highlight behind the page */
  --input-focus-bg: #fffaf0;      /* textarea/input background on focus */
  --anchor-quote-hover: #f4e4d4;  /* quoted-passage hover wash */
  --scrollbar-thumb: #e0d7c5;
  --toast-bg: var(--ink);         /* the toast is a dark chip in light mode… */
  --toast-fg: #fdf8ee;            /* …so it stays dark-on-light in both themes */
  /* Whole glyph images for the version picker — a var() can't reach inside a
     url() string, so each recolored glyph is swapped as a full background-image
     (chevron on the trigger, checkmark on the selected menu item). */
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239a4d2e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  --vp-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13'%3E%3Cpath d='M2 7l3 3 6-7' stroke='%239a4d2e' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.03), 0 6px 16px -12px rgba(60, 40, 20, 0.4);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.03), 0 12px 30px -18px rgba(60, 40, 20, 0.35);

  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;

  --bar-h: 60px;
  --sidebar-w: 380px;
  --radius: 14px;

  color-scheme: light;
}

/* ----------------------------------------------------------------- Dark theme
   The whole shell is variable-driven, so dark mode is a palette swap. The warm
   "artifyde/paper" character is preserved: surfaces are warm charcoals, not pure
   black, and the terracotta accent is lifted a few stops so it reads on a dark
   ground. Two entry points share one palette: an explicit, persisted choice
   (`[data-theme="dark"]`) and the OS preference (the media query). The media
   query is gated on `:not([data-theme="light"])` so a reader who deliberately
   picked light is never yanked back to dark by their OS. The toast keeps a dark
   chip + light text in both themes, so it overrides the swapped --toast-* vars. */
:root[data-theme="dark"] {
  --ink: #ece4d6;
  --ink-soft: #c6bdae;
  --muted: #968b7d;
  --muted-strong: #a99e8e; /* clears AA on the dark card surface */
  --paper: #1b1813;
  --card: #262019;
  --card-2: #2f2820;
  --line: #3b332a;
  --line-soft: #322b23;
  --accent: #d2895c;
  --accent-soft: #c97a4e;
  --accent-wash: #34281e;
  --good: #7ab489;
  --good-wash: #1f2a20;
  --good-border: #33422f;
  --danger: #e0795f;

  --accent-hover: #e09a6c;
  --accent-border: #4a3a2c;
  --paper-glow: #2a2118;
  --input-focus-bg: #332b21;
  --anchor-quote-hover: #3a2c20;
  --scrollbar-thumb: #3b332a;
  --toast-bg: #3a322a;
  --toast-fg: #ece4d6;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23d2895c' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  --vp-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13'%3E%3Cpath d='M2 7l3 3 6-7' stroke='%23d2895c' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.2), 0 6px 16px -12px rgba(0, 0, 0, 0.7);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 14px 34px -18px rgba(0, 0, 0, 0.75);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ece4d6;
    --ink-soft: #c6bdae;
    --muted: #968b7d;
    --muted-strong: #a99e8e;
    --paper: #1b1813;
    --card: #262019;
    --card-2: #2f2820;
    --line: #3b332a;
    --line-soft: #322b23;
    --accent: #d2895c;
    --accent-soft: #c97a4e;
    --accent-wash: #34281e;
    --good: #7ab489;
    --good-wash: #1f2a20;
    --good-border: #33422f;
    --danger: #e0795f;

    --accent-hover: #e09a6c;
    --accent-border: #4a3a2c;
    --paper-glow: #2a2118;
    --input-focus-bg: #332b21;
    --anchor-quote-hover: #3a2c20;
    --scrollbar-thumb: #3b332a;
    --toast-bg: #3a322a;
    --toast-fg: #ece4d6;
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23d2895c' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  --vp-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13'%3E%3Cpath d='M2 7l3 3 6-7' stroke='%23d2895c' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

    --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.2), 0 6px 16px -12px rgba(0, 0, 0, 0.7);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 14px 34px -18px rgba(0, 0, 0, 0.75);

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--paper-glow), transparent),
    var(--paper);
  /* Keep the glow a single highlight. Without this, a tall page whose body is
     only viewport-high (e.g. /docs) re-tiles the gradient every viewport,
     painting horizontal seams/color bands as you scroll. */
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ----------------------------------------------------------------- App bar */

.app-bar {
  height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 20px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Left cluster: brand, a hairline divider, then the page title inline. Keeping
   it on one row (rather than a stacked brand block) is what lets the bar read
   calm even with a long title. */
.bar-left {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  text-decoration: none;
  color: inherit;
}
a.brand:hover { text-decoration: none; }

.bar-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  flex: none;
}

.app-title {
  font: 500 13.5px/1.2 var(--sans);
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 34vw;
}

/* Gallery active/archived toggle — a quiet segmented control in the bar. */
.gallery-views {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  margin-left: 4px;
  padding: 2px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
}
.gallery-view {
  padding: 4px 11px;
  border-radius: 999px;
  font: 600 12px/1 var(--sans);
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.gallery-view:hover { color: var(--ink-soft); text-decoration: none; }
.gallery-view.is-active {
  color: var(--ink);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), var(--shadow-sm);
  flex: none;
}
.mark.big { width: 56px; height: 56px; font-size: 32px; border-radius: 14px; }

.brand-name {
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.bar-tools {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

/* Version picker — a compact pill trigger that opens a custom menu of versions.
   It replaces a native <select> so the open list stays on the warm paper palette
   instead of the OS popup chrome. The trigger carries the version author's initial
   chip (full email on hover) plus the "v2 · current" label. A stale snapshot tints
   the pill border; the "· current" label and stale banner carry freshness in
   words, so there's no cryptic status dot. */
.version-picker {
  position: relative;
  display: inline-flex;
}
.vp-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px 5px 6px;
  box-shadow: var(--shadow-sm);
  font: 600 13px/1 var(--sans);
  color: var(--ink);
  cursor: pointer;
  max-width: 240px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.vp-trigger:hover { background: var(--card-2); border-color: var(--accent-soft); }
.vp-trigger:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 1px;
}
.vp-author {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  background: var(--accent-wash);
  color: var(--accent);
  font: 700 11px/1 var(--sans);
  border: 1px solid var(--line-soft);
}
.vp-current {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vp-caret {
  width: 10px;
  height: 7px;
  flex: none;
  margin-left: 2px;
  background: var(--select-arrow) no-repeat center / 10px 7px;
  transition: transform 0.18s ease;
}
.vp-trigger[aria-expanded="true"] .vp-caret { transform: rotate(180deg); }

.version-picker.is-stale .vp-trigger { border-color: var(--accent-soft); }

/* The version list — styled like the account menu so the two dropdowns read as
   one family. Right-aligned to the trigger so it never spills past the viewport
   edge (the picker lives near the right side of the navbar). */
.vp-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  max-height: min(60vh, 360px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}
.vp-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  font: 600 13px/1 var(--sans);
  color: var(--ink-soft);
  text-decoration: none;
}
.vp-item:hover { background: var(--card-2); color: var(--ink); text-decoration: none; }
.vp-item:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -1px; }
.vp-item.is-selected { color: var(--ink); }
.vp-check {
  width: 14px;
  height: 14px;
  flex: none;
  opacity: 0;
  background: var(--vp-check) no-repeat center / 13px 13px;
}
.vp-item.is-selected .vp-check { opacity: 1; }
.vp-item-label { flex: 1; white-space: nowrap; }
.vp-tag {
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 999px;
  flex: none;
}
.vp-tag.is-current { background: var(--good-wash); color: var(--good); }

/* Account menu — a single avatar collapses the viewer's identity, the
   owner-only archive control, and sign-out into one dropdown. The gallery
   reuses the same menu (identity · Docs · sign-out). */
.acct { position: relative; display: inline-flex; }
.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  font: 700 13px/1 var(--sans);
  cursor: pointer;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.avatar:hover { background: var(--accent-hover); }
.avatar:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.acct-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 236px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
  transition: width 0.16s ease;
}
/* The drill-down into the share view widens the popover to fit the controls. */
.acct-menu.is-sharing { width: 312px; }
.acct-panel[hidden] { display: none; }
/* Share… trigger drills down, so it gets a forward chevron pinned to the right. */
.menu-chevron { margin-left: auto; color: var(--muted); font-size: 15px; line-height: 1; }
.acct-id {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 4px;
}
.acct-email {
  font: 600 12px/1.3 var(--mono);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acct-sub { font-size: 11.5px; color: var(--muted); }
.acct-menu .menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  font: 600 13px/1 var(--sans);
  color: var(--ink-soft);
  cursor: pointer;
  text-decoration: none;
}
/* Some menu items are real <form> submits (e.g. the gallery's no-JS sign-out);
   let the button fill the row like a plain menu item. */
.acct-menu form { display: contents; }
.acct-menu .menu-item:hover { background: var(--card-2); }
.acct-menu .menu-item.danger { color: var(--danger); }
.acct-menu .menu-item:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: -1px;
}

/* Buttons */
.primary-btn,
.ghost-btn,
.link-btn {
  font-family: var(--sans);
  cursor: pointer;
  border-radius: 9px;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.05s ease;
}
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.55; cursor: default; }

.ghost-btn {
  background: var(--card);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}
.ghost-btn:hover { background: var(--card-2); border-color: var(--accent-soft); }

/* Theme toggle — a small icon button shared by every shell bar (viewer,
   gallery, docs). The crescent glyph is theme-agnostic (it reads as "switch
   theme" in both modes), so it needs no JS to swap the icon; only the
   aria-label/title flip to announce the destination state. */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.theme-toggle:hover { border-color: var(--accent-soft); color: var(--accent); }
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}
.theme-toggle-icon {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  /* Carve a crescent out of a filled disc with an offset inset shadow. */
  box-shadow: inset -4px -2px 0 0 currentColor;
  flex: none;
}

/* Comments sidebar toggle (full view). Lives in the comments header as a small
   icon button (a panel glyph). When the sidebar is hidden it's unreachable, so
   the .sidebar-reopen edge tab below takes over. */
.sidebar-toggle {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  flex: none;
}
.sidebar-toggle:hover { border-color: var(--accent-soft); color: var(--accent); }
.sidebar-toggle-icon {
  width: 15px;
  height: 12px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  position: relative;
  flex: none;
  opacity: 0.85;
}
.sidebar-toggle-icon::after {
  content: "";
  position: absolute;
  top: -1.5px;
  bottom: -1.5px;
  right: -1.5px;
  width: 5px;
  border: 1.5px solid currentColor;
  border-radius: 0 3px 3px 0;
  background: currentColor;
}

/* Edge tab that re-opens the sidebar once it's been collapsed. Hidden until
   the full-view class lands on <html>; rendered in the Artifyde accent so it
   reads as the one live control on the seam. */
.sidebar-reopen {
  position: absolute;
  top: 20px;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-right: 0;
  border-radius: 10px 0 0 10px;
  color: #fff;
  font: 650 12px/1 var(--sans);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 5;
  /* Parked off-screen while the sidebar is shown; slides in when hidden. */
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.sidebar-reopen:hover { background: var(--accent-hover); }
.sidebar-reopen .sidebar-toggle-icon { opacity: 1; }
.sidebar-hidden .sidebar-reopen {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 2px 4px;
  font-size: 12px;
  font-weight: 600;
}
.link-btn:hover { color: var(--accent-hover); }
.link-btn-danger { color: var(--danger); }
.link-btn-danger:hover { color: var(--danger); opacity: 0.8; }

/* ----------------------------------------------------------- Stale banner */
.stale-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 20px;
  font-size: 13px;
  color: var(--ink-soft);
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border-bottom: 1px solid var(--line);
}
.stale-banner b { color: var(--accent); }

/* -------------------------------------------------------- Archived banner */
.archived-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 20px;
  font-size: 13px;
  color: var(--ink-soft);
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border-bottom: 1px solid var(--line);
}
.archived-banner b { color: var(--ink); }

/* ---------------------------------------------------------------- Stage */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  height: calc(100vh - var(--bar-h));
  height: calc(100dvh - var(--bar-h));
  /* Anchors the .sidebar-reopen edge tab; clips the sidebar as its track
     collapses so it slides off the seam instead of leaving a gap. */
  position: relative;
  overflow: hidden;
  transition: grid-template-columns 0.24s ease;
}
body:has(.stale-banner) .stage,
body:has(.archived-banner) .stage {
  height: auto;
  min-height: calc(100vh - var(--bar-h));
}

/* Full view: the in-header toggle hides the sidebar and hands the whole stage to
   the rendered page. The class is set on <html> (early head script + app.js), so
   the collapsed track is the painted state on load — no open→shut flash. The
   sidebar keeps its full width and is clipped by the stage, so collapsing reads
   as a slide-out rather than a reflow. */
.sidebar-hidden .stage {
  grid-template-columns: minmax(0, 1fr) 0;
}
@media (prefers-reduced-motion: reduce) {
  .stage,
  .sidebar-reopen {
    transition: none;
  }
}

.canvas {
  padding: 0;
  min-width: 0;
  min-height: 0;
  position: relative; /* anchors the floating markup picker */
}
.agent-frame {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  display: block;
}

/* ------------------------------------------------- Parent-owned highlights
   On scripts-enabled pages (pages.allow_scripts) the embed runs the artifact's
   own JS, so highlight marks are rendered HERE, in the trusted shell, from
   bridge-reported geometry (overlay.js) — agent JS can't delete or click-hijack
   them. Visuals mirror the in-frame marks (markup-bridge.ts MARK_CSS). The
   layer is pointer-transparent so it never blocks the iframe; only the marks
   themselves are clickable. */
.hl-overlay {
  position: absolute;
  inset: 0;
  overflow: hidden; /* rects near the fold must not leak outside the pane */
  pointer-events: none;
  z-index: 20; /* over the iframe, under the picker dock (30) */
}
.hl-overlay-mark {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  background: rgba(201, 122, 78, 0.26);
  box-shadow: inset 0 0 0 1px rgba(154, 77, 46, 0.3);
  border-radius: 2px;
  transition: background-color 0.15s ease;
}
.hl-overlay-mark:hover {
  background: rgba(201, 122, 78, 0.42);
}
.hl-overlay-mark[data-active] {
  background: rgba(201, 122, 78, 0.6);
  box-shadow: inset 0 0 0 1px rgba(154, 77, 46, 0.6);
}
.hl-overlay-mark[data-resolved] {
  background: rgba(63, 111, 79, 0.18);
  box-shadow: inset 0 0 0 1px rgba(63, 111, 79, 0.28);
}

/* ------------------------------------------------- Floating markup picker
   Docked over the rendered page: one control, two explicit modes (Text /
   Element). app.js sets [data-mode] + aria-pressed and relays the mode to the
   markup bridge; the LED and status line follow the armed state. */
.picker-dock {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 6px 14px 6px 12px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.picker-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  flex: none;
}
.picker-dock:not([data-mode="off"]) .picker-led {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-soft);
}
.picker-modes {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
}
.picker-mode {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 6px 13px;
  border-radius: 999px;
  font: 600 12.5px/1 var(--sans);
  color: var(--ink-soft);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.picker-mode:hover { color: var(--accent); }
.picker-mode[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.picker-mode:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}
.picker-ico {
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1;
}
.picker-status {
  font: 500 11px/1.2 var(--mono);
  letter-spacing: 0.02em;
  color: var(--muted-strong);
  padding-right: 4px;
  white-space: nowrap;
}
.picker-dock:not([data-mode="off"]) .picker-status { color: var(--accent); }
@media (max-width: 700px) {
  .picker-status { display: none; }
  .picker-dock { padding-right: 8px; }
}

/* ---------------------------------------------------------------- Sidebar */
.sidebar {
  width: var(--sidebar-w); /* fixed so the collapsing grid track clips, not reflows */
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, var(--card), var(--card-2));
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 20px 0;
}
.sidebar-head h2 {
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: -0.01em;
  margin: 0;
}
.version-pill {
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-wash);
  border: 1px solid var(--accent-border);
  padding: 5px 9px;
  border-radius: 999px;
  flex: none;
}
.sidebar-sub {
  margin: 6px 20px 0;
  font-size: 12.5px;
  /* --muted (#8b8178) on the sidebar's near-white surface is only ~3.4:1 at
     this size — below WCAG AA. --muted-strong keeps the hushed hint tone while
     clearing 4.5:1. */
  color: var(--muted-strong);
}

/* Visually hidden but exposed to assistive tech (heading nav, screen readers).
   Absolutely positioned so it never participates in layout/grid flow. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.thread-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.loading,
.empty-state {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 28px 12px;
}
.empty-state .emoji { font-size: 22px; display: block; margin-bottom: 6px; }

/* Comment thread cards */
.thread {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 14px 14px 12px;
}
.thread.resolved { opacity: 0.72; background: var(--card-2); }

/* Collapse controls -------------------------------------------------------- */
.sidebar-head-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.collapse-all-btn { font-size: 11px; color: var(--muted); }
.collapse-all-btn:hover { color: var(--accent); }

/* Chevron used by the per-thread caret and the resolved group. Bare borders so
   it inherits currentColor; rotation encodes the open/closed state. */
.caret {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); /* right = closed (base) */
  transition: transform 0.15s ease;
  flex: none;
}

.thread-toggle {
  position: absolute;
  top: 11px;
  right: 9px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.thread-toggle:hover { background: var(--card-2); color: var(--ink-soft); }
.thread-toggle .caret { transform: rotate(45deg); } /* down = expanded */
.thread.collapsed .thread-toggle .caret { transform: rotate(-45deg); }

/* Leave room for the caret so a long author/email doesn't run under it. */
.thread > .comment-head { padding-right: 22px; }

.thread-reply-count {
  display: none;
  margin-top: 8px;
  font: 600 11px/1 var(--mono);
  color: var(--muted);
}
.thread.collapsed .thread-reply-count { display: block; }
.thread.collapsed > .comment-body {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread.collapsed .replies,
.thread.collapsed > .comment-actions,
.thread.collapsed > .anchor-quote { display: none; }

/* Resolved group ----------------------------------------------------------- */
.resolved-group {
  border-top: 1px dashed var(--line);
  margin-top: 4px;
  padding-top: 12px;
}
.resolved-group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--muted);
}
.resolved-group-head:hover { color: var(--ink-soft); }
.resolved-group.open .resolved-group-head .caret { transform: rotate(45deg); }
.rg-check { color: var(--good); font-size: 12px; }
.rg-label {
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.rg-count {
  font: 600 10px/1 var(--mono);
  color: var(--good);
  background: var(--good-wash);
  border: 1px solid var(--good-border);
  padding: 3px 7px;
  border-radius: 999px;
}
.resolved-group-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}
/* The group label already says "Resolved"; the per-thread tag is redundant here. */
.resolved-group-body .resolved-tag { display: none; }

.comment-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
}
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  font: 700 11px/1 var(--sans);
  color: #fff;
  background: var(--accent-soft);
  text-transform: uppercase;
}
.comment-meta { min-width: 0; line-height: 1.25; }
.comment-author {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comment-time { font: 500 11px/1 var(--mono); color: var(--muted); }
.resolved-tag {
  margin-left: auto;
  font: 600 9px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--good);
  background: var(--good-wash);
  border: 1px solid var(--good-border);
  padding: 4px 7px;
  border-radius: 999px;
  flex: none;
}

.comment-body {
  font-size: 14px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.comment-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
}

/* Replies */
.replies {
  margin-top: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reply .avatar { width: 22px; height: 22px; font-size: 10px; }
.reply .comment-author { font-size: 12.5px; }

/* Inline reply composer */
.reply-form {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.reply-form textarea,
.composer textarea {
  width: 100%;
  resize: vertical;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
}
.reply-form textarea:focus,
.composer textarea:focus {
  outline: none;
  border-color: var(--accent-soft);
  background: var(--input-focus-bg);
}
.reply-form-actions { display: flex; gap: 8px; }

/* Composer at sidebar bottom */
.composer {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 14px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none;
}
.composer textarea { rows: 3; min-height: 64px; }
.composer-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ------------------------------------------------------------------ Markup */

/* Pending-selection chip above the composer (the passage being marked up). */
.anchor-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: var(--accent-wash);
  border: 1px solid var(--accent-border);
  border-radius: 9px;
  font-size: 12.5px;
}
.anchor-chip-label {
  font: 600 9px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  flex: none;
}
.anchor-chip-quote {
  min-width: 0;
  flex: 1;
  color: var(--ink-soft);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.anchor-chip-clear {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.anchor-chip-clear:hover { color: var(--accent); }

/* Quoted passage shown on an anchored comment; clicks scroll to the highlight. */
.anchor-quote {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0 0 8px;
  padding: 6px 9px;
  background: var(--accent-wash);
  border: 1px solid var(--accent-border);
  border-left: 3px solid var(--accent-soft);
  border-radius: 7px;
  color: var(--ink-soft);
  font: italic 12.5px/1.4 var(--serif);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.anchor-quote:hover { background: var(--anchor-quote-hover); text-decoration: none; }

/* Brief flash when a thread is focused from a highlight click in the doc. */
.thread.flash { animation: thread-flash 1.2s ease; }
@keyframes thread-flash {
  0% { box-shadow: 0 0 0 2px var(--accent-soft); }
  100% { box-shadow: var(--shadow-sm); }
}

.signin-cta {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 16px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  flex: none;
}
.signin-copy { margin: 0; font-size: 13px; color: var(--ink-soft); }

/* Inline sign-in panel (email prompt) injected by app.js */
.signin-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.signin-panel input[type="email"] {
  width: 100%;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
}
.signin-panel input[type="email"]:focus {
  outline: none;
  border-color: var(--accent-soft);
  background: var(--input-focus-bg);
}
.signin-note {
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--accent-wash);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.45;
}
.signin-note .dev-link {
  display: block;
  margin-top: 6px;
  font: 500 11.5px/1.4 var(--mono);
  word-break: break-all;
}

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 13px;
  font-weight: 550;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, 0.5);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 86vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ---------------------------------------------------------------- 404 */
.error-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.error-card {
  text-align: center;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 44px 36px;
  box-shadow: var(--shadow);
}
.error-card .mark { margin: 0 auto 18px; }
.error-card h1 {
  font-family: var(--serif);
  font-size: 40px;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.error-card p { color: var(--ink-soft); font-size: 15px; margin: 0; }
.error-card code {
  font: 500 13px/1 var(--mono);
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 6px;
}

/* Dedicated sign-in card (/login) — tighten the rhythm between the copy and
   the email form, which the shared .error-card spacing leaves cramped. */
.signin-card .signin-copy { font-size: 14px; line-height: 1.55; }
.signin-card .signin-copy + .signin-copy { margin-top: 4px; }
.signin-card .signin-panel { margin-top: 24px; }
/* The post-submit confirmation replaces the form via outerHTML, so it must
   carry the same top margin the panel had — otherwise it sits flush to the copy. */
.signin-card .signin-note { margin-top: 24px; }

/* ---------------------------------------------------------------- Scrollbar */
.thread-list::-webkit-scrollbar { width: 10px; }
.thread-list::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}

/* ============================================================ Responsive */
@media (max-width: 900px) {
  :root { --sidebar-w: 340px; }
}

@media (max-width: 760px) {
  /* Sidebar stacks BELOW the iframe on narrow screens, so it's a normal page
     section rather than a collapsing grid track. The desktop grid-track
     collapse is inert here, so collapsing folds the comment body instead (see
     .sidebar-hidden rules below) — keeping the in-header toggle reachable so
     the artifact can take the full screen and the comments fold back open. */
  .stage,
  .sidebar-hidden .stage {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  /* A shorter frame so the comments stacked below aren't buried under a
     near-full-height artifact — the comments header peeks into view sooner. */
  .agent-frame { height: 52vh; min-height: 300px; }
  .sidebar {
    /* Fill the stacked column. The desktop fixed width is only there so the
       collapsing grid track clips instead of reflowing; in a single-column
       layout it would leave a gap (or overflow) on the right. */
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: none;
  }
  /* The reopen edge tab pins to the desktop grid seam — meaningless stacked, so
     drop it. The in-header toggle stays: it's how comments collapse on mobile. */
  .sidebar-reopen { display: none; }

  /* Collapsed: fold the comments down to just their header row and hand the
     freed height to the artifact. Tapping the header toggle flips it back. */
  .sidebar-hidden .sidebar-sub,
  .sidebar-hidden .thread-list,
  .sidebar-hidden .composer,
  .sidebar-hidden .signin-cta,
  .sidebar-hidden .collapse-all-btn { display: none; }
  .sidebar-hidden .sidebar-head { padding-bottom: 16px; }
  .sidebar-hidden .agent-frame { height: calc(100dvh - var(--bar-h) - 64px); }

  .thread-list { overflow: visible; }
  .bar-tools { gap: 10px; }
  /* Drop the inline page title under the divider; it still lives in the
     document <title>, and the bar stays brand · version · avatar. */
  .bar-divider, .app-title { display: none; }
}

@media (max-width: 460px) {
  .app-bar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .stage,
  .sidebar-hidden .stage { height: auto; }
  /* Trim the artifact a touch more on phones, and tighten the comments column
     gutters so the cards get the full width instead of cramped margins. */
  .agent-frame { height: 46vh; min-height: 260px; }
  .vp-trigger { max-width: 150px; }
  .sidebar-head { padding: 16px 14px 0; }
  .sidebar-sub { margin: 6px 14px 0; }
  .thread-list { padding: 14px 14px 8px; }
  .composer { padding: 12px 14px 14px; }
  .signin-cta { padding: 14px 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================ Gallery
   Signed-in home: "Your artifacts". Thumbnails are sandboxed iframes pointed
   at /raw, zoomed out via a transform so a full artifact reads at tile scale. */

.gallery-page { min-height: 100dvh; }

/* Inline logout form inside the app bar shouldn't add layout. */
.app-bar form { margin: 0; display: inline-flex; }

.gallery-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 22px 56px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

/* Tile */
.tile {
  --z: 0.3; /* thumbnail zoom-out: artifact viewport ≈ tile-width / z */
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  color: var(--ink);
  text-decoration: none;
  transition: box-shadow 0.15s ease, transform 0.08s ease, border-color 0.15s ease;
}
.tile:hover {
  text-decoration: none;
  border-color: var(--accent-soft);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.tile:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

.tile-preview {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--card-2); /* warm placeholder shows through until the frame paints */
  border-bottom: 1px solid var(--line);
}
/* Faint monogram behind the thumbnail: gives a loading (or never-painted) tile an
   intentional surface instead of a blank white box. The frame fades in over it. */
.tile-ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 600 34px/1 var(--serif);
  color: var(--line-soft);
  background: var(--card-2);
  user-select: none;
}
.tile-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--z));
  height: calc(100% / var(--z));
  transform: scale(var(--z));
  transform-origin: top left;
  border: 0;
  background: #fff;
  pointer-events: none; /* clicks fall through to the tile anchor */
  opacity: 0;
  transition: opacity 0.3s ease;
}
.tile-frame.is-loaded { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .tile-frame { transition: none; }
}
.tile-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 600 12px/1 var(--mono);
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--card-2);
}
/* Subtle top sheen so busy artifacts don't fight the card chrome. */
.tile-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 253, 248, 0.12), transparent 22%);
}
/* Visibility badge: who can reach this artifact, at a glance. Sits over the
   preview's top-right corner. Private is the louder accent state (it's the
   default and the one worth noticing); public reads as a quiet neutral chip. */
.tile-vis {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  padding: 3px 8px;
  border-radius: 999px;
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.tile-vis[data-vis="private"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, rgba(255, 253, 248, 0.7));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.tile-vis[data-vis="public"] {
  color: var(--muted);
  background: rgba(255, 253, 248, 0.7);
  border: 1px solid var(--line);
}

/* Archived marker: top-left so it never collides with the visibility badge.
   The tile itself reads slightly muted to signal a frozen, shelved artifact. */
.tile-archived {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 3px 8px;
  border-radius: 999px;
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.7);
  border: 1px solid var(--line);
  backdrop-filter: blur(4px);
}
.tile.is-archived .tile-preview { opacity: 0.82; }
.tile.is-archived:hover .tile-preview { opacity: 1; }

.tile-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px 13px;
  min-width: 0;
}
.tile-title {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-meta {
  font: 600 11px/1.3 var(--mono);
  letter-spacing: 0.02em;
  color: var(--accent);
}
.tile-time { font: 500 11px/1.3 var(--mono); color: var(--muted); }

/* ---- Empty state ---- */
/* Gallery search — a quiet, full-row field above the grid. Submits on Enter
   (plain GET back to '/'), so it needs no script. */
.gallery-search { margin: 0 0 18px; }
.gallery-search-input {
  width: 100%;
  max-width: 420px;
  padding: 9px 14px;
  font: 500 14px/1.4 var(--sans);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.gallery-search-input::placeholder { color: var(--ink-soft); opacity: 0.7; }
.gallery-search-input:focus-visible {
  outline: none;
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-soft) 25%, transparent);
}

.gallery-empty {
  text-align: center;
  max-width: 440px;
  margin: 8vh auto 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 44px 36px;
  box-shadow: var(--shadow);
}
.gallery-empty .mark { margin: 0 auto 18px; }
.gallery-empty h2 {
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}
.gallery-empty p { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 18px; }
.gallery-cmd {
  margin: 0;
  text-align: left;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
}
.gallery-cmd code {
  font: 500 12.5px/1.5 var(--mono);
  color: var(--ink-soft);
  white-space: pre;
}

@media (max-width: 520px) {
  .gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
  .gallery-main { padding: 18px 14px 40px; }
}

/* ---- owner share dialog ------------------------------------------------- */
/* Inline share panel — a second view inside the account dropdown (no modal).
   The dropdown widens (.is-sharing) to fit; its own padding wraps the panel. */
.acct-panel-share {
  display: flex;
  flex-direction: column;
  padding: 4px 6px 6px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
.acct-panel-share form { display: block; }
.share-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 14px;
}
.share-head h2 {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 650;
  margin: 0;
  color: var(--ink);
}
.share-back {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  padding: 2px 8px 4px;
  border-radius: 8px;
}
.share-back:hover { background: var(--card-2); color: var(--ink); }
.share-back:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -1px; }

.share-vis {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.share-vis-opt {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: 11px 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  font-family: var(--sans);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.share-vis-opt:hover { border-color: var(--accent-soft); }
.share-vis-opt.is-active {
  border-color: var(--accent);
  background: var(--accent-wash);
}
.share-vis-title { font-size: 14px; font-weight: 650; color: var(--ink); }
.share-vis-sub { font-size: 11.5px; color: var(--muted-strong); line-height: 1.3; }

.share-invite-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.share-invite-row { display: flex; gap: 8px; }
.share-email {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 13px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
}
.share-email:focus { outline: none; border-color: var(--accent-soft); }
.share-invite-note { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }

.share-grants { list-style: none; margin: 12px 0 0; padding: 0; max-height: 132px; overflow-y: auto; }
.share-grant {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
}
.share-grant-email { font-size: 13px; color: var(--ink); overflow-wrap: anywhere; }
.share-grant-remove {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  padding: 4px 6px;
  border-radius: 7px;
  flex: none;
}
.share-grant-remove:hover { background: var(--card-2); }
.share-grants-empty { font-size: 12.5px; color: var(--muted); padding: 8px 0 2px; }

.share-link {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.share-link-input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink-soft);
}
.share-link .ghost-btn { flex: none; }

/* On narrow screens a 312px right-anchored popover can clip; let the share view
   take nearly the full width instead. */
@media (max-width: 420px) {
  .acct-menu.is-sharing {
    width: calc(100vw - 24px);
    max-width: 360px;
  }
}

/* ============================================================================
   VERSION COMPARE  (GET /p/:id/compare)
   Two renders side by side + the from-version's comments in a right sidebar.
   The source diff is a separate mode (?mode=source). Built on the shared design
   tokens, so the dark theme is a free palette swap.
   ========================================================================= */

.cmp-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: 12px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.cmp-pill b { color: var(--good); }
.cmp-arrow { color: var(--muted-strong); font-weight: 400; }

/* Base-version picker (you can only compare up, so the picker chooses the base
   and `to` is implied). */
.cmp-pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.cmp-pick-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted-strong);
  font-weight: 600;
}
.cmp-pick select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.vp-compare { white-space: nowrap; }

/* Preview ⇄ Source segmented toggle. */
.cmp-mode {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--card-2);
}
.cmp-mode-btn {
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted-strong);
  text-decoration: none;
  border: 0;
}
.cmp-mode-btn + .cmp-mode-btn { border-left: 1px solid var(--line); }
.cmp-mode-btn.is-active { background: var(--card); color: var(--ink); }
.cmp-mode-btn:not(.is-active):hover { color: var(--ink); }

/* Scroll-lock toggle. */
.cmp-lock {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted-strong);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.cmp-lock:hover { color: var(--ink); border-color: var(--accent-soft); }
.cmp-lock-icon {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.cmp-lock[aria-pressed='true'] {
  color: var(--accent);
  background: var(--accent-wash);
  border-color: var(--accent-border);
}
.cmp-lock[aria-pressed='true'] .cmp-lock-icon { background: var(--accent); }

/* ---- preview layout: two panes + a right comments sidebar -------------- */
.cmp-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  height: calc(100vh - var(--bar-h));
  height: calc(100dvh - var(--bar-h));
  overflow: hidden;
}
.cmp-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  overflow: hidden;
}
.cmp-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.cmp-pane-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
  font-size: 13px;
}
.cmp-vtag { font-weight: 700; }
.cmp-vauthor {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted-strong);
}
.cmp-vbadge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
}
.cmp-vbadge.old {
  background: var(--paper);
  color: var(--muted-strong);
  border: 1px solid var(--line);
}
.cmp-vbadge.cur {
  background: var(--good-wash);
  color: var(--good);
  border: 1px solid var(--good-border);
}
/* Positioned wrapper so the shell's highlight overlay (.hl-overlay) aligns
   exactly with the iframe box, below the pane header. */
.cmp-frame-wrap {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}
.cmp-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}

/* ---- right-hand comments sidebar (feedback left on the from version) --- */
.cmp-sidebar {
  width: var(--sidebar-w);
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, var(--card), var(--card-2));
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.cmp-sidebar .thread-list { flex: 1; }
.cmp-sidebar .thread { cursor: pointer; }
/* Anchored cards advertise that they jump the left pane on click. */
.cmp-sidebar .thread:has(.anchor-quote):hover { border-color: var(--accent-soft); }

/* ---- source-diff mode (a separate full-width page) --------------------- */
.cmp-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 20px 48px;
}
.cmp-source {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.cmp-source-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.cmp-source-head h2 { margin: 0; font-size: 14px; }
.cmp-source-hint { color: var(--muted-strong); font-size: 12px; }
.cmp-empty { padding: 22px 16px; color: var(--muted-strong); font-size: 13.5px; }
.diff { font: 12.5px/1.7 var(--mono); }
.drow { display: grid; grid-template-columns: 48px 48px 1fr; align-items: baseline; }
.drow .gut {
  text-align: right;
  padding: 0 10px;
  color: var(--muted);
  border-right: 1px solid var(--line-soft);
  user-select: none;
}
.drow .code { padding: 0 14px; white-space: pre-wrap; word-break: break-word; }
.drow.add { background: var(--good-wash); }
.drow.add .code::before { content: "+ "; color: var(--good); font-weight: 700; }
.drow.del { background: var(--accent-wash); }
.drow.del .code::before { content: "- "; color: var(--accent); font-weight: 700; }
.drow.ctx .code::before { content: "\00a0\00a0"; }
.drow.gap { background: var(--card-2); }
.drow.gap .code { color: var(--muted-strong); font-style: italic; }
.drow.gap .code::before { content: "\00a0\00a0"; }

/* ---- single-version "nothing to compare" state ------------------------ */
.cmp-blank {
  max-width: 520px;
  margin: 14vh auto 0;
  padding: 0 24px;
  text-align: center;
}
.cmp-blank h1 { font-size: 22px; margin: 0 0 10px; }
.cmp-blank p { color: var(--muted-strong); line-height: 1.6; margin: 0 0 22px; }

@media (max-width: 960px) {
  /* Stack the comments under the panes; let the page scroll as a whole. */
  .cmp-stage {
    display: block;
    height: auto;
    overflow: visible;
  }
  .cmp-split { height: 70vh; }
  .cmp-sidebar {
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .cmp-pill { display: none; }
}
@media (max-width: 640px) {
  .cmp-split { grid-template-columns: 1fr; height: auto; }
  .cmp-pane { min-height: 60vh; }
  .cmp-pick .cmp-pick-field { font-size: 0; }
}
