/* Touch controls and the touch HUD (owner: WP-A, touch.md §8 and §13.2). Media queries: only the MQ
   strings from client/js/ui/layout.js plus the features the contract test allows (PLAN C36). The
   templates are body classes (tc-phoneLand, tc-phonePort, tc-tablet) set by TouchControls from the
   pure layout, and the --tc-* variables (px) say where the controls are. Keyboard and mouse play is
   untouched except the ☰ Room menu button. Nothing here animates faster than 2 Hz. */

/* ── The layer ─────────────────────────────────────────────────────────────────────────────── */
#tc-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
  padding: var(--sa-t) var(--sa-r) var(--sa-b) var(--sa-l);
}
#touch {
  position: fixed;
  inset: 0;
  z-index: var(--z-touch, 7);
  overflow: hidden;
  contain: strict;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#touch.dormant {
  pointer-events: none;
  opacity: 0;
}
#touch.covered {
  visibility: hidden;
  pointer-events: none;
}
body.touch-ui #gl {
  touch-action: none;
}
#touch button {
  margin: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: default;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Buttons ──────────────────────────────────────────────────────────────────────────────── */
#touch .tc-btn,
#touch .tc-sys {
  position: absolute;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1px;
  opacity: var(--tc-alpha, 0.6);
  background: rgba(13, 15, 20, 0.55);
  border: 2px solid var(--cyan-hi, #7fe6ff);
  color: var(--white, #fff);
  line-height: 1;
  font-family: var(--display, sans-serif);
  font-weight: 900;
}
#touch .tc-btn {
  border-radius: 50%;
}
#touch .tc-sys {
  border-radius: 12px;
  font-size: 1.35rem;
}
#touch .tc-btn[hidden],
#touch .tc-sys[hidden] {
  display: none;
}
#touch .tc-ico {
  font-size: 1.45em;
}
/* K7: the coach, the help and the How-to cards name the buttons by these words. At least 12 px, larger
   with Settings → Text size (0.75rem = 12 px × --ts) where the button has room (a 6-letter word fills
   about 0.21 of its width per px), and a dark halo so they read over the scene at any see-through level. */
#touch .tc-word {
  font-size: max(12px, min(max(0.75rem, calc(0.86em * var(--ts, 1))), calc(var(--tc-d, 60px) * 0.21)));
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.75);
}
#touch .tc-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 22px;
  padding: 2px 5px;
  border-radius: 99px;
  background: var(--ink, #0d0f14);
  border: 1px solid var(--amber, #ff9f1c);
  color: var(--amber-hi, #ffc15e);
  font: 800 0.66rem var(--body, sans-serif);
  text-align: center;
}
#touch .tc-badge:empty {
  display: none;
}
#touch .tc-btn.on,
#touch .tc-sys.on {
  opacity: 1;
  transform: scale(0.94);
  background: rgba(31, 178, 255, 0.35);
}
#touch .tc-btn.dim {
  opacity: calc(var(--tc-alpha, 0.6) * 0.55);
  border-style: dashed;
}
#touch .tc-btn.lit {
  border-color: var(--amber, #ff9f1c);
  color: var(--amber-hi, #ffc15e);
  opacity: 1;
}
/* A context hint is about this button: a cyan ring, glowing slowly (1.25 s each way, 0.4 Hz). */
#touch .tc-btn.hl,
#touch .tc-sys.hl {
  opacity: max(var(--tc-alpha, 0.6), 0.85);
  box-shadow: 0 0 0 3px var(--cyan, #1fb2ff);
  animation: tc-glow 1.25s ease-in-out infinite alternate;
}
@keyframes tc-glow {
  from {
    box-shadow: 0 0 0 3px var(--cyan, #1fb2ff);
  }
  to {
    box-shadow: 0 0 0 3px var(--cyan, #1fb2ff), 0 0 14px 4px rgba(31, 178, 255, 0.55);
  }
}

/* ── The stick ────────────────────────────────────────────────────────────────────────────── */
#touch .tc-joy,
#touch .tc-knob,
#touch .tc-move {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
#touch .tc-joy {
  opacity: calc(var(--tc-alpha, 0.6) * 0.6);
  will-change: transform;
}
#touch .tc-joy.live {
  opacity: max(var(--tc-alpha, 0.6), 0.75);
}
#touch .tc-ring {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: start center;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  color: transparent;
  font: 900 1rem var(--display, sans-serif);
}
#touch .tc-joy.sprint .tc-ring {
  border: 3px solid var(--amber, #ff9f1c);
  color: var(--amber-hi, #ffc15e);
}
#touch .tc-base {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(100% * var(--tc-base, 0.77));
  height: calc(100% * var(--tc-base, 0.77));
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--cyan-hi, #7fe6ff);
  background: rgba(13, 15, 20, 0.4);
}
#touch .tc-knob {
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  border: 2px solid var(--white, #fff);
  opacity: calc(var(--tc-alpha, 0.6) * 0.7);
  will-change: transform;
}
#touch .tc-knob.live {
  opacity: 1;
}
#touch .tc-move {
  margin-left: -30px;
  width: 60px;
  text-align: center;
  font: 900 0.72rem var(--display, sans-serif);
  letter-spacing: 0.08em;
  color: var(--cyan-hi, #7fe6ff);
}
#touch .tc-joy[hidden],
#touch .tc-knob[hidden],
#touch .tc-move[hidden] {
  display: none;
}

