#appearance { position: relative; flex: none; }
#appearance > summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  font-size: 12px;
}
#appearance > summary::-webkit-details-marker { display: none; }
#appearance > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.appearance-options {
  position: absolute;
  z-index: 25;
  right: 0;
  top: calc(100% + 6px);
  width: min(325px, 88vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px #0005;
  padding: 12px;
}
.appearance-options fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 0;
  margin: 0 0 8px;
  border: 0;
}
.appearance-options legend { padding: 0 0 5px; color: var(--muted); font-size: 12px; }
.appearance-options button { text-align: left; padding: 6px; font-size: 12px; }
.appearance-options button[aria-pressed="true"] { border-color: var(--accent); }
.appearance-options button[data-swatch]::before {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  margin-right: 5px;
  vertical-align: -1px;
  background: var(--swatch);
  content: "";
}
[data-swatch=classic] { --swatch: #23362b; }
[data-swatch=paper] { --swatch: #ece5d9; }
[data-swatch=ocean] { --swatch: #1d3d5a; }
[data-swatch=plum] { --swatch: #412648; }
[data-swatch=dc] { --swatch: #d8e8ee; }
.appearance-options p { color: var(--muted); font-size: 12px; margin: 0; }
.appearance-options p:empty { display: none; }

:root[data-theme=paper] {
  color-scheme: light;
  --bg: #f8f5ee; --panel: #fffdf8; --line: #8a7f72;
  --text: #29231d; --muted: #51453a; --accent: #315a43;
  --appearance-surface: #f0e9de; --appearance-control: #fffaf1;
  --appearance-raised: #eee4d4; --appearance-selected: #dce9dd; --appearance-edge: #627b67;
  --appearance-soft-text: #51453a; --appearance-link: #315a43; --appearance-action-text: #fffdf8;
  --appearance-notice: #fbedd2; --appearance-notice-text: #624407; --appearance-notice-edge: #84600e;
  --appearance-error-surface: #f9e1df; --appearance-error-text: #842d28; --appearance-error-edge: #953e38;
  --appearance-warning-badge: #704c12; --appearance-urgent-badge: #8d332d; --appearance-badge-text: #fff;
  --appearance-panel-overlay: #fffaf1;
}

:root[data-theme=ocean] {
  color-scheme: dark;
  --bg: #101d2b; --panel: #16283b; --line: #637f9c;
  --text: #e9f5ff; --muted: #bacfe1; --accent: #9bdaf6;
  --appearance-surface: #152638; --appearance-control: #1a3046;
  --appearance-raised: #203750; --appearance-selected: #23425b; --appearance-edge: #7299b9;
  --appearance-soft-text: #bacfe1; --appearance-link: #a7e5ff; --appearance-action-text: #132837;
  --appearance-notice: #39301e; --appearance-notice-text: #ffe09a; --appearance-notice-edge: #ccab63;
  --appearance-error-surface: #43292e; --appearance-error-text: #ffd0cb; --appearance-error-edge: #d18a86;
  --appearance-warning-badge: #ffdb87; --appearance-urgent-badge: #ffaeaa; --appearance-badge-text: #1b1620;
  --appearance-panel-overlay: #1a3046;
}

:root[data-theme=plum] {
  color-scheme: dark;
  --bg: #231a27; --panel: #302333; --line: #95799d;
  --text: #f8edf6; --muted: #e0c8df; --accent: #f9c5f0;
  --appearance-surface: #2b2031; --appearance-control: #35263a;
  --appearance-raised: #3d2d43; --appearance-selected: #49354e; --appearance-edge: #a68cac;
  --appearance-soft-text: #e0c8df; --appearance-link: #ffd3f5; --appearance-action-text: #35233a;
  --appearance-notice: #3d3026; --appearance-notice-text: #ffe1a9; --appearance-notice-edge: #c9ac80;
  --appearance-error-surface: #492834; --appearance-error-text: #ffd0d7; --appearance-error-edge: #d990a1;
  --appearance-warning-badge: #ffdd9c; --appearance-urgent-badge: #ffb3c4; --appearance-badge-text: #261925;
  --appearance-panel-overlay: #35263a;
}

:root[data-theme=dc] {
  color-scheme: light;
  --bg: #f0f6f7; --panel: #fcffff; --line: #738791;
  --text: #142b39; --muted: #385460; --accent: #12536a;
  --appearance-surface: #e5eff2; --appearance-control: #f3f9fa;
  --appearance-raised: #dce9ed; --appearance-selected: #d4e6eb; --appearance-edge: #567782;
  --appearance-soft-text: #385460; --appearance-link: #12536a; --appearance-action-text: #fff;
  --appearance-notice: #fbedd2; --appearance-notice-text: #624407; --appearance-notice-edge: #84600e;
  --appearance-error-surface: #f8e1e6; --appearance-error-text: #7e2d3e; --appearance-error-edge: #9b4756;
  --appearance-warning-badge: #704c12; --appearance-urgent-badge: #8d3345; --appearance-badge-text: #fff;
  --appearance-panel-overlay: #f3f9fa;
}

#appearance-panels { display: none; }
[data-layout=spacious] #appearance-panels { display: block; font-size: 12px; padding: 6px; }
[data-layout=spacious]:not([data-show-secondary]) main > :is(
  #limits, #focus, .toolbar, #runtime-diagnostics, #charter, #pbar, .reply-order-row, footer,
  .pane[data-pane=limits], .pane[data-pane=focus], .pane[data-pane=toolbar],
  .pane[data-pane=runtime], .pane[data-pane=charter], .pane[data-pane=pbar]
) { display: none !important; }
[data-layout=spacious] .message :is(pre, .md),
[data-layout=spacious] #prompt { font-size: 16px; line-height: 1.65; }
[data-layout=spacious] .message { max-width: 75ch; margin-block: 24px; }
[data-layout=spacious] .message.user { padding: 18px 22px; }
[data-layout=spacious] #composer { padding-block: 16px; }
[data-layout=spacious] #prompt { min-height: 76px; }

[data-layout=compact] .sidebar { padding: 14px 10px; }
[data-layout=compact] .brand { gap: 8px; font-size: 16px; }
[data-layout=compact] :is(.logo, .pav) { flex-shrink: 0; }
[data-layout=compact] .logo { width: 30px; height: 30px; }
[data-layout=compact] .sectionlabel { margin: 18px 0 6px; }
[data-layout=compact] .identity { padding-top: 16px; }
[data-layout=compact] .new { margin-top: 8px; }
[data-layout=compact] .session { margin-bottom: 2px; font-size: 12px; }
[data-layout=compact] .pchip { gap: 4px; font-size: 11px; }
[data-layout=compact] .pav { width: 18px; height: 18px; font-size: 10px; }
[data-layout=compact] main { padding-block: 10px; }
[data-layout=compact] main > header { padding-block: 2px; }
[data-layout=compact] main > header h1 { font-size: 16px; }
[data-layout=compact] .message { margin-block: 7px; }
[data-layout=compact] .message.user { padding: 7px 10px; }
[data-layout=compact] .message .role { margin-bottom: 3px; }
[data-layout=compact] .message :is(pre, .md) { font-size: 13px; line-height: 1.4; }
[data-layout=compact] .message .md p { margin-bottom: .45em; }
[data-layout=compact] .message .md p:last-child { margin-bottom: 0; }
[data-layout=compact] #composer { margin-top: 6px; padding: 8px; }
[data-layout=compact] #prompt { min-height: 45px; }
[data-layout=compact] .composefoot { margin-top: 5px; }

@media (min-width: 551px) {
  [data-layout=compact] .shell { grid-template-columns: var(--sbw, 208px) minmax(0, 1fr); }
  [data-layout=compact] #files { width: 27%; padding: 7px 9px; }
  [data-layout=compact] main { padding-inline: clamp(12px, 1.6vw, 24px); }
  [data-layout=compact] #prompt { font-size: 13px; line-height: 1.4; }
  [data-layout=compact] .sidebar :is(.session, .node, .agent, .new) { padding: 4px 7px; }
  [data-layout=spacious] .shell { grid-template-columns: var(--sbw, 300px) minmax(0, 1fr); }
  [data-layout=spacious] .sidebar :is(.session, .node) { padding-block: 12px; font-size: 14px; }
}

@media (min-width: 551px) and (max-width: 800px) {
  [data-layout=compact] .shell { grid-template-columns: var(--sbw, 162px) minmax(0, 1fr); }
  [data-layout=spacious] .shell { grid-template-columns: var(--sbw, 270px) minmax(0, 1fr); }
  [data-layout=compact] .brand small { letter-spacing: 0; }
}

@media (max-width: 550px) {
  main > header:has(#appearance) { gap: 5px; flex-wrap: wrap; }
  main > header:has(#appearance) .titlebox { min-width: 0; flex: 1; }
  #appearance > summary { padding-inline: 6px; }
}

.box > #appearance {
  --line: var(--appearance-edge, #627184);
  --panel: var(--appearance-control, #161b22);
  --accent: var(--appearance-link, #a8d2ff);
  --muted: var(--appearance-soft-text, #b9c7d6);
  float: right;
}
.box > #appearance button {
  width: auto;
  margin: 0;
  border-color: var(--line);
  background: var(--appearance-surface, #18222e);
  color: var(--text, #e6edf3);
}
.box > #appearance button[aria-pressed="true"] { border-color: var(--accent); }
:root[data-theme]:not([data-theme=classic]) body:has(.box > #appearance) {
  background: var(--bg);
  color: var(--text);
}
:root[data-theme]:not([data-theme=classic]) .box .choice { border-color: var(--line); }
:root[data-theme]:not([data-theme=classic]) .box :is(input,textarea,button:not(.primary)) {
  background: var(--appearance-control);
  border-color: var(--line);
  color: var(--text);
}
:root[data-theme]:not([data-theme=classic]) .box :is(.primary,.wallet-link) {
  background: var(--accent);
  color: var(--appearance-action-text);
}
:root[data-theme]:not([data-theme=classic]) .box a { color: var(--accent); }
:root[data-theme]:not([data-theme=classic]) .box .wallet-link { color: var(--appearance-action-text); }
:root[data-theme]:not([data-theme=classic]) .box .err { color: var(--appearance-error-text); }
:root[data-theme]:not([data-theme=classic]) .box small { color: var(--muted); }

[data-swatch=terminal] { --swatch: #24282a; }
[data-swatch=neutral] { --swatch: #d7dadc; }
[data-swatch=warm] { --swatch: #eedac6; }

:root[data-theme=terminal] {
  color-scheme: dark;
  --bg: #141719; --panel: #1f2427; --line: #5d696e;
  --text: #e5e9e8; --muted: #b1bcbd; --accent: #b8ebae;
  --appearance-surface: #1a1f21; --appearance-control: #22282b;
  --appearance-raised: #293236; --appearance-selected: #303e36; --appearance-edge: #799485;
  --appearance-soft-text: #b1bcbd; --appearance-link: #bef0b6; --appearance-action-text: #142214;
  --appearance-notice: #342d20; --appearance-notice-text: #ffe0a1; --appearance-notice-edge: #a58a52;
  --appearance-error-surface: #3b282b; --appearance-error-text: #ffceca; --appearance-error-edge: #b17c7b;
  --appearance-warning-badge: #ffd884; --appearance-urgent-badge: #ffb9b0; --appearance-badge-text: #231a13;
  --appearance-panel-overlay: #22282b;
}
[data-theme=terminal] body { font-family: ui-monospace, Consolas, monospace; }
[data-theme=terminal] :is(button, select, #composer, .message.user, .appearance-options) { border-radius: 4px; }

:root[data-theme=neutral] {
  color-scheme: light;
  --bg: #fafafa; --panel: #fff; --line: #8b8f93;
  --text: #212326; --muted: #52575d; --accent: #333e4a;
  --appearance-surface: #f0f1f2; --appearance-control: #fff;
  --appearance-raised: #e9ebed; --appearance-selected: #dce2e7; --appearance-edge: #68737d;
  --appearance-soft-text: #52575d; --appearance-link: #304c65; --appearance-action-text: #fff;
  --appearance-notice: #f8efd9; --appearance-notice-text: #64480c; --appearance-notice-edge: #8e6c24;
  --appearance-error-surface: #f9e3e2; --appearance-error-text: #802d2b; --appearance-error-edge: #9e4d49;
  --appearance-warning-badge: #765219; --appearance-urgent-badge: #823433; --appearance-badge-text: #fff;
  --appearance-panel-overlay: #fff;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme=neutral] {
    color-scheme: dark;
    --bg: #222324; --panel: #2c2e30; --line: #72777d;
    --text: #f1f2f3; --muted: #c3c7ce; --accent: #d4dee7;
    --appearance-surface: #282a2c; --appearance-control: #35383b;
    --appearance-raised: #393d41; --appearance-selected: #444b52; --appearance-edge: #929ba5;
    --appearance-soft-text: #c3c7ce; --appearance-link: #bed8f0; --appearance-action-text: #22272d;
    --appearance-notice: #3a3426; --appearance-notice-text: #ffdf9a; --appearance-notice-edge: #b69b60;
    --appearance-error-surface: #442e32; --appearance-error-text: #ffd2ce; --appearance-error-edge: #cf8e88;
    --appearance-warning-badge: #ffe0a0; --appearance-urgent-badge: #ffbdb9; --appearance-badge-text: #221819;
    --appearance-panel-overlay: #35383b;
  }
}
[data-layout=feed] #messages,
[data-layout=feed] #composer { width: 100%; max-width: 52rem; margin-inline: auto; }
[data-layout=feed] #composer { border-radius: 26px; padding-inline: 16px; }
[data-layout=feed] .message { max-width: 100%; }
[data-layout=feed] .message:not(.user) pre { font-family: inherit; }

:root[data-theme=warm] {
  color-scheme: light;
  --bg: #f7f0e6; --panel: #fff9f2; --line: #998674;
  --text: #372c25; --muted: #635449; --accent: #824b34;
  --appearance-surface: #f0e6da; --appearance-control: #fff9f2;
  --appearance-raised: #eee1d3; --appearance-selected: #e8d7c4; --appearance-edge: #94755f;
  --appearance-soft-text: #635449; --appearance-link: #824b34; --appearance-action-text: #fff9f2;
  --appearance-notice: #faedce; --appearance-notice-text: #634508; --appearance-notice-edge: #896a31;
  --appearance-error-surface: #f7e1da; --appearance-error-text: #842f29; --appearance-error-edge: #a85c50;
  --appearance-warning-badge: #745319; --appearance-urgent-badge: #883f31; --appearance-badge-text: #fff;
  --appearance-panel-overlay: #fff9f2;
}
[data-theme=warm] :is(h1,h2) { font-family: Georgia, serif; }
[data-theme=warm] #composer { border-radius: 18px; background: var(--appearance-control); }
[data-theme=warm] .message:not(.user) pre { font-family: inherit; }

.appearance-options {
  max-height: min(28rem, calc(100dvh - 7rem));
  overflow: auto;
}
.appearance-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
[data-labels=icons] .appearance-icon-control {
  font-size: 0 !important;
  min-width: 34px;
  min-height: 32px;
}
[data-labels=icons] #appearance > summary.appearance-icon-control { text-align: center; }
[data-labels=icons] :is(.twisty, .dots).appearance-icon-control { min-width: 26px; min-height: 28px; }
[data-labels=icons] :is(.twisty, .dots) > .appearance-icon { width: 15px; height: 15px; }
[data-labels=icons] .appearance-icon-control:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 550px) {
  main #appearance { position: static; }
  main .appearance-options { right: 0; top: 100%; }
  [data-labels=icons] main > header { align-content: flex-start; }
  [data-labels=icons] main > header .appearance-icon-control { min-width: 40px; min-height: 40px; }
  [data-labels=icons] .composefoot > div { display: flex; flex-wrap: wrap; gap: 4px; }
}

/* Автор реплики: цвет по адресу/id и аватар у первой реплики серии (tasks/2026-11-29-author-color-avatar.md).
   Оттенок --au-h ставит participants.js; яркость берётся смесью с цветом текста темы, поэтому контраст держит тема. */
.message.authored { --au: hsl(var(--au-h) 70% 50%); --au-ink: color-mix(in oklab, var(--au) 55%, var(--text)); }
.message.authored > .role { display: flex; align-items: center; flex-wrap: wrap; gap: 0 6px; overflow-wrap: anywhere; }
.message.authored > .role .msg-link { margin-left: auto; order: 9; }
.message .au-av {
  display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: color-mix(in oklab, var(--au) 30%, var(--appearance-raised, #222b30)); color: var(--au-ink);
  font-size: 11px; font-weight: 700; letter-spacing: 0;
}
.message.authored.au-cont { margin-top: 6px; }
:root:not([data-authors=plain]) .message.authored > .role { color: var(--au-ink); font-weight: 700; }
:root:not([data-authors=plain]) .message.authored:not(.user) { border-left: 3px solid var(--au); padding-left: 12px; }
:root:not([data-authors=plain]) .message.authored.user {
  background: color-mix(in oklab, var(--au) 12%, var(--appearance-raised, #222b30));
  border-left: 3px solid var(--au);
}
[data-authors=plain] .message.authored > .role { color: var(--text); font-weight: 700; }
[data-authors=plain] .message .au-av { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--muted); }
[data-layout=compact] .message .au-av { width: 18px; height: 18px; font-size: 9px; }
@media (max-width: 550px) {
  .message .au-av { width: 20px; height: 20px; font-size: 10px; }
  .message.user { margin-left: 0; }
}
