/* Touch / Pencil interaction layer (touch.mjs, loupe.mjs, views.mjs).
 * Colours and type come from theme.css tokens; body.nvg redefines them, so
 * night mode needs no extra rules here. Everything sits inside the map
 * container, above the canvas, below app chrome. */

.tg-host {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
/* Chrome layer: sibling of #map (outside its NVG filter), same box, above the
 * map and reticle (5), below the status bar (20) and sheets (22+). Children opt
 * back in to pointer events. */
.tg-layer {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.tg-radial, .tg-views, .tg-ruler-chip { pointer-events: auto; }

/* —— radial menu —— */
.tg-radial {
  position: absolute;
  left: 0;
  top: 0;
  width: 240px;
  height: 240px;
  z-index: 30;
  display: none;
  touch-action: none;
}
.tg-radial.on { display: block; }
.tg-radial svg { overflow: visible; display: block; }
.tg-radial.pulse svg { animation: tg-pop 140ms cubic-bezier(.2, .8, .3, 1); }
.tg-radial.pulse::before {
  content: "";
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  border: 2px solid var(--hi);
  animation: tg-pulse 420ms ease-out forwards;
  pointer-events: none;
}
@keyframes tg-pop { from { transform: scale(.72); opacity: .4; } to { transform: scale(1); opacity: 1; } }
@keyframes tg-pulse { from { transform: scale(.4); opacity: .9; } to { transform: scale(1.12); opacity: 0; } }

.tg-wedge { cursor: pointer; outline: none; }
.tg-wedge path {
  fill: var(--panel);
  fill-opacity: .94;
  stroke: var(--line-hi);
  stroke-width: 1;
  transition: fill 80ms;
}
.tg-wedge text { fill: var(--text); text-anchor: middle; pointer-events: none; }
.tg-glyph { font: 600 18px var(--font); }
.tg-icon { fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.tg-wedge.hot .tg-icon,
.tg-wedge:focus-visible .tg-icon { stroke: var(--hi-ink); }
.tg-wlabel {
  font: 600 var(--fs-1, 11px) var(--font);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.tg-wedge.hot path,
.tg-wedge:focus-visible path { fill: var(--hi); fill-opacity: 1; stroke: var(--hi); }
.tg-wedge.hot text,
.tg-wedge:focus-visible text { fill: var(--hi-ink); }

/* affiliation ring: MIL-STD-2525 fill colours, dark ink */
.tg-wedge.affil-f path { stroke: var(--fr); }
.tg-wedge.affil-h path { stroke: var(--ho); }
.tg-wedge.affil-n path { stroke: var(--ne); }
.tg-wedge.affil-u path { stroke: var(--uk); }
.tg-wedge.affil-f .tg-glyph { fill: var(--fr); }
.tg-wedge.affil-h .tg-glyph { fill: var(--ho); }
.tg-wedge.affil-n .tg-glyph { fill: var(--ne); }
.tg-wedge.affil-u .tg-glyph { fill: var(--uk); }
.tg-wedge.affil-f.hot path { fill: var(--fr); stroke: var(--fr); }
.tg-wedge.affil-h.hot path { fill: var(--ho); stroke: var(--ho); }
.tg-wedge.affil-n.hot path { fill: var(--ne); stroke: var(--ne); }
.tg-wedge.affil-u.hot path { fill: var(--uk); stroke: var(--uk); }
.tg-wedge[class*="affil-"].hot text { fill: var(--hi-ink); }

.tg-hub { cursor: pointer; outline: none; }
.tg-hub circle { fill: var(--bg); stroke: var(--hi); stroke-width: 1.5; }
.tg-hub text { fill: var(--dim); text-anchor: middle; }
.tg-hub:focus-visible circle { stroke-width: 3; }

/* —— loupe —— */
.tg-loupe {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--tg-loupe, 140px);
  height: var(--tg-loupe, 140px);
  z-index: 29;
  pointer-events: none;
  display: none;
}
.tg-loupe.on { display: block; }
.tg-loupe-map,
.tg-loupe-canvas {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--hi);
  box-shadow: 0 0 0 1px var(--bg), 0 6px 18px rgba(0, 0, 0, .55);
  background: var(--bg);
}
.tg-loupe-canvas { width: 100%; height: 100%; }
.tg-loupe-map .maplibregl-canvas { border-radius: 50%; }
.tg-loupe-cross { position: absolute; inset: 0; }
.tg-loupe-cross::before,
.tg-loupe-cross::after {
  content: "";
  position: absolute;
  background: var(--hi);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6);
}
.tg-loupe-cross::before { left: 50%; top: 30%; bottom: 30%; width: 1px; }
.tg-loupe-cross::after { top: 50%; left: 30%; right: 30%; height: 1px; }
.tg-loupe-label {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  z-index: 29;
  white-space: nowrap;
  padding: 3px 7px;
  background: var(--panel);
  border: 1px solid var(--line-hi);
  color: var(--hi);
  font: 400 var(--fs-2, 13px) var(--mono);
  font-variant-numeric: tabular-nums;
}
.tg-loupe-label.detached { left: 0; top: 0; bottom: auto; display: none; pointer-events: none; }
.tg-loupe-label.detached.on { display: block; }

/* —— two-finger ruler / measure readout —— */
.tg-ruler { position: absolute; inset: 0; z-index: 28; pointer-events: none; display: none; }
.tg-ruler.on { display: block; }
.tg-ruler-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.tg-ruler-casing { stroke: rgba(0, 0, 0, .7); stroke-width: 6; stroke-linecap: round; }
.tg-ruler-line { stroke: var(--hi); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 8 5; }
.tg-ruler.live .tg-ruler-line { stroke-dasharray: none; }
.tg-ruler-end { fill: var(--hi); stroke: var(--bg); stroke-width: 2; }
.tg-ruler-chip {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 9px;
  background: var(--panel);
  border: 1px solid var(--hi);
  color: var(--text);
  font: 400 var(--fs-2, 13px) var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: auto;
}
.tg-ruler-keep {
  font: 600 var(--fs-1, 11px) var(--font);
  letter-spacing: .06em;
  min-height: 32px;
  padding: 0 10px;
  background: var(--hi);
  color: var(--hi-ink);
  border: 0;
  cursor: pointer;
  display: none;
}
.tg-ruler.lifted .tg-ruler-keep:not([hidden]) { display: inline-block; }
@media (pointer: coarse) { .tg-ruler-keep { min-width: 44px; min-height: 44px; } }

/* —— measure start pin, ring tags —— */
.tg-pin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--hi);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 4px rgba(227, 167, 47, .35);
  animation: tg-blink 1s ease-in-out infinite alternate;
}
@keyframes tg-blink { to { box-shadow: 0 0 0 9px rgba(227, 167, 47, 0); } }
.tg-ringtag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 5px;
  background: var(--panel);
  border: 1px solid var(--hi-dim);
  color: var(--hi);
  font: 400 var(--fs-1, 11px) var(--mono);
  white-space: nowrap;
}
.tg-ringx {
  border: 0;
  background: transparent;
  color: var(--dim);
  font: 600 14px var(--font);
  padding: 0 2px;
  cursor: pointer;
  min-width: 22px;
  min-height: 22px;
}
@media (pointer: coarse) { .tg-ringx { min-width: 44px; min-height: 44px; } }