/* ── Bubbles (context hints and the coach) ───────────────────────────────────────────────── */
#touch .tc-bubble {
  position: absolute;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--glass-2, rgba(20, 24, 33, 0.86));
  border: 1px solid var(--line, rgba(255, 255, 255, 0.16));
  color: var(--white, #fff);
  font: 800 0.78rem/1.25 var(--body, sans-serif);
  pointer-events: none;
  box-sizing: border-box;
}
#touch .tc-bubble.left {
  text-align: right;
}
#touch .tc-bubble.above {
  text-align: center;
}
#touch .tc-bubble.gizmo {
  border-color: var(--purple, #b388ff);
}
#touch .tc-bubble.coach {
  border: 2px solid var(--cyan, #1fb2ff);
  font-size: 0.85rem;
}
#touch .tc-bubble[hidden] {
  display: none;
}

/* ── Cards in #hud that take their own taps ──────────────────────────────────────────────── */
#hud .tc-coach-skip,
#hud .tc-rotate,
#hud .spec-bar,
#hud .hud-menu-btn,
#hud .run-retry,
#hud .run-x,
#hud .board-x {
  pointer-events: auto;
}
#hud .tc-coach-skip {
  position: absolute;
  left: var(--tc-mid-x, 50%);
  bottom: calc(var(--tc-mid-b, 16px) + 4px);
  transform: translateX(-50%);
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border-radius: 99px;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.16));
  background: var(--glass-2, rgba(20, 24, 33, 0.86));
  color: var(--silver, #cfd6e0);
  font: 800 0.85rem var(--body, sans-serif);
}
#hud .tc-coach-skip[hidden] {
  display: none;
}
#hud .tc-rotate {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 16px;
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
}
#hud .tc-rotate[hidden] {
  display: none;
}
#hud .tc-rotate p {
  margin: 0;
  font-weight: 800;
}
#hud .tc-rotate-ico {
  font-size: 2rem;
  color: var(--cyan-hi, #7fe6ff);
}
#hud .tc-rotate-row {
  display: grid;
  gap: 8px;
  width: 100%;
}
#hud .tc-rotate .btn {
  min-height: 44px;
}

/* ── Keyboard mode: the ☰ Room menu button (ui.md §4.11); hidden while touch controls are up ─ */
#hud .hud-menu-btn {
  position: absolute;
  top: calc(var(--sa-t, 0px) + 14px);
  left: calc(var(--sa-l, 0px) + 14px);
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 12px;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.16));
  background: var(--glass, rgba(13, 15, 20, 0.74));
  color: var(--white, #fff);
  font: 900 1rem var(--body, sans-serif);
  cursor: pointer;
}
#hud .hud-menu-btn:focus-visible {
  outline: 2px solid var(--cyan-hi, #7fe6ff);
  outline-offset: 2px;
}
body:not(.touch-ui) #hud .voice-hud {
  top: calc(var(--sa-t, 0px) + 66px);
}
body.touch-ui #hud .hud-menu-btn {
  display: none;
}

