/* Rift Haven — on-screen touch controls (iPhone fullscreen web app).
   Desktop is untouched: every rule here is scoped under html.touch, which the
   Shell lane's gate in index.html sets. See docs/mobile-contract.md. */

html.touch {
  --tz-l-w: 190px;
  --tz-r-w: 270px;
  --tz-h: 200px;
}
@media (orientation: portrait) {
  html.touch {
    --tz-l-w: 0px;
    --tz-r-w: 0px;
    --tz-h: 230px;
  }
}

html.touch #tc-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font);
}
html.touch #tc-layer.is-off { display: none !important; }

/* ---------- movement pad ---------- */
html.touch #tc-padzone {
  position: absolute;
  left: var(--safe-l, 0px);
  bottom: var(--safe-b, 0px);
  width: 190px;
  height: var(--tz-h);
  pointer-events: auto;
  touch-action: none;
}
html.touch #tc-pad {
  --pad-d: 148px;
  --pad-r: 52px;
  position: fixed;
  left: 0;
  top: 0;
  width: var(--pad-d);
  height: var(--pad-d);
  margin: calc(var(--pad-d) / -2) 0 0 calc(var(--pad-d) / -2);
  border-radius: 50%;
  border: 2px solid rgba(199, 125, 255, 0.34);
  background: radial-gradient(circle at 42% 38%, rgba(38, 46, 82, 0.34), rgba(10, 14, 28, 0.16));
  box-shadow: inset 0 0 34px rgba(199, 125, 255, 0.12), 0 6px 20px rgba(0, 0, 0, 0.24);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  transition: opacity 0.14s ease;
  will-change: transform;
}
html.touch #tc-pad.rest { opacity: 0.5; }
html.touch #tc-pad.rest #tc-knob { opacity: 0.55; transform: translate(-50%, -50%) scale(0.72); }

html.touch #tc-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 38% 32%, rgba(226, 206, 255, 0.95), rgba(199, 125, 255, 0.55) 55%, rgba(96, 52, 160, 0.6));
  border: 1.5px solid rgba(236, 224, 255, 0.8);
  box-shadow: 0 0 16px rgba(199, 125, 255, 0.45), 0 2px 8px rgba(0, 0, 0, 0.4);
  opacity: 0.95;
  pointer-events: none;
  will-change: transform;
}
html.touch #tc-pad.rest #tc-knob { transition: transform 0.12s ease, opacity 0.14s ease; }

html.touch .tc-dir {
  position: absolute;
  width: 15px;
  height: 9px;
  fill: rgba(214, 222, 255, 0.42);
  transition: fill 0.08s ease, filter 0.08s ease;
  pointer-events: none;
}
html.touch .tc-dir.on { fill: var(--acc2); filter: drop-shadow(0 0 5px rgba(42, 255, 198, 0.85)); }
html.touch .tc-dir.tc-up { left: 50%; top: 9px; transform: translateX(-50%); }
html.touch .tc-dir.tc-down { left: 50%; bottom: 9px; transform: translateX(-50%) rotate(180deg); }
html.touch .tc-dir.tc-left { left: 9px; top: 50%; transform: translateY(-50%) rotate(-90deg); }
html.touch .tc-dir.tc-right { right: 9px; top: 50%; transform: translateY(-50%) rotate(90deg); }

