/* AI-Control Plástev — world-anchored overlays in #world (engine.js).
   Every overlay is a zero-size .eng-anchor positioned by transform each frame;
   its child hangs above that point (bubbles, nameplates on the cell floor).
   #world is pointer-transparent; only real buttons opt back in. */

.eng-anchor {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform, opacity;
  /* A class change inside one overlay re-lays out only that overlay, never the whole #world layer */
  contain: layout style;
  pointer-events: none;
  --eng-shade: color-mix(in srgb, var(--ink) 28%, transparent);
  --eng-shade-soft: color-mix(in srgb, var(--ink) 12%, transparent);
  --eng-shade-deep: color-mix(in srgb, var(--ink) 45%, transparent);
}

/* Paint order: work / sleep / offline bubbles < plates < urgent bubbles (attn, done) < floats < actions.
   A wandering robot's bubble never hides another cell's name; "needs you" and "done" always stay on top. */
.eng-anchor--bubble { z-index: 1; }
.eng-anchor--plate { z-index: 2; }
.eng-anchor--bubble.is-urgent { z-index: 3; }
.eng-anchor--prog, .eng-anchor--float { z-index: 4; }
.eng-anchor--actions { z-index: 5; }

/* ── Nameplates: real buttons resting on the cell's own floor, just inside its front wall ── */
.eng-plate {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% -100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  margin: 0;
  padding: 4px 9px 4px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--eng-shade-soft), 0 4px 10px -6px var(--eng-shade-deep);
  font: inherit;
  white-space: nowrap;
  line-height: 1.2;
  pointer-events: auto;
  cursor: pointer;
}
.eng-plate:hover { border-color: var(--ink-soft); }
.eng-plate__hex { width: 14px; height: 12px; flex: none; }
.eng-plate__name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--step--1);
  overflow: hidden;
  text-overflow: ellipsis;
}
.eng-plate__machine {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  color: var(--ink-soft);
}
/* Overview shows name + tint hex; the machine appears when zoomed in */
.eng-anchor--plate:not(.is-near) .eng-plate__machine { display: none; }
/* Phones far out: tint hex only until the robot is selected or the plate is focused */
.eng-anchor--plate.is-compact .eng-plate:not(.is-selected):not(:focus-visible) { padding: 4px 6px; }
.eng-anchor--plate.is-compact .eng-plate:not(.is-selected):not(:focus-visible) .eng-plate__name { display: none; }
.eng-plate.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 4px 10px -6px var(--eng-shade-deep); }

/* Vlákna = plástve: a THREAD plate is two lines — the conversation's own title, and under it the project it belongs
   to (spec §10). .eng-plate is one inline-flex row, which would read „Titul  Projekt“ side by side; and unlike the
   machine name on a folder plate, which project a conversation is in must be readable without zooming in, because
   two cells of one project sit next to each other and only that line tells them apart. */
.eng-plate--thread {
  display: inline-grid;
  grid-template-columns: auto max-content;
  align-items: center;
  column-gap: 6px;
  row-gap: 0;
  text-align: left;
}
.eng-plate--thread .eng-plate__hex { grid-row: 1 / span 2; align-self: center; }
.eng-plate--thread .eng-plate__name,
.eng-plate--thread .eng-plate__machine { grid-column: 2; min-width: 0; }
/* Room label (a cluster of a project's thread cells): the project's name plus how many live threads it holds.
   One row, the count quieter and one step smaller than the name, and never broken across lines — „2 vlákna“
   wrapped under the project reads as a second label. */
.eng-plate--cluster .eng-plate__count { margin-left: 6px; font-size: 0.86em; color: var(--ink-soft); white-space: nowrap; }
/* A room that is a VS CODE WINDOW rather than a folder (project.window): the same plate, with the window mark
   that tells the owner which of the two kinds of group he is looking at. Nothing louder — the group itself is
   already drawn by the shared walls and the crown; this only has to be nameable at a glance. */