/* ── Spectate bar: ◀ Watching NAME ▶ (keyboard and touch) ───────────────────────────────── */
#hud .spec-bar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sa-b, 0px) + 16px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: 99px;
  max-width: calc(100vw - 32px);
}
#hud .spec-bar[hidden] {
  display: none;
}
#hud .spec-bar button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.16));
  background: var(--ink-2, #161a22);
  color: var(--white, #fff);
  font-size: 1.1rem;
  cursor: pointer;
}
#hud .spec-name {
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}

/* ── Time trials on touch: ↻ Try again and ✕ on the finish card ─────────────────────────── */
#hud .run-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
#hud .run-actions .grow {
  flex: 1;
  min-width: 0;
}
#hud .run-retry,
#hud .run-x,
#hud .board-x {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.16));
  background: var(--ink-2, #161a22);
  color: var(--white, #fff);
  font: 900 0.95rem var(--body, sans-serif);
  cursor: pointer;
}
#hud .run-retry {
  padding: 0 14px;
  border-color: var(--cyan, #1fb2ff);
  color: var(--cyan-hi, #7fe6ff);
}
#hud .board-x {
  float: right;
}

/* ── Touch mode: the HUD moves clear of the thumbs (touch.md §8.2) ─────────────────────── */
body.touch-ui .panel,
body.touch-ui .toast {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body.touch-ui #hud .panel,
body.touch-ui #toasts .toast {
  background: var(--glass-2, rgba(20, 24, 33, 0.86));
}
body.touch-ui #hud .hints,
body.touch-ui #hud .up-cue {
  display: none;
}
body.touch-ui #hud .scoreboard {
  pointer-events: auto;
}
body.touch-ui #hud .gizmo-tip {
  pointer-events: none;
  max-height: calc(100dvh - var(--tc-row1-h, 60px) - 16px);
}
body.touch-ui #hud .gizmo-tip .tip-x {
  pointer-events: auto;
  width: 44px;
  height: 44px;
}
body.touch-ui #hud .gizmo-tip.compact .tip-text {
  font-size: 0.86rem;
}
body.touch-ui #hud .pill {
  font-size: 0.78rem;
  padding: 5px 10px;
}
body.touch-ui #hud .pill.timer {
  font-size: 1rem;
  min-width: 64px;
}
body.touch-ui #hud .voice-hud .pill {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.touch-ui #toasts {
  max-width: min(480px, var(--tc-topc-w, 480px));
}
body.touch-ui #hud ~ #toasts .toast {
  font-size: 0.85rem;
  max-width: 100%;
}
body.touch-ui #hud ~ #toasts .toast:nth-last-child(n + 3) {
  display: none;
}
body.touch-ui #hud .combo .chain > :nth-last-child(n + 6) {
  display: none;
}
body.touch-ui #hud .editor-bar {
  top: calc(var(--tc-row1-h, 60px) + 4px);
  bottom: auto;
  left: calc(var(--tc-left-w, 8px));
  right: calc(var(--tc-right-w, 8px));
  transform: none;
  max-width: none;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  touch-action: pan-x;
  scrollbar-width: none;
  padding: 6px;
}
body.touch-ui #hud .editor-bar::-webkit-scrollbar {
  display: none;
}
body.touch-ui #hud .editor-bar > * {
  flex: none;
  min-height: 44px;
}
body.touch-ui #hud .editor-help {
  display: none;
}
body.touch-ui #hud .editor-help.tc-open {
  display: block;
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100vw - 32px));
  box-sizing: border-box;
  z-index: 2;
}
body.touch-ui #hud .editor-help .tip-x {
  width: 44px;
  height: 44px;
}
body.touch-ui #hud .wheel.touch .slot {
  width: 84px;
  margin-left: -42px;
  font-size: 0.8rem;
  padding: 6px 2px;
}
body.touch-ui #hud .wheel.touch .slot.hub {
  width: 110px;
  margin-left: -55px;
  font-size: 0.72rem;
}

