/* Heads-up display over the 3D scene. The scene is always black, so the HUD is dark-only. */
.hud {
  --surface: rgba(18, 18, 18, 0.82);
  --surface-raised: #1f1f1e;
  --track: #2c2c2a;
  --rule: rgba(255, 255, 255, 0.08);
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8a8980;
  --neutral-fill: #c3c2b7;
  --starved: #ffffff; /* neutral — red would collide with the Cleaning task colour */

  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  color: var(--text-primary);
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--rule);
  border-radius: 12px;
  font: 400 13px/1.35 'Roboto', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.hud * {
  font-family: inherit;
  font-weight: inherit;
}

.hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
}

.hud-title {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.hud-toggle {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.hud-toggle::before {
  content: '–';
  font-size: 18px;
}

.hud.is-collapsed .hud-toggle::before {
  content: '+';
}

.hud-toggle:hover,
.hud-toggle:focus-visible {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.hud.is-collapsed .hud-body {
  display: none;
}

.hud-body {
  overflow-y: auto;
  padding: 0 14px 12px;
}

.hud-section {
  padding: 10px 0;
  border-top: 1px solid var(--rule);
}

.hud-heading {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* --- Colony stats ------------------------------------------------------- */
.hud-stat {
  display: grid;
  grid-template-columns: 92px 1fr 56px;
  align-items: center;
  gap: 10px;
  min-height: 22px;
}

.hud-stat-label {
  color: var(--text-secondary);
}

.hud-stat-value {
  text-align: right;
  color: var(--text-primary);
}

.hud-stat-value--big {
  font-size: 15px;
  font-weight: 500;
}

.hud-meter {
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}

.hud-meter-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--neutral-fill);
  transition: width 240ms linear;
}

/* --- Allocation stacked bar --------------------------------------------- */
.hud-stack {
  display: flex;
  gap: 2px;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--track);
}

.hud-stack-seg {
  flex: 0 1 0;
  min-width: 2px;
  background: var(--task);
  transition: flex-grow 240ms linear;
}

.hud-stack-seg[hidden] {
  display: none;
}

/* --- Task rows ---------------------------------------------------------- */
.hud-task-head,
.hud-task {
  display: grid;
  grid-template-columns: 118px 1fr 90px;
  align-items: center;
  gap: 10px;
}

.hud-task-head {
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.hud-demand-head {
  display: flex;
  justify-content: space-between;
}

.hud-task {
  position: relative;
  padding: 5px 4px;
  margin: 0 -4px;
  border-radius: 6px;
  outline: none;
  cursor: default;
}

.hud-task:hover,
.hud-task:focus-visible {
  background: var(--surface-raised);
}

.hud-task-name {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-swatch {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--task);
}

.hud-work {
  display: grid;
  grid-template-columns: 1fr 26px;
  align-items: center;
  gap: 6px;
}

.hud-bar {
  height: 8px;
  border-radius: 0 4px 4px 0;
  background: var(--track);
  overflow: hidden;
}

.hud-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 0 4px 4px 0;
  background: var(--task);
  transition: width 240ms linear;
}

.hud-count {
  text-align: right;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Diverging demand bar: left of centre = over-served, right = under-served. */
.hud-demand {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--track);
}

.hud-demand-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  border-radius: 4px 0 0 4px;
  background: var(--text-muted);
  transition:
    left 240ms linear,
    width 240ms linear;
}

.hud-demand-fill.is-under {
  border-radius: 0 4px 4px 0;
  background: var(--neutral-fill);
}

.hud-task.is-starved .hud-demand-fill {
  background: var(--starved);
}

.hud-demand-mid {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: calc(50% - 1px);
  width: 2px;
  background: var(--text-secondary);
}

/* Share of ants that know where this task is (only with AUTODISCOVERING). */
.hud-known {
  position: absolute;
  left: 4px;
  bottom: 1px;
  height: 2px;
  width: 0;
  max-width: 96px;
  background: var(--task);
  opacity: 0.55;
  transition: width 240ms linear;
}

.hud-note {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

/* --- Tooltip ------------------------------------------------------------ */
.hud-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 11;
  min-width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--rule, rgba(255, 255, 255, 0.08));
  border-radius: 8px;
  background: #1f1f1e;
  color: #ffffff;
  font: 400 12px/1.4 'Roboto', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms;
}

.hud-tip.is-visible {
  opacity: 1;
}

.hud-tip strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}

.hud-tip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: #c3c2b7;
}

.hud-tip-value {
  color: #ffffff;
}

