/* AI-Control Plástev — screen UI (hud.js). Tokens live in index.html :root.
   Quiet, dense RTS panel: the world carries the colour, the HUD carries precision. */

.aic-hud {
  --bar-h: 56px;
  /* Darker state inks for icons/text on light paper (derived from tokens, never alone — always with a shape). */
  --attn-ink: color-mix(in srgb, var(--attn) 55%, var(--ink));
  --warn-ink: color-mix(in srgb, var(--attn) 45%, var(--ink));
  --done-ink: color-mix(in srgb, var(--done) 72%, var(--ink));
  --work-ink: color-mix(in srgb, var(--work) 85%, var(--ink));
  --sleep-ink: color-mix(in srgb, var(--sleep) 85%, var(--ink));
  --off-ink: color-mix(in srgb, var(--off) 70%, var(--ink));
  --hover-line: color-mix(in srgb, var(--line) 50%, var(--ink-soft));
  font-family: var(--font-body);
  color: var(--ink);
  /* JetBrains Mono would join "--" and "->" into glyphs; commands must read literally. */
  font-variant-ligatures: no-contextual;
}
.aic-hud .is-attn { --st: var(--attn); --st-ink: var(--attn-ink); }
.aic-hud .is-work { --st: var(--work); --st-ink: var(--work-ink); }
.aic-hud .is-done { --st: var(--done); --st-ink: var(--done-ink); }
.aic-hud .is-sleep { --st: var(--sleep); --st-ink: var(--sleep-ink); }
.aic-hud .is-off { --st: var(--off); --st-ink: var(--off-ink); }

.aic-hud .sr-only,
.aic-hud .goal:not(.is-active) .goal-state {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.aic-hud .ic { display: block; flex: none; }
.aic-hud .ic-knock { stroke: var(--paper); }
.aic-hud button, .aic-hud input, .aic-hud select, .aic-hud textarea { font-family: inherit; }

/* ── Buttons ── */
.hud-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); color: var(--ink);
  font: 600 var(--step--1)/1 var(--font-body);
  white-space: nowrap; cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.hud-btn:hover { background: var(--paper-2); border-color: var(--hover-line); }
.hud-btn:active:not(:disabled) { transform: translateY(1px); }
.hud-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.hud-btn.is-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.hud-btn.is-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.hud-btn.is-dark { background: var(--graphite); border-color: var(--graphite); color: var(--paper); }
.hud-btn.is-dark:hover { background: var(--ink); }
.hud-btn.is-attn { background: var(--attn); border-color: var(--attn); color: var(--ink); }
.hud-btn.is-attn:hover { background: color-mix(in srgb, var(--attn) 85%, var(--ink)); }
.hud-btn.is-quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }
.hud-btn.is-quiet:hover { background: var(--paper-2); color: var(--ink); }
.hud-btn.is-small { height: 30px; padding: 0 10px; }
.hud-icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-soft); cursor: pointer;
}
.hud-icon-btn .ic { width: 18px; height: 18px; }
.hud-icon-btn:hover { background: var(--paper-2); border-color: var(--line); color: var(--ink); }
.hud-icon-btn[aria-expanded="true"] { background: var(--paper-2); border-color: var(--line); color: var(--ink); }
.hud-icon-btn.is-dark { width: 28px; height: 28px; color: var(--paper); }
.hud-icon-btn.is-dark:hover { background: color-mix(in srgb, var(--paper) 14%, transparent); border-color: transparent; color: var(--paper); }

/* ── Command bar ── */
.hud-bar {
  position: absolute; z-index: 25;
  top: var(--gutter); left: var(--gutter); right: var(--gutter);
  height: var(--bar-h); box-sizing: border-box;
  display: flex; align-items: center; gap: 12px;
  padding-inline: 12px 8px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-panel);
  pointer-events: auto;
}
.hud-brand { display: flex; align-items: center; gap: 10px; flex: none; }
.hud-logo-glyph { display: block; flex: none; }
.hud-logo-glyph .lg-hex { fill: var(--accent); }
.hud-logo-glyph .lg-inner { fill: none; stroke: var(--paper); stroke-width: 1.4; opacity: 0.45; }
.hud-logo-glyph .lg-eye { fill: var(--paper); }
.hud-logo { font: 700 var(--step-0)/1 var(--font-display); letter-spacing: -0.01em; white-space: nowrap; }
.hud-sub {
  padding-left: 10px; border-left: 1px solid var(--line);
  font: 600 var(--step--2)/1 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft);
}
.hud-badge {
  position: relative;
  padding: 5px 7px;
  border: 1px dashed var(--hover-line); border-radius: var(--r-sm);
  background: var(--paper-2); color: var(--ink-soft);
  font: 600 var(--step--2)/1 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase;
  white-space: nowrap; cursor: help;
}
.hud-tip {
  position: absolute; z-index: 5; top: calc(100% + 10px); left: 0;
  width: 250px; padding: 8px 10px;
  background: var(--graphite); color: var(--paper);
  border-radius: var(--r-sm);
  font: 400 var(--step--1)/1.4 var(--font-body); letter-spacing: 0; text-transform: none; white-space: normal;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  pointer-events: none;
}
.hud-badge:hover .hud-tip, .hud-badge:focus-visible .hud-tip { opacity: 1; visibility: visible; transform: none; }

