/* Velvet Pool · cartoon theme (2026-10-13 visual refresh).
   One theme, one file: petroleum surfaces, emerald primary, turquoise accents, cream details.
   Contrast of the token pairs is measured by dev/contrast.mjs. */
:root {
  --bg: #2eb8d6; /* room floor / fallback */
  --surface: #084d5c; /* HUD, menus, panels */
  --surface-hi: #0d6274; /* secondary buttons, raised rows */
  --surface-lo: #053947; /* inset tracks, inputs */
  --ink: #f5fcfc; /* text on surfaces */
  --ink-dim: #d2ecef; /* secondary text */
  --ink-faint: #a9d4da; /* small labels */
  --line: rgba(117, 228, 241, 0.26);
  --focus: #75e4f1; /* focus ring, active player, selected */
  --on-focus: #04332d; /* text on the cyan selection */
  --emerald: #27b881; /* primary action */
  --emerald-hi: #4fd39c;
  --emerald-lo: #149468;
  --on-emerald: #04332d;
  --turquoise: #16a8b3;
  --cream: #fff0cc;
  --on-cream: #04332d;
  --warm: #f5bf54;
  --danger: #ec735f; /* foul: borders and fills */
  --danger-ink: #ffb8ab; /* foul: text on surfaces */
  --radius: 16px;
  --ui: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --shadow: 0 16px 40px rgba(2, 40, 52, 0.38), 0 2px 0 rgba(255, 255, 255, 0.06) inset;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
}
body {
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
svg {
  display: block;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}

#safe-probe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* ---------- Room: a floor seen straight from above (never a wall or a horizon) ---------- */
#room {
  /* a light blur on the floor only (never on the table, balls or HUD); the extra margin hides the blurred edge */
  position: fixed;
  inset: -12px;
  pointer-events: none;
  background: var(--bg) url(../assets/bg/room-topdown-landscape.webp) center / cover no-repeat;
  filter: blur(3px);
}
body.portrait #room {
  background-image: url(../assets/bg/room-topdown-portrait.webp);
}
/* a calm petroleum veil on the floor behind the top bar and the controls, so chairs and plants
   never compete with the power handle and labels; it lives under the table canvas */
#room::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      90deg,
      rgba(6, 62, 76, 0.62),
      rgba(6, 62, 76, 0) 150px,
      rgba(6, 62, 76, 0) calc(100% - 150px),
      rgba(6, 62, 76, 0.62)
    ),
    linear-gradient(180deg, rgba(6, 62, 76, 0.5), rgba(6, 62, 76, 0) 90px);
}
body.portrait #room::after {
  background: linear-gradient(
    180deg,
    rgba(6, 62, 76, 0.62),
    rgba(6, 62, 76, 0) 150px,
    rgba(6, 62, 76, 0) calc(100% - 170px),
    rgba(6, 62, 76, 0.7)
  );
}
body.is-menu #room::after {
  opacity: 0.4;
}
@media (max-width: 960px) and (max-resolution: 1.5dppx) {
  #room {
    background-image: url(../assets/bg/room-topdown-landscape-small.webp);
  }
  body.portrait #room {
    background-image: url(../assets/bg/room-topdown-portrait-small.webp);
  }
}

canvas#gl,
canvas#fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}
canvas#fx {
  pointer-events: none;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
body.is-menu #hud,
body.is-demo #hud {
  opacity: 0;
}
body.is-menu #hud *,
body.is-demo #hud * {
  pointer-events: none !important;
}

.topbar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(env(safe-area-inset-top) + 10px) calc(var(--sr, env(safe-area-inset-right)) + 14px)
    0 calc(var(--sl, env(safe-area-inset-left)) + 14px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  /* chat, pause and full screen get a column only when they are shown (no empty gaps at the edge) */
  grid-auto-flow: column;
  grid-auto-columns: auto;
}

/* Player cards: name, group (icon + name + balls left); the full rack only where it fits. */
.player {
  container-type: inline-size;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
  max-width: 370px;
  justify-self: start;
  padding: 6px 12px 6px 6px;
  border-radius: 20px;
  background: rgba(8, 77, 92, 0.94);
  border: 2px solid rgba(117, 228, 241, 0.2);
  box-shadow: 0 6px 18px rgba(2, 40, 52, 0.3);
  transition:
    border-color 0.3s,
    box-shadow 0.3s;
}
.player.right {
  justify-self: end;
  padding: 6px 6px 6px 12px;
}
.player.active {
  border-color: var(--focus);
  box-shadow:
    0 0 0 3px rgba(117, 228, 241, 0.22),
    0 8px 22px rgba(2, 40, 52, 0.35);
}
.avatar {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  background: radial-gradient(circle at 35% 30%, var(--emerald-hi), var(--emerald-lo) 75%);
  color: var(--on-emerald);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.avatar.cpu {
  background: radial-gradient(circle at 35% 30%, #1a7f93, #063f4c 75%);
  color: var(--ink);
}
body.is-online .avatar.cpu {
  background: radial-gradient(circle at 35% 30%, #8c6ad1, #45307a 75%);
  color: #fff;
}
.player.active .avatar {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--focus);
}
.pinfo {
  min-width: 0;
  flex: 1;
}
.player.right .pinfo {
  text-align: right;
}
.pname {
  font-weight: 800;
  font-size: 14.5px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pname small {
  font-weight: 700;
  color: var(--ink-faint);
  font-size: 11.5px;
  margin-left: 5px;
}
/* whose turn, by shape as well as colour: a play mark before the active name */
.player.active .pname::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-right: 6px;
  vertical-align: 1px;
  border-left: 8px solid var(--focus);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}
.pline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 3px;
  min-width: 0;
}
.player.right .pline {
  flex-direction: row-reverse;
}
.pgroup {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.player.right .pgroup {
  flex-direction: row-reverse;
}
.gicon {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-size: cover;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.gname {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--focus);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gcount {
  flex: none;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.16);
  color: var(--ink);
}
body.is-practice .pline {
  display: none;
}
/* the cards open the balls panel */
.player {
  pointer-events: auto;
  cursor: pointer;
}
.player:hover {
  border-color: rgba(117, 228, 241, 0.6);
}
.player.active:hover {
  border-color: var(--focus);
}
body.is-practice .player {
  pointer-events: none;
  cursor: default;
}
.gcount.bump {
  animation: bump 0.45s ease-out;
}
@keyframes bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.25);
    background: var(--focus);
    color: var(--on-focus);
  }
  100% {
    transform: scale(1);
  }
}
.prack {
  display: none;
  gap: 3px;
  align-items: center;
}
@container (min-width: 330px) {
  .prack {
    display: flex;
  }
}
/* narrow cards (phones in portrait): the name and the group need the room more than the avatar does;
   the active card still has its border and the play mark */
