/* The battle for a finger (step 29 E6 - docs/SERIES_PLAN.md E6 points 4-5, docs/series/audit/touch.md 4.3-4.4): the touch
   bar along the bottom of the map (src/ui/touchbar.js) and what stands on it (the selection panel, the group bar: --tb-h,
   its height, set by the bar), the long press's ring (ui/longpress.js), the battle HUD's targets under body.touch (the
   sidebar's tools, the radar's buttons, the panels' buttons and tiles, the group bar's slots and views), the key badges
   hidden on touch. Loaded last (after touch.css: the page, the menus, the safe area --sa-*). */

/* ---------------- the bar: its groups of buttons along the bottom of the map, the camera's on the right; a group that
   does not fit goes up a row. Only the buttons take the finger - the map between them stays the map. */
#touchbar { position: absolute; left: calc(10px + var(--sa-l, 0px)); right: 10px; bottom: calc(10px + var(--sa-b, 0px)); z-index: 7;
  display: flex; flex-wrap: wrap-reverse; align-items: flex-end; gap: calc(6px * var(--hud)) calc(10px * var(--hud)); pointer-events: none; }
#chat-box:not([hidden]) ~ #touchbar { bottom: calc(52px + var(--sa-b, 0px)); }
#replay-bar:not([hidden]) ~ #touchbar { bottom: calc(60px + var(--sa-b, 0px)); }
.tb-grp { display: flex; gap: calc(4px * var(--hud)); padding: calc(4px * var(--hud)); border-radius: calc(var(--r, 3px) + 3px); pointer-events: auto;
  background: rgba(0, 0, 0, .52); box-shadow: 0 0 0 1px rgba(0, 0, 0, .65), inset 0 1px 0 rgba(255, 255, 255, .05), 0 4px 14px rgba(0, 0, 0, .45); }
.tb-camera { margin-left: auto; }
#app #touchbar .tb-b { width: calc(56px * var(--hud)); min-width: 0; height: calc(48px * var(--hud)); padding: 0; touch-action: manipulation; }
#app #touchbar .tb-b svg.hi { width: calc(24px * var(--hud)); height: calc(24px * var(--hud)); }
body:not(.touch) #app #touchbar .tb-b:has(> kbd:not([hidden])) > svg.hi { translate: calc(-3px * var(--hud)) calc(-3px * var(--hud)); }  /* (a mouse player's bar: the key in the corner) */
#app #touchbar .tb-mode .tb-b { color: #fff; border-color: #2a0806; background: linear-gradient(#b83d2d, #6c1c14);
  box-shadow: inset 0 1px 0 rgba(255, 190, 170, .3), 0 0 8px rgba(216, 58, 44, .5); }
.tb-toggles .tb-b.on svg.hi { filter: drop-shadow(0 0 4px rgba(255, 255, 255, .55)); }

/* what stands on the bar: the selection panel (in its corner - a dragged one stays where it was put) and the group bar */
#view-wrap.tb-on > #sel-panel, #view-wrap.tb-on > #group-bar { bottom: calc(var(--tb-h, 0px) + 16px + var(--sa-b, 0px)); }
#view-wrap.tb-on > #chat-box:not([hidden]) ~ #sel-panel { bottom: calc(var(--tb-h, 0px) + 58px + var(--sa-b, 0px)); }
#view-wrap.tb-on > #replay-bar:not([hidden]) ~ #sel-panel { bottom: calc(var(--tb-h, 0px) + 66px + var(--sa-b, 0px)); }
/* the panels' common orders are the bar's: not twice on a small screen (E, the works, repair, sell, the power stay) */
#view-wrap.tb-on #sel-panel .sp-actions .hb:is([data-a="stop"], [data-a="stand"], [data-a="plain"], [data-a="guard"], [data-a="post"], [data-a="scatter"], [data-a="land"]) { display: none; }