.hud-chips {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 2px;
  overflow-x: auto; scrollbar-width: none;
}
.hud-chips::-webkit-scrollbar { display: none; }
.hud-chip {
  position: relative; flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 10px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  font: 500 var(--step--1)/1 var(--font-body); white-space: nowrap;
  cursor: pointer;
}
.hud-chip .ic { color: var(--st-ink, var(--ink-soft)); }
.hud-chip:hover:not(:disabled) { background: var(--paper-2); border-color: var(--line); }
.hud-chip:disabled { cursor: default; color: var(--ink-soft); }
.hud-chip:disabled .ic { opacity: 0.5; }
.hud-chip-count { font: 600 var(--step--1)/1 var(--font-mono); }
.hud-chip.is-hot {
  background: color-mix(in srgb, var(--attn) 18%, var(--paper));
  border-color: color-mix(in srgb, var(--attn) 70%, var(--paper));
  font-weight: 600;
}
.hud-chip.is-hot:hover:not(:disabled) { background: color-mix(in srgb, var(--attn) 28%, var(--paper)); border-color: var(--attn); }
.hud-chip-dot { display: none; position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--attn); }
.hud-chip.is-hot .hud-chip-dot { display: block; }
.hud-chip.is-hot .hud-chip-dot::after {
  content: ''; position: absolute; inset: -4px;
  border: 2px solid var(--attn); border-radius: 50%;
  animation: hud-ping 1.6s ease-out infinite;
}
.hud-chip.is-agents { cursor: default; color: var(--ink-soft); }
.hud-chip.is-agents .ic { color: var(--ink-soft); }
.hud-chip-sep { flex: none; width: 1px; height: 22px; margin: 0 6px; background: var(--line); }

.hud-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.hud-switch {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 8px;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  font: 500 var(--step--1)/1 var(--font-body);
  cursor: pointer;
}
.hud-switch:hover { background: var(--paper-2); }
.hud-switch-track { position: relative; flex: none; width: 32px; height: 18px; border-radius: 9px; background: var(--hover-line); transition: background-color 0.15s; }
.hud-switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 35%, transparent);
  transition: transform 0.15s;
}
.hud-switch[aria-checked="true"] .hud-switch-track { background: var(--accent); }
.hud-switch[aria-checked="true"] .hud-switch-thumb { transform: translateX(14px); }

.hud-help-wrap { position: relative; }
.hud-pop {
  position: absolute; z-index: 6; top: calc(100% + 14px); right: -8px;
  width: min(340px, calc(100vw - 32px)); box-sizing: border-box;
  /* Short viewports (landscape phones, docked devtools): scrolls instead of cutting off its last control */
  max-height: calc(100vh - 92px); max-height: calc(100dvh - 92px);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-panel);
}
.hud-pop-title {
  margin: 0 0 12px;
  font: 700 var(--step--2)/1.2 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft);
}
.hud-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.hud-legend li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.hud-legend-ic {
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--st) 16%, var(--paper));
  color: var(--st-ink);
}
.hud-legend-text { font-size: var(--step--1); line-height: 1.35; }
.hud-legend-text strong { display: block; font-weight: 600; }
.hud-legend-text span { color: var(--ink-soft); }
.hud-pop-foot { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: var(--step--1); color: var(--ink-soft); }

/* ── State pill ── */
.hud-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 9px 0 7px; box-sizing: border-box;
  border: 1px solid color-mix(in srgb, var(--st) 45%, var(--paper)); border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--st) 15%, var(--paper));
  font: 600 var(--step--1)/1 var(--font-body); white-space: nowrap;
}
.hud-pill .ic { color: var(--st-ink); }
.hud-pill.is-small { height: 22px; padding: 0 7px 0 5px; font-size: var(--step--2); }
.hud-pill.is-small .ic { width: 14px; height: 14px; }