@container (max-width: 175px) {
  .avatar {
    display: none;
  }
  .gcount {
    min-width: 18px;
    padding: 0 5px;
  }
}
@container (max-width: 130px) {
  .pgroup {
    gap: 3px;
  }
  .gicon {
    width: 14px;
    height: 14px;
  }
  body .player .pgroup .gname {
    font-size: 10px;
    letter-spacing: 0;
  }
  .gcount {
    min-width: 16px;
    font-size: 11px;
    padding: 0 4px;
  }
}
body.portrait.compact .player {
  padding: 5px 8px;
}
.prack .mb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-size: cover;
  flex: none;
  transition:
    transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1),
    opacity 0.4s,
    filter 0.4s;
}
.prack .mb.gone {
  opacity: 0.22;
  filter: grayscale(1);
  transform: scale(0.72);
}
.prack .mb.pop {
  animation: pop 0.55s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.4);
  }
  100% {
    transform: scale(0.72);
  }
}
.prack .mb.eight {
  margin-left: 5px;
  box-shadow: 0 0 0 2px var(--cream);
}
.player.right .prack .mb.eight {
  margin-left: 0;
  margin-right: 5px;
  order: -1;
}
.prack .mb.eight.dim {
  opacity: 0.4;
}

.status {
  text-align: center;
  min-width: 0;
  padding: 6px 20px 7px;
  border-radius: 999px;
  background: rgba(8, 77, 92, 0.94);
  border: 2px solid var(--focus);
  box-shadow: 0 6px 18px rgba(2, 40, 52, 0.3);
}
.status-main {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-sub {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cream);
  margin-top: 1px;
  white-space: nowrap;
}
.status-sub:empty {
  display: none;
}
.status-sub.warn {
  color: var(--danger-ink);
}

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--line);
  background: rgba(8, 77, 92, 0.94);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(2, 40, 52, 0.3);
  transition:
    transform 0.15s,
    background 0.2s;
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0;
}
.icon-btn.back svg {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Notice (short feedback near the top of the felt; placed by hud._placeNotice) ---------- */
.notice {
  --accent: var(--focus);
  position: absolute;
  left: 50%;
  top: 30%;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: min(calc(100vw - 24px), 420px);
  padding: 10px 16px 10px 12px;
  border-radius: 18px;
  background: rgba(8, 77, 92, 0.97);
  border: 1.5px solid rgba(117, 228, 241, 0.28);
  box-shadow:
    inset 4px 0 0 var(--accent),
    0 10px 26px rgba(2, 40, 52, 0.42);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(0.97);
  transition:
    opacity 0.15s ease-in,
    transform 0.15s ease-in; /* exit */
}
.notice.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
  transition:
    opacity 0.2s ease-out,
    transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.notice-icon {
  flex: none;
  min-width: 40px;
  height: 40px;
  padding: 0 4px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--accent);
}
.notice.show .notice-icon {
  animation: iconPop 0.26s ease-out 0.05s both;
}
@keyframes iconPop {
  0% {
    transform: scale(0.8);
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}
.notice-icon svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.notice-icon .nball {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-size: cover;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.notice-icon .nball + .nball {
  margin-left: -8px;
}
.notice-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.notice-cat {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.notice-cat:empty {
  display: none;
}
.notice-title {
  font-size: clamp(17px, 2.2vmin + 6px, 22px);
  font-weight: 800;
  line-height: 1.22;
  color: var(--ink);
}
.notice-chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(117, 228, 241, 0.2);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-dim);
  line-height: 1.3;
}
.notice-chip:has(span:empty) {
  display: none;
}
.notice-chip .chip-ball {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-size: cover;
  flex: none;
}
.notice-chip .chip-ball[hidden] + span {
  padding-left: 6px;
}
/* kinds: the accent (bar, icon, category) changes; the main text stays light */
.notice.foul {
  --accent: var(--danger-ink);
  border-color: rgba(236, 115, 95, 0.5);
}
.notice.lose,
.notice.conn {
  --accent: var(--danger-ink);
}
.notice.group,
.notice.info {
  --accent: var(--focus);
}
.notice.eight,
.notice.win {
  --accent: var(--warm);
}
.notice.pot {
  --accent: var(--emerald-hi);
}
/* compact: a quick note (your pots), one line */
.notice.compact {
  padding: 6px 14px 6px 8px;
  gap: 9px;
  border-radius: 999px;
}
.notice.compact .notice-icon {
  min-width: 30px;
  height: 30px;
  background: none;
}
.notice.compact .notice-title {
  font-size: 15px;
}
body.portrait.compact .notice {
  padding: 8px 14px 8px 10px;
  gap: 10px;
}
body.portrait.compact .notice-icon {
  min-width: 34px;
  height: 34px;
}
body.portrait.compact .notice-title {
  font-size: 17px;
}
body.short-land .notice {
  padding: 7px 12px 7px 9px;
  gap: 9px;
}
body.short-land .notice-icon {
  min-width: 32px;
  height: 32px;
}
body.short-land .notice-title {
  font-size: 16px;
}
@media (prefers-reduced-motion: reduce) {
  .notice,
  .notice.show {
    transform: translate(-50%, 0);
  }
}
body.reduce-motion .notice,
body.reduce-motion .notice.show {
  transform: translate(-50%, 0);
  transition: opacity 0.12s !important;
}

/* ---------- Controls ---------- */
.ctrl {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  transition:
    opacity 0.3s,
    filter 0.3s;
}
.ctrl.disabled {
  opacity: 0.4;
  filter: saturate(0.35);
  pointer-events: none;
}
.ctrl-label {
  position: absolute;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  color: var(--ink);
  text-shadow:
    0 1px 3px rgba(2, 40, 52, 0.9),
    0 0 8px rgba(2, 40, 52, 0.6);
}

/* Power: pull the handle (gesture unchanged); the badge shows the % or "cancel" while dragging. */
#power {
  width: 64px;
  height: 300px;
}
#power .power-track {
  position: absolute;
  left: 50%;
  top: 12px;
  bottom: 12px;
  width: 18px;
  transform: translateX(-50%);
  border-radius: 12px;
  background: var(--surface-lo);
  border: 2px solid rgba(117, 228, 241, 0.45);
  box-shadow:
    inset 0 2px 5px rgba(0, 0, 0, 0.45),
    0 3px 10px rgba(2, 40, 52, 0.35);
  overflow: hidden;
}
#power .power-fill {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 0%;
  background: linear-gradient(180deg, #4fe0ec 0%, #9be37a 38%, #f5bf54 70%, #ff8a3d 100%);
  background-size: 100% var(--track-len, 276px);
}
#power .power-ticks {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    180deg,
    transparent 0 calc(10% - 1px),
    rgba(255, 255, 255, 0.12) calc(10% - 1px) 10%
  );
}
#power .power-handle {
  position: absolute;
  left: 50%;
  top: 12px;
  width: 54px;
  height: 32px;
  transform: translate(-50%, -50%);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
  background: linear-gradient(180deg, #fffaf0, var(--cream) 55%, #f0d9a6);
  box-shadow:
    0 5px 12px rgba(2, 40, 52, 0.45),
    inset 0 -3px 0 rgba(150, 110, 45, 0.25);
  transition:
    box-shadow 0.2s,
    transform 0.12s;
}
#power:not(.disabled) .power-handle {
  box-shadow:
    0 0 0 2px var(--focus),
    0 5px 12px rgba(2, 40, 52, 0.45),
    inset 0 -3px 0 rgba(150, 110, 45, 0.25);
}
#power .power-handle span {
  width: 24px;
  height: 2.5px;
  border-radius: 2px;
  background: rgba(8, 77, 92, 0.55);
}
#power.dragging .power-handle {
  transform: translate(-50%, -50%) scale(1.06);
}
#power .power-value {
  position: absolute;
  left: calc(100% + 6px);
  top: 12px;
  transform: translateY(-50%);
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--focus);
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
#power.dragging .power-value {
  opacity: 1;
}
#power.cancel .power-value {
  border-color: var(--danger);
  color: var(--danger-ink);
}
body.hand-left #power .power-value {
  left: auto;
  right: calc(100% + 6px);
}
#power .ctrl-label {
  left: 50%;
  top: -22px;
  transform: translateX(-50%);
}
/* which way to pull: a chevron engraved mid-track */
#power::before {
  content: '';
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--cream);
  border-bottom: 2px solid var(--cream);
  transform: translate(-50%, -70%) rotate(45deg);
  pointer-events: none;
  opacity: 0.85;
}
#power.dragging::before {
  opacity: 0;
}