/* ---------- action buttons ---------- */
html.touch .tc-btn {
  position: absolute;
  right: calc(var(--safe-r, 0px) + var(--x0, 0px));
  bottom: calc(var(--safe-b, 0px) + var(--y0, 0px));
  width: var(--d, 52px);
  height: var(--d, 52px);
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 2px solid rgba(180, 196, 255, 0.26);
  background: radial-gradient(circle at 36% 30%, rgba(52, 60, 100, 0.86), rgba(12, 16, 30, 0.86));
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.09);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--text, #e8ecff);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.07s ease, border-color 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  will-change: transform;
}
html.touch .tc-btn.tc-gone { display: none !important; }
html.touch .tc-btn .tc-ico {
  width: 76%;
  height: 76%;
  object-fit: cover;
  border-radius: 50%; /* round like the button, not a square clipped by it */
  pointer-events: none;
}
html.touch .tc-btn .tc-ico.round { width: 100%; height: 100%; } /* skill discs fill the whole button */
html.touch .tc-btn .tc-svg {
  width: 56%;
  height: 56%;
  pointer-events: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
html.touch .tc-btn .tc-glyph {
  position: absolute;
  left: 4px;
  top: 2px;
  z-index: 4;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  pointer-events: none;
}
html.touch .tc-btn .tc-cd {
  --sweep: 0deg;
  position: absolute;
  inset: 0;
  z-index: 2;
  background: conic-gradient(from 0deg, rgba(3, 5, 12, 0.76) 0deg var(--sweep), transparent var(--sweep) 360deg);
  pointer-events: none;
}
html.touch .tc-btn .tc-cdt {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  text-shadow: 0 1px 3px #000, 0 0 5px #000;
  pointer-events: none;
}
html.touch .tc-btn .tc-cnt {
  /* Bottom-centre, inside the circle (a corner badge gets cut off by the round edge). */
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translateX(-50%);
  z-index: 4;
  padding: 0 4px;
  border-radius: 6px;
  background: rgba(6, 8, 18, 0.72);
  font-size: 11px;
  font-weight: 800;
  line-height: 14px;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
html.touch .tc-btn .tc-cnt:empty { display: none; }
/* Key letters mean nothing without a keyboard, and a corner label is clipped by the circle. */
html.touch .tc-btn .tc-glyph { display: none; }

html.touch .tc-btn.pressed {
  transform: scale(0.92);
  border-color: rgba(199, 125, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(199, 125, 255, 0.34), 0 0 18px rgba(199, 125, 255, 0.55), inset 0 0 14px rgba(199, 125, 255, 0.24);
  filter: brightness(1.22);
}
html.touch .tc-btn.empty { display: none; } /* no ability in that loadout slot: no ghost button */
html.touch .tc-btn.locked { opacity: 0.44; filter: saturate(0.5); }
html.touch .tc-btn.ready { border-color: rgba(126, 240, 255, 0.46); }
html.touch .tc-btn.active-buff { border-color: var(--good, #7affb0); box-shadow: 0 0 0 1px var(--good, #7affb0), 0 0 14px rgba(122, 255, 176, 0.35); }

/* Attack / Jump read as the two primary actions. */
html.touch #tc-x { border-color: rgba(199, 125, 255, 0.62); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 20px rgba(199, 125, 255, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1); }
html.touch #tc-x .tc-glyph { font-size: 12px; left: 7px; top: 5px; }
html.touch #tc-j { border-color: rgba(42, 255, 198, 0.5); color: #d8fff4; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.42), 0 0 16px rgba(42, 255, 198, 0.16); }

/* ---------- landscape placement (default) ----------
   12 controls inside the contract's 270x200 bottom-right box. --x0 is the gap
   from the right safe edge, --y0 the gap from the bottom safe edge. Attack is
   ~84px, every other target is >= 52px, and no two targets overlap.
   Attack column (right): Attack / Jump / Tab stacked.
   Grid (left of it, 3 x 3): potions + loot on the thumb row, Q W E above, R + active protocol on top. */
html.touch #tc-x    { --d: 84px; --x0: 12px;  --y0: 0px; }
html.touch #tc-j    { --d: 60px; --x0: 24px;  --y0: 88px; }
html.touch #tc-tab  { --d: 52px; --x0: 28px;  --y0: 148px; }
html.touch #tc-hp   { --d: 52px; --x0: 100px; --y0: 0px; }
html.touch #tc-mp   { --d: 52px; --x0: 152px; --y0: 0px; }
html.touch #tc-loot { --d: 52px; --x0: 204px; --y0: 0px; }
html.touch #tc-q    { --d: 52px; --x0: 100px; --y0: 74px; }
html.touch #tc-w    { --d: 52px; --x0: 152px; --y0: 74px; }
html.touch #tc-e    { --d: 52px; --x0: 204px; --y0: 74px; }
html.touch #tc-r    { --d: 52px; --x0: 100px; --y0: 148px; }
html.touch #tc-act  { --d: 52px; --x0: 152px; --y0: 148px; }

/* ---------- portrait placement ----------
   Same cluster, nudged up into the 230px-tall portrait band and kept clear of
   the movement pad (columns start right of #tc-padzone). */
@media (orientation: portrait) {
  /* A portrait side inset is the Dynamic Island strip at the top of that edge (folded Duo): the
     bottom controls use the full width beneath it. */
  html.touch #tc-layer { --safe-l: 0px; --safe-r: 0px; }
  html.touch #tc-padzone { width: 148px; height: 180px; }
  html.touch #tc-pad { --pad-d: 128px; --pad-r: 44px; }
  html.touch #tc-knob { width: 50px; height: 50px; }

  html.touch #tc-x    { --d: 84px; --x0: 8px;   --y0: 15px; }
  html.touch #tc-j    { --d: 64px; --x0: 18px;  --y0: 103px; }
  html.touch #tc-tab  { --d: 52px; --x0: 24px;  --y0: 167px; }
  html.touch #tc-hp   { --d: 52px; --x0: 92px;  --y0: 15px; }
  html.touch #tc-mp   { --d: 52px; --x0: 144px; --y0: 15px; }
  html.touch #tc-loot { --d: 52px; --x0: 196px; --y0: 15px; }
  html.touch #tc-q    { --d: 52px; --x0: 92px;  --y0: 89px; }
  html.touch #tc-w    { --d: 52px; --x0: 144px; --y0: 89px; }
  html.touch #tc-e    { --d: 52px; --x0: 196px; --y0: 89px; }
  html.touch #tc-r    { --d: 52px; --x0: 92px;  --y0: 163px; }
  html.touch #tc-act  { --d: 52px; --x0: 144px; --y0: 163px; }
}

/* ---------- short portrait (folded Duo: 678px tall, Dynamic Island on the right edge) ----------
   ~380px of usable width and little height: a smaller cluster (46px buttons, 44pt+ targets, 74px
   Attack) in a 180px band. R / active protocol / scoreboard (Abyss vs Crucible: never both at once)
   share the short top row. */
@media (orientation: portrait) and (max-height: 800px) {
  html.touch { --tz-h: 180px; }
  html.touch #tc-padzone { width: 138px; height: 170px; }
  html.touch #tc-pad { --pad-d: 116px; --pad-r: 40px; }
  html.touch #tc-knob { width: 46px; height: 46px; }
  html.touch #tc-x    { --d: 74px; --x0: 6px;   --y0: 10px; }
  html.touch #tc-j    { --d: 56px; --x0: 15px;  --y0: 92px; }
  html.touch #tc-hp   { --d: 46px; --x0: 86px;  --y0: 10px; }
  html.touch #tc-mp   { --d: 46px; --x0: 134px; --y0: 10px; }
  html.touch #tc-loot { --d: 46px; --x0: 182px; --y0: 10px; }
  html.touch #tc-q    { --d: 46px; --x0: 86px;  --y0: 66px; }
  html.touch #tc-w    { --d: 46px; --x0: 134px; --y0: 66px; }
  html.touch #tc-e    { --d: 46px; --x0: 182px; --y0: 66px; }
  html.touch #tc-r    { --d: 46px; --x0: 86px;  --y0: 122px; }
  html.touch #tc-act, html.touch #tc-tab { --d: 46px; --x0: 134px; --y0: 122px; }
}

/* Short portrait wide enough for a 4-column grid (folded Duo, 466px): full-size buttons spread over
   the whole width, R joins Q W E and the active protocol / scoreboard join the potions, so there is
   no top row and the band is only 170px. */
@media (orientation: portrait) and (max-height: 800px) and (min-width: 440px) {
  html.touch { --tz-h: 170px; }
  html.touch #tc-padzone { width: 130px; height: 160px; }
  html.touch #tc-pad { --pad-d: 124px; --pad-r: 43px; }
  html.touch #tc-knob { width: 48px; height: 48px; }
  html.touch #tc-x    { --d: 84px; --x0: 8px;   --y0: 10px; }
  html.touch #tc-j    { --d: 62px; --x0: 19px;  --y0: 100px; }
  html.touch #tc-hp   { --d: 52px; --x0: 98px;  --y0: 10px; }
  html.touch #tc-mp   { --d: 52px; --x0: 156px; --y0: 10px; }
  html.touch #tc-loot { --d: 52px; --x0: 214px; --y0: 10px; }
  html.touch #tc-act, html.touch #tc-tab { --d: 52px; --x0: 272px; --y0: 10px; }
  html.touch #tc-q    { --d: 52px; --x0: 98px;  --y0: 68px; }
  html.touch #tc-w    { --d: 52px; --x0: 156px; --y0: 68px; }
  html.touch #tc-e    { --d: 52px; --x0: 214px; --y0: 68px; }
  html.touch #tc-r    { --d: 52px; --x0: 272px; --y0: 68px; }
}

/* Wide portrait (unfolded Duo, 600px+): the folded 4-column grid scaled up for the bigger screen. */
@media (orientation: portrait) and (min-width: 600px) {
  html.touch { --tz-h: 210px; }
  html.touch #tc-padzone { width: 190px; height: 210px; }
  html.touch #tc-pad { --pad-d: 160px; --pad-r: 56px; }
  html.touch #tc-knob { width: 60px; height: 60px; }
  html.touch #tc-x    { --d: 100px; --x0: 12px;  --y0: 14px; }
  html.touch #tc-j    { --d: 72px;  --x0: 26px;  --y0: 126px; }
  html.touch #tc-hp   { --d: 64px;  --x0: 126px; --y0: 14px; }
  html.touch #tc-mp   { --d: 64px;  --x0: 198px; --y0: 14px; }
  html.touch #tc-loot { --d: 64px;  --x0: 270px; --y0: 14px; }
  html.touch #tc-act, html.touch #tc-tab { --d: 64px; --x0: 342px; --y0: 14px; }
  html.touch #tc-q    { --d: 64px;  --x0: 126px; --y0: 90px; }
  html.touch #tc-w    { --d: 64px;  --x0: 198px; --y0: 90px; }
  html.touch #tc-e    { --d: 64px;  --x0: 270px; --y0: 90px; }
  html.touch #tc-r    { --d: 64px;  --x0: 342px; --y0: 90px; }
}

/* Tall landscape (unfolded Duo, 600px+ tall): the side inset belongs to the island and status strip,
   which sit at the top or middle of that edge, well above the 200px control corners, so the controls
   go all the way into the bottom corners. Phones in landscape (under 600px tall) keep the inset. */
@media (orientation: landscape) and (min-height: 600px) {
  html.touch #tc-layer { --safe-l: 0px; --safe-r: 0px; }
}
/* Rift Haven — on-screen touch controls (iPhone fullscreen web app).
   Desktop is untouched: every rule here is scoped under html.touch, which the
   Shell lane's gate in index.html sets. See docs/mobile-contract.md. */

html.touch {
  --tz-l-w: 190px;
  --tz-r-w: 270px;
  --tz-h: 200px;
}
@media (orientation: portrait) {
  html.touch {
    --tz-l-w: 0px;
    --tz-r-w: 0px;
    --tz-h: 230px;
  }
}

html.touch #tc-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font);
}
html.touch #tc-layer.is-off { display: none !important; }

/* ---------- movement pad ---------- */
html.touch #tc-padzone {
  position: absolute;
  left: var(--safe-l, 0px);
  bottom: var(--safe-b, 0px);
  width: 190px;
  height: var(--tz-h);
  pointer-events: auto;
  touch-action: none;
}
html.touch #tc-pad {
  --pad-d: 148px;
  --pad-r: 52px;
  position: fixed;
  left: 0;
  top: 0;
  width: var(--pad-d);
  height: var(--pad-d);
  margin: calc(var(--pad-d) / -2) 0 0 calc(var(--pad-d) / -2);
  border-radius: 50%;
  border: 2px solid rgba(199, 125, 255, 0.34);
  background: radial-gradient(circle at 42% 38%, rgba(38, 46, 82, 0.34), rgba(10, 14, 28, 0.16));
  box-shadow: inset 0 0 34px rgba(199, 125, 255, 0.12), 0 6px 20px rgba(0, 0, 0, 0.24);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  transition: opacity 0.14s ease;
  will-change: transform;
}
html.touch #tc-pad.rest { opacity: 0.5; }
html.touch #tc-pad.rest #tc-knob { opacity: 0.55; transform: translate(-50%, -50%) scale(0.72); }

html.touch #tc-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 38% 32%, rgba(226, 206, 255, 0.95), rgba(199, 125, 255, 0.55) 55%, rgba(96, 52, 160, 0.6));
  border: 1.5px solid rgba(236, 224, 255, 0.8);
  box-shadow: 0 0 16px rgba(199, 125, 255, 0.45), 0 2px 8px rgba(0, 0, 0, 0.4);
  opacity: 0.95;
  pointer-events: none;
  will-change: transform;
}
html.touch #tc-pad.rest #tc-knob { transition: transform 0.12s ease, opacity 0.14s ease; }

html.touch .tc-dir {
  position: absolute;
  width: 15px;
  height: 9px;
  fill: rgba(214, 222, 255, 0.42);
  transition: fill 0.08s ease, filter 0.08s ease;
  pointer-events: none;
}
html.touch .tc-dir.on { fill: var(--acc2); filter: drop-shadow(0 0 5px rgba(42, 255, 198, 0.85)); }
html.touch .tc-dir.tc-up { left: 50%; top: 9px; transform: translateX(-50%); }
html.touch .tc-dir.tc-down { left: 50%; bottom: 9px; transform: translateX(-50%) rotate(180deg); }
html.touch .tc-dir.tc-left { left: 9px; top: 50%; transform: translateY(-50%) rotate(-90deg); }
html.touch .tc-dir.tc-right { right: 9px; top: 50%; transform: translateY(-50%) rotate(90deg); }

/* ---------- action buttons ---------- */
html.touch .tc-btn {
  position: absolute;
  right: calc(var(--safe-r, 0px) + var(--x0, 0px));
  bottom: calc(var(--safe-b, 0px) + var(--y0, 0px));
  width: var(--d, 52px);
  height: var(--d, 52px);
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 2px solid rgba(180, 196, 255, 0.26);
  background: radial-gradient(circle at 36% 30%, rgba(52, 60, 100, 0.86), rgba(12, 16, 30, 0.86));
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.09);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--text, #e8ecff);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.07s ease, border-color 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  will-change: transform;
}
html.touch .tc-btn.tc-gone { display: none !important; }
html.touch .tc-btn .tc-ico {
  width: 76%;
  height: 76%;
  object-fit: cover;
  border-radius: 50%; /* round like the button, not a square clipped by it */
  pointer-events: none;
}
html.touch .tc-btn .tc-ico.round { width: 100%; height: 100%; } /* skill discs fill the whole button */
html.touch .tc-btn .tc-svg {
  width: 56%;
  height: 56%;
  pointer-events: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
html.touch .tc-btn .tc-glyph {
  position: absolute;
  left: 4px;
  top: 2px;
  z-index: 4;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  pointer-events: none;
}
html.touch .tc-btn .tc-cd {
  --sweep: 0deg;
  position: absolute;
  inset: 0;
  z-index: 2;
  background: conic-gradient(from 0deg, rgba(3, 5, 12, 0.76) 0deg var(--sweep), transparent var(--sweep) 360deg);
  pointer-events: none;
}
html.touch .tc-btn .tc-cdt {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  text-shadow: 0 1px 3px #000, 0 0 5px #000;
  pointer-events: none;
}
html.touch .tc-btn .tc-cnt {
  /* Bottom-centre, inside the circle (a corner badge gets cut off by the round edge). */
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translateX(-50%);
  z-index: 4;
  padding: 0 4px;
  border-radius: 6px;
  background: rgba(6, 8, 18, 0.72);
  font-size: 11px;
  font-weight: 800;
  line-height: 14px;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
html.touch .tc-btn .tc-cnt:empty { display: none; }
/* Key letters mean nothing without a keyboard, and a corner label is clipped by the circle. */
html.touch .tc-btn .tc-glyph { display: none; }

html.touch .tc-btn.pressed {
  transform: scale(0.92);
  border-color: rgba(199, 125, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(199, 125, 255, 0.34), 0 0 18px rgba(199, 125, 255, 0.55), inset 0 0 14px rgba(199, 125, 255, 0.24);
  filter: brightness(1.22);
}
html.touch .tc-btn.empty { display: none; } /* no ability in that loadout slot: no ghost button */
html.touch .tc-btn.locked { opacity: 0.44; filter: saturate(0.5); }
html.touch .tc-btn.ready { border-color: rgba(126, 240, 255, 0.46); }
html.touch .tc-btn.active-buff { border-color: var(--good, #7affb0); box-shadow: 0 0 0 1px var(--good, #7affb0), 0 0 14px rgba(122, 255, 176, 0.35); }

/* Attack / Jump read as the two primary actions. */
html.touch #tc-x { border-color: rgba(199, 125, 255, 0.62); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 20px rgba(199, 125, 255, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1); }
html.touch #tc-x .tc-glyph { font-size: 12px; left: 7px; top: 5px; }
html.touch #tc-j { border-color: rgba(42, 255, 198, 0.5); color: #d8fff4; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.42), 0 0 16px rgba(42, 255, 198, 0.16); }

/* ---------- landscape placement (default) ----------
   12 controls inside the contract's 270x200 bottom-right box. --x0 is the gap
   from the right safe edge, --y0 the gap from the bottom safe edge. Attack is
   ~84px, every other target is >= 52px, and no two targets overlap.
   Attack column (right): Attack / Jump / Tab stacked.
   Grid (left of it, 3 x 3): potions + loot on the thumb row, Q W E above, R + active protocol on top. */
html.touch #tc-x    { --d: 84px; --x0: 12px;  --y0: 0px; }
html.touch #tc-j    { --d: 60px; --x0: 24px;  --y0: 88px; }
html.touch #tc-tab  { --d: 52px; --x0: 28px;  --y0: 148px; }
html.touch #tc-hp   { --d: 52px; --x0: 100px; --y0: 0px; }
html.touch #tc-mp   { --d: 52px; --x0: 152px; --y0: 0px; }
html.touch #tc-loot { --d: 52px; --x0: 204px; --y0: 0px; }
html.touch #tc-q    { --d: 52px; --x0: 100px; --y0: 74px; }
html.touch #tc-w    { --d: 52px; --x0: 152px; --y0: 74px; }
html.touch #tc-e    { --d: 52px; --x0: 204px; --y0: 74px; }
html.touch #tc-r    { --d: 52px; --x0: 100px; --y0: 148px; }
html.touch #tc-act  { --d: 52px; --x0: 152px; --y0: 148px; }

/* ---------- portrait placement ----------
   Same cluster, nudged up into the 230px-tall portrait band and kept clear of
   the movement pad (columns start right of #tc-padzone). */
@media (orientation: portrait) {
  /* A portrait side inset is the Dynamic Island strip at the top of that edge (folded Duo): the
     bottom controls use the full width beneath it. */
  html.touch #tc-layer { --safe-l: 0px; --safe-r: 0px; }
  html.touch #tc-padzone { width: 148px; height: 180px; }
  html.touch #tc-pad { --pad-d: 128px; --pad-r: 44px; }
  html.touch #tc-knob { width: 50px; height: 50px; }

  html.touch #tc-x    { --d: 84px; --x0: 8px;   --y0: 15px; }
  html.touch #tc-j    { --d: 64px; --x0: 18px;  --y0: 103px; }
  html.touch #tc-tab  { --d: 52px; --x0: 24px;  --y0: 167px; }
  html.touch #tc-hp   { --d: 52px; --x0: 92px;  --y0: 15px; }
  html.touch #tc-mp   { --d: 52px; --x0: 144px; --y0: 15px; }
  html.touch #tc-loot { --d: 52px; --x0: 196px; --y0: 15px; }
  html.touch #tc-q    { --d: 52px; --x0: 92px;  --y0: 89px; }
  html.touch #tc-w    { --d: 52px; --x0: 144px; --y0: 89px; }
  html.touch #tc-e    { --d: 52px; --x0: 196px; --y0: 89px; }
  html.touch #tc-r    { --d: 52px; --x0: 92px;  --y0: 163px; }
  html.touch #tc-act  { --d: 52px; --x0: 144px; --y0: 163px; }
}

/* ---------- short portrait (folded Duo: 678px tall, Dynamic Island on the right edge) ----------
   ~380px of usable width and little height: a smaller cluster (46px buttons, 44pt+ targets, 74px
   Attack) in a 180px band. R / active protocol / scoreboard (Abyss vs Crucible: never both at once)
   share the short top row. */
@media (orientation: portrait) and (max-height: 800px) {
  html.touch { --tz-h: 180px; }
  html.touch #tc-padzone { width: 138px; height: 170px; }
  html.touch #tc-pad { --pad-d: 116px; --pad-r: 40px; }
  html.touch #tc-knob { width: 46px; height: 46px; }
  html.touch #tc-x    { --d: 74px; --x0: 6px;   --y0: 10px; }
  html.touch #tc-j    { --d: 56px; --x0: 15px;  --y0: 92px; }
  html.touch #tc-hp   { --d: 46px; --x0: 86px;  --y0: 10px; }
  html.touch #tc-mp   { --d: 46px; --x0: 134px; --y0: 10px; }
  html.touch #tc-loot { --d: 46px; --x0: 182px; --y0: 10px; }
  html.touch #tc-q    { --d: 46px; --x0: 86px;  --y0: 66px; }
  html.touch #tc-w    { --d: 46px; --x0: 134px; --y0: 66px; }
  html.touch #tc-e    { --d: 46px; --x0: 182px; --y0: 66px; }
  html.touch #tc-r    { --d: 46px; --x0: 86px;  --y0: 122px; }
  html.touch #tc-act, html.touch #tc-tab { --d: 46px; --x0: 134px; --y0: 122px; }
}

/* Short portrait wide enough for a 4-column grid (folded Duo, 466px): full-size buttons spread over
   the whole width, R joins Q W E and the active protocol / scoreboard join the potions, so there is
   no top row and the band is only 170px. */
@media (orientation: portrait) and (max-height: 800px) and (min-width: 440px) {
  html.touch { --tz-h: 170px; }
  html.touch #tc-padzone { width: 130px; height: 160px; }
  html.touch #tc-pad { --pad-d: 124px; --pad-r: 43px; }
  html.touch #tc-knob { width: 48px; height: 48px; }
  html.touch #tc-x    { --d: 84px; --x0: 8px;   --y0: 10px; }
  html.touch #tc-j    { --d: 62px; --x0: 19px;  --y0: 100px; }
  html.touch #tc-hp   { --d: 52px; --x0: 98px;  --y0: 10px; }
  html.touch #tc-mp   { --d: 52px; --x0: 156px; --y0: 10px; }
  html.touch #tc-loot { --d: 52px; --x0: 214px; --y0: 10px; }
  html.touch #tc-act, html.touch #tc-tab { --d: 52px; --x0: 272px; --y0: 10px; }
  html.touch #tc-q    { --d: 52px; --x0: 98px;  --y0: 68px; }
  html.touch #tc-w    { --d: 52px; --x0: 156px; --y0: 68px; }
  html.touch #tc-e    { --d: 52px; --x0: 214px; --y0: 68px; }
  html.touch #tc-r    { --d: 52px; --x0: 272px; --y0: 68px; }
}

/* Keep the controls on the same solid-panel palette as the touch HUD. */
html.touch #tc-pad {
  border: 1px solid var(--hair);
  background: var(--inset);
  box-shadow: inset 0 0 0 1px var(--hair);
}
html.touch #tc-pad.rest { opacity: 0.68; }
html.touch #tc-pad.rest #tc-knob { opacity: 0.72; }
html.touch #tc-knob {
  border: 1px solid var(--hair);
  background: rgba(255, 255, 255, .18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 2px 6px rgba(0, 0, 0, .3);
}
html.touch .tc-dir.on { filter: none; }
html.touch .tc-btn {
  border: 1px solid var(--hair);
  background: var(--inset);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .04), 0 3px 8px rgba(0, 0, 0, .3);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
html.touch .tc-btn .tc-ico { width: 72%; height: 72%; }
html.touch .tc-btn .tc-svg { width: 64%; height: 64%; }
html.touch .tc-btn.pressed {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-line), 0 2px 6px rgba(0, 0, 0, .3);
  filter: none;
}
html.touch .tc-btn.ready { border-color: var(--accent-line); }
html.touch .tc-btn.active-buff { box-shadow: none; }
html.touch #tc-x, html.touch #tc-j {
  border-color: var(--hair);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .04), 0 3px 8px rgba(0, 0, 0, .3);
  color: var(--t1);
}
html.touch #tc-x.pressed, html.touch #tc-j.pressed {
  border-color: var(--accent);
  background: var(--accent-soft);
}
html.touch .tc-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Avatar Editor & character creator on touch ----------
   The editor is a solid full-screen sheet inside the safe area. Portrait stacks the stage over the
   tabs and the content (the stage takes about 30% of the height); landscape keeps the stage on the
   left, about 40% of the width, with the controls beside it. */
