/* Ghostwriter. Built on polr.css tokens; light theme only.
   The page is a workspace: app bar, toolbar, outline, a page on a canvas, an agent rail, a status bar. */
html { color-scheme: light; }
:root { --space-5: 20px; } /* the design tokens skip 5 */
body { margin: 0; background: var(--ground); --appbar: 56px; --subbar: 48px; --statusbar: 28px; }
[hidden] { display: none !important; }
.grow { flex: 1; min-width: var(--space-2); }

/* App bar */
.appbar { position: sticky; top: 0; z-index: 30; height: var(--appbar); display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-4); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; flex: none; }
.brand:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--radius-sm); }
.logo { display: flex; align-items: flex-end; gap: 3px; width: 28px; height: 28px; padding: 5px; border-radius: 8px; background: var(--ink); }
.logo i { display: block; flex: 1; border-radius: 2px; background: var(--accent); }
.logo i:nth-child(1) { height: 60%; }
.logo i:nth-child(2) { height: 100%; background: var(--amber); }
.logo i:nth-child(3) { height: 40%; background: var(--violet); }
.brand-name { font: 700 18px/24px var(--font-display); letter-spacing: -0.01em; }
.vsep { flex: none; width: 1px; height: 24px; background: var(--line); }
.docmeta { display: flex; flex-direction: column; min-width: 0; }
.docname { font: 600 14px/18px var(--font-sans); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36ch; }
.savestate { font: 400 12px/16px var(--font-sans); color: var(--ink-muted); }
.btn-sm { height: 34px; padding: 0 14px; }
.presence { flex: none; display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px 0 4px; border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); font: 600 12px/16px var(--font-sans); color: var(--ink-muted); }
.avatar { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--sunken); color: var(--ink-muted); }
.presence.on { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.presence.on .avatar { background: var(--violet); color: #fff; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--good); }
.presence.busy .avatar { animation: pulse 900ms ease-in-out infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 0 2px var(--surface), 0 0 0 6px color-mix(in srgb, var(--violet) 45%, transparent); } }

/* Toolbar row */
.subbar { position: sticky; top: var(--appbar); z-index: 25; height: var(--subbar); display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-4); background: var(--surface); border-bottom: 1px solid var(--line); }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 3px; background: var(--ground); border-radius: var(--radius-pill); overflow-x: auto; scrollbar-width: none; min-width: 0; }
.toolbar::-webkit-scrollbar { display: none; }
.tool { flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; transition: background-color 140ms ease-out, transform 140ms ease-out; }
.tool:hover { background: var(--sunken); }
.tool:active { transform: translateY(1px); }
.tool:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tool[aria-pressed="true"] { background: var(--violet-soft); color: var(--violet-text); }
.tool[disabled] { opacity: 0.35; cursor: not-allowed; background: transparent; }
.tool-sm { width: 24px; height: 24px; border-radius: var(--radius-sm); color: var(--ink-muted); }
.sep { flex: none; width: 1px; height: 18px; margin: 0 6px; background: var(--line-strong); opacity: 0.35; }
.status { display: inline-flex; align-items: center; gap: var(--space-2); flex: none; }
.status .caption { color: var(--ink); max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sel-chip { flex: none; }

/* Three columns: outline, page, agent rail. Only the columns stick; the window scrolls.
   Pageless: no sheet of paper. The text sits on the white surface in a centred reading column,
   and the outline floats beside it without a border, so the whole editor reads as one plane. */
.workspace { display: grid; grid-template-columns: 252px minmax(0, 1fr) 340px; align-items: start; min-height: calc(100dvh - var(--appbar) - var(--subbar) - var(--statusbar)); }
.nav, .rail { position: sticky; top: calc(var(--appbar) + var(--subbar)); height: calc(100dvh - var(--appbar) - var(--subbar) - var(--statusbar)); overflow-y: auto; background: var(--surface); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
/* As tall as its headings (up to the window), so it stays put under the toolbar all the way down. */
.nav { border-right: 0; padding-top: var(--space-6); height: auto; max-height: calc(100dvh - var(--appbar) - var(--subbar) - var(--statusbar)); box-sizing: border-box; }
.rail { border-left: 1px solid var(--line); }
.doc-ico { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--violet-soft); color: var(--violet-text); }
.nav-h, .rail-title { margin: var(--space-2) 0 0; font: 600 11px/16px var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.rail-title { margin: 0; flex: 1; }
.outline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.outline button { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 6px 10px; border-radius: var(--radius-md); font: 500 14px/20px var(--font-sans); color: var(--ink); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outline button:hover { background: var(--ground); }
.outline button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.outline .l1 button { font-weight: 700; }
.outline .l3 button { padding-left: 26px; color: var(--ink-muted); font-size: 13px; }
.outline .l2 button { padding-left: 18px; }
.outline-empty { color: var(--ink-muted); margin: 0; }
.rail-head { display: flex; align-items: center; gap: var(--space-2); }
.rail-body { flex: 1; min-height: 0; overflow-y: auto; }
.rail .polr-tabs { flex: none; }

/* The canvas: a page on a gray desk */
.canvas { min-width: 0; align-self: stretch; padding: 0 var(--space-6) 30vh; display: flex; flex-direction: column; align-items: center; background: var(--surface); }
/* The column fills the window's height, so a click anywhere below the text puts the caret at the end. */
.sheet { flex: 1; width: 100%; max-width: 760px; box-sizing: border-box; background: transparent; padding: clamp(32px, 7vh, 72px) var(--space-6) var(--space-8); min-height: calc(100dvh - var(--appbar) - var(--subbar) - var(--statusbar) - 30vh); display: flex; flex-direction: column; cursor: text; }
.hint { max-width: 760px; width: 100%; box-sizing: border-box; padding: var(--space-4) var(--space-6) 0; color: var(--ink-muted); margin: 0; font-size: 12px; line-height: 18px; }
.hint .value { background: var(--sunken); padding: 1px 5px; border-radius: var(--radius-sm); }

/* Status bar */
.statusbar { position: sticky; bottom: 0; z-index: 25; height: var(--statusbar); display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-4); background: var(--surface); border-top: 1px solid var(--line); font: 400 12px/16px var(--font-sans); color: var(--ink-muted); }
.rev { color: var(--ink-muted); font-size: 12px; }

.editor { flex: 1; font: 400 16px/27px var(--font-sans); color: var(--ink); outline: none; caret-color: var(--accent); white-space: pre-wrap; min-height: 360px; }
.editor::selection, .editor ::selection { background: var(--violet-soft); color: var(--ink); }
.editor .blk { margin: 0 0 var(--space-4); max-width: 68ch; overflow-wrap: anywhere; }
.editor h1, .editor h2, .editor h3 { font-family: var(--font-display); color: var(--ink); letter-spacing: -0.015em; }
.editor .lvl-1 { font: 700 32px/38px var(--font-display); margin-top: var(--space-6); }
.editor .lvl-2 { font: 650 24px/30px var(--font-display); margin-top: var(--space-6); }
.editor .lvl-3 { font: 650 18px/24px var(--font-display); margin-top: var(--space-4); }
.editor .blk:first-child { margin-top: 0; }
.editor blockquote.blk { padding-left: var(--space-4); border-left: 2px solid var(--line-strong); color: var(--ink-muted); margin-left: 0; }
.editor .blk-list { padding-left: var(--space-6); }
.editor .blk-list li { margin: 0 0 var(--space-1); padding-left: 2px; }
.editor .blk-list li::marker { color: var(--ink-muted); }
/* Placeholders on empty headings and quotes, and on a document with nothing in it */
.editor h1:has(> br:only-child)::before, .editor h2:has(> br:only-child)::before, .editor h3:has(> br:only-child)::before,
.editor blockquote:has(> br:only-child)::before, .editor.is-empty p::before { content: attr(data-ph); color: var(--ink-muted); pointer-events: none; float: left; height: 0; }
.editor.is-writing { cursor: default; }

/* Typewriter. Erasing is red, typing is orange, then amber fades out. */
.tw-erase, .tw-type { border-radius: var(--radius-sm); transition: background-color 140ms ease-out; }
.tw-erase { background: var(--danger-soft); box-shadow: 0 0 0 4px var(--danger-soft); color: var(--danger-text); }
.tw-type { background: var(--accent-soft); box-shadow: 0 0 0 4px var(--accent-soft); }
.tw-caret { display: inline-block; width: 0.55em; height: 1.1em; margin-left: 1px; vertical-align: text-bottom; background: var(--accent); animation: caret 700ms steps(1) infinite; }
.tw-erase .tw-caret { background: var(--danger); }
@keyframes caret { 50% { opacity: 0; } }
.arrive { animation: arrive 160ms ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(4px); } }
.collapse { opacity: 0; transition: opacity 160ms ease-out; }
.just-edited { border-radius: var(--radius-sm); animation: settle 6.5s ease-out forwards; }
@keyframes settle {
  0%, 12% { background: color-mix(in srgb, var(--amber) 55%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 55%, transparent); }
  100% { background: transparent; box-shadow: 0 0 0 4px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .tw-caret { animation: none; }
  .arrive { animation: none; }
}

/* Agent rail */
.rail .polr-card p, .rail p { font-size: 14px; line-height: 20px; }
.row { display: flex; align-items: center; gap: var(--space-2); }
.empty { color: var(--ink-muted); margin: var(--space-2) 0 0; }

.changes, .tools { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.change { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); background: var(--surface); }
.change button.jump { all: unset; cursor: pointer; display: block; border-radius: var(--radius-sm); }
.change button.jump:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.change .meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.change .meta .value { color: var(--ink-muted); font-size: 12px; }
.change .label { font: 600 13px/18px var(--font-sans); color: var(--ink); margin-top: var(--space-1); }
.change.undone { opacity: 0.55; }
.nodes { display: flex; flex-direction: column; gap: 6px; }
.node { font: 400 13px/19px var(--font-sans); padding: 4px 8px; border-radius: var(--radius-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
.node .id { font: 500 11px/16px var(--font-mono); opacity: 0.75; margin-right: 6px; }
.node.old { background: var(--danger-soft); color: var(--danger-text); text-decoration: line-through; text-decoration-thickness: 1px; }
.node.new { background: var(--good-soft); color: var(--good-text); }

.tools li { display: flex; flex-direction: column; gap: 2px; }
.tools .value { color: var(--ink); }
.tools .caption { color: var(--ink-muted); font-size: 12px; line-height: 17px; }

/* The title is the first block of the canvas */
.editor .blk-title { font: 700 36px/42px var(--font-display); letter-spacing: -0.02em; margin: 0 0 var(--space-6); max-width: none; }
.editor .blk-title:has(> br:only-child)::before { content: attr(data-ph); color: var(--ink-muted); pointer-events: none; float: left; height: 0; }
.mcp-text { margin: 0 0 var(--space-3); color: var(--ink-muted); }

/* A selection the agent can still see after focus leaves the document */
::highlight(remembered) { background: var(--violet-soft); color: var(--ink); }

/* The simulated agent session. It is the person's own agent, a different app from this
   site, so it is dark, uses system fonts and has its own chrome. */
.agent {
  --surface: #171b24; --ground: #0e1117; --sunken: #0b0e14; --line: #2a2f3c; --line-strong: #7d8499;
  --ink: #edeff5; --ink-muted: #a3aabc; --accent: #ff8a4c; --on-accent: #12151c;
  --violet: #a996ff; --violet-soft: #2c2266; --violet-text: #bfb1ff;
  --good: #4fd08a; --good-soft: #123624; --good-text: #6fe0a2;
  --accent-soft: #3a1c0c; --accent-text: #ffab7a;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  position: fixed; top: auto; right: var(--space-4); bottom: var(--space-4); z-index: 20;
  width: min(420px, calc(100vw - 32px)); max-height: min(62vh, 560px);
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--ground); color: var(--ink); color-scheme: dark; font-family: var(--font-sans);
  border: 1px solid #3a4052; border-radius: 22px; padding: var(--space-4);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: agent-up 460ms cubic-bezier(0.2, 0.9, 0.25, 1);
  transition: transform 420ms cubic-bezier(0.5, 0, 0.75, 0.2), opacity 420ms ease-in;
}
.agent[hidden] { display: none; }
.agent.leaving { transform: translateY(calc(100% + 40px)); opacity: 0.6; }
.agent-bar { position: relative; display: flex; align-items: center; justify-content: center; height: 18px; margin: -4px 0 -2px; }
.agent-dots { position: absolute; left: 0; display: flex; gap: 8px; }
.dot { all: unset; box-sizing: border-box; width: 12px; height: 12px; border-radius: 50%; cursor: pointer; position: relative; border: 1px solid rgba(0, 0, 0, 0.25); }
.dot:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.dot-close { background: #ff5f57; }
.dot-min { background: #febc2e; }
.dot-max { background: #28c840; }
.agent-dots:hover .dot::after { position: absolute; inset: 0; display: grid; place-items: center; font: 700 9px/1 var(--font-sans); color: rgba(0, 0, 0, 0.6); }
.agent-dots:hover .dot-close::after { content: "\00d7"; font-size: 11px; }
.agent-dots:hover .dot-min::after { content: "\2212"; }
.agent-dots:hover .dot-max::after { content: "+"; }
.agent-title { font: 500 12px/18px var(--font-sans); color: var(--ink-muted); }
.agent-head { display: flex; align-items: center; gap: var(--space-3); }
.agent-avatar { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--violet); color: #12151c; }
.agent-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.agent-name { font: 650 15px/20px var(--font-sans); color: var(--ink); }
.agent-sub { font: 400 12px/16px var(--font-sans); color: var(--ink-muted); }
.agent-link { display: flex; align-items: center; gap: var(--space-2); padding: 6px 10px; border-radius: var(--radius-pill); background: var(--sunken); border: 1px solid var(--line); color: var(--ink-muted); min-width: 0; }
.agent-link svg { flex: none; }
.agent-link.sending { border-color: var(--violet); color: var(--violet-text); animation: send-pulse 700ms ease-in-out infinite alternate; }
@keyframes send-pulse { to { background: var(--violet-soft); } }
.agent-link .value { font: 400 11px/16px var(--font-mono); color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-said { margin: 0; align-self: flex-end; max-width: 88%; padding: 8px 14px; background: var(--violet); color: #12151c; border-radius: 18px 18px 4px 18px; font: 500 15px/22px var(--font-sans); min-height: 22px; overflow-wrap: anywhere; }
.agent-said:empty { display: none; }
.agent-said.typing::after { content: ""; display: inline-block; width: 0.5em; height: 1em; margin-left: 2px; vertical-align: text-bottom; background: #12151c; animation: caret 700ms steps(1) infinite; }
.agent-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); overflow-y: auto; min-height: 0; scrollbar-color: #3a4052 transparent; }
.step { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: var(--space-3); animation: step-in 180ms ease-out; }
.s-ico { width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--line-strong); box-sizing: border-box; }
.step.run .s-ico { border-color: var(--line); border-top-color: var(--accent); animation: spin 800ms linear infinite; }
.step.ok .s-ico { border: 0; background: var(--good); position: relative; }
.step.ok .s-ico::after { content: ""; position: absolute; left: 5px; top: 2.5px; width: 4px; height: 8px; border: solid #0e1117; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.s-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.s-tag { font: 500 11px/16px var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.s-tag.s-call { color: var(--violet-text); }
.s-text { margin: 0; font: 400 13px/19px var(--font-sans); color: var(--ink); overflow-wrap: anywhere; }
.s-text.value { font: 500 12px/18px var(--font-mono); }
.s-fn { margin: 0; font: 400 11px/16px var(--font-mono); color: var(--ink-muted); overflow-wrap: anywhere; }
.step.run .s-text { color: var(--ink-muted); }
.step.final .s-tag { color: var(--good-text); }
.step.final .s-text { font-weight: 600; }
.s-out { margin: var(--space-1) 0 0; padding: 4px 8px; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--radius-sm); font: 400 12px/17px var(--font-mono); color: var(--ink-muted); overflow-wrap: anywhere; }
.agent-note { margin: 0; color: var(--ink-muted); font-family: var(--font-sans); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes step-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes agent-up { from { transform: translateY(calc(100% + 40px)); } }
@media (prefers-reduced-motion: reduce) {
  .agent { animation: none; transition: opacity 200ms; }
  .agent.leaving { transform: none; opacity: 0; }
  .step { animation: none; }
  .step.run .s-ico { animation: none; border-top-color: var(--accent); }
}

/* Phones: the agent panel is a bottom sheet that shrinks to one line once the edit starts */
@media (max-width: 900px) {
  .agent { left: var(--space-2); right: var(--space-2); bottom: var(--space-2); width: auto; max-height: 44vh; padding: var(--space-3); gap: var(--space-2); border-radius: 20px; }
  .agent .agent-link { display: none; }
  .agent .agent-said { font-size: 14px; line-height: 20px; }
  .agent.compact { max-height: none; }
  .agent.compact .agent-said, .agent.compact .agent-note, .agent.compact .agent-link, .agent.compact .step:not(:last-child) { display: none; }
  .agent.compact .agent-steps { overflow: visible; }
  .agent.compact .s-out, .agent.compact .s-fn { display: none; }
}


/* Only the step list scrolls; the request bubble and header keep their full height */
.agent > * { flex: none; }
.agent > .agent-steps { flex: 0 1 auto; }

/* Narrower windows: the outline folds away first, then the rail drops under the page */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 320px; }
  .nav { display: none; }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
  .rail-body { overflow: visible; }
  .canvas { padding: 0 0 var(--space-8); }
  .sheet { min-height: 60vh; padding: var(--space-6) var(--space-4) var(--space-6); }
  .hint { padding: var(--space-3) var(--space-4) 0; }
  .vsep, .presence-text, .btn-label { display: none; }
  .presence { padding: 0 4px; }
  #reset { display: none; }
  .subbar { padding: 0 var(--space-2); }
  .status .caption { display: none; }
  #sel-chip { display: none; }
}


/* The agent rail is a sidebar that starts collapsed; the app bar button opens it. */
.menu-btn { position: relative; flex: none; width: 34px; height: 34px; }
.menu-btn[aria-expanded="true"] { background: var(--violet-soft); color: var(--violet-text); }
.rail-badge { position: absolute; top: -3px; right: -3px; min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box; border-radius: var(--radius-pill); background: var(--accent); color: #fff; font: 600 11px/16px var(--font-mono); text-align: center; }
/* With the rail closed, an empty column the outline's width keeps the text centred in the window. */
.workspace.rail-collapsed { grid-template-columns: 252px minmax(0, 1fr) 252px; }
.workspace.rail-collapsed .rail { display: none; }
@media (max-width: 1180px) {
  .workspace.rail-collapsed { grid-template-columns: minmax(0, 1fr); }
}

/* Back to the document list: the logo. Which screen is showing decides what the app bar offers. */
body[data-screen="home"] .only-editor { display: none !important; }
body[data-screen="editor"] .only-home { display: none !important; }
body[data-screen="home"], body[data-screen="editor"] { background: var(--surface); }
body[data-screen="signin"] .only-editor, body[data-screen="signin"] .only-home { display: none !important; }

/* Document name in the app bar: looks like text until you hover or focus it, like Docs */
.docname-input { width: min(36ch, 38vw); height: 28px; padding: 0 6px; margin: 0 0 0 -6px; box-sizing: border-box; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--ink); font: 600 16px/24px var(--font-sans); text-overflow: ellipsis; }
.docname-input::placeholder { color: var(--ink-muted); font-weight: 500; }
.docname-input:hover { border-color: var(--line-strong); }
.docname-input:focus { outline: none; border-color: var(--focus); background: var(--surface); box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 30%, transparent); }

/* Search */
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 12px; height: 44px; margin-left: var(--space-6); padding: 0 16px; box-sizing: border-box; border-radius: var(--radius-pill); background: var(--ground); color: var(--ink-muted); transition: background-color 140ms ease-out, box-shadow 140ms ease-out; }
.search:focus-within { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(18,21,28,0.2), 0 4px 14px rgba(18,21,28,0.1); }
.search input { flex: 1; min-width: 0; border: 0; padding: 0; background: transparent; color: var(--ink); font: 400 16px/24px var(--font-sans); outline: none; }
.search input::placeholder { color: var(--ink-muted); }

/* Home */
.home-wrap { max-width: 1040px; margin: 0 auto; padding: 0 var(--space-5); }
.home-h { margin: 0 0 var(--space-4); font: 600 16px/24px var(--font-sans); color: var(--ink); }
.home-start { padding: var(--space-5) 0 var(--space-6); background: var(--ground); border-bottom: 1px solid var(--line); }
.start-row { display: flex; flex-wrap: wrap; gap: var(--space-5); }
.start-card { all: unset; box-sizing: border-box; display: flex; flex-direction: column; gap: 10px; width: 150px; cursor: pointer; }
.start-thumb { display: grid; place-items: center; width: 150px; height: 190px; box-sizing: border-box; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface); color: var(--accent); transition: border-color 140ms ease-out; }
.start-thumb.demo { color: var(--violet-text); }
.start-card:hover .start-thumb { border-color: var(--accent); }
.start-card:focus-visible .start-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }
.start-label { font: 500 14px/20px var(--font-sans); color: var(--ink); }
.home-recent { padding: var(--space-5) 0 80px; background: var(--surface); min-height: 50vh; }
.recent-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.recent-head .home-h { margin: 0; }
.recent-head .caption { color: var(--ink-muted); }
.seg { display: flex; gap: 2px; }

.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-5); }
.docs-empty { grid-column: 1 / -1; margin: var(--space-6) 0; color: var(--ink-muted); text-align: center; }
.doc-card { position: relative; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); overflow: hidden; transition: border-color 140ms ease-out, box-shadow 140ms ease-out; }
.doc-card:hover, .doc-card:focus-within { border-color: var(--line-strong); box-shadow: 0 1px 4px rgba(18,21,28,0.1); }
.doc-open { display: block; color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); }
.doc-open:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.doc-thumb { height: 200px; padding: 14px 16px 0; overflow: hidden; background: var(--ground); }
.doc-thumb-page { height: 100%; box-sizing: border-box; padding: 10px 10px 0; overflow: hidden; background: var(--surface); box-shadow: 0 0 0 1px var(--line); color: var(--ink); font: 400 6.5px/9px var(--font-sans); }
.doc-thumb-page > div { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; margin-bottom: 2px; }
.doc-thumb-page .t-title { margin-bottom: 5px; font: 700 10px/13px var(--font-display); }
.doc-thumb-page .t-heading { margin-top: 4px; font-weight: 700; }
.doc-thumb-page .t-quote { padding-left: 4px; border-left: 1px solid var(--line-strong); color: var(--ink-muted); }
.doc-foot { display: flex; align-items: center; gap: var(--space-2); padding: 8px 4px 8px 10px; }
.doc-foot .doc-ico { flex: none; width: 28px; height: 28px; border-radius: var(--radius-md); }
.doc-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.doc-name { font: 600 14px/20px var(--font-sans); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta .caption { color: var(--ink-muted); font-size: 12px; line-height: 16px; }
.doc-more { flex: none; color: var(--ink-muted); }
.doc-rename { width: 100%; box-sizing: border-box; height: 24px; padding: 0 4px; border: 1px solid var(--focus); border-radius: var(--radius-sm); font: 600 14px/20px var(--font-sans); color: var(--ink); background: var(--surface); outline: none; }

/* List layout: a row per document; the whole row opens it */
.docs.as-list { display: flex; flex-direction: column; gap: 0; }
.docs.as-list .doc-card { flex-direction: row; align-items: center; border-width: 0 0 1px; border-radius: 0; box-shadow: none; overflow: visible; }
.docs.as-list .doc-card:hover { background: var(--ground); }
.docs.as-list .doc-open { position: absolute; inset: 0; border: 0; }
.docs.as-list .doc-thumb { display: none; }
.docs.as-list .doc-foot { position: relative; flex: 1; padding: 10px 4px 10px 8px; pointer-events: none; }
.docs.as-list .doc-more, .docs.as-list .doc-rename { pointer-events: auto; }
.docs.as-list .doc-meta { flex-direction: row; align-items: baseline; gap: var(--space-4); }
.docs.as-list .doc-name { flex: 1; min-width: 0; }

/* Actions menu */
.menu { position: absolute; z-index: 60; min-width: 190px; padding: 6px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 4px 18px rgba(18,21,28,0.18); }
.menu-item { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 8px 16px; font: 400 14px/20px var(--font-sans); color: var(--ink); cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--ground); }
.menu-item.danger { color: var(--danger-text, #a3261a); }

/* Snackbar */
.snack { position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translateX(-50%); display: flex; align-items: center; gap: var(--space-4); max-width: calc(100vw - 32px); padding: 10px 12px 10px 16px; border-radius: 6px; background: var(--ink); color: #fff; font: 400 14px/20px var(--font-sans); box-shadow: 0 4px 18px rgba(18,21,28,0.3); }
.snack-btn { all: unset; cursor: pointer; padding: 4px 10px; border-radius: var(--radius-sm); color: var(--amber); font-weight: 600; }
.snack-btn:hover, .snack-btn:focus-visible { background: rgba(255,255,255,0.12); }

@media (max-width: 900px) {
  .search { margin-left: var(--space-2); height: 40px; }
  .home-wrap { padding: 0 var(--space-4); }
  .docname-input { width: 30vw; }
}
@media (max-width: 600px) {
  .brand-name { display: none; }
  .docname-input { width: 46vw; }
  .savestate { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .docs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .start-card, .start-thumb { width: 120px; }
  .start-thumb { height: 152px; }
}

/* Inside an MCP host (Claude), set by host.js. The host sizes the frame, so the page must not size
   itself to the viewport. Inline = a card in the conversation (it grows with its content);
   fullscreen = the side panel or full screen (a fixed frame, the page scrolls inside it). */
html[data-embedded] body { padding: var(--safe-top, 0) var(--safe-right, 0) var(--safe-bottom, 0) var(--safe-left, 0); }
html[data-embedded][data-display="inline"] .appbar,
html[data-embedded][data-display="inline"] .subbar,
html[data-embedded][data-display="inline"] .statusbar { position: static; }
html[data-embedded][data-display="inline"] .nav,
html[data-embedded][data-display="inline"] .rail,
html[data-embedded][data-display="inline"] .hint { display: none; }
html[data-embedded][data-display="inline"] .workspace { display: block; min-height: 0; }
html[data-embedded][data-display="inline"] .canvas { padding: 0; }
html[data-embedded][data-display="inline"] .sheet { min-height: 320px; padding: var(--space-6) var(--space-6) var(--space-8); }
html[data-embedded][data-display="inline"] .home-recent { min-height: 0; padding-bottom: var(--space-6); }
html[data-embedded][data-display="inline"] .home-start { padding: var(--space-4) 0; }
html[data-embedded][data-display="inline"] .start-thumb, html[data-embedded][data-display="inline"] .start-card { width: 110px; }
html[data-embedded][data-display="inline"] .start-thumb { height: 120px; }

/* The app bar menu and the debug panel (debug.js). */
.menu-main { min-width: 230px; }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.menu-hint { font: 600 12px/16px var(--font-mono); color: var(--ink-muted); }
.menu-item[aria-checked="true"] .menu-hint { color: var(--good-text); }
.menu-sep { height: 1px; margin: 6px 0; background: var(--line); }

.debug { position: fixed; right: 8px; bottom: 8px; z-index: 80; display: flex; flex-direction: column; width: min(440px, calc(100vw - 16px)); max-height: min(75vh, 640px); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 8px 28px rgba(18,21,28,0.25); }
.debug-head { display: flex; align-items: center; gap: var(--space-2); padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.debug-title { margin: 0; font: 700 15px/20px var(--font-display); }
.debug-body { overflow: auto; padding: 4px 16px 16px; }
.debug-sub { margin: 14px 0 4px; font: 600 11px/16px var(--font-sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.debug-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 0; font: 400 12px/18px var(--font-mono); }
.debug-dl dt { color: var(--ink-muted); }
.debug-dl dd { margin: 0; overflow-wrap: anywhere; }
.debug-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: 14px; }
.debug-log { list-style: none; margin: 0; padding: 0; font: 400 11px/16px var(--font-mono); }
.debug-line { display: grid; grid-template-columns: 56px 40px minmax(0, 1fr); gap: 6px; padding: 2px 0; border-top: 1px solid var(--line); }
.debug-time, .debug-kind { color: var(--ink-muted); }
.debug-text { overflow-wrap: anywhere; }
.debug-error .debug-text, .debug-error .debug-kind { color: var(--danger-text); }
.debug-warn .debug-kind { color: var(--accent-text); }
.debug-host .debug-kind { color: var(--violet-text); }
@media (max-width: 900px) { .debug { right: 0; bottom: 0; left: 0; width: auto; border-radius: 10px 10px 0 0; } }

/* Ask AI: shown only inside an MCP host that accepts messages from the view (set by host.js + main.js). */
.btn-ask { gap: 6px; }
.ask-pop { position: fixed; z-index: 70; top: calc(var(--appbar) + 6px + var(--safe-top, 0px)); right: calc(12px + var(--safe-right, 0px)); width: min(340px, calc(100vw - 24px)); box-sizing: border-box; padding: var(--space-3); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 6px 24px rgba(18,21,28,0.2); display: grid; gap: var(--space-2); }
.ask-label { font: 600 13px/18px var(--font-sans); color: var(--ink); }
.ask-pop textarea { width: 100%; box-sizing: border-box; resize: vertical; min-height: 64px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); font: 400 14px/20px var(--font-sans); }
.ask-pop textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.ask-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ask-chip { padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--ink); font: 500 12px/18px var(--font-sans); cursor: pointer; }
.ask-chip:hover { background: var(--sunken); }
.ask-sel { margin: 0; font: 400 12px/16px var(--font-mono); color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.ask-status { flex: 1; font: 400 12px/16px var(--font-sans); color: var(--ink-muted); }
/* A card an newer card has replaced: it has paused (no polling, no tools), so cover it. */
.superseded { position: fixed; inset: 0; z-index: 90; display: grid; align-content: center; justify-items: center; gap: var(--space-2); padding: var(--space-6); text-align: center; background: var(--surface); color: var(--ink); font: 400 14px/21px var(--font-sans); }
.superseded p { margin: 0; max-width: 34ch; }

/* Sign-in (only when the server has it on) */
.signin { display: grid; place-items: center; min-height: calc(100vh - 120px); padding: var(--space-6) var(--space-4); }
.signin-card { box-sizing: border-box; width: min(420px, 100%); padding: var(--space-8); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-card); text-align: center; }
.signin-h { margin: 0 0 var(--space-3); font: 600 22px/28px var(--font-display); }
.signin-text { margin: 0 0 var(--space-6); color: var(--ink-muted); }
.signin-card .polr-btn { min-height: 44px; min-width: 160px; justify-content: center; }
html[data-display="inline"] .signin { min-height: 320px; }

/* Connected apps (account.js) */
.apps-panel { right: 8px; top: 64px; bottom: auto; }
.apps-intro { margin: 12px 0; }
.apps-list { list-style: none; margin: 0; padding: 0; }
.apps-item { display: flex; align-items: center; gap: var(--space-3); padding: 10px 0; border-top: 1px solid var(--line); }
.apps-text { flex: 1; min-width: 0; }
.apps-name { font: 600 14px/20px var(--font-sans); overflow-wrap: anywhere; }
.apps-empty { padding: 10px 0; }