/* horizontal power (portrait): one slim row under the table */
body.portrait #power {
  width: 300px;
  height: 64px;
}
body.portrait #power .power-track {
  left: 12px;
  right: 12px;
  top: 50%;
  bottom: auto;
  width: auto;
  height: 16px;
  transform: translateY(-50%);
}
body.portrait #power .power-fill {
  top: 0;
  bottom: 0;
  height: auto;
  width: 0%;
  right: 0;
  left: auto;
  background: linear-gradient(270deg, #4fe0ec 0%, #9be37a 38%, #f5bf54 70%, #ff8a3d 100%);
  background-size: var(--track-len, 276px) 100%;
  background-position: right;
}
body.portrait.hand-left #power .power-fill {
  right: auto;
  left: 0;
  background: linear-gradient(90deg, #4fe0ec 0%, #9be37a 38%, #f5bf54 70%, #ff8a3d 100%);
  background-size: var(--track-len, 276px) 100%;
}
body.portrait #power .power-ticks {
  background: repeating-linear-gradient(
    90deg,
    transparent 0 calc(10% - 1px),
    rgba(255, 255, 255, 0.12) calc(10% - 1px) 10%
  );
}
body.portrait #power .power-handle {
  top: 50%;
  left: auto;
  width: 30px;
  height: 44px;
  flex-direction: row;
}
body.portrait #power .power-handle span {
  width: 2.5px;
  height: 18px;
}
body.portrait #power .power-value {
  left: auto;
  top: -22px;
  transform: translateX(-50%);
}
body.portrait #power .ctrl-label {
  top: -13px;
  left: 2px;
  transform: none;
}
body.portrait.hand-left #power .ctrl-label {
  left: auto;
  right: 2px;
}
body.portrait #power::before {
  transform: translate(-30%, -50%) rotate(135deg);
}
body.portrait.hand-left #power::before {
  transform: translate(-70%, -50%) rotate(-45deg);
}

/* Fine aim wheel (touch only) */
#fine {
  width: 46px;
  height: 210px;
}
#fine .fine-wheel {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(8, 77, 92, 0.72);
  border: 2px solid rgba(117, 228, 241, 0.45);
  box-shadow: 0 4px 12px rgba(2, 40, 52, 0.3);
}
#fine .fine-ridges {
  position: absolute;
  inset: -40px 0;
  background:
    linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.25),
      transparent 30%,
      rgba(255, 255, 255, 0.18) 50%,
      transparent 70%,
      rgba(0, 0, 0, 0.25)
    ),
    repeating-linear-gradient(180deg, rgba(255, 240, 204, 0.5) 0 2px, transparent 2px 7px);
}
#fine .fine-wheel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(8, 77, 92, 0.95),
    transparent 26%,
    transparent 74%,
    rgba(8, 77, 92, 0.95)
  );
  pointer-events: none;
}
#fine .ctrl-label {
  left: 50%;
  top: -15px;
  transform: translateX(-50%);
}
body.portrait #fine {
  width: 210px;
  height: 46px;
}
body.portrait #fine .fine-ridges {
  inset: 0 -40px;
  background:
    linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.25),
      transparent 30%,
      rgba(255, 255, 255, 0.18) 50%,
      transparent 70%,
      rgba(0, 0, 0, 0.25)
    ),
    repeating-linear-gradient(90deg, rgba(255, 240, 204, 0.5) 0 2px, transparent 2px 7px);
}
body.portrait #fine .fine-wheel {
  border-radius: 12px;
}
body.portrait #fine .fine-wheel::after {
  background: linear-gradient(
    90deg,
    rgba(8, 77, 92, 0.95),
    transparent 26%,
    transparent 74%,
    rgba(8, 77, 92, 0.95)
  );
}
body.portrait #fine .ctrl-label {
  top: -17px;
  left: 2px;
  transform: none;
}
body.portrait.hand-left #fine .ctrl-label {
  left: auto;
  right: 2px;
}
/* Mouse players: the wheel replaces the on-screen fine-aim control */
body.mouse-input #fine {
  display: none;
}

/* Spin button: the dot shows the chosen spot, the label names it */
.spin-btn {
  width: 58px;
  height: 58px;
  border: none;
  background: none;
  padding: 0;
}
.spin-ball {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #ffffff, #f4f1e8 45%, #cfc8b8 92%);
  box-shadow:
    0 5px 14px rgba(2, 40, 52, 0.45),
    0 0 0 3px var(--surface),
    0 0 0 5px rgba(117, 228, 241, 0.55);
}
.spin-btn.has-spin .spin-ball {
  box-shadow:
    0 5px 14px rgba(2, 40, 52, 0.45),
    0 0 0 3px var(--surface),
    0 0 0 5px var(--warm);
}
.spin-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, #ff7a6c, #d12a20);
  box-shadow:
    0 0 0 2px #fff,
    0 1px 3px rgba(0, 0, 0, 0.5);
}
.spin-btn .ctrl-label {
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.spin-state {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--cream);
}
body.portrait .spin-btn {
  width: 50px;
  height: 50px;
}
body.portrait .spin-btn .ctrl-label {
  top: -16px;
}
body.portrait .spin-btn .ctrl-label small {
  display: none;
}

/* Spin panel: a temporary dialog over the table. The tinted backdrop says the shot is on hold. */
.spin-panel {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 40, 50, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.spin-panel.open {
  opacity: 1;
  pointer-events: auto;
}
.spin-card {
  width: min(300px, 100%);
  padding: 18px 20px 16px;
  border-radius: 26px;
  text-align: center;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transform: scale(0.94);
  transition: transform 0.25s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.spin-panel.open .spin-card {
  transform: none;
}
.spin-card h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}
.spin-big {
  position: relative;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  touch-action: none;
  cursor: crosshair;
  background: radial-gradient(circle at 36% 30%, #ffffff, #f4f1e8 45%, #cfc8b8 92%);
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.35),
    0 0 0 4px var(--surface-hi);
}
.spin-cross {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    linear-gradient(
      90deg,
      transparent calc(50% - 0.5px),
      rgba(0, 0, 0, 0.2) calc(50% - 0.5px) calc(50% + 0.5px),
      transparent calc(50% + 0.5px)
    ),
    linear-gradient(
      180deg,
      transparent calc(50% - 0.5px),
      rgba(0, 0, 0, 0.2) calc(50% - 0.5px) calc(50% + 0.5px),
      transparent calc(50% + 0.5px)
    );
}
.spin-limit {
  position: absolute;
  inset: 17%;
  border-radius: 50%;
  border: 1.5px dashed rgba(0, 0, 0, 0.25);
}
.spin-big .spin-dot {
  width: 28px;
  height: 28px;
}
.spin-state.big {
  font-size: 15px;
  font-weight: 800;
  color: var(--cream);
  min-height: 20px;
}
.spin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.spin-actions .btn {
  padding: 11px 10px;
}
.spin-help {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-dim);
  text-wrap: balance;
}
@media (max-height: 460px) {
  .spin-card {
    width: min(520px, 100%);
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 18px;
    row-gap: 8px;
    text-align: left;
  }
  .spin-card .spin-big {
    grid-row: 1 / span 4;
    grid-column: 1;
    width: 150px;
    height: 150px;
  }
  .spin-card > :not(.spin-big) {
    grid-column: 2;
  }
}