html.touch .av-ed { display: grid; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 10px; height: auto; }
html.touch .av-left { height: auto; }
/* Keep the portrait preview compact so the tabs and controls start sooner. */
html.touch .av-left .av-screen { flex: none; height: clamp(156px, 20vh, 188px); }
html.touch .av-right { max-height: none; overflow: visible; }
html.touch .av-panel { overflow: visible; }
html.touch .win-body { overflow-y: auto; }
html.touch .av-ed .expr { min-height: 44px; font-size: 16px; }
html.touch .av-ofacts .sq { min-width: 44px; min-height: 44px; }
html.touch .bq .le-tabs button, html.touch .bq .av-slots button { min-height: 44px; }
@media (orientation: landscape) {
  html.touch .av-ed { grid-template-columns: 40% minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; }
  html.touch .av-left { height: 100%; min-height: 0; }
  /* Let the stage take the remaining column height while keeping Save below it. */
  html.touch .av-left .av-screen { height: auto; }
  /* A short sheet: the slot rail has to stay beside the grid without spilling out of it. */
  html.touch .av-rails { gap: 3px; }
  html.touch .av-rail { width: var(--h-touch); height: var(--h-touch); }
  html.touch .av-rail img { width: 30px; height: 30px; }
}

/* Keep two complete item rows visible above the selected name and dye controls. */
html.touch .av-grid {
  grid-template-columns: repeat(auto-fill, 62px); grid-auto-rows: 62px;
  min-height: calc(62px * 2 + var(--s2)); max-height: 28vh;
}
@media (orientation: landscape) { html.touch .av-grid { max-height: 138px; } }

