/* EW picture (web/ew.mjs): map labels and the track card.
 * DESIGN.md: labels are cartographic text (console.css styles them in the console shell);
 * simulated tracks are marked on the map by the SYN- prefix and the white ring, and by one
 * neutral SIM tag in the card. EW labels hide below z5 (ew.mjs puts .ew-z-lo on the map).
 * The card is the selection panel on the right, under the HUD (console.css places it):
 * kinematics first, a small photo figure with its credit, then the reference.
 * Tokens: --cx-* with DESIGN.md fallbacks; body.nvg re-points them (theme.css palette). */

body {
  --pb-panel: var(--cx-panel, #1c2127);
  --pb-raised: var(--cx-raised, #252a31);
  --pb-hover: var(--cx-hover, #2f343c);
  --pb-line: var(--cx-line, rgba(255, 255, 255, .10));
  --pb-line-hi: var(--cx-line-hi, rgba(255, 255, 255, .22));
  --pb-ink: var(--cx-ink, #f6f7f9);
  --pb-dim: var(--cx-dim, #abb3bf);
  --pb-mute: var(--cx-mute, #8f99a8);
  --pb-sel: var(--cx-select, #2d72d2);
  --pb-sel-ink: var(--cx-select-ink, #fff);
  --pb-focus: var(--cx-focus, #4c90f0);
  --pb-ok: var(--cx-ok, #32a467);
  --pb-warn: var(--cx-warn, #ec9a3c);
  --pb-bad: var(--cx-bad, #e76a6e);
  --pb-font: var(--cx-font, "Public Sans", system-ui, sans-serif);
  --pb-mono: var(--cx-mono, "IBM Plex Mono", ui-monospace, monospace);
  --pb-r: var(--cx-r, 2px);
  --pb-shadow: var(--cx-shadow, 0 6px 20px rgba(0, 0, 0, .45));
  --pb-field: rgba(0, 0, 0, .28);
}
body.nvg {
  --pb-panel: var(--cx-panel, var(--panel)); --pb-raised: var(--cx-raised, var(--panel-2)); --pb-hover: var(--cx-hover, var(--hover));
  --pb-line: var(--cx-line, var(--line)); --pb-line-hi: var(--cx-line-hi, var(--line-hi));
  --pb-ink: var(--cx-ink, var(--text)); --pb-dim: var(--cx-dim, var(--dim)); --pb-mute: var(--cx-mute, var(--mute));
  --pb-sel: var(--cx-select, var(--hi)); --pb-sel-ink: var(--cx-select-ink, var(--hi-ink)); --pb-focus: var(--cx-focus, var(--hi));
  --pb-ok: var(--cx-ok, var(--ok)); --pb-warn: var(--cx-warn, var(--warn)); --pb-bad: var(--cx-bad, var(--bad));
  --pb-field: #000; --pb-shadow: none;
}

/* ———————————————————————— map labels (DOM markers) ———————————————————————— */
.ew-label {
  display: grid; grid-template-columns: auto; align-items: baseline;
  padding: 1px 4px;
  color: var(--pb-ink); background: transparent; border: 0; border-radius: 0;
  font: 600 12px/1.25 var(--pb-font); letter-spacing: 0; text-align: left;
  text-shadow: 0 0 2px #000, 0 0 2px #000, 0 1px 3px rgba(0, 0, 0, .8);
  white-space: nowrap; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ew-label-name { color: var(--pb-ink); }
.ew-label-meta { font: 400 11px/1.25 var(--pb-mono); letter-spacing: 0; color: var(--pb-dim); }
.ew-label-meta:empty { display: none; }
.ew-label.ew-label-hidden { visibility: hidden; pointer-events: none; } /* ew.mjs declutter */
/* SIM is not repeated on the map: the SYN- prefix and the white ring carry it. */
.ew-label .ew-sim-tag, .ew-sim-tag { display: none; }
/* EW labels hide below z5 (ew.mjs toggles .ew-z-lo on the map container). */
.ew-z-lo .ew-label { display: none; }
.ew-stale .ew-label { opacity: .45; }
@media (pointer: coarse) { .ew-label { padding: 4px 6px; } }   /* bigger tap target */
body.nvg .ew-label, body.nvg .ew-label-name, body.nvg .ew-label-meta { color: var(--text); }

/* ———————————————————————— track card ———————————————————————— */
.ewc {
  --ewc-pad: 12px;
  --ewc-head: 40px;
  --ewc-x: 32px;
  --ewc-ctl: 28px;
  --ewc-row: 32px;
  position: fixed; z-index: 45;
  display: flex; flex-direction: column;
  color: var(--pb-ink); background: var(--pb-panel);
  border: 1px solid var(--pb-line); border-radius: var(--pb-r);
  box-shadow: var(--pb-shadow);
  font: 400 13px/1.4 var(--pb-font);
  overflow: hidden;
}
.ewc[data-form="phone"], .ewc[data-form="tablet"],
:root:is([data-input="touch"], [data-input="pen"]) .ewc {
  --ewc-pad: 16px; --ewc-head: 48px; --ewc-x: 44px; --ewc-ctl: 44px; --ewc-row: 44px;
}
.ewc svg { display: block; flex: none; }
.ewc :focus-visible { outline: 2px solid var(--pb-focus); outline-offset: 2px; }
/* Placement outside the console shell (console.css docks it on the right, under the HUD). */
.ewc, .ewc[data-form="desktop"] {
  left: calc(var(--tool-w, 0px) + var(--safe-l, 0px) + 12px);
  top: calc(var(--bar-h, 0px) + var(--safe-t, 0px) + 12px);
  width: 340px;
  max-height: calc(100dvh - var(--bar-h, 0px) - var(--safe-t, 0px) - var(--safe-b, 0px) - 24px);
}
.ewc[data-form="tablet"] {
  left: var(--safe-l, 0px); right: auto;
  top: calc(var(--bar-h, 0px) + var(--safe-t, 0px));
  bottom: calc(var(--dock-h, 0px) + var(--safe-b, 0px));
  width: min(380px, 46vw); max-height: none;
}
.ewc[data-form="phone"] {
  left: 0; right: 0; top: var(--safe-t, 0px); bottom: 0;
  width: auto; max-height: none;
  padding-bottom: var(--safe-b, 0px);
}

/* header: affiliation letter · name and what it is · close */
.ewc-h {
  flex: none; display: flex; align-items: flex-start; gap: 10px;
  min-height: var(--ewc-head); padding: 0 4px 0 var(--ewc-pad);
  border-bottom: 1px solid var(--pb-line);
}
.ewc-aff {
  flex: none; display: grid; place-items: center;
  width: 22px; height: 20px; margin-top: calc((var(--ewc-head) - 20px) / 2);
  border: 1px solid currentColor; border-radius: var(--pb-r);
  font: 600 11px/1 var(--pb-mono); color: var(--uk, #ffff80);
}
.ewc[data-a="f"] .ewc-aff { color: var(--fr, #80e0ff); }
.ewc[data-a="h"] .ewc-aff { color: var(--ho, #ff3031); }
.ewc[data-a="n"] .ewc-aff { color: var(--ne, #aaffaa); }
.ewc-t {
  flex: 1; min-width: 0; display: grid; gap: 2px; align-content: center;
  min-height: var(--ewc-head); padding: 8px 0;
}
.ewc-name, .ewc-t strong { font: 600 13px/1.25 var(--pb-font); letter-spacing: 0; color: var(--pb-ink); overflow-wrap: anywhere; }
.ewc-sub { font: 400 12px/1.35 var(--pb-font); letter-spacing: 0; color: var(--pb-dim); white-space: normal; overflow-wrap: break-word; }
.ewc-x {
  flex: none; display: grid; place-items: center;
  width: var(--ewc-x); height: var(--ewc-x); margin-top: calc((var(--ewc-head) - var(--ewc-x)) / 2); padding: 0;
  color: var(--pb-dim); background: transparent; border: 0; border-radius: var(--pb-r); cursor: pointer;
}
.ewc-x svg { width: 16px; height: 16px; }
.ewc-x:hover { color: var(--pb-ink); background: var(--pb-hover); }
.ewc-b {
  flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: var(--ewc-pad) var(--ewc-pad) 16px;
  scrollbar-color: var(--pb-line-hi) transparent; scrollbar-width: thin;
}
.ewc-lost .ewc-h { opacity: .6; }
.ewc-lost .ewc-live dd { color: var(--pb-mute); }

/* SIM, once: neutral tag + what it covers */
.ewc-simrow { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font: 400 12px/1.3 var(--pb-font); color: var(--pb-dim); }
.ewc-tag {
  flex: none; padding: 2px 4px;
  border: 1px solid var(--pb-line-hi); border-radius: var(--pb-r);
  font: 600 11px/1 var(--pb-font); letter-spacing: .06em; text-transform: uppercase; color: var(--pb-dim);
}

/* live data: caption labels, mono values, no box */
.ewc-live, .ewc-specs {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; align-items: baseline;
  margin: 0; padding: 0; background: none; border: 0;
}
.ewc-live dt, .ewc-specs dt {
  font: 600 11px/1.6 var(--pb-font); letter-spacing: .06em; text-transform: uppercase; color: var(--pb-mute);
}
.ewc-live dd, .ewc-specs dd {
  margin: 0; min-width: 0;
  font: 400 13px/1.5 var(--pb-mono); font-variant-numeric: tabular-nums slashed-zero; color: var(--pb-ink);
  overflow-wrap: anywhere;
}
/* The HUD above the card already shows the position (console shell, every form). */
.ui-console:has(.cx-hud:not([hidden])) .ewc .ewc-pos { display: none; }

/* photo: a small figure with its credit beside it */
.ewc-fig {
  display: grid; grid-template-columns: 136px minmax(0, 1fr); gap: 10px; align-items: start;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--pb-line);
}
.ewc-fig[hidden] { display: none; }
.ewc-hero, .ewc-wthumb {
  position: relative; margin: 0;
  aspect-ratio: 3 / 2; background: var(--pb-raised) center / cover no-repeat;
  border-radius: var(--pb-r); overflow: hidden;
}
.ewc-hero img, .ewc-wthumb img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity 180ms ease-out;
}
.ewc-hero img.ewc-ready, .ewc-wthumb img.ewc-ready { opacity: 1; }
body.nvg .ewc-hero, body.nvg .ewc-wthumb { filter: grayscale(1) brightness(.35) sepia(1) saturate(3) hue-rotate(-38deg); }
.ewc-credit { margin: 4px 0 0; font: 400 11px/1.4 var(--pb-font); color: var(--pb-mute); overflow-wrap: anywhere; }
.ewc-fig .ewc-credit { margin: 0; }

/* reference */
.ewc-details { padding: 0; }
.ewc-loading { padding: 12px 0 0; font: 400 12px/1.4 var(--pb-font); color: var(--pb-mute); }
.ewc-summary { margin: 12px 0 0; font: 400 13px/1.45 var(--pb-font); color: var(--pb-dim); }
.ewc-sec { margin-top: 16px; }
.ewc-sec h3 {
  margin: 0 0 8px; padding: 0; border: 0;
  font: 600 12px/1.2 var(--pb-font); letter-spacing: 0; text-transform: none; color: var(--pb-dim);
}
.ewc-sec > .ewc-credit { margin-top: 8px; }
.ewc-row { display: grid; gap: 2px; padding: 8px 0; border-top: 1px solid var(--pb-line); }
.ewc-sec h3 + .ewc-row, .ewc-sec h3 + .ewc-row-btn, .ewc-sec h3 + .ewc-weapon { border-top: 0; padding-top: 0; }
.ewc-row-btn {
  width: calc(100% + 16px); min-height: var(--ewc-row); margin: 0 -8px; padding: 8px;
  color: inherit; background: transparent; border: 0; border-top: 1px solid var(--pb-line); border-radius: 0;
  text-align: left; font: inherit; cursor: pointer;
}
.ewc-sec h3 + .ewc-row-btn { padding-top: 8px; }
.ewc-row-btn:hover { background: var(--pb-hover); }
.ewc-row-name { font: 500 13px/1.3 var(--pb-font); color: var(--pb-ink); }
.ewc-row-meta { font: 400 12px/1.35 var(--pb-mono); font-variant-numeric: tabular-nums slashed-zero; color: var(--pb-dim); }
.ewc-link {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--ewc-ctl); margin: 12px 0 0 -8px; padding: 0 8px;
  color: var(--pb-dim); background: transparent; border: 0; border-radius: var(--pb-r);
  font: 500 13px/1 var(--pb-font); letter-spacing: 0; text-transform: none; cursor: pointer;
}
.ewc-link svg { width: 16px; height: 16px; }
.ewc-link:hover { color: var(--pb-ink); background: var(--pb-hover); }
.ewc-weapon { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-top: 1px solid var(--pb-line); }
.ewc-weapon > .ewc-wtext:only-child { grid-column: 1 / -1; }
.ewc-wthumb { aspect-ratio: 4 / 3; }
.ewc-wtext { display: grid; gap: 2px; min-width: 0; }
.ewc-wsum { font: 400 12px/1.4 var(--pb-font); color: var(--pb-dim); }
.ewc-wtext .ewc-credit { margin: 4px 0 0; }

/* phone: the figure takes the width it has */
.ewc[data-form="phone"] .ewc-fig { grid-template-columns: 160px minmax(0, 1fr); }

@media (prefers-reduced-motion: reduce) {
  .ewc-hero img, .ewc-wthumb img { transition: none; }
}