.eng-plate--cluster.is-window .eng-plate__name::before {
  content: "▣ "; color: var(--ink-soft); font-size: 0.9em;
}
/* …and a window that stopped being reported: greyed out, still there. Its cells keep their places for half an
   hour (LIMITS.windowGoneKeep) — a group must never vanish under the hand that is reaching for it. */
.eng-plate--cluster.is-gone { opacity: 0.6; }
.eng-plate--cluster.is-gone .eng-plate__count { font-style: italic; }
/* …so it survives the rule above that hides the small slot at overview distance. */
.eng-anchor--plate:not(.is-near) .eng-plate--thread .eng-plate__machine { display: block; }
/* Phones far out: back to the tint hex alone, exactly like a folder plate. */
.eng-anchor--plate.is-compact .eng-plate--thread:not(.is-selected):not(:focus-visible) .eng-plate__machine { display: none; }

/* '+' slot label: hangs just below the '+' sign, inside the slot. engine.js keeps it clear of cells that hold
   a project: glyph only where the name would reach one (the name returns on keyboard focus), glyph centred
   on the slot when zoomed far out */
.eng-plate--add {
  translate: -50% 4px;             /* engine.js PLUS_GAP */
  border-style: dashed;
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--paper);
}
.eng-plate--add svg { width: 14px; height: 14px; flex: none; }
.eng-anchor--add.is-centred .eng-plate--add { translate: -50% -50%; }
.eng-anchor--add.is-compact .eng-plate--add:not(:focus-visible) { padding: 4px 6px; }
.eng-anchor--add.is-compact .eng-plate--add:not(:focus-visible) .eng-plate__name { display: none; }
.eng-plate--add:hover,
.eng-plate--add.is-hover { background: var(--accent); color: var(--accent-ink); border-style: solid; border-color: var(--accent); }

/* ── State bubbles above the robot ── */
.eng-bubble {
  position: absolute;
  left: 0;
  bottom: 10px;
  translate: -50% 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transform-origin: 50% 100%;
  line-height: 1;
}
.eng-bubble svg { width: 16px; height: 16px; flex: none; }
/* speech-bubble tail */
.eng-bubble--attn::after,
.eng-bubble--done::after,
.eng-actions::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: inherit;
  border-right: inherit;
  border-bottom: inherit;
  translate: -50% 0;
  rotate: 45deg;
  border-radius: 0 0 3px 0;
}

.eng-bubble--attn {
  padding: 6px 12px 6px 8px;
  border: 2px solid var(--ink);
  border-radius: var(--r-lg);
  background: var(--attn);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--eng-shade);
  animation: eng-pulse 1.3s ease-in-out infinite;
}
.eng-bubble__glyph {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--attn);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step-1);
}
.eng-bubble__text {
  display: none;
  font-weight: 700;
  font-size: var(--step--1);
}
/* "Potřebuju tě" reads at every distance except far out (big hives, phones) */
.eng-anchor--bubble:not(.is-far) .eng-bubble--attn .eng-bubble__text { display: inline; }
.eng-anchor.is-far .eng-bubble--attn { padding-right: 8px; }

.eng-bubble--done {
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--done);
  color: var(--accent-ink);
  box-shadow: 0 3px 0 var(--eng-shade);
  animation: eng-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}
.eng-bubble--done svg { width: 22px; height: 22px; }
.eng-bubble--done.is-small { padding: 2px; border-width: 1.5px; box-shadow: none; animation: none; }
.eng-bubble--done.is-small svg { width: 12px; height: 12px; }
.eng-bubble--done.is-small::after { display: none; }

.eng-bubble--work {
  padding: 4px 8px 4px 5px;
  border-radius: 999px;
  background: var(--work);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 var(--eng-shade);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--step--1);
}
.eng-bubble--work.is-solo { padding: 4px; }
/* Solo robot: a spinning gear. With sub-agents: the agent glyph (same as the HUD chip) + count */
.eng-bubble--work.is-solo svg { animation: eng-spin 3.2s linear infinite; }