/* The creator: stage over the rows, every control reachable, nothing overlapping. */
html.touch #authForm.creating { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
html.touch #authForm.creating .cr-stage { min-height: 0; height: clamp(210px, 30vh, 250px); }
html.touch #authForm.creating .pick { width: auto; flex: 1 1 auto; min-width: 0; }
html.touch #authForm.creating .row-line { align-items: center; }
/* A row is never wider than the card: the weapon row is the tightest one, so it sets the sizes. */
html.touch .login-card { padding-left: 12px; padding-right: 12px; }
html.touch .row-line { gap: var(--s2); }
html.touch .row-line > label { width: 76px; font-size: var(--f-xs); }
html.touch .cr-picks { gap: var(--s2); }
html.touch .class-card { width: 60px; height: 60px; }
html.touch .class-card img { width: 44px; height: 44px; image-rendering: pixelated; }
/* Colour swatches use a 30px face; the shared gap keeps every 44px touch target separate. */
html.touch .sw:not(.big) { width: 30px; height: 30px; min-width: 30px; }
html.touch .sws { display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 30px)); gap: 10px; min-width: 0; max-width: 100%; }
html.touch .sws .sw:not(.big) { width: auto; min-width: 0; aspect-ratio: 1; height: auto; }
@media (orientation: landscape) { html.touch .av-dyes .sws { gap: 6px; } }
html.touch .sw::before { inset: calc(-1 * var(--s2)); }
html.touch .av-flip, html.touch .av-dice { width: var(--h-touch); height: var(--h-touch); min-height: var(--h-touch); }
/* Landscape is short: the stage sits beside the rows, like the desktop card. Its column is wide
   enough for the character at the largest whole scale, so the preview is not a thumbnail. */