/* Phone landscape: row 1 across the top, a narrow top-right column, the band between the thumbs. */
body.touch-ui.tc-phoneLand #hud .hud-top {
  top: calc(var(--sa-t, 0px) + 16px);
  max-width: calc(100vw - 2 * max(var(--tc-left-w, 8px), var(--tc-right-w, 8px)) - 16px);
  overflow: hidden;
}
body.touch-ui.tc-phoneLand #hud .hud-top .pill-txt {
  display: none;
}
body.touch-ui.tc-phoneLand #hud .hud-top .pill:first-child .pill-txt {
  display: inline;
}
body.touch-ui.tc-phoneLand #hud .it-banner,
body.touch-ui.tc-phoneLand #hud .pause-note {
  top: calc(var(--tc-row1-h, 60px) + 4px);
}
body.touch-ui.tc-phoneLand #toasts {
  top: calc(var(--tc-row1-h, 60px) + 4px);
}
body.touch-ui.tc-phoneLand.hud-it #toasts {
  top: calc(var(--tc-row1-h, 60px) + 48px);
}
/* In play on a landscape phone the toasts sit in the free band beside the action cluster, above the
   stick, so a long one (the touch welcome is 4–5 lines) never covers FLIP, GRAB or the context
   button (WP-Z1: 667×375 with a simulated notch had it over three of them). Mirrored when
   left-handed. A toast taller than the band is cut at the stick rather than drawn over it. */
body.touch-ui.tc-phoneLand #hud:not([hidden]) ~ #toasts {
  left: calc(var(--sa-l, 0px) + 8px);
  right: calc(var(--tc-cluster-w, 300px) + 8px);
  transform: none;
  max-width: none;
  max-height: calc(100dvh - var(--tc-row1-h, 60px) - 4px - var(--tc-joy-h, 170px) - 8px);
  overflow: hidden;
}
body.touch-ui.tc-phoneLand.hud-it #hud:not([hidden]) ~ #toasts {
  max-height: calc(100dvh - var(--tc-row1-h, 60px) - 48px - var(--tc-joy-h, 170px) - 8px);
}
body.touch-ui.tc-phoneLand.tc-lefty #hud:not([hidden]) ~ #toasts {
  left: calc(var(--tc-cluster-w, 300px) + 8px);
  right: calc(var(--sa-r, 0px) + 8px);
}
/* The band holds one toast: the newest shows, an older one waits out its time hidden. */
body.touch-ui.tc-phoneLand #hud:not([hidden]) ~ #toasts .toast:nth-last-child(n + 2) {
  display: none;
}
body.touch-ui.tc-phoneLand #hud .hud-tr,
body.touch-ui.tc-phoneLand #hud .hud-score {
  top: calc(var(--sa-t, 0px) + 8px);
  right: var(--tc-right-w, 8px);
  max-width: min(260px, 36vw);
  max-height: calc(var(--tc-row1-h, 60px) - var(--sa-t, 0px) - 8px + var(--tc-tr-h, 80px));
  overflow: hidden;
}
body.touch-ui.tc-phoneLand #hud .hud-score:not([hidden]) {
  display: block;
  min-width: 0;
  width: min(220px, 34vw);
  box-sizing: border-box;
  padding: 6px 10px;
  font-size: 0.78rem;
}
body.touch-ui.tc-phoneLand #hud .hud-score h3 {
  margin: 0 0 2px;
  font-size: 0.8rem;
}
body.touch-ui.tc-phoneLand #hud .hud-score .r:nth-child(n + 5):not(.me) {
  display: none;
}
body.touch-ui.tc-phoneLand #hud .hud-tr .arch-card > :nth-child(n + 4) {
  display: none;
}
body.touch-ui.tc-phoneLand #hud .run-panel.finish {
  position: fixed;
  top: calc(var(--tc-row1-h, 60px) + 4px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: min(420px, 60vw);
  max-height: calc(100dvh - var(--tc-row1-h, 60px) - var(--tc-cluster-h, 200px));
  overflow: hidden;
  box-sizing: border-box;
  z-index: 3;
}
body.touch-ui.tc-phoneLand #hud .voice-hud,
body.touch-ui.tc-tablet #hud .voice-hud {
  top: calc(var(--tc-row1-h, 60px) + 4px);
  left: calc(var(--sa-l, 0px) + 8px);
  max-width: var(--tc-tl-w, 300px);
}
body.touch-ui.tc-phoneLand #hud .gizmo-tip {
  top: calc(var(--tc-row1-h, 60px) + 4px);
  left: calc(var(--sa-l, 0px) + 8px);
  width: min(300px, 38vw);
  max-height: max(92px, var(--tc-tl-h, 80px));
  overflow: hidden;
  padding: 6px 8px 6px 10px;
}
body.touch-ui.tc-phoneLand #hud:has(.voice-hud > *) .gizmo-tip {
  top: calc(var(--tc-row1-h, 60px) + 80px);
}
body.touch-ui.tc-phoneLand #hud .hud-br,
body.touch-ui.tc-tablet #hud .hud-br {
  left: var(--tc-mid-x, 50%);
  right: auto;
  bottom: calc(var(--tc-mid-b, 16px) + 2px);
  transform: translateX(-50%);
  align-items: center;
}
body.touch-ui.tc-phoneLand #hud .energy,
body.touch-ui.tc-tablet #hud .energy {
  width: min(220px, var(--tc-mid-w, 220px));
  box-sizing: border-box;
}
body.touch-ui.tc-phoneLand #hud .combo {
  left: var(--tc-mid-x, 50%);
  bottom: calc(var(--tc-mid-b, 16px) + 10px);
  max-width: var(--tc-mid-w, 300px);
}
body.touch-ui.tc-phoneLand #hud:has(.hud-br .energy) .combo {
  bottom: calc(var(--tc-mid-b, 16px) + 56px);
}
body.touch-ui.tc-phoneLand #hud .combo .chain {
  font-size: 0.9rem;
}

