/* Touch controls — floating joystick (left zone) + action button (right).
   Elements are created by js/input/touch.js on touch devices only.

   Material language: a thin luminous ring over glass, tinted by the active
   world's accent (the controls dress with the world like the rest of the
   HUD). The maze stays visible through both — the old solid grey discs
   read as stickers on top of the game. */

/* ── Floating stick: rests faintly in the left thumb zone so the player
   knows it exists, jumps under the finger on touch ── */
.stick {
  position: fixed;
  /* Home spot — inline left/top from a touch override this; released
     fingers clear the inline styles and the stick drifts back here.
     Center sits 160px above the safe-area edge — the action button's
     center matches (bottom 128 + half of 64). */
  left: 25vw;
  top: calc(100dvh - env(safe-area-inset-bottom, 0px) - 160px);
  width: 104px;
  height: 104px;
  margin: -52px 0 0 -52px; /* left/top are (re)set to the touch point */
  border-radius: 50%;
  /* Ring, not disc: a crisp accent-tinted rim, a shallow glass well inside,
     and a faint machined sheen sweeping the metal. */
  border: 1.5px solid color-mix(in srgb, var(--c-accent) 42%, rgba(255, 255, 255, 0.22));
  background:
    conic-gradient(from 215deg,
      transparent 0%, rgba(255, 255, 255, 0.05) 12%, transparent 30%,
      transparent 55%, rgba(255, 255, 255, 0.04) 68%, transparent 85%),
    radial-gradient(circle at 50% 38%,
      rgba(255, 255, 255, 0.05), transparent 58%),
    radial-gradient(circle at 50% 50%,
      color-mix(in srgb, var(--c-surface) 30%, transparent) 55%,
      color-mix(in srgb, var(--c-surface) 55%, transparent) 82%,
      transparent 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 0 26px rgba(0, 0, 0, 0.38),
    0 0 0 4px color-mix(in srgb, var(--c-accent) 7%, transparent),
    0 8px 24px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(2px);
  z-index: 150;
  pointer-events: none; /* the viewport owns the gesture */
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

/* Faint resting hint while the maze is on screen */
.stick--zone { opacity: 0.3; transform: scale(1); }

/* Under a finger: awake, lit, world-coloured */
.stick--live {
  opacity: 0.9;
  transform: scale(1);
  transition: opacity 0.08s ease, transform 0.08s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 0 26px rgba(0, 0, 0, 0.38),
    0 0 0 4px color-mix(in srgb, var(--c-accent) 12%, transparent),
    0 0 22px color-mix(in srgb, var(--c-glow) 38%, transparent),
    0 8px 24px rgba(0, 0, 0, 0.38);
}

.stick__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  /* Glass orb: hard specular up-left, world-accent body, weighted base */
  border: 1px solid color-mix(in srgb, var(--c-accent) 36%, rgba(255, 255, 255, 0.26));
  background:
    radial-gradient(circle at 34% 26%,
      rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.10) 38%, transparent 58%),
    radial-gradient(circle at 50% 55%,
      color-mix(in srgb, var(--c-accent) 30%, var(--c-surface)),
      color-mix(in srgb, var(--c-surface) 88%, black) 85%);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.4),
    inset 0 -5px 10px rgba(0, 0, 0, 0.4),
    0 5px 12px rgba(0, 0, 0, 0.5);
}

/* The orb lifts and lights while steering */
.stick--live .stick__knob {
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.45),
    inset 0 -5px 10px rgba(0, 0, 0, 0.4),
    0 0 18px color-mix(in srgb, var(--c-glow) 60%, transparent),
    0 8px 16px rgba(0, 0, 0, 0.55);
}

/* Released: the knob glides home instead of teleporting */
.stick:not(.stick--live) .stick__knob {
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

/* Chevrons at the four compass points — thin strokes, not filled wedges.
   The one you steer toward flares: the control answers the finger. */
.stick__arrows {
  position: absolute;
  inset: -14px; /* the compass points live outside the glass */
  width: calc(100% + 28px);
  height: calc(100% + 28px);
  overflow: visible;
  pointer-events: none;
}

.stick__chev {
  fill: none;
  stroke: color-mix(in srgb, var(--c-text-bright) 62%, transparent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.55;
  transition: opacity 0.1s ease, stroke 0.1s ease;
}

.stick--dir-up    .stick__chev--up,
.stick--dir-down  .stick__chev--down,
.stick--dir-left  .stick__chev--left,
.stick--dir-right .stick__chev--right {
  opacity: 1;
  stroke: color-mix(in srgb, var(--c-accent) 70%, white);
  filter: drop-shadow(0 0 5px var(--c-glow));
}

/* ── Action button: fixed in the right thumb zone ── */
.act-btn {
  /* Hidden until the maze is on screen — the visible state also supplies
     the centering, so a stray `display` can never unhide it again. */
  display: none;
  position: fixed;
  right: 18px;
  /* Center at 160px from the safe-area edge — level with the stick's home */
  bottom: calc(128px + env(safe-area-inset-bottom, 0px));
  width: 72px;
  height: 72px;
  padding: 0;
  line-height: 0;
  border-radius: 50%;
  /* Same family as the stick: accent ring, glass well, machined sheen */
  border: 1.5px solid color-mix(in srgb, var(--c-accent) 46%, rgba(255, 255, 255, 0.24));
  background:
    conic-gradient(from 40deg,
      transparent 0%, rgba(255, 255, 255, 0.05) 14%, transparent 32%,
      transparent 58%, rgba(255, 255, 255, 0.04) 72%, transparent 88%),
    radial-gradient(circle at 50% 30%,
      rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.02) 50%, transparent 70%),
    radial-gradient(circle at 50% 50%,
      color-mix(in srgb, var(--c-surface) 55%, transparent) 50%,
      color-mix(in srgb, var(--c-surface) 80%, transparent) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -8px 18px rgba(0, 0, 0, 0.42),
    0 0 0 4px color-mix(in srgb, var(--c-accent) 8%, transparent),
    0 8px 22px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(3px);
  color: var(--c-text-bright);
  opacity: 0.88;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  z-index: 150;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}

@media (hover: none) and (pointer: coarse) {
  .act-btn.act-btn--active {
    display: grid;
    place-items: center;
  }
}

/* Press ripple — an accent bloom from the centre, gone in a blink */
.act-btn::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: radial-gradient(circle,
    color-mix(in srgb, var(--c-glow) 55%, transparent) 0%,
    transparent 68%);
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}

.act-btn--pressed {
  transform: scale(0.93);
  border-color: color-mix(in srgb, var(--c-accent) 70%, rgba(255, 255, 255, 0.3));
  box-shadow:
    inset 0 2px 12px rgba(0, 0, 0, 0.55),
    0 0 20px color-mix(in srgb, var(--c-glow) 50%, transparent),
    0 3px 10px rgba(0, 0, 0, 0.35);
}

.act-btn--pressed::after {
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.05s ease, transform 0.16s ease-out;
}

/* The glyph is geometry: it fills a square box, so its centre is the
   button's centre no matter the font. A faint machined inner ring keeps
   the ✕ from floating in a void. */
.act-btn__glyph {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

.act-btn__glyph .act-btn__x {
  stroke-width: 2.6;
}

.act-btn__glyph .act-btn__rim {
  stroke: color-mix(in srgb, var(--c-accent) 50%, currentColor);
  stroke-width: 1;
  opacity: 0.35;
}

.act-btn--pressed .act-btn__glyph .act-btn__x {
  stroke: color-mix(in srgb, var(--c-accent) 45%, white);
}