/* Contextual hints: short, on empty felt, no bobbing */
.hint {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  padding: 10px 14px;
  border-radius: 14px;
  max-width: 260px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  background: var(--cream);
  color: var(--on-cream);
  border: 2px solid rgba(8, 77, 92, 0.25);
  box-shadow: 0 10px 26px rgba(2, 40, 52, 0.35);
  transition:
    opacity 0.3s,
    transform 0.3s;
}
.hint.show {
  opacity: 1;
  transform: none;
}

/* Mouse: a chip shows a pinned aim and how to release it */
.aim-lock {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 11px;
  min-height: 36px;
  border-radius: 999px;
  background: rgba(8, 77, 92, 0.94);
  border: 2px solid var(--line);
  color: var(--ink);
  font: 700 12px/1 var(--ui);
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(2, 40, 52, 0.3);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.aim-lock svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--focus);
  stroke-width: 2;
  stroke-linecap: round;
}
.aim-lock b {
  color: var(--focus);
  font-weight: 800;
}
.aim-lock span {
  color: var(--ink-dim);
  font-weight: 600;
}
.aim-lock.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.aim-lock:hover {
  border-color: var(--focus);
}

/* ---------- Screens ---------- */
/* No backdrop blur: the demo table keeps animating underneath and a full-screen filter is costly on phones. */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, var(--sr, env(safe-area-inset-right)))
    max(16px, env(safe-area-inset-bottom)) max(16px, var(--sl, env(safe-area-inset-left)));
  background: rgba(3, 40, 50, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  overflow-y: auto;
}
.screen.open {
  opacity: 1;
  pointer-events: auto;
}
.screen:not(.open),
.screen:not(.open) * {
  pointer-events: none !important;
}
#menu {
  background: rgba(3, 40, 50, 0.32);
}
.screen,
.profile-body,
.rank-list,
.rules-body,
.online-card,
.lobby {
  scrollbar-width: thin;
  scrollbar-color: rgba(117, 228, 241, 0.45) transparent;
}
/* panels arrive after their backdrop: text never shows without the panel behind it */
.screen .panel,
.screen .menu-card {
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition:
    transform 0.3s cubic-bezier(0.2, 1.2, 0.4, 1) 0.1s,
    opacity 0.2s ease 0.1s;
}
.screen.open .panel,
.screen.open .menu-card {
  opacity: 1;
  transform: none;
}
.screen,
.screen * {
  touch-action: pan-y;
}

.menu-card,
.panel {
  width: min(420px, 100%);
  padding: 24px 24px 20px;
  border-radius: 28px;
  background: linear-gradient(180deg, #0b5a6b, var(--surface) 40%);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel.narrow {
  width: min(360px, 100%);
}
.panel.wide {
  width: min(640px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: hidden;
}
.panel h2 {
  font-weight: 800;
  font-size: clamp(19px, 6vw, 24px);
  margin: 0;
  text-align: center;
  overflow-wrap: anywhere;
}
.panel-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  margin-bottom: 2px;
}

/* Logo: the wordmark image (its alt text is the accessible title) */
.logo {
  text-align: center;
}
.wordmark {
  margin: 0;
  line-height: 0;
}
.wordmark img {
  width: min(300px, 82%);
  height: auto;
  max-height: 160px;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(2, 40, 52, 0.35));
}
.logo-sub {
  margin-top: 4px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.logo-ball {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background: radial-gradient(circle at 34% 28%, #5a5a5a, #121212 45%, #000 100%);
  box-shadow: 0 8px 18px rgba(2, 40, 52, 0.45);
}
.logo-ball::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 16%;
  left: 26%;
  top: 14%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  filter: blur(2px);
}
.logo-ball span {
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: #fcfaf3;
  color: #111;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
}
.logo-ball.spin {
  animation: spin 1.4s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.field-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 7px;
  text-align: center;
}

/* Segmented choices: the selected one is filled cyan with dark text (obvious, not only a hue change) */
.seg {
  display: flex;
  padding: 4px;
  gap: 4px;
  border-radius: 16px;
  background: var(--surface-lo);
  border: 2px solid rgba(117, 228, 241, 0.18);
}
.seg button {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 8px;
  min-height: 40px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 14px;
  color: var(--ink-dim);
  transition:
    background 0.2s,
    color 0.2s;
}
.seg button:hover {
  color: var(--ink);
}
.seg button.on {
  background: var(--focus);
  color: var(--on-focus);
  box-shadow: inset 0 -2px 0 rgba(4, 51, 45, 0.18);
}
.seg.small button {
  padding: 7px 8px;
  min-height: 36px;
  font-size: 12.5px;
}
.seg button {
  min-width: 0;
  overflow-wrap: anywhere;
}
@media (max-width: 359px) {
  .seg button {
    padding-left: 4px;
    padding-right: 4px;
    font-size: 12.5px;
  }
}

.btn {
  pointer-events: auto;
  border: 2px solid rgba(117, 228, 241, 0.35);
  border-radius: 16px;
  padding: 12px 16px;
  min-height: 46px;
  font-weight: 800;
  font-size: 15px;
  background: var(--surface-hi);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
  transition:
    transform 0.12s,
    filter 0.2s,
    border-color 0.2s;
}
.btn:hover {
  border-color: var(--focus);
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.55;
}
.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn.primary {
  border: none;
  color: var(--on-emerald);
  background: linear-gradient(180deg, var(--emerald-hi), var(--emerald) 60%);
  box-shadow:
    inset 0 -4px 0 var(--emerald-lo),
    0 8px 18px rgba(2, 40, 52, 0.3);
}
.btn.primary:hover {
  filter: brightness(1.05);
}
.btn.big {
  padding: 15px 18px;
  font-size: 17px;
  min-height: 54px;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.btn.ghost:hover {
  border-color: var(--line);
}
.btn.danger {
  background: #c5432f;
  border-color: transparent;
  color: #fff;
}
.menu-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.lang-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.lang-row button {
  border: 2px solid transparent;
  background: none;
  padding: 6px 12px;
  min-height: 36px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
}
.lang-row button.on {
  background: var(--focus);
  color: var(--on-focus);
}

.rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 700;
  font-size: 14px;
}
.row > span {
  flex: none;
}
.row .seg {
  flex: 0 1 auto;
}
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 52%;
  height: 8px;
  border-radius: 8px;
  outline: none;
  background: linear-gradient(90deg, var(--emerald) var(--v, 50%), var(--surface-lo) var(--v, 50%));
  box-shadow: inset 0 0 0 1px rgba(117, 228, 241, 0.25);
}
input[type='range']:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, #ffffff, #f4f1e8 45%, #cfc8b8 92%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
input[type='range']::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, #ffffff, #f4f1e8 45%, #cfc8b8 92%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
/* Toggles: the knob position says on/off, the fill repeats it */
.toggle {
  flex: none;
  width: 54px;
  height: 32px;
  border-radius: 999px;
  border: 2px solid rgba(117, 228, 241, 0.3);
  background: var(--surface-lo);
  position: relative;
  padding: 0;
  transition: background 0.2s;
}
.toggle i {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #cfe3e6;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition:
    transform 0.25s cubic-bezier(0.3, 1.4, 0.5, 1),
    background 0.2s;
}
.toggle.on {
  background: var(--emerald);
  border-color: var(--emerald-hi);
}
.toggle.on i {
  transform: translateX(22px);
  background: #fff;
}

