/* Mando: the screen is a two-thumb gamepad. Wide left zone moves, right zone acts,
   pause and seat sit top centre, out of the thumbs' way. Words only during pauses. */
body.mando-active { overflow: hidden; overscroll-behavior: none; }
.mando-active .topbar { display: none; }
.mando-active .connection {
  position: fixed;
  z-index: 5;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  width: max-content;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
  border: 1px solid #7a6030;
  border-radius: 6px;
}

.mando-deck {
  --mando-player: #f2b33d;
  --mando-ink: #121a2a;
  --mando-face: #1d2740;
  --mando-rim: #4a5675;
  --mando-muted: #aeb6cb;
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 0.7fr) minmax(0, 1.3fr);
  grid-template-areas: "strip strip" "stage stage" "move act";
  gap: 10px 12px;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 115%, #1b2540 0%, #121a2a 64%);
  color: var(--paper, #f2e7cb);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* Player colour along the top edge: whose controller this is, at a glance. */
.mando-deck::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--mando-player);
}
.mando-deck[data-move="none"] .mando-zone-act,
.mando-deck[data-actions="0"] .mando-zone-move { grid-column: 1 / -1; }

.mando-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Top strip: who / pause + seat / score. */
.mando-strip {
  grid-area: strip;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.mando-who { display: flex; align-items: center; gap: 8px; min-width: 0; margin: 0; }
.mando-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--mando-player); }
.mando-deck[data-seat] .mando-dot { display: none; }
.mando-names { display: grid; min-width: 0; line-height: 1.15; }
.mando-names strong,
.mando-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mando-names strong { font-size: 0.95rem; font-weight: 700; }
.mando-title {
  color: var(--muted, #c4bba3);
  font-family: var(--display, sans-serif);
  font-stretch: condensed;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.mando-title:empty { display: none; }

.mando-hub { display: flex; align-items: center; gap: 8px; }
.mando-pause {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px 0 12px;
  border: 1.5px solid #ffffff3d;
  border-radius: 999px;
  background: #ffffff0d;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}
.mando-pause[hidden] { display: none; }
.mando-pause svg { width: 18px; height: 18px; flex: none; }
.mando-pause[aria-busy="true"],
.mando-resume[aria-busy="true"] { opacity: 0.6; cursor: progress; }
.mando-deck[data-paused] .mando-pause { border-color: transparent; background: var(--mando-player); color: var(--mando-ink); }
.mando-seat {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 38px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--mando-player);
  color: var(--mando-ink);
  box-shadow: 0 0 0 3px #ffffff1a;
  font-size: 0.86rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}
.mando-seat[hidden] { display: none; }

.mando-score { display: flex; justify-self: end; align-items: baseline; gap: 5px; margin: 0; color: var(--muted, #c4bba3); font-size: 0.78rem; font-weight: 700; }
.mando-score strong {
  color: var(--paper, #f2e7cb);
  font-family: var(--display, sans-serif);
  font-stretch: condensed;
  font-size: 2rem;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

/* Stage: messages, and the big resume target while paused. */
.mando-stage {
  grid-area: stage;
  position: relative;
  z-index: 4;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  min-height: 0;
  padding: 0 4px;
  overflow: hidden;
  text-align: center;
  pointer-events: none;
}
.mando-status { display: grid; justify-items: center; gap: 8px; max-width: 100%; }
.mando-kicker {
  margin: 0;
  color: var(--mando-player);
  font-family: var(--display, sans-serif);
  font-stretch: condensed;
  font-size: clamp(2rem, 9vw, 3.4rem);
  font-weight: 700;
  line-height: 0.95;
  text-transform: uppercase;
}
.mando-message { max-width: 28ch; margin: 0; font-size: clamp(1rem, 4vw, 1.3rem); line-height: 1.3; overflow-wrap: anywhere; }
.mando-deck[data-phase="play"]:not([data-paused]) .mando-message {
  padding: 0.45em 0.9em;
  border: 1.5px solid var(--mando-player);
  border-radius: 10px;
  background: #121a2ae0;
  font-weight: 650;
}
.mando-resume {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 28px 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--mando-player);
  color: var(--mando-ink);
  box-shadow: 0 10px 28px #0008;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}
.mando-resume svg { width: 22px; height: 22px; }
.mando-resume[hidden] { display: none; }
.mando-stunned { background: radial-gradient(120% 80% at 50% 115%, #4a1f2a 0%, #121a2a 64%); }
.mando-stunned .mando-kicker { color: var(--alert, #ff9b85); }

/* Touch zones: no boxes to aim at, just a faint floor that brightens under a thumb. */
.mando-zone {
  position: relative;
  min-width: 0;
  min-height: 0;
  container-type: size;
  border-radius: 26px;
  background: #ffffff05;
  touch-action: none;
  transition: background-color 140ms ease, opacity 160ms ease;
}
.mando-zone.mando-touching { background: #ffffff0b; }
.mando-zone-move { grid-area: move; z-index: 2; }
.mando-zone-act { grid-area: act; z-index: 1; }
.mando-deck[data-phase]:not([data-phase="play"]) .mando-zone,
.mando-deck[data-paused] .mando-zone { opacity: 0.32; }
.mando-zone svg { display: block; width: 1em; height: 1em; pointer-events: none; }

.mando-rest {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  color: var(--mando-muted);
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 120ms ease;
}
.mando-rest span { font-size: 0.76rem; font-weight: 750; letter-spacing: 0.16em; text-transform: uppercase; }
.mando-rest small { font-size: 0.74rem; }
.mando-touching .mando-rest { opacity: 0; }
@container (max-height: 130px) { .mando-rest small { display: none; } }

/* Floating stick: invisible at rest, born centred under the first touch. */
.mando-stick {
  --size: clamp(104px, 46cqh, 172px);
  position: absolute;
  left: 0;
  top: 0;
  width: var(--size);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid var(--mando-player);
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff10 0 32%, #182136d9 33%);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.88);
  transition: opacity 90ms ease, transform 90ms ease;
  pointer-events: none;
}
.mando-thumb {
  width: 44%;
  aspect-ratio: 1;
  border: 3px solid var(--mando-player);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #56688a, #2b3650 70%);
  box-shadow: 0 6px 14px #0007;
}

/* Floating slider for X-only games. */
.mando-slide {
  --w: clamp(156px, 64cqw, 250px);
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: clamp(56px, 22cqh, 72px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 0 10px;
  border: 2px solid var(--mando-player);
  border-radius: 999px;
  background: #182136d9;
  color: var(--mando-muted);
  font-size: 1.4rem;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
  transition: opacity 90ms ease, transform 90ms ease;
  pointer-events: none;
}
.mando-slide .mando-thumb { width: auto; height: 78%; }
.mando-stick.mando-floating,
.mando-slide.mando-floating { opacity: 1; transform: translate(-50%, -50%); transition: opacity 60ms ease; }

/* Direction buttons kept for keyboards and screen readers; shown only when focused. */
.mando-a11y {
  position: absolute;
  left: 50%;
  bottom: 10px;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
}
.mando-a11y button {
  display: grid;
  place-items: center;
  min-width: 64px;
  min-height: 52px;
  padding: 0;
  border: 2px solid var(--mando-player);
  border-radius: 16px;
  background: #243049;
  color: #fff8e8;
  font-size: 1.6rem;
}
.mando-a11y button:not(:focus-visible) {
  position: absolute;
  width: 1px;
  min-width: 0;
  height: 1px;
  min-height: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
}
.mando-a11y button.mando-held { background: #efe3c9; color: var(--mando-ink); }

/* Action cluster: A (slot 1) is largest; B sits to its right on the same line.
   Extra actions take a smaller row above. Anchored low and right, where the thumb rests. */
.mando-cluster {
  --a: min(50cqh, 40cqw, 152px);
  position: absolute;
  right: clamp(4px, 6cqw, 44px);
  bottom: clamp(6px, 13cqh, 80px);
  display: grid;
  grid-template-areas: "a b";
  align-items: center;
  justify-items: center;
  gap: clamp(10px, 4cqw, 26px);
  pointer-events: none;
}
.mando-cluster[data-count="1"] { grid-template-areas: "a"; }
.mando-cluster[data-count="3"] { --a: min(36cqh, 34cqw, 126px); grid-template-areas: ". c" "a b"; }
.mando-cluster[data-count="4"] { --a: min(36cqh, 30cqw, 126px); grid-template-areas: "c d" "a b"; }

.mando-action {
  --size: var(--a);
  --ring: var(--mando-player);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: conic-gradient(var(--ring) var(--mando-charge, 100%), #2c3550 0);
  color: var(--paper, #f2e7cb);
  font: inherit;
  pointer-events: auto;
  transition: transform 70ms ease;
}
.mando-action[data-slot="1"] { grid-area: a; }
.mando-action[data-slot="2"] { grid-area: b; --size: calc(var(--a) * 0.76); }
.mando-action[data-slot="3"] { grid-area: c; --size: calc(var(--a) * 0.66); }
.mando-action[data-slot="4"] { grid-area: d; --size: calc(var(--a) * 0.66); }

.mando-face {
  display: grid;
  grid-template-columns: 100%;
  align-content: center;
  justify-items: center;
  gap: 2px;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #2a3654, var(--mando-face) 70%);
  box-shadow: inset 0 -7px 0 #00000055;
  pointer-events: none;
}
.mando-glyph { font-size: calc(var(--size) * 0.3); line-height: 1; }
/* The label gets the whole face width and is never cut: short action words read whole. */
.mando-name {
  width: 100%;
  white-space: nowrap;
  text-align: center;
  font-size: clamp(0.7rem, calc(var(--size) * 0.14), 1.05rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
/* Letter badge: identifies the button, the function name says what it does. */
.mando-badge {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: clamp(22px, calc(var(--size) * 0.26), 32px);
  aspect-ratio: 1;
  border: 2px solid var(--ring);
  border-radius: 50%;
  background: var(--mando-ink);
  font-size: clamp(0.68rem, calc(var(--size) * 0.12), 0.95rem);
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
}
.mando-action[data-state="charging"] .mando-face { background: #161d30; }
.mando-action[data-state="charging"] .mando-face > * { opacity: 0.5; }
.mando-action[data-state="inactive"] { --ring: var(--mando-rim); }
.mando-action.mando-held { transform: scale(0.94); }
.mando-action.mando-held .mando-face { background: #efe3c9; box-shadow: none; color: var(--mando-ink); }
.mando-action.mando-held .mando-face > * { opacity: 1; }

.mando-deck button:focus-visible { outline: 3px solid #f2bf64; outline-offset: 4px; }
.mando-keyboard {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(2px, env(safe-area-inset-bottom));
  z-index: 3;
  margin: 0;
  color: var(--muted, #c4bba3);
  font-size: 0.76rem;
  text-align: center;
  pointer-events: none;
}
@media (any-pointer: coarse) { .mando-keyboard { display: none; } }

/* Landscape (phone held sideways, tablet): hands on the sides, messages float over the middle. */
@media (orientation: landscape) {
  .mando-deck {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "strip strip" "move act";
    gap: 8px 14px;
  }
  .mando-stage { grid-row: 2; grid-column: 1 / -1; align-content: start; padding-top: 2px; }
  .mando-deck:not([data-phase="play"]) .mando-stage,
  .mando-deck[data-paused] .mando-stage { align-content: center; }
  .mando-deck:not([data-phase="play"]) .mando-status,
  .mando-deck[data-paused] .mando-status {
    padding: 14px 24px;
    border-radius: 18px;
    background: #121a2ae8;
  }
  .mando-kicker { font-size: clamp(1.6rem, 5vw, 2.8rem); }
  .mando-message { font-size: clamp(0.92rem, 2.2vw, 1.15rem); }
  .mando-deck[data-phase="play"]:not([data-paused]) .mando-message { max-width: min(40ch, 46vw); font-size: 0.9rem; }
}

/* Short landscape phones (e.g. 667×320): reclaim height for the thumbs. */
@media (orientation: landscape) and (max-height: 360px) {
  .mando-deck { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .mando-strip { min-height: 40px; }
  .mando-pause { min-height: 40px; }
  .mando-seat { min-width: 34px; height: 34px; }
  .mando-score strong { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mando-zone, .mando-rest, .mando-action,
  .mando-stick, .mando-slide, .mando-stick.mando-floating, .mando-slide.mando-floating { transition: none; }
  .mando-stick, .mando-slide { transform: translate(-50%, -50%); }
}

/* Warm-up round: the points stay out of sight; nothing counts yet. */
.mando-deck[data-practice] .mando-score { visibility: hidden; }