/* The run panel's compact form (touch phones): name and clock on one line, gates and pace below;
   tc-compact (a very short screen) keeps only the clock and the gate count. */
body.touch-ui #hud .run-panel.compact {
  padding: 6px 10px;
  width: min(260px, 36vw);
  box-sizing: border-box;
}
body.touch-ui #hud .run-panel.compact .run-head {
  display: flex;
  align-items: center;
  gap: 6px;
}
body.touch-ui #hud .run-panel.compact .run-head .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.touch-ui #hud .run-panel.compact .run-clock {
  font-size: 1.05rem;
}
body.touch-ui #hud .run-panel.compact .run-gates {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}
body.touch-ui.tc-compact #hud .run-panel.compact .run-head .grow,
body.touch-ui.tc-compact #hud .run-panel.compact .run-pips,
body.touch-ui.tc-compact #hud .run-panel.compact .run-pace,
body.touch-ui.tc-compact #hud .run-panel.compact .tier {
  display: none;
}
body.touch-ui.tc-compact #hud .run-panel.compact .run-gates {
  position: absolute;
  top: 8px;
  right: 10px;
}

/* Phone portrait: row 1, the pills in row 2, then one stack at full width; the controls below. */
body.touch-ui.tc-phonePort #hud .hud-top {
  top: calc(var(--tc-row1-h, 60px) + 4px);
  max-width: calc(100vw - 24px);
  flex-wrap: wrap;
  justify-content: center;
}
body.touch-ui.tc-phonePort #hud .it-banner,
body.touch-ui.tc-phonePort #hud .pause-note {
  top: calc(var(--tc-row2-h, 100px) + 4px);
  max-width: calc(100vw - 24px);
}
body.touch-ui.tc-phonePort #toasts {
  top: calc(var(--tc-row2-h, 100px) + 4px);
  left: calc(var(--sa-l, 0px) + 12px);
  right: calc(var(--sa-r, 0px) + 12px);
  transform: none;
  max-width: none;
}
body.touch-ui.tc-phonePort #hud .hud-tr {
  top: calc(var(--tc-row2-h, 100px) + 4px);
  left: calc(var(--sa-l, 0px) + 12px);
  right: calc(var(--sa-r, 0px) + 12px);
  max-width: none;
  align-items: stretch;
}
body.touch-ui.tc-phonePort:has(#toasts > .toast) #hud .hud-tr {
  top: calc(var(--tc-row2-h, 100px) + 64px);
}
/* K6: while the first-time guide runs on an upright phone, the track card waits (one layer of
   instructions at a time, and "Skip the guide" never lands on it); it comes back when the guide ends. */