.rules-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding-right: 4px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-dim);
}
.rules-body h3 {
  font-weight: 800;
  color: var(--ink);
  font-size: 17px;
  margin: 10px 0 6px;
}
.rules-body li {
  margin: 6px 0;
  padding-left: 2px;
}
.rules-body li::marker {
  color: var(--focus);
  font-weight: 800;
}

/* Result */
.result {
  text-align: center;
}
.result-badge {
  margin-top: -2px;
}
.result-title {
  font-size: 32px !important;
}
.result.win .result-title {
  color: var(--emerald-hi);
}
.result-reason {
  color: var(--cream);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: -6px;
}
.result-note {
  margin: -4px 0 0;
  text-align: center;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--danger-ink);
}
.result-note:empty {
  display: none;
}
.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}
.result-score span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.result-score b {
  font-size: 32px;
  font-weight: 800;
  color: var(--warm);
}
/* a score sheet with dotted leaders */
.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin: 4px 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--surface-lo);
  border: 1px solid var(--line);
}
.stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
}
.stat span {
  order: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-dim);
}
.stat::after {
  content: '';
  order: 1;
  flex: 1;
  border-bottom: 2px dotted rgba(117, 228, 241, 0.3);
  transform: translateY(-4px);
}
.stat b {
  order: 2;
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
}

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  background: var(--surface);
  transition: opacity 0.5s;
  z-index: 10;
  text-align: center;
}
#loading.done {
  opacity: 0;
  pointer-events: none;
}
.loading-text {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
#fatal {
  z-index: 20;
}
#fatal p {
  color: var(--ink-dim);
  line-height: 1.5;
  text-align: center;
}

/* ---------- Compact (phones) & portrait ---------- */
body.compact .player {
  padding: 5px 10px 5px 5px;
  gap: 8px;
}
body.compact .player.right {
  padding: 5px 5px 5px 10px;
}
body.compact .avatar {
  width: 34px;
  height: 34px;
  font-size: 15px;
}
body.compact .pname {
  font-size: 13px;
}
body.compact .status {
  padding: 5px 16px 6px;
}
body.compact .status-main {
  font-size: 15px;
}
body.compact .status-sub {
  font-size: 10px;
  letter-spacing: 0.05em;
}

body.portrait .topbar {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  grid-auto-flow: row;
  row-gap: 8px;
  gap: 8px;
}
body.portrait .topbar .status {
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: center;
  max-width: 100%;
}
body.portrait .topbar #p0 {
  grid-column: 1;
  grid-row: 1;
}
body.portrait .topbar #p1 {
  grid-column: 2;
  grid-row: 1;
}
body.portrait .topbar #pauseBtn {
  grid-column: 3;
  grid-row: 1;
}
body.portrait .player {
  max-width: none;
}
body.portrait .gname {
  font-size: 11px;
  letter-spacing: 0.02em;
}
body.portrait.compact .topbar {
  row-gap: 6px;
}
body.portrait.compact .status {
  padding: 3px 16px 4px;
}
body.portrait.compact .status-main {
  font-size: 14.5px;
}
body.portrait.compact .status-sub {
  font-size: 9.5px;
}
body.short-land .topbar {
  padding-top: calc(env(safe-area-inset-top) + 5px);
}
body.short-land .status-main {
  font-size: 14px;
}
body.short-land .pline {
  margin-top: 1px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation: none !important;
  transition-duration: 0.01ms !important;
}

/* ---------- Tap to start ---------- */
#splash {
  background: rgba(3, 40, 50, 0.28);
  cursor: pointer;
  z-index: 5;
}
.splash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(22px, 6vh, 56px);
  text-align: center;
}
.splash-card .wordmark img {
  width: min(460px, 86vw);
  max-height: 38vh;
}
.splash-card .logo-sub {
  color: var(--ink);
  text-shadow: 0 1px 4px rgba(2, 40, 52, 0.8);
}
.tap-start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 26px 0 18px;
  border-radius: 999px;
  border: 2px solid rgba(8, 77, 92, 0.25);
  background: var(--cream);
  color: var(--on-cream);
  font-family: var(--ui);
  font-weight: 800;
  font-size: clamp(15px, 2.4vmin, 18px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow:
    inset 0 -4px 0 rgba(150, 110, 45, 0.25),
    0 10px 24px rgba(2, 40, 52, 0.3);
  animation: tapPulse 1.8s ease-in-out infinite;
}
.tap-start svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--surface);
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes tapPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
  }
}
#splash.leaving {
  opacity: 0;
  transition: opacity 0.15s ease;
}
#splashLang {
  background: rgba(8, 77, 92, 0.92);
  border-radius: 999px;
  padding: 4px;
  border: 2px solid var(--line);
}

/* ---------- Menu ---------- */
/* mode cards: the CPU match is a card with its difficulty and Play; the other modes are rows */
.mode-cpu {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px;
  border-radius: 20px;
  background: var(--surface-lo);
  border: 2px solid rgba(79, 211, 156, 0.45);
}
.mode-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mode-cpu .seg {
  background: rgba(0, 0, 0, 0.18);
}
.mode {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 12px;
  text-align: left;
  min-height: 58px;
  padding: 8px 12px 8px 10px;
  border-radius: 18px;
  color: var(--ink);
  background: var(--surface-hi);
  border: 2px solid rgba(117, 228, 241, 0.3);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
  transition:
    transform 0.12s,
    border-color 0.2s;
}
.mode:hover {
  border-color: var(--focus);
}
.mode:active {
  transform: scale(0.98);
}
.mode-ic {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(117, 228, 241, 0.12);
  flex: none;
}
.mode-cpu .mode-ic {
  background: rgba(79, 211, 156, 0.16);
}
.mode-ic svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--focus);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mode-cpu .mode-ic svg {
  stroke: var(--emerald-hi);
}
.mode-tx {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.mode-tx b {
  font-size: 15.5px;
  font-weight: 800;
  line-height: 1.2;
}
.mode-tx small {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-dim);
  line-height: 1.3;
}
.mode-go {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink-faint);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.menu-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
@media (max-width: 359px) {
  .menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 2px;
  }
}
.menu-grid .btn {
  flex-direction: column;
  gap: 5px;
  padding: 6px 2px;
  min-height: 64px;
  background: none;
  border: none;
  box-shadow: none;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.15;
  white-space: normal;
  min-width: 0;
  overflow-wrap: break-word;
  hyphens: auto;
  text-align: center;
  color: var(--ink);
}
.menu-grid .btn svg {
  width: 22px;
  height: 22px;
  padding: 10px;
  box-sizing: content-box;
  border-radius: 50%;
  background: var(--surface-hi);
  border: 2px solid rgba(117, 228, 241, 0.35);
  color: var(--focus);
  stroke-width: 1.8;
}
.menu-grid .btn:hover svg {
  border-color: var(--focus);
}