/* —— gesture toast, Pencil hover chip —— */
.tg-toast {
  position: absolute;
  left: 50%;
  top: 14px;
  z-index: 31;
  transform: translate(-50%, -8px);
  opacity: 0;
  padding: 5px 12px;
  background: var(--panel);
  border: 1px solid var(--line-hi);
  border-left: 2px solid var(--hi);
  color: var(--text);
  font: 400 var(--fs-2, 13px) var(--mono);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 120ms, transform 120ms;
}
.tg-toast.on { opacity: 1; transform: translate(-50%, 0); }
.tg-penchip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 31;
  padding: 2px 6px;
  background: var(--panel);
  border: 1px solid var(--hi-dim);
  color: var(--hi);
  font: 400 var(--fs-1, 11px) var(--mono);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 90ms;
}
.tg-penchip.on { opacity: 1; }

/* —— drop target —— */
.tg-drop {
  position: absolute;
  inset: 0;
  z-index: 32;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 9, .62);
  pointer-events: none;
}
.tg-drop.on { display: flex; }
.tg-drop-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 44px;
  border: 2px dashed var(--hi);
  background: var(--panel);
  color: var(--text);
}
.tg-drop-box b { font: 600 var(--fs-3, 15px) var(--font); letter-spacing: .08em; color: var(--hi); }
.tg-drop-box span { font: 400 var(--fs-1, 11px) var(--mono); color: var(--dim); }