/* ---------------- the ×5 toggle by the cameos (#sb-tools; the next taps on a unit's cameo queue five) */
#app #sb-tools .tb-batch .hb-t { font: 700 calc(13px * var(--hud))/1 var(--font-n, Consolas), monospace; letter-spacing: 0; }
#app #sb-tools .tb-batch:has(> .hb-t:not(:empty)) { padding: 0; }

/* ---------------- a long press: the ring that fills under the finger */
#lp-ring { position: fixed; z-index: 40; width: 68px; height: 68px; margin: -34px 0 0 -34px; pointer-events: none; }
#lp-ring svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
#lp-ring circle { fill: none; stroke-width: 4; }
#lp-ring .lp-bg { stroke: rgba(0, 0, 0, .5); }
#lp-ring .lp-fg { stroke: var(--gold); stroke-dasharray: 100; stroke-linecap: round; filter: drop-shadow(0 0 3px rgba(240, 200, 80, .65)); }

/* ---------------- the group bar on touch: empty slots 1-5, the four camera views; Queue lit - a long press adds (+) */
body.touch #app #group-bar button { width: calc(52px * var(--hud)); height: calc(44px * var(--hud)); touch-action: manipulation; }
#app #group-bar .gb-empty { background: rgba(0, 0, 0, .55); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); }
#group-bar .gb-empty b { opacity: .6; }
body.touch #app #group-bar .gb-mark { width: calc(42px * var(--hud)); }
#group-bar .gb-mark.first { margin-left: calc(7px * var(--hud)); }
#group-bar .gb-mark b { inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(12px * var(--hud)); color: var(--muted, #9a958a); }
#group-bar .gb-mark.set b { color: var(--gold); }
#app #group-bar .gb-mark.set { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--gold) 70%, transparent); }
#view-wrap.tb-shift #group-bar.gb-touch .gb-grp:not(.gb-empty)::after { content: '+'; position: absolute; right: 3px; top: 1px; z-index: 1;
  font: 700 calc(14px * var(--hud))/1 var(--font-n, Consolas), monospace; color: var(--gold); text-shadow: 1px 1px 0 #000; pointer-events: none; }
#view-wrap.tb-shift #group-bar.gb-touch .gb-grp:not(.gb-empty) span { bottom: 2px; }

/* ---------------- the battle HUD's targets for a finger (Apple: 44 pt; the panels keep their width) */
body.touch #app #sb-tools .hb { height: calc(44px * var(--hud)); touch-action: manipulation; }
body.touch #mm-tools { gap: 4px; }
body.touch #app #mm-tools button { width: calc(36px * var(--hud)); height: calc(32px * var(--hud)); font-size: calc(15px * var(--hud)); border-radius: 3px; }
body.touch #app .sp-min { width: calc(40px * var(--hud)); height: calc(40px * var(--hud)); font-size: calc(16px * var(--hud)); align-self: center; }  /* (a finger's 40 - the E6b/c check; compact.css 44 x 40) */
body.touch .sp-actions { gap: 5px; }
body.touch #app .sp-actions > button { min-height: calc(40px * var(--hud)); font-size: calc(12.5px * var(--hud)); }
body.touch #app .sp-actions .hb { min-width: calc(40px * var(--hud)); height: calc(40px * var(--hud)); }
body.touch .sg-cells { grid-template-columns: repeat(auto-fill, minmax(calc(56px * var(--hud)), 1fr)); }
body.touch .cameo, body.touch #app .sg-cell, body.touch .power-btn { touch-action: manipulation; }
/* no keyboard under the finger: the key badges go (a mouse player's bar shows them) */
body.touch #app .hb kbd, body.touch .sp-actions kbd, body.touch #cmd-grid .cameo kbd { display: none; }
body.touch .sp-actions .hb:has(> kbd) > svg.hi { translate: none; }
/* a long press on a picture never opens Safari's "Save image" */
.cameo img, #group-bar img, .sg-cell img, .sp-head img, .power-btn img { -webkit-touch-callout: none; }
