/*
SPDX-FileCopyrightText: 2026 Veselin Kolev and BRAIN++ AI Factory at Sofia Tech Park
SPDX-License-Identifier: GPL-3.0-or-later
*/

:root {
  --bg: #0d1117;
  --card: rgba(22, 27, 34, 0.93);
  --line: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #1f6feb;
  --ok: #2ea043;
  --warn: #d29922;
  --err: #f85149;
  --gutter: 16px;
  --topbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Every text size and box width is in rem, so one root size scales the whole
   interface. It steps up on wide screens -- on a 4K desktop 13px is unreadable
   -- and the boxes grow with it; each one scrolls when its content no longer
   fits the height it is allowed. */
html { font-size: 13px; }
@media (min-width: 1900px) { html { font-size: 14px; } }
@media (min-width: 2500px) { html { font-size: 15px; } }
@media (min-width: 3400px) { html { font-size: 18px; } }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
/* On body, not html: on the root element 1rem means the browser default, so a
   font shorthand there would override the root size set above. */
body { font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }

.muted { color: var(--muted); }
.small { font-size: 0.923rem; }
code { font: 0.923rem ui-monospace, SFMono-Regular, Menlo, monospace; background: #21262d; padding: 0 4px; border-radius: 4px; }
a { color: #58a6ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--gutter);
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.secondary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.compact-only { display: none; }
button.solo { border: 1px solid var(--line); border-radius: 6px; }
.group { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }

button, select {
  font: inherit;
  color: var(--text);
  background: #21262d;
  border: 0;
  padding: 5px 10px;
  cursor: pointer;
}
.group button + button { border-left: 1px solid var(--line); }
button:hover { background: #30363d; }
button:disabled { color: var(--muted); cursor: default; background: #21262d; }
button[aria-pressed="true"] { background: var(--accent); }
button.toggle { border: 1px solid var(--line); border-radius: 6px; font-weight: 600; }
select { border: 1px solid var(--line); border-radius: 6px; }
.select { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }

#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; }

.card {
  position: fixed;
  z-index: 4;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  backdrop-filter: blur(6px);
}
.card h2 { margin: 2px 0 6px; font-size: 1.231rem; display: flex; align-items: center; gap: 6px; }
.card h3 { margin: 10px 0 4px; font-size: 0.923rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.hud-title { font-weight: 600; display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }

#catalog { left: var(--gutter); top: calc(var(--topbar-h) + 12px); width: 23rem; max-height: calc(100vh - var(--topbar-h) - 24px); overflow: auto; }
.cat-group + .cat-group { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.cat-head { color: var(--muted); font-size: 0.846rem; text-transform: uppercase; letter-spacing: 0.05em; margin: 4px 0; }
.scenarios, .steps { list-style: none; margin: 0; padding: 0; }
.scenario { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; background: none; border-radius: 6px; padding: 4px 6px; }
.scenario.on { background: rgba(31, 111, 235, 0.3); }
.sc-title { font-weight: 600; }
.sc-meta { color: var(--muted); font-size: 0.846rem; }
.steps { margin: 2px 0 6px 8px; border-left: 2px solid var(--line); }
.step { display: grid; grid-template-columns: 18px 1fr auto; gap: 4px; align-items: center; width: 100%; text-align: left; background: none; padding: 2px 6px; border-radius: 4px; }
.step.on { background: rgba(255, 211, 61, 0.18); }
.step-n { color: var(--muted); font-variant-numeric: tabular-nums; }

#step { left: calc(2 * var(--gutter) + 23rem); bottom: var(--gutter); width: min(48rem, calc(100vw - 23rem - 21rem - 5 * var(--gutter))); max-height: 46vh; overflow: auto; }
.step-head { display: flex; justify-content: space-between; align-items: center; }
.summary { margin: 0 0 6px; color: #c9d1d9; font-style: italic; }
.step-text { margin: 4px 0 8px; }
.messages { margin: 0 0 6px; padding-left: 0; list-style: none; counter-reset: m; }
.messages li { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; font-size: 0.923rem; padding: 1px 0; }
.messages .dot { align-self: center; }
.m-route { color: var(--muted); }
.m-n { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 12px; }
.m-label { font-family: ui-monospace, monospace; font-size: 0.885rem; }

.gates { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.gate { font-size: 0.846rem; padding: 2px 7px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.gate b { font-weight: 700; margin-right: 2px; }
.gate-pass { border-color: var(--ok); color: #7ee787; }
.gate-deny { border-color: var(--err); color: #ffa198; background: rgba(248, 81, 73, 0.12); }
.gate-now { box-shadow: 0 0 0 2px #ffd33d; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip { font-size: 0.885rem; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); background: #161b22; text-align: left; }

.refs { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; font: 0.885rem ui-monospace, monospace; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tag { font-size: 0.846rem; padding: 0 6px; border-radius: 10px; border: 1px solid currentColor; font-weight: 600; }
.tag-ok { color: var(--ok); }
.tag-err { color: var(--err); }
.tag-design { color: #d29922; }

#panel { right: var(--gutter); top: calc(var(--topbar-h) + 12px); width: 29rem; max-height: calc(100vh - var(--topbar-h) - 220px); overflow: auto; }
#panel p { margin: 6px 0; }
.panel-actions { float: right; }
.panel-actions button { border-radius: 6px; padding: 2px 8px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

#legend { right: var(--gutter); bottom: var(--gutter); width: 21rem; max-height: 40vh; overflow: auto; }
.legend-title { font-weight: 600; cursor: pointer; }
.legend-item { display: flex; align-items: center; gap: 8px; margin: 2px 0; font-size: 0.923rem; }
.sw { width: 14px; height: 10px; border-radius: 2px; flex: none; }
.sw.line { height: 4px; }
#legend p { margin: 4px 0 6px; }

.hint { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--topbar-h) + 6px); z-index: 3; pointer-events: none; white-space: nowrap; }

@media (max-width: 1200px) {
  #legend { display: none; }
  #step { width: calc(100vw - 23rem - 3 * var(--gutter)); }
}

/* Small screens -- phones and small tablets, portrait or landscape. Kept in
   step with compactQuery in js/main.js. One-row top bar; the scenario list is
   a drawer; the step card and the actor panel are bottom sheets; the camera
   frames the scene in what is left between the bar and the sheet. */
@media (max-width: 900px), (max-height: 520px) {
  :root { --gutter: 8px; }
  html { font-size: 13px; }
  .compact-only { display: inline-flex; align-items: center; justify-content: center; }
  .wide-only, .lbl, .hint, #legend { display: none; }
  #drawer-toggle .lbl { display: inline; }

  .topbar { flex-wrap: nowrap; gap: 6px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .controls { flex-wrap: nowrap; gap: 6px; }
  .topbar button, .topbar select { min-height: 40px; min-width: 40px; padding: 6px 10px; font-size: 16px; }
  #drawer-toggle, #more-toggle { border: 1px solid var(--line); border-radius: 6px; white-space: nowrap; gap: 6px; }

  .secondary { display: none; }
  body[data-more="open"] .secondary {
    display: flex; flex-direction: column; align-items: stretch; gap: 10px;
    position: fixed; top: calc(var(--topbar-h) + 4px); right: 8px; z-index: 7;
    padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
  body[data-more="open"] .secondary .group button { flex: 1; }
  body[data-more="open"] .secondary .select { justify-content: space-between; }

  #catalog {
    top: var(--topbar-h); left: 0; bottom: 0; width: min(86vw, 340px); max-height: none;
    border-radius: 0 10px 10px 0; z-index: 6;
    /* No slide animation: closing it in the same moment as re-rendering the
       list and re-framing the camera left the slide-out stalled on screen. */
    transform: translateX(-105%);
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  body[data-drawer="open"] #catalog { transform: none; box-shadow: 8px 0 24px rgba(0, 0, 0, 0.5); }
  .scenario, .step { min-height: 40px; }

  #step {
    left: 0; right: 0; bottom: 0; width: auto; max-height: 44dvh;
    border-radius: 12px 12px 0 0; padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #step h2 { font-size: 15px; }
  .step-top { cursor: pointer; }
  .sheet-toggle { margin-left: auto; background: none; font-size: 18px; min-width: 40px; min-height: 32px; padding: 0 8px; }
  .sheet-closed { display: none; }
  body[data-sheet="collapsed"] #step .step-body,
  body[data-sheet="collapsed"] .sheet-open { display: none; }
  body[data-sheet="collapsed"] .sheet-closed { display: inline; }

  #panel {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 62dvh; z-index: 6;
    border-radius: 12px 12px 0 0; padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .panel-actions button { min-width: 40px; min-height: 36px; font-size: 18px; }

}

/* Phones held sideways: very little height, so the sheets may take more of it. */
@media (max-height: 520px) {
  #step { max-height: 50dvh; }
  #panel { max-height: 80dvh; }
}

/* Message tags: screen-space, laid out each frame so none overlap. */
.msg-tags { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.msg-leaders { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.msg-leaders line { stroke-width: 1.5; opacity: 0.8; }
.msg-tag {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: center; gap: 6px;
  max-width: 28rem; padding: 3px 8px 3px 3px;
  background: rgba(13, 17, 23, 0.9); border: 1.5px solid; border-radius: 6px;
  font: 600 1.2rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: #e6edf3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0.8;
}
.msg-tag.now { opacity: 1; box-shadow: 0 0 0 2px rgba(255, 211, 61, 0.55); }
.msg-tag i.party, .actor-tag i.party, .sw.party { flex: none; font: 800 0.9em/1.35 system-ui, sans-serif; font-style: normal; color: #0d1117; text-align: center; border-radius: 50%; }
.msg-tag i.party { min-width: 1.35em; }
.actor-tag i.party { float: left; min-width: 1.35em; margin: 0.1em 0.35em 0 0; }
/* Actor names on a small screen (labels.js): screen-space, under the message
   tags, letting taps through to the scene. */
.actor-tags { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.actor-leaders { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.actor-leaders line { stroke: #8b949e; stroke-width: 1; opacity: 0.7; }
.actor-tag {
  position: absolute; left: 0; top: 0; max-width: 62vw;
  padding: 3px 7px; background: rgba(13, 17, 23, 0.88); border: 1px solid #30363d; border-radius: 6px;
  font: 600 1.25rem/1.25 system-ui, sans-serif; color: #e6edf3;
}
.actor-tag b, .actor-tag small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actor-tag small { font-weight: 400; font-size: 0.72em; color: #8b949e; }
.sw.party { display: inline-block; width: 1.35em; height: 1.35em; font-size: 0.85rem; vertical-align: middle; }
/* A contract chip (K1, K2, ...) is two characters wide: a pill, not a disc. */
.msg-tag i.party.contract, .sw.party.contract { border-radius: 0.7em; padding: 0 0.3em; }
.sw.party.contract { width: auto; min-width: 1.35em; }
.msg-tag b { flex: none; min-width: 18px; padding: 1px 5px; border-radius: 4px; color: #0d1117; text-align: center; }

/* Small screens, after the rules above so they win. Only the number and the
   party chip on the arc, large enough to read and to tap: the full text is in
   the step sheet's numbered list, and on a phone it would cover the scene. */
@media (max-width: 900px), (max-height: 520px) {
  .msg-tag { padding: 3px; border-width: 1.5px; gap: 4px; font-size: 1.6rem; pointer-events: auto; cursor: pointer; }
  .msg-tag b { min-width: 2em; padding: 2px 8px; }
  .msg-tag span { display: none; }
  /* Tapped open: the number, the chip and the text, which wraps. */
  .msg-tag.expanded { padding: 3px 10px 3px 3px; gap: 6px; max-width: 86vw; z-index: 1; opacity: 1; }
  .msg-tag.expanded span { display: inline; white-space: normal; font-size: 0.8em; }
}