/* ── Drawer ── */
.hud-drawer {
  position: absolute; z-index: 20;
  top: calc(var(--gutter) + var(--bar-h) + 12px); right: var(--gutter); bottom: var(--gutter);
  width: min(440px, 100vw - 32px);
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
  pointer-events: auto;
  animation: hud-drawer-in 0.2s ease-out;
}
.dr-head {
  flex: none;
  display: grid; grid-template-columns: auto 1fr auto; column-gap: 12px;
  padding: 14px 10px 0 16px;
  border-bottom: 1px solid var(--line);
}
.dr-glyph { padding-top: 2px; }
.dr-glyph .ic { width: 32px; height: 32px; }
.dr-heading { min-width: 0; }
.dr-title {
  margin: 0; font: 700 var(--step-1)/1.25 var(--font-display); text-wrap: balance; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
/* Machine · host on one line; the path on its own line, cut with an ellipsis (full path in the title) */
.dr-meta, .dr-path {
  margin: 4px 0 0; font: 400 var(--step--2)/1.5 var(--font-mono); color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dr-path { margin-top: 0; }
.dr-sep { margin: 0 6px; opacity: 0.6; }
.dr-state { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.dr-since { font: 400 var(--step--2)/1 var(--font-mono); color: var(--ink-soft); }
.dr-close { margin-top: -4px; }
.dr-tabs { grid-column: 1 / -1; display: flex; gap: 2px; margin: 12px 0 0 -8px; }
.dr-tab {
  position: relative;
  padding: 10px 12px 11px;
  border: 0; border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: transparent; color: var(--ink-soft);
  font: 600 var(--step--1)/1 var(--font-body);
  cursor: pointer;
}
.dr-tab:hover { background: var(--paper-2); color: var(--ink); }
.dr-tab[aria-selected="true"] { color: var(--ink); }
.dr-tab[aria-selected="true"]::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--accent); }
.dr-tab-dot { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--attn); vertical-align: 1px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--attn) 30%, transparent); }
.dr-panel { flex: 1 1 auto; min-height: 0; }
.dr-panel:focus { outline: none; }