/* —— saved views strip —— */
.tg-views {
  position: absolute;
  left: 50%;
  bottom: var(--tg-dock-clear, 12px); /* the map box already ends above the dock + safe area */
  transform: translateX(-50%);
  z-index: 27;
  display: none;
  gap: 6px;
  max-width: calc(100% - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.tg-views.on { display: flex; }
.tg-views::-webkit-scrollbar { display: none; }
.tg-card {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 112px;
  min-height: 48px;
  padding: 4px 26px 4px 9px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line-hi);
  color: var(--text);
  cursor: pointer;
}
.tg-card b { font: 600 var(--fs-2, 13px) var(--font); letter-spacing: .04em; }
.tg-card span { font: 400 var(--fs-1, 11px) var(--mono); color: var(--dim); }
.tg-card:hover,
.tg-card:active { border-color: var(--hi-dim); }
.tg-card:focus-visible { outline: 2px solid var(--hi); outline-offset: 1px; }
.tg-card-add,
.tg-card-brief { padding-right: 9px; }
.tg-card-add b { color: var(--hi); }
.tg-card-brief { background: var(--hi); border-color: var(--hi); }
.tg-card-brief b,
.tg-card-brief span { color: var(--hi-ink); }
.tg-card-x {
  position: absolute;
  top: 0;
  right: 0;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--mute);
  font: 600 14px var(--font);
  cursor: pointer;
}
.tg-card-x:hover,
.tg-card-x:active { color: var(--bad); }
@media (pointer: coarse) {
  .tg-card { min-height: 52px; }
  .tg-card:not(.tg-card-add):not(.tg-card-brief) { padding-right: 48px; }
  .tg-card-x { width: 44px; height: 44px; }
}

/* Same floor when device.mjs reports a finger or Pencil and (pointer) is still fine. */
:root:is([data-input="touch"], [data-input="pen"]) .tg-ruler-keep { min-width: 44px; min-height: 44px; }
:root:is([data-input="touch"], [data-input="pen"]) .tg-ringx { min-width: 44px; min-height: 44px; }
:root:is([data-input="touch"], [data-input="pen"]) .tg-card { min-height: 52px; }
:root:is([data-input="touch"], [data-input="pen"]) .tg-card:not(.tg-card-add):not(.tg-card-brief) { padding-right: 48px; }
:root:is([data-input="touch"], [data-input="pen"]) .tg-card-x { width: 44px; height: 44px; }
/* Briefing (brief.mjs) hides working chrome; the map, banner and brief bar remain. */
body.tg-briefing #sheet,
body.tg-briefing #dock,
body.tg-briefing .maplibregl-ctrl-bottom-left { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .tg-radial.pulse svg,
  .tg-radial.pulse::before,
  .tg-pin { animation: none; }
  .tg-toast { transition: none; }
}