@media (orientation: landscape) {
  html.touch #authForm.creating { display: grid; grid-template-columns: 36% minmax(0, 1fr); grid-template-areas: "stage rows" "stage btn" "err err" "conn conn"; gap: 4px 12px; align-items: start; }
  html.touch #authForm.creating .cr-stage { grid-area: stage; height: clamp(150px, 46vh, 180px); }
  html.touch #authForm.creating .class-pick { grid-area: rows; }
  html.touch #authForm.creating #authBtn { grid-area: btn; }
  /* Landscape is short: compact the rows while keeping tabs and the submit control touch-sized. */
  html.touch #authForm { --ar-w: 30px; --sw: 20px; }
  html.touch #authForm.creating .pick { min-height: var(--h-touch); padding: 0 var(--s2); }
  html.touch #authForm .step-name { font-size: var(--f-sm); }
  html.touch #authForm .sws { gap: var(--s1); }
  html.touch #authForm .class-card { width: 44px; height: 44px; }
  html.touch #authForm .class-card img { width: 36px; height: 36px; }
  /* The wardrobe grid has to show two rows plus the dye row in a 390px-tall sheet. */
  html.touch .av-grid { grid-template-columns: repeat(auto-fill, 62px); }
  html.touch .av-grid { grid-auto-rows: 62px; }
  html.touch .av-card { width: 62px; height: 62px; min-height: 0; }
  html.touch .av-card img { width: 46px; height: 46px; }
  html.touch .av-ed { --sw: 24px; }
  html.touch #authForm.creating .row-line { margin-bottom: 0; }
}