.eng-bubble--off {
  padding: 4px 8px 4px 6px;
  border-radius: 999px;
  background: var(--off);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--step--2);
}
.eng-bubble--off svg { width: 14px; height: 14px; }

.eng-bubble--sleep {
  bottom: 0;
  gap: 2px;
  align-items: flex-end;
  translate: -15% 0;
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--sleep);
  /* paper halo so the letters hold on any floor */
  text-shadow:
    2px 0 0 var(--paper), -2px 0 0 var(--paper), 0 2px 0 var(--paper), 0 -2px 0 var(--paper),
    1.5px 1.5px 0 var(--paper), -1.5px -1.5px 0 var(--paper), 1.5px -1.5px 0 var(--paper), -1.5px 1.5px 0 var(--paper),
    0 3px 6px var(--eng-shade);
}
.eng-bubble--sleep span { display: inline-block; animation: eng-zzz 2.8s ease-in-out infinite; }
.eng-bubble--sleep span:nth-child(1) { font-size: var(--step-0); }
.eng-bubble--sleep span:nth-child(2) { font-size: var(--step-2); animation-delay: 0.45s; }
.eng-bubble--sleep span:nth-child(3) { font-size: var(--step-0); animation-delay: 0.9s; }

/* ── Construction progress chip by the scaffold (near zoom only) ── */
.eng-anchor--prog:not(.is-near) { display: none; }
.eng-prog {
  position: absolute;
  left: 0;
  bottom: 0;
  translate: -50% 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px 3px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--eng-shade-soft);
  font: 600 var(--step--2)/1 var(--font-mono);
  white-space: nowrap;
}
.eng-prog svg { width: 12px; height: 12px; color: var(--work); }

/* ── Action bubble (robot selected): INFO / CHAT ── */
.eng-actions {
  position: absolute;
  left: 0;
  bottom: 12px;
  translate: -50% 0;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 2px solid var(--ink);
  border-radius: var(--r-lg);
  background: var(--paper);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--ink) 22%, transparent), 0 14px 28px -14px color-mix(in srgb, var(--ink) 50%, transparent);
  animation: eng-pop 0.3s cubic-bezier(0.3, 1.5, 0.5, 1) both;
  pointer-events: auto;
}
.eng-actions__btn {
  min-width: 72px;
  min-height: 38px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, transform 0.12s;
}
.eng-actions__btn:hover { border-color: var(--ink-soft); background: var(--paper); }
.eng-actions__btn:active { transform: translateY(1px); }
.eng-actions__btn--primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.eng-actions__btn--primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.eng-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── Floating "+1 úroveň" ── */
.eng-float {
  position: absolute;
  left: 0;
  bottom: 0;
  translate: -50% 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px 3px 6px;
  border-radius: 999px;
  background: var(--graphite);
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--step--1);
  white-space: nowrap;
  animation: eng-rise 2s ease-out both;
}
.eng-float svg { width: 14px; height: 14px; color: var(--done); }

@keyframes eng-pulse { 0%, 100% { scale: 1; } 50% { scale: 1.07; } }
@keyframes eng-pop { from { scale: 0.3; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes eng-spin { to { rotate: 360deg; } }
@keyframes eng-zzz {
  0% { opacity: 0; transform: translate(0, 4px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(6px, -14px); }
}
@keyframes eng-rise {
  0% { opacity: 0; transform: translateY(8px) scale(0.7); }
  15% { opacity: 1; transform: translateY(0) scale(1.05); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-40px) scale(1); }
}

@media (pointer: coarse) {
  .eng-actions__btn { min-height: 44px; min-width: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  .eng-bubble--attn, .eng-bubble--work svg, .eng-bubble--sleep span { animation: none; }
  .eng-bubble--sleep span { opacity: 1; }
}