/* INFO */
.dr-info { overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 16px; }
.info-about { margin: 0 0 12px; font-size: var(--step--1); color: var(--ink-soft); text-wrap: pretty; }
.info-attn {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  margin-bottom: 12px; padding: 10px 10px 10px 12px;
  border: 1px solid color-mix(in srgb, var(--attn) 60%, var(--paper)); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--attn) 13%, var(--paper));
}
.info-attn > .ic { width: 20px; height: 20px; color: var(--attn-ink); }
.info-attn-text { min-width: 0; font-size: var(--step--1); line-height: 1.35; }
.info-attn-text strong { display: block; }
.info-attn-text span { color: var(--ink-soft); }
.info-sec { padding: 14px 0; border-top: 1px solid var(--line); }
.info-about + .info-sec, .info-attn + .info-sec, .dr-info > .info-sec:first-child { border-top: 0; padding-top: 2px; }
.info-sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.info-sec-head h3 {
  margin: 0;
  font: 700 var(--step--2)/1.2 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft); text-wrap: balance;
}
.info-sec-aside { font: 600 var(--step--2)/1 var(--font-mono); color: var(--ink-soft); }
.info-empty { margin: 0; font-size: var(--step--1); color: var(--ink-soft); }
.now-activity { margin: 0 0 10px; font-size: var(--step-0); font-weight: 500; overflow-wrap: anywhere; }
.now-activity code, .history-title code {
  padding: 1px 5px; border-radius: 4px; background: var(--paper-2);
  font: 500 0.88em/1.3 var(--font-mono);
}
/* Result of a finished project, on top of INFO */
.info-result {
  margin-bottom: 12px; padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--done) 55%, var(--paper)); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--done) 11%, var(--paper));
}
.info-result-head { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: var(--step--1); font-weight: 600; }
.info-result-head .ic { width: 18px; height: 18px; color: var(--done-ink); }
.info-result-text { margin: 0 0 6px; font-size: var(--step--1); text-wrap: pretty; }
.info-result-meta { margin: 0 0 8px; font: 400 var(--step--2)/1.4 var(--font-mono); color: var(--ink-soft); }
.link-btn {
  padding: 0; border: 0; background: none; color: var(--accent-strong);
  font: 600 var(--step--1)/1.4 var(--font-body);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; cursor: pointer;
}
.link-btn:hover { color: var(--accent); text-decoration-thickness: 2px; }
/* Recently finished tasks */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history-item { display: grid; grid-template-columns: 18px 1fr auto; gap: 1px 10px; align-items: start; font-size: var(--step--1); }
.history-item > .ic { grid-row: span 2; width: 18px; height: 18px; margin-top: 1px; color: var(--done-ink); }
.history-title { min-width: 0; font-weight: 600; }
.history-time { font: 400 var(--step--2)/1.7 var(--font-mono); color: var(--ink-soft); white-space: nowrap; }
.history-result { grid-column: 2 / -1; font: 400 var(--step--2)/1.4 var(--font-mono); color: var(--ink-soft); overflow-wrap: anywhere; }
.task { padding: 10px 12px 9px; border-radius: var(--r-md); background: var(--paper-2); }
.task-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.task-title { font-size: var(--step--1); font-weight: 600; }
.task-pct { font: 600 var(--step--1)/1 var(--font-mono); }
.task-bar { height: 8px; overflow: hidden; border-radius: 4px; background: color-mix(in srgb, var(--ink) 10%, var(--paper-2)); }
.task-fill { display: block; height: 100%; border-radius: 4px; background: var(--tint, var(--accent)); transition: width 0.4s ease; }
.task-note { margin: 8px 0 0; font-size: var(--step--2); color: var(--ink-soft); }
.agents { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.agent {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
}
.agent-type { padding: 4px 6px; border-radius: var(--r-sm); background: var(--graphite); color: var(--paper); font: 600 var(--step--2)/1 var(--font-mono); white-space: nowrap; }
.agent-task { min-width: 0; font-size: var(--step--1); line-height: 1.35; }
.agent-time { font: 400 var(--step--2)/1 var(--font-mono); color: var(--ink-soft); white-space: nowrap; }
.goals { list-style: none; margin: 0; padding: 0; display: grid; }
.goal { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: var(--step--1); }
.goal .ic { width: 18px; height: 18px; }
.goal.is-done .ic { color: var(--done-ink); }
.goal.is-done .goal-title { color: var(--ink-soft); }
.goal.is-active .ic { color: var(--work-ink); }
.goal.is-active .goal-title { font-weight: 600; }
.goal.is-todo .ic { color: var(--off-ink); }
.goal-state { font: 600 var(--step--2)/1 var(--font-mono); color: var(--work-ink); }
.build { display: flex; align-items: center; gap: 14px; }
.pips { display: flex; gap: 3px; flex: none; }
.pip { width: 22px; height: 22px; color: color-mix(in srgb, var(--ink-soft) 45%, var(--paper)); }
.pip.is-next { stroke-dasharray: 3 2.4; }
.build-text { margin: 0; font-size: var(--step--1); color: var(--ink-soft); line-height: 1.35; }
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.link { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; font-size: var(--step--1); }
.link a { color: var(--accent-strong); font-weight: 600; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.link a:hover { color: var(--accent); text-decoration-thickness: 2px; }
.link-url { font: 400 var(--step--2)/1.3 var(--font-mono); color: var(--ink-soft); }
.link.is-missing { align-items: center; gap: 8px; }
.link.is-missing .ic { width: 15px; height: 15px; color: var(--off-ink); }
.link-label { font-weight: 600; }
.link-missing { color: var(--ink-soft); }
.info-foot { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.info-foot > .hud-btn { margin-left: -10px; }
.info-foot.is-confirm { padding: 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper-2); }
.info-foot.is-confirm p { margin: 0 0 10px; font-size: var(--step--1); }
.info-foot-actions { display: flex; gap: 8px; }

/* CHAT */
.dr-chat { display: flex; flex-direction: column; }
.chat-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 44px; box-sizing: border-box; padding: 6px 10px 6px 16px;
  border-bottom: 1px solid var(--line);
}
.chat-bar.is-empty { display: none; }
.chat-status { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink-soft); }
.chat-agents { display: inline-flex; align-items: center; gap: 4px; font: 600 var(--step--2)/1 var(--font-mono); white-space: nowrap; }
.chat-agents .ic { width: 14px; height: 14px; }
.chat-typing-note { font-size: var(--step--2); }
.chat-log {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px 12px;
  overflow-y: auto; overscroll-behavior: contain;
}
.chat-log:focus-visible { outline-offset: -3px; }
.msg-time { font: 400 var(--step--2)/1 var(--font-mono); color: var(--ink-soft); }
.msg-user { align-self: flex-end; max-width: 86%; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; margin: 8px 0 2px; }
.msg-bubble {
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--paper));
  border-radius: var(--r-md) var(--r-md) var(--r-sm) var(--r-md);
  background: color-mix(in srgb, var(--accent) 11%, var(--paper));
  font-size: var(--step--1); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-assistant { display: grid; grid-template-columns: 20px 1fr; gap: 8px; align-items: start; margin-top: 4px; }