/* ---------- Practice ---------- */
.practice-bar {
  position: absolute;
  display: none;
  gap: 8px;
  pointer-events: auto;
  z-index: 2;
}
body.is-practice .practice-bar {
  display: flex;
}
body.is-practice #p1 {
  visibility: hidden;
}
.pbtn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  min-height: 44px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: rgba(8, 77, 92, 0.94);
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(2, 40, 52, 0.3);
  transition:
    transform 0.12s,
    border-color 0.2s,
    background 0.2s;
}
.pbtn:active {
  transform: scale(0.95);
}
.pbtn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.pbtn.on {
  background: var(--focus);
  color: var(--on-focus);
  border-color: transparent;
}
body.compact .pbtn span {
  display: none;
}
body.compact .pbtn {
  padding: 9px 12px;
}

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 70px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
  width: min(92vw, 360px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 10px;
  border-radius: 18px;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--focus);
  box-shadow: 0 14px 34px rgba(2, 40, 52, 0.4);
  animation: toastIn 0.45s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.toast.out {
  animation: toastOut 0.4s ease both;
}
.toast .ti {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--on-cream);
  background: var(--warm);
}
.toast small {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream);
}
.toast b {
  font-size: 16px;
  font-weight: 800;
}
.toast.plain {
  padding: 12px 16px;
  justify-content: center;
  text-align: center;
}
.toast.plain b {
  font-size: 14px;
  font-weight: 700;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-14px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.96);
  }
}
.ti svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Quick chat (online) ---------- */
#chatBtn {
  display: none;
}
body.is-online.chat-on #chatBtn {
  display: grid;
}
#chatBtn svg {
  width: 21px;
  height: 21px;
}
body.portrait #chatBtn {
  position: absolute;
  z-index: 5;
  top: calc(env(safe-area-inset-top) + 10px + 44px + 8px);
  left: calc(var(--sl, env(safe-area-inset-left)) + 14px);
}
body.portrait:not(.compact) #chatBtn {
  top: calc(env(safe-area-inset-top) + 10px + 56px + 8px);
} /* taller cards on tablets */
/* portrait: the status pill leaves room for the chat button (left) and full screen (right) */
body.portrait.is-online.chat-on .topbar .status {
  max-width: calc(100% - 116px);
}
body.portrait.is-online.chat-on .status-sub {
  white-space: normal;
  text-wrap: balance;
}
@media (max-width: 360px) {
  body.portrait.compact .status-sub {
    font-size: 9px;
    letter-spacing: 0.02em;
  }
}
.chat-pop {
  position: absolute;
  z-index: 7;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(8, 77, 92, 0.98);
  border: 2px solid var(--line);
  box-shadow: 0 12px 28px rgba(2, 40, 52, 0.45);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px) scale(0.97);
  transform-origin: top right;
  transition:
    opacity 0.15s,
    transform 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.chat-pop.open {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}
.chat-pop button {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid rgba(117, 228, 241, 0.3);
  background: var(--surface-hi);
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
}
.chat-pop button:hover {
  border-color: var(--focus);
}
.chat-pop button:active {
  transform: scale(0.96);
}
/* what a player just said replaces the group line of their card for a moment */
.psay {
  display: none;
  align-self: flex-start;
  max-width: 100%;
  margin-top: 3px;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--on-cream);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player.right .psay {
  margin-left: auto;
}
.player.saying .psay {
  display: block;
  animation: sayIn 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.player.saying .pline {
  display: none;
}
@keyframes sayIn {
  from {
    opacity: 0;
    transform: translateY(3px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Two players on one device ---------- */
body.is-duo .avatar.cpu {
  background: radial-gradient(circle at 35% 30%, #ffd98a, #d7962c 75%);
  color: #3a2405;
}
.duo-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.duo-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}
.duo-av {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 17px;
}
.duo-av.one {
  background: radial-gradient(circle at 35% 30%, var(--emerald-hi), var(--emerald-lo) 75%);
  color: var(--on-emerald);
}
.duo-av.two {
  background: radial-gradient(circle at 35% 30%, #ffd98a, #d7962c 75%);
  color: #3a2405;
}
.duo-note {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-faint);
  text-align: center;
}
#duoSetup {
  padding-bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--kb, 0px));
  transition: padding-bottom 0.2s;
}

/* ---------- Balls panel (tap a player card) ---------- */
.racks-panel {
  gap: 10px;
  max-height: calc(100dvh - 32px);
}
.racks-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.rk-block {
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--surface-lo);
  border: 2px solid rgba(117, 228, 241, 0.16);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rk-block.active {
  border-color: var(--focus);
}
.rk-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.rk-head b {
  font-size: 16px;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rk-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--focus);
}
.rk-group i,
.rk-eight i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-size: cover;
}
.rk-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 2px;
}
.rk-balls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 24px;
}
.rk-ball {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-size: cover;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
.rk-balls.small .rk-ball {
  width: 26px;
  height: 26px;
  opacity: 0.55;
  box-shadow: none;
}
.rk-none {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
}
.rk-eight {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-dim);
}
.rk-eight.free {
  color: var(--warm);
}
.rk-note {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-dim);
  text-align: center;
}
/* phones lying down: the two players side by side instead of a scroll */
@media (max-height: 560px) and (min-aspect-ratio: 5/4) {
  .panel.narrow.racks-panel {
    width: min(680px, 100%);
    padding: 14px 18px;
  }
  .racks-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
  .racks-body > .rk-note,
  .racks-body > .rk-label,
  .racks-body > .rk-balls {
    grid-column: 1 / -1;
  }
  .rk-ball {
    width: 34px;
    height: 34px;
  }
}

/* ---------- Ranking form ---------- */
.rank-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.rank-form input {
  min-width: 0;
  padding: 12px 14px;
}
.rank-form .btn {
  padding: 12px 14px;
  font-size: 13px;
}
.rank-status {
  grid-column: 1 / -1;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--emerald-hi);
  min-height: 16px;
  text-align: center;
}
.rank-status.error {
  color: var(--danger-ink);
}
.rank-form.done input,
.rank-form.done .btn {
  display: none;
}