@media (max-width: 480px) {
  .hud {
    top: auto;
    bottom: 16px;
    max-height: 55vh;
  }

  .hud-task-head,
  .hud-task {
    grid-template-columns: 92px 1fr 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud *,
  .hud-tip {
    transition: none !important;
  }
}

/* --- Speed control (stays visible when the panel is collapsed) ---------- */
.hud-speed {
  display: grid;
  grid-template-columns: 28px 1fr 56px;
  align-items: center;
  gap: 10px;
  padding: 0 14px 12px;
}

.hud-play {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 11px;
}

/* Icons drawn in CSS: the ❚❚ glyph is missing from Roboto and renders as a box. */
.hud-play::before {
  content: '';
  display: block;
  width: 3px;
  height: 10px;
  margin: 0 auto;
  border-left: 3px solid currentColor;
  border-right: 3px solid currentColor;
  box-sizing: content-box;
}

.hud-play.is-paused::before {
  width: 0;
  height: 0;
  margin-left: calc(50% - 3px);
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent currentColor;
}

.hud-play:hover,
.hud-play:focus-visible {
  background: var(--track);
}

.hud-slider {
  width: 100%;
  margin: 0;
  accent-color: var(--neutral-fill);
  cursor: pointer;
}

.hud-speed-value {
  text-align: right;
  font-weight: 500;
}

.hud-tip * {
  font-family: inherit;
}

.hud-stat-note {
  color: var(--text-muted);
  font-size: 12px;
}

/* Workforce bar: awake (solid) then asleep (faded) share of the same track. */
.hud-bar {
  display: flex;
}

.hud-bar-fill {
  flex: none;
}

.hud-bar-fill--asleep {
  opacity: 0.35;
}

.hud-bar-fill:has(+ .hud-bar-fill--asleep:not([style*='width: 0%'])) {
  border-radius: 0;
}

.hud-stack-seg--asleep {
  background-image: repeating-linear-gradient(135deg, transparent 0 3px, rgba(0, 0, 0, 0.35) 3px 5px);
}

.hud-stat.is-empty .hud-stat-value {
  color: #ffffff;
  font-weight: 500;
}


.hud-note--tight {
  margin-top: 2px;
}

/* --- About panel (same surface as the HUD, docked right) --------------- */
.hud.about {
  left: auto;
  right: 16px;
  width: min(360px, calc(100vw - 32px));
  user-select: text;
}

.about-body {
  color: var(--text-secondary);
  line-height: 1.5;
}

.about-body b {
  color: var(--text-primary);
  font-weight: 500;
}

.about-intro {
  margin: 0 0 10px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}

.about-section {
  border-top: 1px solid var(--rule);
}

.about-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  color: var(--text-primary);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.about-section summary::-webkit-details-marker {
  display: none;
}

.about-section summary::after {
  content: '+';
  color: var(--text-muted);
  font-size: 15px;
}

.about-section[open] summary::after {
  content: '–';
}

.about-section summary:focus-visible {
  outline: 2px solid var(--text-secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

.about-content {
  padding-bottom: 10px;
}

.about-content p {
  margin: 0 0 8px;
}

.about-content ul,
.about-content ol {
  margin: 0;
  padding-left: 18px;
}

.about-content li + li {
  margin-top: 6px;
}

.about-content kbd,
.about-content code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.about-footer a {
  color: var(--text-secondary);
}

.about-footer a:hover {
  color: var(--text-primary);
}

/* Phones: the Anthill panel moves to the bottom, About stays at the top. */
@media (max-width: 480px) {
  .hud.about {
    top: 16px;
    bottom: auto;
    max-height: 40vh;
  }
}

.hud-task {
  cursor: pointer;
}

/* Pinned task: stays lit, with an edge in the task's colour. */
.hud-task.is-pinned {
  background: var(--surface-raised);
  box-shadow: inset 3px 0 0 var(--task);
}

/* --- evolut additions ---------------------------------------------------- */
.hud-tabs {
  display: flex;
  gap: 2px;
  padding: 2px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: var(--track);
}

.hud-tab {
  flex: 1;
  padding: 5px 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.hud-tab[aria-selected='true'] {
  background: var(--surface-raised);
  color: var(--text-primary);
  font-weight: 500;
}

.hud-tab:focus-visible,
.hud-button:focus-visible {
  outline: 2px solid var(--text-secondary);
  outline-offset: 1px;
}

.hud code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.hud-op {
  color: var(--text-muted);
}

.hud-right {
  text-align: right;
}

.hud-verified {
  display: grid;
  grid-template-columns: 1fr 40px;
  align-items: center;
  gap: 6px;
}

.hud-meter-fill--task {
  background: var(--task);
  opacity: 0.6;
}

.hud-legend,
.hud-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 8px;
  color: var(--text-secondary);
}

.hud-legend-item,
.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.hud-stat--wide {
  grid-template-columns: 92px 1fr 56px;
}

.hud-run {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 10px;
}

.hud-button {
  padding: 6px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.hud-button:hover {
  background: var(--track);
}

.hud-button:disabled {
  color: var(--text-muted);
  cursor: progress;
}

/* --- Right dock: Champions above Transfer test --------------------------- */
.hud-dock {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hud-dock > .hud {
  position: static;
  width: auto;
  max-height: none;
  min-height: 0;
  flex: 0 1 auto;
}

.hud-dock > .hud.champions {
  flex: 0 1 60%;
}

@media (max-width: 480px) {
  .hud-dock {
    max-height: 40vh;
  }
}

/* --- Champions ---------------------------------------------------------- */
.champ-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.champ {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-raised);
  outline: none;
}

.champ:hover,
.champ:focus-visible {
  box-shadow: inset 0 0 0 1px var(--text-muted);
}

.champ-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}

.champ-title {
  flex: 1;
  color: var(--text-primary);
  font-weight: 500;
}

.champ-time {
  color: var(--text-muted);
  font-size: 12px;
}

.champ-alive {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
}

.champ-alive.is-alive {
  background: var(--text-primary);
  border-color: var(--text-primary);
}

/* One cell per task, in task colour; filled strength = success rate of the verified gene. */
.champ-strip {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}

.champ-cell {
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--track);
  color: var(--text-primary);
  font: 500 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  isolation: isolate;
}

.champ-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--task);
  opacity: var(--fill, 0);
}

.champ-details summary {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.champ-details summary:focus-visible {
  outline: 2px solid var(--text-secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

.champ-gene {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.champ-gene-meta {
  color: var(--text-muted);
  font-size: 11px;
}

.hud-opchip {
  padding: 1px 0;
  border-radius: 4px;
  text-align: center;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--task) 55%, transparent);
}

.champ-cell.is-alias {
  outline: 1px dashed var(--text-primary);
  outline-offset: -3px;
}

.champ-legend {
  margin-bottom: 8px;
}

.champ-count {
  color: var(--text-primary);
  font-weight: 500;
}