.msg-avatar .ic { width: 20px; height: 20px; }
.msg-text { margin: 0; font-size: var(--step--1); white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; }
.msg-body .msg-time { display: block; margin-top: 4px; }
.msg.is-flash .msg-text { border-radius: 4px; background: color-mix(in srgb, var(--done) 18%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--done) 18%, transparent); transition: background-color 0.3s; }
.msg-system {
  align-self: center; max-width: 92%;
  padding: 3px 10px; margin: 2px 0;
  border-radius: var(--r-sm); background: var(--paper-2);
  font-size: var(--step--2); line-height: 1.35; color: var(--ink-soft); text-align: center;
}
.msg-tool { margin-left: 28px; }
.tool-row {
  width: 100%; display: flex; align-items: center; gap: 7px;
  padding: 5px 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper-2); color: var(--ink);
  font: 400 var(--step--2)/1.3 var(--font-mono); text-align: left;
  cursor: pointer;
}
.tool-row:hover { border-color: var(--hover-line); }
.tool-glyph { display: grid; place-items: center; flex: none; width: 14px; }
.tool-glyph .ic { width: 14px; height: 14px; }
.msg-tool[data-status="ok"] .tool-glyph { color: var(--done-ink); }
.msg-tool[data-status="running"] .tool-glyph { color: var(--work-ink); }
.msg-tool[data-status="running"] .tool-glyph .ic { animation: hud-spin 0.9s linear infinite; }
.msg-tool[data-status="error"] .tool-glyph { color: var(--warn-ink); }
.msg-tool[data-status="error"] .tool-out { color: var(--warn-ink); }
.tool-name { flex: none; font-weight: 600; }
.tool-arg { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-out { flex: 0 1 auto; max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.tool-chev { width: 12px; height: 12px; color: var(--ink-soft); transition: transform 0.15s; }
.tool-row[aria-expanded="true"] .tool-chev { transform: rotate(90deg); }
.tool-detail { margin-top: 4px; padding: 8px 10px 4px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); }
.tool-label { display: block; margin-bottom: 4px; font: 700 var(--step--2)/1 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); }
.tool-code { margin: 0 0 8px; font: 400 var(--step--2)/1.45 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-typing { align-items: center; }
.typing-dots { justify-self: start; display: inline-flex; gap: 4px; padding: 8px 10px; border-radius: var(--r-md); background: var(--paper-2); }
.typing-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-soft); animation: hud-dot 1.2s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }

.chat-attn {
  flex: none; margin: 0 12px 10px; padding: 12px;
  border: 1px solid color-mix(in srgb, var(--attn) 65%, var(--paper)); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--attn) 12%, var(--paper));
  box-shadow: 0 -10px 18px -14px color-mix(in srgb, var(--ink) 40%, transparent);
  animation: hud-rise 0.2s ease-out;
}
.chat-attn:focus { outline: none; }
.chat-attn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.attn-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.attn-head > .ic { width: 20px; height: 20px; color: var(--attn-ink); }
.attn-title { flex: 1 1 auto; margin: 0; font-size: var(--step--1); font-weight: 600; }
.attn-title code { padding: 2px 5px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); font: 600 var(--step--1)/1 var(--font-mono); }
.attn-id { padding: 4px 6px; border-radius: var(--r-sm); background: var(--graphite); color: var(--paper); font: 600 var(--step--2)/1 var(--font-mono); white-space: nowrap; }
.attn-desc { margin: 8px 0; font-size: var(--step--1); }
.attn-code {
  max-height: 8.5em; overflow: auto;
  margin: 0 0 10px; padding: 8px 10px;
  border-radius: var(--r-sm); background: var(--graphite); color: var(--paper);
  font: 400 var(--step--1)/1.45 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.attn-actions { display: flex; gap: 8px; }
.attn-actions .hud-btn { flex: 1 1 0; }
.attn-question { margin: 8px 0 6px; font-size: var(--step-0); font-weight: 500; text-wrap: pretty; }
.attn-hint {
  padding: 0; border: 0; background: none;
  color: var(--accent-strong); font: 500 var(--step--1)/1.4 var(--font-body);
  text-align: left; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  cursor: pointer;
}
.attn-hint:hover { color: var(--accent); }

.chat-composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 4px; border-top: 1px solid var(--line); }
.chat-attn:not([hidden]) + .chat-composer { border-top: 0; padding-top: 0; }
.chat-input {
  flex: 1 1 auto; min-width: 0; box-sizing: border-box;
  min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--paper-2); color: var(--ink);
  font: 400 var(--step--1)/1.45 var(--font-body);
  resize: none; overflow-y: hidden;
}
.chat-input:hover { border-color: var(--hover-line); }
.chat-input:focus { background: var(--paper); border-color: var(--accent); }
.chat-input::placeholder { color: color-mix(in srgb, var(--ink-soft) 80%, var(--paper)); }
.chat-send { height: 38px; }
.chat-hint { flex: none; margin: 0; padding: 2px 14px 10px; font: 400 var(--step--2)/1.2 var(--font-mono); color: var(--ink-soft); }

