/* The on-screen touch controls (js/touch.ts, laid out by Input/TouchLayout.cs; #72, #71): round
   buttons in the HUD's look (dark glass, light text, one font), a floating stick, a small press
   scale. Their boxes come from C#; only the look is here. */

.touch {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: var(--touch-opacity, 0.7);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* While the controls show, the browser keeps its own gestures (page zoom, scroll) to itself. */
html:has(#touch),
html:has(#touch) body,
html:has(#touch) #app {
  touch-action: none;
}

.touch-zone,
.touch-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}

.touch-btn {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(18, 16, 26, 0.78);
  border: 3px solid rgba(255, 255, 255, 0.3);
  color: var(--ui-text, #f4f2fa);
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition:
    transform 70ms ease-out,
    background-color 70ms ease-out;
}

.touch-btn.down {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.85);
}

/* The main button of each game stands out a little. */
.touch-dash,
.touch-boost,
.touch-ability {
  background: rgba(244, 242, 250, 0.9);
  color: #1d1a26;
  border-color: transparent;
}

.touch-dash.down,
.touch-boost.down,
.touch-ability.down {
  background: #ffffff;
}

/* Siegeometry: the ability waits for a full meter; the chosen amount is lit. */
.touch-ability:not(.ready) {
  background: rgba(18, 16, 26, 0.78);
  color: rgba(244, 242, 250, 0.55);
  border: 3px dashed rgba(255, 255, 255, 0.3);
}

.touch-amount {
  text-transform: none;
}

.touch-amount.on {
  background: rgba(244, 242, 250, 0.9);
  color: #1d1a26;
  border-color: transparent;
}

/* The stick: a ring where it rests, or where the thumb went down, and the knob under the thumb. */
.touch-stick,
.touch-knob {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  pointer-events: none;
}

.touch-stick {
  border: 3px solid rgba(255, 255, 255, 0.32);
  background: rgba(18, 16, 26, 0.35);
  opacity: 0.6;
}

.touch-knob {
  background: rgba(244, 242, 250, 0.75);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  opacity: 0.55;
}

.touch.stick-held .touch-stick,
.touch.stick-held .touch-knob {
  opacity: 1;
}

.high-contrast .touch-btn {
  background: rgba(6, 5, 10, 0.95);
  border-color: #ffffff;
}

.reduced-motion .touch-btn {
  transition: none;
}

/* The ability button fills up as the meter does. */
.touch-ability:not(.ready) {
  background:
    conic-gradient(rgba(244, 242, 250, 0.35) calc(var(--meter, 0) * 360deg), transparent 0),
    rgba(18, 16, 26, 0.78);
}

/* The controls stand in for Siegeometry's bottom bar (amount, ability); the hints show only the
   touch line, up top (hints.css). */
html:has(#touch) .sg-bottom {
  display: none;
}

/* Siegeometry's ability meter over the controls (#70): they hide the bottom bar and are hidden
   from screen readers, so this is the meter a phone player sees and hears (a progress bar). Its
   box comes from C# (TouchLayout: as wide as the buttons, just above them); held by its bottom
   edge, so bigger text makes it grow upwards. */
.sg-touch-meter {
  display: none;
}

html:has(#touch) .sg-touch-meter {
  display: flex;
  align-items: flex-end;
  position: fixed;
  left: var(--tm-l, auto);
  bottom: var(--tm-b, 0px);
  width: var(--tm-w, auto);
  min-height: var(--tm-h, 36px);
  z-index: 11;
  pointer-events: none;
}

.sg-tmeter {
  display: flex;
  align-items: center;
  gap: 0.4em;
  width: 100%;
  box-sizing: border-box;
  padding: 0.3em 0.7em;
  border-radius: 1em;
  background: rgba(18, 16, 26, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: var(--ui-text, #f4f2fa);
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 800;
  font-size: max(var(--fs-small), 0.85em);
  line-height: 1.2;
}

.sg-tmeter .icon {
  display: grid;
  color: var(--c);
}

.sg-tmeter .bar {
  flex: 1;
  height: 0.5em;
  border-radius: 1em;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.sg-tmeter .bar i {
  display: block;
  height: 100%;
  width: calc(var(--m, 0) * 100%);
  background: var(--c);
  border-radius: inherit;
}

.sg-tmeter .ready {
  display: none;
}

.sg-tmeter.full {
  background: #f7c548;
  color: #1d1a26;
  border-color: transparent;
}

.sg-tmeter.full .icon {
  color: inherit;
}

.sg-tmeter.full .ready {
  display: inline;
}

.sg-tmeter.full :is(.bar, .pct) {
  display: none;
}

/* The ability running: the icon glows like the HUD card's meter (.sg-meter.active, app.css). */
.sg-tmeter.active .icon {
  animation: sg-glow 0.9s ease-in-out infinite alternate;
}

.reduced-motion .sg-tmeter.active .icon {
  animation: none;
}

.sg-tmeter .ready {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A landscape tablet or laptop (a phone on its side keeps the meter clear of its chip column,
   TouchLayout): the meter's height follows the text size only, and the player cards on its side
   stack up from just above it (scrolling if they must), so none hides under it (#70). */
@media (orientation: landscape) and (min-height: 500px) {
  html:has(#touch) .sg-hud {
    --tm-hh: max(var(--tm-h, 36px), calc(var(--fs-small) * 2.3));
  }

  html:has(#touch) .sg-touch-meter {
    height: var(--tm-hh);
    min-height: 0;
  }

  html:has(#touch) .sg-touch-meter .sg-tmeter {
    height: 100%;
    font-size: var(--fs-small);
  }

  html:has(#touch) .sg-hud:has(.sg-touch-meter:not(.lefty)) .pg-right,
  html:has(#touch) .sg-hud:has(.sg-touch-meter.lefty) .pg-left {
    top: auto;
    bottom: calc(var(--tm-b, 0px) + var(--tm-hh) + 10px);
    transform: none;
    max-height: calc(100% - var(--tm-b, 0px) - var(--tm-hh) - 10px - var(--sa-t, 0px) - 4.5em);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    pointer-events: auto;
  }
}

.high-contrast .sg-tmeter:not(.full) {
  background: rgba(6, 5, 10, 0.95);
  border-color: #ffffff;
}