body.touch-ui.tc-phonePort.tc-coaching #hud .hud-tr .arch-card {
  display: none;
}
body.touch-ui.tc-phonePort #hud .hud-tr .coin-counter {
  position: fixed;
  top: calc(var(--sa-t, 0px) + 16px);
  right: var(--tc-right-w, 8px);
}
body.touch-ui.tc-phonePort #hud .hud-tr .coin-chain,
body.touch-ui.tc-phonePort #hud .hud-tr .coin-note {
  align-self: flex-end;
}
body.touch-ui.tc-phonePort #hud .run-panel.compact,
body.touch-ui.tc-phonePort #hud .run-panel {
  width: auto;
}
body.touch-ui.tc-phonePort #hud .hud-score {
  display: none;
}
body.touch-ui.tc-phonePort #hud .voice-hud {
  top: calc(var(--tc-row2-h, 100px) + 4px);
  left: calc(var(--sa-l, 0px) + 12px);
  max-width: calc(100vw - 24px);
}
body.touch-ui.tc-phonePort #hud:has(.voice-hud > *) .hud-tr,
body.touch-ui.tc-phonePort #hud:has(.voice-hud > *) .gizmo-tip {
  top: calc(var(--tc-row2-h, 100px) + 84px);
}
body.touch-ui.tc-phonePort #hud .gizmo-tip {
  top: calc(var(--tc-row2-h, 100px) + 4px);
  left: calc(var(--sa-l, 0px) + 12px);
  right: calc(var(--sa-r, 0px) + 12px);
  width: auto;
}
body.touch-ui.tc-phonePort #hud .hud-br,
body.touch-ui.tc-phonePort #hud .combo {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  bottom: calc(max(var(--tc-joy-h, 160px), var(--tc-cluster-h, 300px)) + 8px);
  align-items: center;
}
body.touch-ui.tc-phonePort #hud:has(.hud-br .energy) .combo {
  bottom: calc(max(var(--tc-joy-h, 160px), var(--tc-cluster-h, 300px)) + 56px);
}
body.touch-ui.tc-phonePort #hud .center-msg {
  top: 30%;
}

/* Tablets: the desktop places, moved under row 1 and clear of the cluster. */
body.touch-ui.tc-tablet #hud .hud-top {
  top: calc(var(--sa-t, 0px) + 14px);
  max-width: calc(100vw - 2 * max(var(--tc-left-w, 8px), var(--tc-right-w, 8px)) - 16px);
}
body.touch-ui.tc-tablet #hud .it-banner {
  top: calc(var(--tc-row1-h, 68px) + 8px);
}
body.touch-ui.tc-tablet #toasts {
  top: calc(var(--tc-row1-h, 68px) + 12px);
}
body.touch-ui.tc-tablet #hud .hud-tr,
body.touch-ui.tc-tablet #hud .hud-score {
  top: var(--tc-row1-h, 68px);
  right: calc(var(--sa-r, 0px) + 14px);
}
body.touch-ui.tc-tablet #hud .hud-score:not([hidden]) {
  display: block;
}
body.touch-ui.tc-tablet #hud .combo {
  bottom: max(118px, calc(var(--tc-cluster-h, 240px) + 8px));
}

/* ── Settings → Touch and the touch Controls help (touchsettings.js) ─────────────────────── */
.tc-set .tc-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tc-set .tc-choice {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
}
.tc-set .tc-slider input[type='range'] {
  width: 100%;
  min-height: 44px;
}
.tc-set .tc-check {
  min-height: 44px;
  align-items: center;
}
.tc-set .tc-check input {
  width: 24px;
  height: 24px;
}
.tc-set .tc-actions .btn,
.tc-help .btn {
  min-height: 44px;
}
.tc-help .tc-help-ctl {
  min-width: 6.5em;
}

/* ── Accessibility ─────────────────────────────────────────────────────────────────────────── */
body.high-contrast #touch .tc-btn,
body.high-contrast #touch .tc-sys {
  background: #000;
  border-color: #fff;
  opacity: max(var(--tc-alpha, 0.6), 0.85);
}
body.high-contrast #touch .tc-bubble {
  background: #000;
  border-color: #fff;
}
body.reduced-motion #touch .tc-btn.on,
body.reduced-motion #touch .tc-sys.on {
  transform: none;
}
body.reduced-motion #touch .tc-btn.hl,
body.reduced-motion #touch .tc-sys.hl {
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  #touch .tc-btn.on,
  #touch .tc-sys.on {
    transform: none;
  }
  #touch .tc-btn.hl,
  #touch .tc-sys.hl {
    animation: none;
  }
}