/* ── Toasts & error pill ── */
.hud-toasts {
  position: absolute; z-index: 30; left: 50%; bottom: var(--gutter);
  transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.hud-toast {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  border-radius: var(--r-md);
  background: var(--graphite); color: var(--paper);
  font: 500 var(--step--1)/1.3 var(--font-body);
  box-shadow: 0 12px 24px -12px color-mix(in srgb, var(--ink) 70%, transparent);
  animation: hud-rise 0.2s ease-out;
}
.hud-toast .ic { width: 16px; height: 16px; opacity: 0.85; }
.hud-toast.is-out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
.hud-error {
  position: absolute; z-index: 31; left: var(--gutter); bottom: var(--gutter);
  max-width: min(520px, calc(100vw - 32px)); box-sizing: border-box;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 4px 4px 10px;
  border-radius: var(--r-md);
  background: var(--graphite); color: var(--paper);
  font: 400 var(--step--2)/1.35 var(--font-mono);
  pointer-events: auto;
}
.hud-error > .ic { color: var(--attn); }
.hud-error-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-error-count { color: var(--attn); font-weight: 600; }

/* ── FPS meter (legend switch or Shift+P) ── */
.hud-pop-perf { margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
.hud-pop-switch { display: flex; width: calc(100% + 16px); margin: 0 -8px; text-align: left; }
.hud-pop-switch-label { font-weight: 600; }
.hud-kbd {
  margin-left: auto; padding: 3px 6px 2px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  background: var(--paper-2); color: var(--ink-soft);
  font: 600 var(--step--2)/1 var(--font-mono);
}
.hud-pop-note { margin: 0; font-size: var(--step--2); line-height: 1.4; color: var(--ink-soft); }
/* Under every panel (the phone sheet and the empty-hive card cover it); never takes the pointer */
.hud-perf {
  position: absolute; z-index: 14; left: var(--gutter); bottom: var(--gutter);
  width: 202px; box-sizing: border-box;
  padding: 8px 10px 9px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: 0 10px 24px -18px color-mix(in srgb, var(--ink) 55%, transparent);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  contain: layout paint style;
  /* Own compositor layer: its four updates a second re-raster only this box. Sharing a layer with the rest of
     the HUD cost 80–150 ms frames over a 5120 px canvas. */
  will-change: transform;
}
/* Above the error pill while it shows (28 px button + 2 × 4 px padding, then an 8 px gap) */
.hud-error:not([hidden]) ~ .hud-perf { bottom: calc(var(--gutter) + 44px); }
.hud-perf[data-state="good"] { --st: var(--done); --st-ink: var(--done-ink); }
.hud-perf[data-state="fair"] { --st: var(--attn); --st-ink: var(--attn-ink); }
.hud-perf[data-state="slow"] { --st: var(--attn); --st-ink: var(--warn-ink); }
.perf-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.perf-fps { display: flex; align-items: baseline; gap: 4px; margin: 0; }
.perf-fps-num { font: 600 var(--step-3)/1 var(--font-mono); letter-spacing: -0.03em; }
.perf-unit { font: 600 var(--step--2)/1 var(--font-mono); color: var(--ink-soft); }
.perf-state {
  display: inline-flex; align-items: center; gap: 4px; margin: 0;
  height: 22px; padding: 0 7px 0 5px; box-sizing: border-box;
  border: 1px solid color-mix(in srgb, var(--st, var(--line)) 45%, var(--paper)); border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--st, var(--paper-2)) 15%, var(--paper));
  font: 600 var(--step--2)/1 var(--font-body); white-space: nowrap;
}
.hud-perf[data-state="slow"] .perf-state { background: color-mix(in srgb, var(--attn) 30%, var(--paper)); }
.perf-state-ic:empty { display: none; }
.perf-state-ic .ic { width: 14px; height: 14px; color: var(--st-ink, var(--ink-soft)); }
.perf-spark { display: block; width: 180px; height: 28px; margin-top: 8px; }
.perf-legend { display: flex; align-items: center; gap: 6px; margin: 3px 0 0; font: 400 var(--step--2)/1.2 var(--font-mono); color: var(--ink-soft); }
.perf-legend-line { width: 14px; border-top: 1px dashed var(--ink); opacity: 0.6; }
.perf-stats { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 8px; margin: 8px 0 0; padding-top: 7px; border-top: 1px solid var(--line); }
.perf-stat { min-width: 0; }
.perf-stat dt { font-size: var(--step--2); line-height: 1.2; color: var(--ink-soft); white-space: nowrap; }
.perf-stat dd { margin: 2px 0 0; font: 600 0.75rem/1.2 var(--font-mono); white-space: nowrap; }