/* ---------- Tabs, profile, ranking ---------- */
.seg.tabs {
  margin-bottom: 2px;
}
.profile-body,
.rank-list {
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding-right: 2px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.stat-grid .stat {
  flex-direction: column-reverse;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-lo);
  border: 1px solid var(--line);
}
.stat-grid .stat::after {
  display: none;
}
.stat-grid .stat span {
  font-size: 12px;
}
.ach-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ach {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--surface-lo);
  border: 1px solid var(--line);
}
.ach .ti {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-faint);
}
.ach.got .ti {
  color: var(--on-cream);
  background: var(--warm);
}
.ach b {
  display: block;
  font-size: 14px;
}
.ach span {
  font-size: 12.5px;
  color: var(--ink-dim);
}
.ach:not(.got) b {
  color: var(--ink-dim);
}
.style-title {
  font-size: 16px;
  font-weight: 800;
  margin: 4px 0 8px;
}
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.swatch {
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 8px;
  background: var(--surface-lo);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  position: relative;
  transition:
    transform 0.12s,
    border-color 0.2s;
}
.swatch:active {
  transform: scale(0.96);
}
.swatch .chip {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}
.swatch .cue-chip {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
}
.swatch .cue-chip i {
  display: block;
  width: 86%;
  height: 7px;
  border-radius: 4px;
}
.swatch.on {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(117, 228, 241, 0.3);
}
.swatch.locked {
  opacity: 0.6;
}
.swatch small {
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-faint);
}
.rank-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
}
.rank-row:nth-child(odd) {
  background: var(--surface-lo);
}
.rank-row .rk {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink-faint);
  text-align: center;
}
.rank-row.top1 .rk {
  color: var(--warm);
}
.rank-row.top2 .rk {
  color: #e3eef0;
}
.rank-row.top3 .rk {
  color: #f0a970;
}
.rank-row .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-row .sc {
  font-size: 16px;
  font-weight: 800;
  color: var(--emerald-hi);
}
.rank-row.me {
  outline: 2px solid var(--focus);
  background: rgba(117, 228, 241, 0.1);
}
.rank-msg {
  text-align: center;
  color: var(--ink-dim);
  padding: 30px 10px;
  font-weight: 700;
}

/* ---------- Online ---------- */
.text-input,
.rank-form input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 2px solid rgba(117, 228, 241, 0.3);
  background: var(--surface-lo);
  color: var(--ink);
  font: 700 16px var(--ui);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
  touch-action: manipulation;
}
.text-input:focus,
.rank-form input:focus {
  border-color: var(--focus);
}
.text-input::placeholder,
.rank-form input::placeholder {
  color: rgba(210, 236, 239, 0.55);
}
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  padding: 12px 10px;
}
.code-input::placeholder {
  color: rgba(210, 236, 239, 0.28);
}
.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.room-code {
  text-align: center;
  font-weight: 800;
  font-size: clamp(40px, 12vw, 54px);
  letter-spacing: 0.18em;
  color: var(--cream);
  user-select: text;
  -webkit-user-select: text;
}
button.room-code {
  border: none;
  background: transparent;
  cursor: copy;
  line-height: 1.1;
  padding: 2px 0 2px 0.18em;
}
.seats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-lo);
  border: 1px solid var(--line);
  font-weight: 700;
}
.seat .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #5c8890;
  flex: none;
}
.seat.ready .dot {
  background: var(--emerald-hi);
}
.seat.off .dot {
  background: var(--danger);
}
.seat .st {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: 700;
}
.seat.empty {
  color: var(--ink-faint);
  font-style: italic;
}
.seat.empty .dot {
  animation: waitPulse 1.6s ease-in-out infinite;
}
@keyframes waitPulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

