.topic-toggle {
  display:inline-flex; align-items:center; justify-content:center; gap:.42rem;
  align-self:flex-start; flex:none;
}
.topic-toggle svg { width:18px; height:18px; flex:none; }
.topic-toggle[aria-expanded="true"] { color:var(--mark); border-color:var(--mark); background:var(--paper); }
body:has(topic-agent) #main > .page-head { flex-wrap:wrap; gap:.55rem 1rem; }
topic-agent {
  --agent-accent:var(--instrument-green);
  --agent-wash:var(--green-paper);
  --agent-paper:var(--leaf);
  --agent-edge:var(--line-strong);
  --agent-placeholder:var(--sub);
  --agent-seal:#8a2d23;
  --agent-seal-ink:#fff4da;
  --agent-lamp:linear-gradient(transparent,transparent);
  position:fixed; inset:0 0 0 auto; z-index:75;
  display:block; width:min(calc(100% - 1.25rem),26rem); min-width:0;
  padding:0 clamp(12px,1.3vw,19px) 20px;
  border-left:3px double var(--agent-edge);
  background:var(--agent-lamp),var(--paper);
  box-shadow:-10px 0 28px rgb(30 18 10 / 14%);
  color:var(--ink); overflow:auto; overscroll-behavior:contain;
  scrollbar-width:thin; scrollbar-color:var(--agent-edge) var(--paper);
  animation:topic-note-open .24s cubic-bezier(.22,1,.36,1);
}
[data-light="night"] topic-agent {
  --agent-wash:#35473b;
  --agent-paper:#392e24;
  --agent-edge:#aa8856;
  --agent-placeholder:#d0bd9d;
  --agent-seal:#a34130;
  --agent-seal-ink:#fff0d1;
  --agent-lamp:radial-gradient(ellipse at 76% -45%,rgb(198 143 61 / 16%),transparent 68%);
}
topic-agent[hidden],topic-agent [hidden] { display:none; }
[data-topic-shade]:not([hidden]) { position:fixed; inset:0; z-index:74; background:rgb(30 18 10 / 44%); touch-action:none; }
.topic-overlay { overflow:hidden; }
@keyframes topic-note-open {
  from { clip-path:inset(0 0 0 100%); }
  to { clip-path:inset(0); }
}
@media (min-width:1200px) {
  .topic-open { --topic-note-width:clamp(21rem,26vw,24rem); }
  .topic-open .page-stage { margin-inline-end:var(--topic-note-width); }
  topic-agent { width:var(--topic-note-width,24rem); }
}
@media (prefers-reduced-motion:reduce) { topic-agent { animation:none; } }
.agent-panel { padding:0 2px; }
.agent-header,.agent-header-actions,.agent-tools,.agent-modes,.agent-send-tools,.agent-words {
  display:flex; align-items:center;
}
.agent-header {
  position:sticky; top:0; z-index:1;
  gap:5px 10px; margin:0 -2px 11px; padding:12px 2px 8px;
  flex-wrap:wrap; background:var(--paper);
  border-bottom:3px double var(--agent-edge);
}
.agent-header h2,.agent-bank h3 { margin:0; font-family:var(--head); color:var(--ink); }
.agent-header h2 { flex:1; font-size:clamp(1.18rem,2vw,1.42rem); line-height:1.35; }
.agent-header .agent-close { display:grid; place-items:center; width:36px; height:36px; padding:0; color:var(--sub); }
.agent-header .agent-close:hover { color:var(--stamp-red); }
.agent-header-actions { width:100%; flex-wrap:wrap; gap:4px 13px; }
.agent-header-actions button,.agent-note button,.agent-error button,.agent-feedback button {
  display:inline-flex; align-items:center; gap:5px; border:0; background:none; border-radius:2px;
  color:var(--secondary,var(--ink)); padding:4px 0; cursor:pointer; font:inherit; font-size:.85rem;
}
.agent-header-actions button:hover,.agent-header-actions button[aria-expanded="true"],
.agent-note button,.agent-error button,.agent-feedback button { color:var(--stamp-red); text-decoration:underline; text-underline-offset:.22em; }
topic-agent svg { width:18px; height:18px; flex:0 0 auto; }
.agent-edition,.agent-note,.agent-bank p { color:var(--secondary,var(--ink)); font-size:.86rem; line-height:1.65; }
.agent-edition { font-size:.76rem; }
.agent-compose {
  display:block; padding:clamp(15px,2vw,21px); border:1px solid var(--agent-edge); border-radius:4px;
  background:var(--rivet) 5px 5px/7px 7px no-repeat,var(--rivet) right 5px top 5px/7px 7px no-repeat,
    var(--rivet) left 5px bottom 5px/7px 7px no-repeat,var(--rivet) right 5px bottom 5px/7px 7px no-repeat,
    var(--agent-lamp),var(--agent-paper);
  box-shadow:inset 0 0 0 2px var(--agent-paper),inset 0 0 0 3px var(--plate-inset),var(--plate-shadow);
}
.agent-compose:focus-within { border-color:var(--agent-accent); }
#agent-prompt {
  resize:vertical; display:block; width:100%; min-height:61px; max-height:240px; margin:0 0 9px;
  padding:0 3px; border:0; border-radius:0; background:transparent; box-shadow:none;
  font:400 clamp(1rem,1.4vw,1.13rem)/1.55 var(--body,sans-serif); color:var(--ink); caret-color:var(--agent-accent);
}
#agent-prompt:focus,#agent-prompt:focus-visible { outline:none; box-shadow:none; }
.legal-text #agent-prompt { min-block-size:7rem; max-block-size:16rem; overflow-y:auto; }
#agent-prompt::placeholder { color:var(--agent-placeholder); opacity:1; }
.agent-tools { justify-content:space-between; flex-wrap:wrap; gap:6px; }
.agent-modes,.agent-send-tools { gap:8px; }
.agent-send-tools { margin-inline-start:auto; }
.agent-option,.agent-send,.agent-mic,.agent-words button {
  display:inline-flex; justify-content:center; align-items:center; gap:5px;
  border:1px solid var(--agent-edge); border-radius:100px; cursor:pointer; font:inherit;
}
.agent-option { position:relative; padding:5px 11px; min-height:34px; white-space:nowrap; border-radius:3px; background:var(--agent-paper); color:var(--agent-accent); font-size:.85rem; }
.agent-option[aria-pressed="true"] { background:var(--agent-wash); border-color:var(--agent-accent); box-shadow:inset 0 0 0 1px var(--agent-accent); font-weight:650; }
.agent-option[aria-pressed="true"]::after { content:""; position:absolute; bottom:-1px; left:calc(50% - 5px); width:10px; height:3px; background:var(--agent-accent); }
.agent-option:hover,.agent-mic:hover { background:var(--agent-wash); }
.agent-send,.agent-mic { width:37px; height:37px; padding:0; }
.agent-send { color:var(--agent-seal-ink); border-color:#69251b;
  background:radial-gradient(circle at 40% 26%,#ad4f38,var(--agent-seal) 67%,#6d291e);
  box-shadow:inset 0 0 0 2px var(--agent-seal),inset 0 0 0 3px #c77d60,0 2px 4px rgb(68 30 13 / 24%);
}
.agent-send:disabled { background:var(--pale); color:var(--secondary); border-color:var(--line-strong); box-shadow:inset 0 0 0 2px var(--pale),inset 0 0 0 3px var(--plate-inset); opacity:.75; }
.agent-send svg { width:21px; height:21px; }
.agent-mic { background:transparent; color:var(--agent-accent); }
topic-agent button:disabled { cursor:default; }
.agent-option:disabled,.agent-header button:disabled { opacity:.55; }
topic-agent button:focus-visible,topic-agent summary:focus-visible,.agent-turns:focus-visible {
  outline:2px solid var(--agent-accent); outline-offset:3px;
}
.agent-bank {
  margin:15px 2px 2px; padding:12px 0 5px; border-top:1px solid var(--line-strong,var(--rule));
}
.agent-bank h3 { font-size:1rem; }
.agent-bank p { margin:3px 0 0; }
.agent-words { flex-wrap:wrap; gap:6px 8px; margin-top:9px; }
.agent-words button { max-width:100%; border-color:var(--line-strong,var(--rule)); border-radius:5px; background:var(--paper); color:var(--ink); padding:5px 10px; font-size:.875rem; overflow-wrap:anywhere; }
.agent-words button:hover,.agent-words button[aria-pressed="true"] { color:var(--stamp-red); border-color:currentColor; }
.agent-words button[aria-pressed="true"] { font-weight:bold; }
.agent-turns,#agent-history:not([hidden]) {
  max-height:clamp(220px,36vh,380px); overflow:auto; overscroll-behavior:contain;
  scrollbar-width:thin; scrollbar-color:var(--line-strong) transparent; margin-bottom:12px;
  border-block:1px solid var(--line-strong,var(--rule));
}
.agent-turns { margin-top:12px; }
.agent-turn { padding:12px 3px; }
.agent-turn+.agent-turn { border-top:1px dotted var(--line-strong,var(--rule)); }
.agent-turn>strong { display:block; font:650 .82rem/1.6 var(--body,sans-serif); color:var(--instrument-green,var(--ink)); }
.agent-turn[data-role="user"]>strong { color:var(--secondary,var(--ink)); }
.agent-answer { max-width:76ch; white-space:pre-wrap; overflow-wrap:anywhere; font-size:.96rem; line-height:1.72; }
.agent-answer p { margin:0; color:inherit; font:inherit; }
.agent-answer p+p { margin-top:.6em; }
.agent-citations { margin-top:5px; font-size:.86rem; }
.agent-citations ol { padding-inline-start:22px; }
.agent-citations summary,.agent-citations a { color:var(--instrument-green,var(--ink)); }
.agent-note,.agent-error,.agent-feedback { margin:5px 0; overflow-wrap:anywhere; }
.agent-feedback,.agent-error { font-size:.88rem; line-height:1.7; }
.agent-error { color:var(--stamp-red); }
.agent-review { margin:10px 0; padding:14px 16px; border:1px solid var(--agent-edge); background:var(--paper); }
.agent-review h3,.agent-review h4 { margin:0 0 5px; font-family:var(--head); }
.agent-review h4,.agent-review details { margin-top:10px; }
.agent-review-text { margin:3px 0; max-width:75ch; white-space:pre-wrap; overflow-wrap:anywhere; }
.agent-review-actions { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:8px; margin-top:12px; }
.agent-review details article { padding:8px 0; border-bottom:1px dotted var(--line); }
.agent-progress { margin-block:8px; }
.agent-reference { margin:0 3px 11px; font-size:.88rem; overflow-wrap:anywhere; }
.agent-reference>.text-button { padding-inline:0; min-height:28px; }
.agent-reference-preview {
  margin:5px 0 0; padding:10px 12px; border-left:2px solid var(--agent-edge); background:var(--paper);
}
.agent-reference-preview h3 { margin:0; font:700 1rem/1.45 var(--head); }
.agent-reference-text { margin:5px 0 8px; max-width:76ch; white-space:pre-wrap; overflow-wrap:anywhere; line-height:1.65; }
.agent-reference-preview .button.outline { margin-top:4px; background:var(--agent-paper); border-color:var(--agent-edge); }
.agent-reference-preview .button.outline:hover:not(:disabled) { background:var(--agent-wash); }
.agent-day { display:grid; grid-template-columns:7.5em minmax(0,1fr); gap:8px; padding:7px 2px; }
.agent-day time { color:var(--secondary,var(--ink)); font-variant-numeric:tabular-nums; font-size:.85rem; padding-top:5px; }
.agent-day button { display:block; text-align:left; background:none; color:var(--ink); border:0; padding:4px; white-space:normal; overflow-wrap:anywhere; cursor:pointer; }
.agent-day button:hover,.agent-day button[aria-current="true"] { color:var(--stamp-red); text-decoration:underline; }
@media (max-width:500px) {
  .agent-header { gap:6px; flex-wrap:wrap; }
  .agent-header-actions { gap:3px 9px; }
  .agent-header-actions button { min-height:32px; }
  .agent-compose { padding:15px 11px 12px; }
  .agent-tools,.agent-modes,.agent-send-tools { gap:4px; }
  .agent-option { padding:4px 7px; min-height:36px; font-size:.81rem; gap:3px; }
  .agent-option svg { width:15px; height:15px; }
  .agent-mic,.agent-send { width:34px; height:34px; }
  .agent-day { grid-template-columns:minmax(0,1fr); gap:0; }
}
@media (max-width:350px) {
  .agent-option { gap:3px; padding:4px 5px; font-size:.755rem; }
  .agent-option svg { width:13px; height:13px; }
  .agent-send,.agent-mic { width:32px; height:32px; }
}