/* Warm-up after boot (hud.js warmUp): the drawer lays out hidden, then is drawn for two frames at 1/255
   opacity, so fonts, styles and GPU raster programs are ready before the first real open. */
.hud-drawer.is-warm { visibility: hidden; animation: none; pointer-events: none; }
.hud-drawer.is-warm-paint { visibility: visible; opacity: 0.004; will-change: opacity; }

/* ── Modal ── */
.hud-modal-backdrop {
  position: absolute; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: var(--gutter);
  background: color-mix(in srgb, var(--graphite) 40%, transparent);
  pointer-events: auto;
  animation: hud-fade 0.15s ease-out;
}
.hud-modal {
  width: min(600px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-panel);
  animation: hud-rise 0.2s ease-out;
}
.modal-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.modal-title { margin: 0; font: 700 var(--step-1)/1.2 var(--font-display); text-wrap: balance; }
.modal-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; gap: 14px; padding: 16px 20px 18px; }
.modal-help { margin: 0; padding: 10px 12px; border-radius: var(--r-md); background: var(--paper-2); font-size: var(--step--1); color: var(--ink-soft); }
.modal-foot { flex: none; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-label { display: flex; align-items: baseline; gap: 8px; padding: 0; font-size: var(--step--1); font-weight: 600; }
.field-opt { font-size: var(--step--2); font-weight: 400; color: var(--ink-soft); }
.input {
  box-sizing: border-box; width: 100%; height: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper-2); color: var(--ink);
  font: 400 var(--step--1)/1 var(--font-body);
}
.input.is-mono { font-family: var(--font-mono); font-size: 0.78rem; }
.input:hover { border-color: var(--hover-line); }
.input:focus { background: var(--paper); border-color: var(--accent); }
.input::placeholder { color: color-mix(in srgb, var(--ink-soft) 75%, var(--paper)); }
.input[aria-invalid="true"] { border-color: var(--warn-ink); background: color-mix(in srgb, var(--attn) 8%, var(--paper)); }
select.input { cursor: pointer; }
.field-hint { margin: 0; font-size: var(--step--2); color: var(--ink-soft); }
.field-err { margin: 0; display: flex; align-items: flex-start; gap: 6px; font-size: var(--step--2); font-weight: 600; line-height: 1.4; color: var(--warn-ink); }
.field-err .ic { width: 14px; height: 14px; margin-top: 1px; }
.fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.fieldset > legend { margin-bottom: 6px; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.swatch { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r-sm); cursor: pointer; }
.swatch:hover { background: var(--paper-2); }
.swatch input, .robot-card input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.swatch-hex { width: 28px; height: 28px; }
.swatch:has(input:checked) { background: var(--paper-2); box-shadow: inset 0 0 0 2px var(--ink); }
.swatch:has(input:focus-visible), .robot-card:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch-custom { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--line); }
.swatch-color-label { font-size: var(--step--1); color: var(--ink-soft); cursor: pointer; }
.swatch-color { width: 38px; height: 30px; padding: 1px 2px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper-2); cursor: pointer; }
.robots { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.robot-card {
  position: relative;
  display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--paper);
  cursor: pointer;
}
.robot-card:hover { border-color: var(--hover-line); background: var(--paper-2); }
.robot-ic { grid-row: span 3; width: 22px; height: 22px; color: var(--ink-soft); }
/* Idle-pose thumbnail in the chosen tint (engine.robotThumbs); 2× pixels for sharp edges */
.robot-thumb { grid-row: span 3; width: 52px; height: 52px; margin: -4px -2px -4px -4px; }
.robot-name { font-size: var(--step--1); font-weight: 600; }
.robot-tag { grid-column: 2; font-size: var(--step--2); line-height: 1.3; color: var(--ink-soft); }
.robot-used { grid-column: 2; font-size: var(--step--2); line-height: 1.3; color: var(--ink-soft); font-weight: 600; }
.robot-card:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: color-mix(in srgb, var(--pick, var(--accent)) 10%, var(--paper)); }
.robot-card:has(input:checked) .robot-ic { color: var(--pick, var(--accent)); }