.av-letter {
  display: block;
}
.online-card [data-show],
.lobby [data-show] {
  display: none !important;
}
#onCard[data-state='start'] [data-show~='start'],
#onCard[data-state='code'] [data-show~='code'],
#onCard[data-state='busy'] [data-show~='busy'],
#onCard[data-state='expired'] [data-show~='expired'],
#onCard[data-state='full'] [data-show~='full'],
#onCard[data-state='offline'] [data-show~='offline'],
#onCard[data-state='guest'] [data-show~='guest'],
#onCard[data-state='name'] [data-show~='name'],
#onCard[data-state='resume'] [data-show~='resume'],
#lobbyCard[data-state='waiting'] [data-show~='waiting'],
#lobbyCard[data-state='countdown'] [data-show~='countdown'] {
  display: flex !important;
}
.on-block {
  flex-direction: column;
  gap: 12px;
}
.on-block p[data-show],
.lobby p[data-show] {
  justify-content: center;
  text-align: center;
}
.on-sub {
  margin: 0;
  text-align: center;
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.45;
  text-wrap: balance;
}
.on-icon {
  display: grid;
  place-items: center;
}
.on-icon svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: var(--warm);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.on-error {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(228, 107, 88, 0.16);
  border: 2px solid var(--danger);
  color: var(--danger-ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}
.on-busy {
  align-items: center;
  padding: 18px 0 10px;
}
.on-busy p {
  margin: 0;
  color: var(--ink-dim);
  font-weight: 700;
  text-align: center;
}
.as-line {
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-dim);
  font-weight: 600;
}
.as-line b {
  color: var(--ink);
}
.as-line.small {
  font-size: 12.5px;
}
.link-btn {
  border: none;
  background: none;
  padding: 6px 4px;
  color: var(--focus);
  font: 800 inherit var(--ui);
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(117, 228, 241, 0.45);
  cursor: pointer;
  min-height: 32px;
}
.link-btn.center {
  align-self: center;
  font-size: 14px;
  min-height: 44px;
}
.name-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.name-row .btn {
  padding: 12px 16px;
}
.choice {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 14px 16px;
  border-radius: 18px;
  border: 2px solid rgba(117, 228, 241, 0.35);
  color: var(--ink);
  background: var(--surface-hi);
  min-height: 76px;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
  transition:
    transform 0.12s,
    filter 0.2s,
    border-color 0.2s;
}
.choice:hover {
  border-color: var(--focus);
}
.choice:active {
  transform: scale(0.98);
}
.choice:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.choice-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
}
.choice-icon svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--focus);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.choice-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.choice-text b {
  font-size: 16.5px;
  font-weight: 800;
}
.choice-text small {
  font-size: 12.5px;
  color: var(--ink-dim);
  font-weight: 600;
}
.choice.primary {
  border: none;
  color: var(--on-emerald);
  background: linear-gradient(180deg, var(--emerald-hi), var(--emerald) 60%);
  box-shadow:
    inset 0 -4px 0 var(--emerald-lo),
    0 8px 18px rgba(2, 40, 52, 0.3);
}
.choice.primary .choice-icon svg {
  stroke: var(--on-emerald);
}
.choice.primary .choice-text small {
  color: var(--on-emerald);
  opacity: 0.85;
}
/* lobby */
.lobby-code-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.lobby-code-wrap .field-label {
  margin-bottom: 2px;
}
.lobby-invite,
.lobby-go {
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
.lobby-go {
  align-items: center;
}
.lobby-arrived {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
}
.lobby-count {
  font-weight: 800;
  font-size: 64px;
  line-height: 1;
  color: var(--warm);
  animation: countPop 1s ease-out infinite;
}
@keyframes countPop {
  0% {
    transform: scale(1.2);
    opacity: 0.5;
  }
  25% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    opacity: 0.9;
  }
}
.lobby-tip {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-faint);
  text-align: center;
  line-height: 1.4;
  text-wrap: balance;
}
.lobby-tip:empty {
  display: none;
}
/* the panel rides up with the iPhone keyboard (visualViewport -> --kb) */
#online,
#lobby {
  padding-bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--kb, 0px));
  transition: padding-bottom 0.2s;
}
.online-card,
.lobby {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (max-height: 520px) {
  .online-card,
  .lobby {
    padding: 18px 20px 16px;
    gap: 10px;
  }
  .choice {
    min-height: 60px;
    padding: 10px 14px;
  }
  .lobby .room-code {
    font-size: 38px;
  }
  .lobby-count {
    font-size: 44px;
  }
}

/* ---------- Settings tabs ---------- */
.set-tabs {
  margin-bottom: 2px;
}
#setRows .row {
  display: none;
}
#setRows[data-tab='sound'] .row[data-tab='sound'],
#setRows[data-tab='game'] .row[data-tab='game'],
#setRows[data-tab='display'] .row[data-tab='display'] {
  display: flex;
}
#setRows .row:last-child {
  border-bottom: none;
}
#setRows .row[hidden] {
  display: none !important;
}
/* on short screens the list of options scrolls inside the panel (title and tabs stay put) */
#settings .panel {
  max-height: calc(100dvh - 24px);
  overflow: hidden;
}
#setRows {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(117, 228, 241, 0.45) transparent;
}
@media (max-width: 420px) {
  .row {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .row > .seg {
    flex: 1 1 100%;
  }
  .row > input[type='range'] {
    flex: 1 1 120px;
    min-width: 0;
  }
}

/* ---------- Short screens (phones lying down, portal iframes): no scrolling, use columns ---------- */
@media (max-height: 560px) and (min-aspect-ratio: 5/4) {
  .menu-card {
    width: min(780px, 100%);
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    column-gap: 26px;
    row-gap: 8px;
    padding: 16px 22px;
    align-items: center;
  }
  .menu-card > .logo {
    grid-column: 1;
    grid-row: 1 / span 4;
    align-self: end;
    margin: 0;
  }
  .menu-card > .lang-row {
    grid-column: 1;
    grid-row: 5 / span 2;
    align-self: start;
    justify-self: center;
    margin-top: 10px;
  }
  .menu-card > :not(.logo):not(.lang-row) {
    grid-column: 2;
  }
  .menu-card .wordmark img {
    width: min(300px, 100%);
    max-height: 150px;
  }
  .menu-card .btn {
    padding: 8px 12px;
    min-height: 42px;
  }
  .menu-card .btn.big {
    padding: 9px 14px;
    min-height: 44px;
    font-size: 15px;
  }
  .menu-grid .btn {
    min-height: 54px;
    padding: 3px 2px;
  }
  .mode-cpu {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
    border-radius: 16px;
  }
  .mode-cpu .mode-head {
    grid-column: 1 / -1;
    gap: 8px;
  }
  .mode-cpu .mode-head .mode-ic {
    width: 28px;
    height: 28px;
  }
  .mode-cpu .mode-head .mode-ic svg {
    width: 18px;
    height: 18px;
  }
  .mode {
    min-height: 44px;
    padding: 4px 10px 4px 6px;
    grid-template-columns: 32px minmax(0, 1fr) 16px;
    gap: 9px;
    border-radius: 14px;
  }
  .mode-ic {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }
  .mode-ic svg {
    width: 20px;
    height: 20px;
  }
  .mode-tx small {
    display: none;
  }
  .menu-grid .btn svg {
    padding: 7px;
    width: 20px;
    height: 20px;
  }
  #pause .panel {
    width: min(560px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 18px 22px;
  }
  #pause .panel > h2,
  #pause .panel > #pauseNote,
  #pause .panel > #resumeBtn {
    grid-column: 1 / -1;
  }
  .result {
    width: min(720px, 100%) !important;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 22px;
    row-gap: 8px;
    padding: 16px 22px;
    align-content: center;
  }
  .result > .result-badge,
  .result > .result-title,
  .result > .result-reason,
  .result > .result-note,
  .result > .result-score {
    grid-column: 1;
  }
  .result > .stats,
  .result > .rank-form,
  .result > #rematchBtn,
  .result > #menuBtn {
    grid-column: 2;
  }
  .result > .result-badge {
    grid-row: 1;
  }
  .result > .result-title {
    grid-row: 2;
  }
  .result > .result-reason {
    grid-row: 3;
  }
  .result > .result-note {
    grid-row: 4;
  }
  .result > .result-score {
    grid-row: 5;
  }
  .result > .stats {
    grid-row: 1 / span 3;
    margin: 0;
  }
  .result > .rank-form {
    grid-row: 4;
  }
  .result > #rematchBtn {
    grid-row: 5;
  }
  .result > #menuBtn {
    grid-row: 6;
  }
  .result .stat {
    padding: 3px 0;
  }
  .result .stat b {
    font-size: 17px;
  }
  .result .btn.big {
    padding: 11px 14px;
    min-height: 48px;
  }
  .splash-card {
    gap: 14px;
  }
  .splash-card .wordmark img {
    max-height: 46vh;
  }
  .panel:not(.narrow):not(.wide) {
    max-height: calc(100dvh - 24px);
    padding: 16px 22px;
    gap: 8px;
  }
  .row {
    padding: 6px 2px;
  }
}
@media (max-height: 420px) and (min-aspect-ratio: 5/4) {
  .menu-card {
    padding: 12px 18px;
    row-gap: 6px;
  }
  .menu-card .field-label {
    margin-bottom: 4px;
  }
  .menu-card .seg button {
    padding: 6px 8px;
    min-height: 36px;
  }
  .menu-card .wordmark img {
    max-height: 120px;
  }
}
/* Portrait phones: the logo shrinks with the height so Play stays in view (order matters: the smaller rule comes last) */
@media (max-height: 760px) and (max-aspect-ratio: 4/5) {
  .menu-card .wordmark img {
    max-height: 124px;
  }
}
/* Small portrait phones (iPhone SE 1st gen, 360x640 Androids): the logo shrinks so Play stays in view */
@media (max-height: 700px) and (max-aspect-ratio: 4/5) {
  .menu-card {
    padding: 16px 16px 14px;
    gap: 9px;
  }
  .menu-card .wordmark img {
    max-height: 104px;
  }
  .menu-card .btn {
    padding: 9px 12px;
    min-height: 42px;
  }
  .menu-card .btn.big {
    padding: 11px 14px;
    min-height: 48px;
    font-size: 16px;
  }
  .menu-grid .btn {
    min-height: 58px;
    padding: 4px 2px;
  }
  .mode-cpu {
    padding: 10px;
    gap: 8px;
  }
  .mode {
    min-height: 52px;
  }
  .result {
    padding: 18px 18px 14px;
    gap: 9px;
  }
  .result .logo-ball {
    width: 40px;
    height: 40px;
  }
  .result-title {
    font-size: 27px !important;
  }
  .result .stat {
    padding: 3px 0;
  }
  .result .stat b {
    font-size: 17px;
  }
  .result .btn.big {
    padding: 12px 14px;
  }
}
@media (max-height: 600px) and (max-aspect-ratio: 4/5) {
  .menu-card .wordmark img {
    max-height: 84px;
  }
  .menu-card {
    gap: 8px;
  }
}

/* ---------- Fullscreen toggle (Android and desktop only; under the pause button) ---------- */
/* landscape: a fifth column of the top bar, next to pause (clear of the side controls); portrait: under pause */
#fsBtn {
  width: 44px;
  height: 44px;
  background: rgba(8, 77, 92, 0.7);
  box-shadow: none;
}
body.portrait #fsBtn {
  position: absolute;
  z-index: 5;
  top: calc(env(safe-area-inset-top) + 10px + 44px + 8px);
  right: calc(var(--sr, env(safe-area-inset-right)) + 14px);
}
#fsBtn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#fsBtn .fs-out {
  display: none;
}
body.is-fs #fsBtn .fs-in {
  display: none;
}
body.is-fs #fsBtn .fs-out {
  display: block;
}
body.is-menu #fsBtn,
body.is-demo #fsBtn {
  display: none;
}