/* Phone wardrobe: cards fill equal columns (no overlap) and two full rows always show. */
@media (orientation: portrait) {
  html.touch .win[data-kind=wardrobe] .av-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: auto; max-height: none; min-height: calc(2 * 72px + var(--s2)); gap: var(--s2); }
  html.touch .win[data-kind=wardrobe] .av-card { width: auto; height: auto; aspect-ratio: 1; }
  html.touch .win[data-kind=wardrobe] .av-card img { width: 72%; height: 72%; }
}
@media (orientation: portrait) {
  /* Dye rows: label above, so the 16 dyes get the full width as two rows of 8. */
  html.touch .av-dyes .row-line { flex-direction: column; align-items: flex-start; gap: var(--s2); }
  html.touch .av-dyes .sws { grid-template-columns: repeat(var(--cols, 8), minmax(0, 30px)); gap: 8px; }
}

/* ↑ morphs into a context icon (talk, portal, door…) when ↑ would act; client/touch.js syncCtx.
   Two icon layers crossfade, so arrow → icon and icon → icon blend (blur + scale + fade) instead of swapping. */
html.touch .tc-ctx {
  position: absolute; left: 50%; top: 3px; width: 24px; height: 24px;
  fill: none; stroke: #fff; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round;
  opacity: 0; transform: translateX(-50%) translateY(3px) scale(.6); filter: blur(3px); pointer-events: none;
  transition: opacity .28s ease, transform .4s cubic-bezier(.2, 1.25, .35, 1), filter .28s ease, stroke .12s ease;
}
html.touch .tc-ctx.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); filter: blur(0); }
html.touch #tc-pad .tc-dir.tc-up { transition: fill .12s ease, opacity .26s ease, transform .34s cubic-bezier(.2, 1.25, .35, 1), filter .26s ease; }
html.touch #tc-pad.ctx .tc-dir.tc-up { opacity: 0; transform: translateX(-50%) translateY(-4px) scale(.5); filter: blur(2px); }
html.touch #tc-pad.rest.ctx { opacity: 0.8; }
html.touch #tc-pad.rest { transition: opacity .3s ease; }
html.touch #tc-pad.ctx .tc-up.on ~ .tc-ctx.show { stroke: var(--acc2); filter: drop-shadow(0 0 5px rgba(42, 255, 198, 0.85)); }
@media (prefers-reduced-motion: reduce) { html.touch .tc-ctx, html.touch #tc-pad .tc-dir.tc-up { transition: opacity .15s ease; transform: translateX(-50%); filter: none; } }