/* ── Empty hive ── */
.hud-empty {
  position: absolute; z-index: 15; left: 50%; bottom: calc(var(--gutter) + 56px);
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 32px)); box-sizing: border-box;
  padding: 16px 18px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-panel);
  text-align: center;
  pointer-events: auto;
}
.hud-empty-title { margin: 0 0 6px; font: 700 var(--step-1)/1.25 var(--font-display); }
.hud-empty-text { margin: 0 0 14px; font-size: var(--step--1); color: var(--ink-soft); text-wrap: pretty; }
.hud-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.hud-pop-restore { margin: 8px 0 0 -10px; }
.hud-switch-short { display: none; }

/* ── Motion ── */
@keyframes hud-ping { from { transform: scale(0.5); opacity: 0.9; } to { transform: scale(1.7); opacity: 0; } }
@keyframes hud-spin { to { transform: rotate(360deg); } }
@keyframes hud-dot { 0%, 60%, 100% { opacity: 0.3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes hud-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes hud-fade { from { opacity: 0; } }
@keyframes hud-drawer-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes hud-sheet-in { from { opacity: 0; transform: translateY(24px); } }

/* ── Narrower desktops: chip labels collapse to icon + count (except the one that needs you) ── */
@media (max-width: 1180px) {
  .hud-sub { display: none; }
  .hud-chip:not(.is-attn):not(.is-agents) .hud-chip-label {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}

/* ── Phones: two-row bar, icon-only actions, bottom-sheet drawer ── */
@media (max-width: 640px) {
  .aic-hud { --bar-h: 100px; }
  /* Vlákna = plástve: on a thread cell .dr-meta carries „počítač · složka · vlákno 2 · s2“, which the ellipsis cut to
     „vl…“ at phone width — and the seat is the one part that says WHICH conversation is open. The path below still
     truncates (a full path never fits and its title carries it), so only this line is let out onto a second row. */
  .dr-meta { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
  .hud-bar { height: auto; flex-wrap: wrap; row-gap: 6px; padding: 6px 6px 0 10px; }
  .hud-brand { flex: 1 1 auto; min-width: 0; gap: 8px; }
  .hud-logo { display: none; }
  .hud-chips {
    order: 3; flex: 1 0 100%; justify-content: flex-start;
    margin: 0 -6px 0 -10px; padding: 5px 6px 6px 8px;
    border-top: 1px solid var(--line);
  }
  .hud-chip { height: 32px; padding: 0 8px; }
  /* More chips off to the right: the row fades out until it is scrolled to the end */
  .hud-chips.is-more {
    -webkit-mask-image: linear-gradient(90deg, var(--ink) 78%, transparent);
    mask-image: linear-gradient(90deg, var(--ink) 78%, transparent);
  }
  .hud-switch-short { display: inline; font: 600 var(--step--2)/1 var(--font-body); color: var(--ink-soft); }
  /* Same selector as the 1180px rule, later in the file: labels come back in the scrollable row. */
  .hud-chip:not(.is-attn):not(.is-agents) .hud-chip-label { position: static; width: auto; height: auto; margin: 0; clip: auto; overflow: visible; }
  .swatch-custom { flex-basis: 100%; margin: 2px 0 0; padding-left: 0; border-left: 0; }
  .hud-btn-label, .hud-switch-label {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  #hud-add { width: 36px; padding: 0; }
  .hud-switch { padding: 0 6px; }
  .hud-tip { left: -40px; }
  .hud-drawer {
    top: auto; left: var(--gutter); right: var(--gutter); bottom: 0;
    /* 72 % leaves a strip above the sheet where the engine parks the focused robot */
    /* fixed height: the chat panel flexes inside it, whatever the header's height */
    width: auto; height: 72vh; height: 72dvh;
    border-bottom: 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
    animation-name: hud-sheet-in;
  }
  .hud-empty { bottom: var(--gutter); }
  .chat-hint { display: none; }
  .chat-composer { padding-bottom: 10px; }
  .chat-send { width: 38px; padding: 0; }
  .hud-toasts { bottom: auto; top: calc(var(--gutter) + var(--bar-h) + 8px); }
  .hud-modal-backdrop { padding: 12px var(--gutter); }
  .field-row { grid-template-columns: 1fr; }
  .robots { grid-template-columns: 1fr 1fr; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 10px 16px; }
}
