:root {
  color-scheme: dark;

  --felt: #08744b;
  --gold: #d99a31;
  --ivory: #f2e3c2;
  --wood: #3a160a;
  --coal: #100d0b;
  --danger: #d7352f;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-width: 960px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--coal);
  color: var(--ivory);
  font-family: "Trebuchet MS", "Arial Narrow", Arial, sans-serif;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #65cfff;
  outline-offset: 3px;
}

::selection {
  background: #d99a31;
  color: #1d0b03;
}

.app,
.lobby,
.game {
  width: 100%;
  height: 100%;
}

.lobby {
  position: relative;
  display: grid;
  place-items: center;
  background: url("../assets/moa/fundo.png") center / cover no-repeat;
}

.lobby__shade {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at center,
    rgb(5 3 1 / 5%) 0 24%,
    rgb(5 3 1 / 80%) 86%
  );
}

.lobby__content {
  position: relative;
  z-index: 1;
  width: min(740px, 72vw);
  text-align: center;
  filter: drop-shadow(0 18px 28px rgb(0 0 0 / 72%));
}

.lobby__coin {
  width: 128px;
  margin-bottom: -18px;
}

.lobby h1 {
  margin: 0;
  color: #ffe2a0;
  font-size: clamp(58px, 7vw, 104px);
  line-height: 0.9;
  letter-spacing: -0.055em;
  text-shadow: 0 3px 0 #6e2f0c;
}

.lobby__subtitle {
  margin: 15px 0 28px;
  color: #e7bd69;
  font-size: 19px;
  letter-spacing: 0.2em;
}

.lobby__actions {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.art-button {
  width: 470px;
  height: 110px;
  border: 0;
  color: #fff5d8;
  background-color: transparent;
  background-position: center;
  background-size: 100% 100%;
  font-size: 25px;
  font-weight: 800;
  text-shadow: 0 2px 2px #1a0802;
  cursor: pointer;
  transition:
    filter 120ms ease,
    transform 120ms ease;
}

.art-button--green {
  background-image: url("../assets/moa/botao-verde.png");
}

.art-button--wood {
  background-image: url("../assets/moa/botao-madeira.png");
}

.art-button:hover {
  filter: brightness(1.14);
  transform: scale(1.015);
}

.difficulty {
  display: flex;
  gap: 8px;
  margin: -8px 0 2px;
}

.difficulty button {
  border: 1px solid rgb(228 170 79 / 58%);
  border-radius: 20px;
  padding: 7px 18px;
  background: rgb(20 10 4 / 86%);
  color: #d9bf8e;
  cursor: pointer;
}

.difficulty button.is-selected {
  background: #d99a31;
  color: #241005;
  font-weight: 800;
}

.lobby__credit {
  margin-top: 24px;
  color: rgb(242 227 194 / 62%);
  font-size: 13px;
}

.game {
  position: relative;
  background: url("../assets/moa/fundo.png") center / cover no-repeat;
}

.game::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgb(4 2 1 / 46%);
  pointer-events: none;
}

.hud {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns:
    clamp(58px, 4.5vw, 78px)
    minmax(760px, min(68vw, 1180px))
    clamp(62px, 5vw, 84px);
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
  height: clamp(104px, 13vh, 140px);
  padding: var(--space-2) var(--space-6) 0;
}

.hud__bar {
  position: relative;
  width: 100%;
  aspect-ratio: 9.47;
}

.hud__bar > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hud__menu,
.hud__spin {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition:
    filter 140ms ease,
    transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.hud__spin {
  position: relative;
}

.hud__menu:hover,
.hud__spin:hover {
  filter: brightness(1.16);
  transform: translateY(-2px);
}

.hud__menu img,
.hud__spin img {
  display: block;
  width: 100%;
}

.hud__spin #spin-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b71717;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px #000;
}

.player {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.player--one {
  --timer-x: 8.87%;
  --info-x: 16.1%;
}

.player--two {
  --timer-x: 91.13%;
  --info-x: 55.6%;
}

.player__info {
  position: absolute;
  left: var(--info-x);
  top: 0;
  width: 28.3%;
  height: 100%;
  text-align: center;
}

.player strong {
  position: absolute;
  left: 50%;
  top: 29%;
  display: grid;
  width: 88%;
  height: 26%;
  place-items: center;
  color: #fff3d4;
  font-size: clamp(14px, 1.1vw, 19px);
  line-height: 1;
  text-shadow: 0 2px 2px #000;
  transform: translate(-50%, -50%);
}

.player__timer {
  --turn-accent: #e7a938;

  position: absolute;
  left: var(--timer-x);
  top: 50%;
  display: grid;
  width: 9.5%;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.player__timer::before {
  position: absolute;
  inset: 8%;
  border-radius: inherit;
  background: conic-gradient(
    var(--turn-accent) var(--timer, 100%),
    rgb(0 0 0 / 68%) 0
  );
  content: "";
  mask: radial-gradient(transparent 64%, #000 66% 72%, transparent 74%);
}

.sprite-number {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  gap: 1%;
  border-radius: 50%;
  background: transparent;
}

.sprite-number img {
  display: block;
  width: auto;
  max-width: 43%;
  height: 42%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgb(0 0 0 / 70%));
}

.player:not(.is-active) {
  opacity: 0.68;
}

.player.is-active .player__timer {
  color: #fff5c7;
  filter: brightness(1.16);
}

.ball-slots {
  position: absolute;
  left: 50%;
  top: 70%;
  display: flex;
  gap: clamp(4px, 0.42vw, 7px);
  justify-content: center;
  width: 90%;
  margin: 0;
  padding: 0;
  list-style: none;
  transform: translate(-50%, -50%);
}

.slot-ball,
.tray-ball {
  display: grid;
  width: clamp(17px, 1.42vw, 23px);
  height: clamp(17px, 1.42vw, 23px);
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid #efe5ce;
  border-radius: 50%;
  background: var(--ball-color, #181818);
  color: #111;
  font:
    800 10px Arial,
    sans-serif;
  box-shadow:
    inset -4px -5px 8px rgb(0 0 0 / 38%),
    0 2px 3px #000;
}

.slot-ball.is-striped,
.tray-ball.is-striped {
  background: linear-gradient(
    #f4ede2 0 24%,
    var(--ball-color) 24% 76%,
    #f4ede2 76%
  );
}

.slot-ball.is-potted {
  opacity: 0.2;
  filter: grayscale(1);
}

.hud__versus {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  width: auto;
  height: 62%;
  aspect-ratio: 1;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
}

.hud__versus img {
  display: block;
  width: auto;
  height: 54%;
  max-width: 54%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgb(0 0 0 / 72%));
}

.game__stage {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns:
    clamp(62px, 5vw, 84px)
    minmax(0, auto)
    clamp(62px, 5vw, 84px);
  justify-content: center;
  align-items: center;
  gap: clamp(14px, 1.5vw, 28px);
  height: calc(100vh - clamp(104px, 13vh, 140px));
  padding: var(--space-2) var(--space-6) var(--space-6);
}

.table-shell {
  position: relative;
  grid-column: 2;
  width: min(70vw, calc((87vh - 140px) * 1.817));

  /* Mesma proporção de mesa.png (1472×810): a área de jogo cobre a imagem
     inteira e src/mesa.ts converte física ↔ pixel sem distorção. */
  aspect-ratio: 1472 / 810;
}

/* Em pé no celular este bloco gira -90° (src/v1.ts converte o toque). */
.table-rotor {
  position: absolute;
  inset: 0;
}

.table-art {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 16px 26px rgb(0 0 0 / 70%));
}

.playfield {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none;
}

.playfield.is-dragging {
  cursor: grabbing;
}

#table-canvas,
.guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.guide {
  overflow: visible;
  pointer-events: none;
}

.guide__aim,
.guide__target {
  stroke: rgb(255 255 255 / 88%);
  stroke-width: 1.8;
  vector-effect: non-scaling-stroke;
}

.guide__target {
  stroke: #f6c86f;
  stroke-width: 2.2;
  stroke-dasharray: 7 5;
}

/* Caminho da branca depois de bater (muda com o efeito). */
.guide__cue {
  stroke: rgb(255 255 255 / 70%);
  stroke-width: 2;
  stroke-dasharray: 3 5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.guide__ghost {
  fill: rgb(255 255 255 / 18%);
  stroke: rgb(255 255 255 / 92%);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

/* Âncora de tamanho zero na ponta do taco; gira em torno dela.
   Tamanho, recuo e altura da ponta vêm de updateCue() em src/v1.ts. */
.cue-wrap {
  position: absolute;
  z-index: 3;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  pointer-events: none;
}

.cue-wrap img {
  position: absolute;
  right: 0;
  max-width: none;
  filter: drop-shadow(0 4px 4px rgb(0 0 0 / 72%));
}

.power-meter {
  position: relative;
  grid-column: 1;
  width: 100%;
  height: min(43vh, 390px);
  align-self: center;
  filter: drop-shadow(0 12px 18px rgb(0 0 0 / 62%));
}

.power-meter > img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.power-meter__track {
  position: absolute;
  right: 17%;
  bottom: 17%;
  width: 13%;
  height: 62%;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(0 0 0 / 48%);
}

#power-level {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(to top, #d33b1f, #f2b632 62%, #fff2b0);
  box-shadow: 0 3px 8px rgb(0 0 0 / 62%);
  transform: scaleY(var(--power, 0));
  transform-origin: bottom;
  transition: transform 70ms linear;
}

#power-value {
  position: absolute;
  left: 50%;
  bottom: 4%;
  min-width: 42px;
  padding: 3px 7px;
  border: 1px solid rgb(226 167 65 / 68%);
  border-radius: 999px;
  background: rgb(17 9 5 / 88%);
  color: #ffe3a5;
  font-size: 12px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
  transform: translateX(-50%);
}

/* O canal da arte canaleta.png é fino demais para bolas legíveis (ainda
   mais no celular); o trilho é desenhado em CSS e as bolas empilham de
   baixo para cima, como no 8 Ball Pool. */
.tray {
  --tray-ball: clamp(18px, 1.6vw, 24px);

  position: relative;
  display: grid;
  grid-column: 3;
  justify-items: center;
  width: 100%;
  height: min(62vh, 540px);
  align-self: center;
}

.tray > img {
  display: none;
}

.tray__balls {
  display: flex;
  width: calc(var(--tray-ball) + 10px);
  height: 100%;
  flex-direction: column-reverse;
  align-items: center;
  gap: 2px;
  margin: 0;
  padding: 5px 0;
  overflow: hidden;
  border: 3px solid #c98e32;
  border-radius: 999px;
  background: linear-gradient(90deg, #0b0604, #2b170b 50%, #0b0604);
  box-shadow:
    inset 0 0 10px #000,
    0 0 0 1px #5a2a0d,
    0 8px 16px rgb(0 0 0 / 62%);
  list-style: none;
}

.tray-ball {
  position: relative;
  width: var(--tray-ball);
  height: var(--tray-ball);
  flex: 0 0 var(--tray-ball);
  border: 0;
  font-size: 0;
}

/* Brilho de bola de verdade por cima da cor/listra. */
.tray-ball::after {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 32% 28%,
    rgb(255 255 255 / 70%) 0 12%,
    transparent 30%,
    rgb(0 0 0 / 35%) 100%
  );
  content: "";
}

.message {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 11.5%;
  min-width: 170px;
  padding: 9px 24px;
  border: 1px solid #d7a242;
  border-radius: 26px;
  background: rgb(24 12 6 / 96%);
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.message.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.game__hint {
  position: absolute;
  z-index: 3;
  bottom: var(--space-2);
  left: 50%;
  margin: 0;
  color: rgb(255 232 190 / 82%);
  font-size: 13px;
  transform: translateX(-50%);
}

dialog {
  border: 2px solid #d99a31;
  border-radius: 18px;
  background: rgb(24 11 5 / 97%);
  color: var(--ivory);
  box-shadow: 0 24px 70px #000;
}

dialog::backdrop {
  background: rgb(0 0 0 / 68%);
  backdrop-filter: blur(3px);
}

.spin-dialog {
  width: 360px;
  padding: 24px 30px 28px;
  text-align: center;
}

.spin-dialog h2,
.game-menu h2 {
  margin: 0 0 7px;
  color: #ffd787;
  font-size: 28px;
}

.spin-dialog p {
  margin: 0 0 20px;
  color: #cbb58e;
}

#spin-close {
  position: absolute;
  right: 12px;
  top: 8px;
  border: 0;
  background: none;
  color: #e8cca0;
  font-size: 28px;
  cursor: pointer;
}

.spin-ball {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 0 auto 18px;
  border: 10px solid #bd842c;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 28%,
    #fff 0 10%,
    #eee0bd 47%,
    #a58a60 100%
  );
  box-shadow:
    inset -18px -22px 28px rgb(0 0 0 / 30%),
    0 7px 18px #000;
  cursor: crosshair;
}

#spin-picker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 19px;
  height: 19px;
  border: 3px solid white;
  border-radius: 50%;
  background: #b81717;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 5px #000;
}

/* Bola grande com as zonas escritas em volta, como no quadro da Silvia
   Taioli: alto segue, baixo puxa, lados abrem. */
.spin-pad {
  display: grid;
  grid-template-areas:
    ". top ."
    "left ball right"
    ". bottom .";
  grid-template-columns: auto auto auto;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
}

.spin-pad .spin-ball {
  grid-area: ball;
  margin: 0;
  touch-action: none;
}

.spin-label {
  color: #ffd787;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.spin-label--top {
  grid-area: top;
}

.spin-label--bottom {
  grid-area: bottom;
}

.spin-label--left {
  grid-area: left;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.spin-label--right {
  grid-area: right;
  writing-mode: vertical-rl;
}

/* Cruz e anel guia dentro da bola. */
.spin-ball::before {
  position: absolute;
  inset: 8%;
  border: 1px dashed rgb(90 60 20 / 45%);
  border-radius: 50%;
  background:
    linear-gradient(rgb(90 60 20 / 35%), rgb(90 60 20 / 35%)) center / 1px
      100% no-repeat,
    linear-gradient(rgb(90 60 20 / 35%), rgb(90 60 20 / 35%)) center / 100%
      1px no-repeat;
  content: "";
  pointer-events: none;
}

.spin-dialog .spin-desc {
  min-height: 2.6em;
  margin: 12px 0 10px;
  color: #ffe6ad;
  font-size: 14px;
  font-weight: 700;
}

.spin-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.spin-reset.spin-ok {
  background: #0b6b41;
}

.hud__spin.has-spin {
  filter: drop-shadow(0 0 6px rgb(242 182 50 / 80%));
}

.spin-reset,
.game-menu button {
  border: 1px solid #c98e32;
  border-radius: 9px;
  padding: 10px 20px;
  background: #47200d;
  color: #ffe6ad;
  cursor: pointer;
}

.game-menu {
  width: 310px;
  padding: 27px;
  text-align: center;
}

.game-menu button {
  display: block;
  width: 100%;
  margin-top: 10px;
}

.room-dialog {
  width: 420px;
}

.room-dialog p {
  margin: 0 0 14px;
  color: #cbb58e;
}

.room-dialog input {
  width: 100%;
  border: 1px solid #c98e32;
  border-radius: 9px;
  padding: 10px 12px;
  background: #1c0d05;
  color: #ffe6ad;
  font: inherit;
  font-size: 14px;
}

.room-dialog .room-code {
  margin: 4px 0 10px;
  color: #fff3d4;
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 0.18em;
  user-select: all;
}

.game-menu #search-choice button small {
  display: block;
  margin-top: 2px;
  color: #cbb58e;
  font-size: 12px;
  font-weight: 400;
}

.lobby__stats {
  margin: 8px 0 0;
  color: #f2e3c2;
  font-size: 14px;
}

.custom-join {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.custom-join input[aria-invalid="true"] {
  border-color: var(--danger);
}

.custom-join input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.game-menu .custom-join button {
  width: auto;
  margin-top: 0;
}

.room-dialog .room-dialog__status {
  margin: 14px 0 0;
  color: #ffd787;
  font-weight: 800;
}

@media (height <= 760px) {
  .hud {
    height: 96px;
    padding-top: 4px;
  }

  .game__stage {
    height: calc(100vh - 96px);
    padding-block: 4px 18px;
  }

  .table-shell {
    width: min(70vw, calc((100vh - 124px) * 1.817));
  }

  .power-meter {
    height: min(42vh, 310px);
  }

  .tray {
    height: min(60vh, 410px);
  }
}

/* Notebook (768–900px de altura): lobby com 4 botões precisa caber. */
@media (541px <= height <= 900px) {
  .lobby__coin {
    width: 96px;
    margin-bottom: -12px;
  }

  .lobby h1 {
    font-size: clamp(54px, 9vh, 84px);
  }

  .lobby__subtitle {
    margin: 10px 0 18px;
  }

  .lobby__actions {
    gap: 6px;
  }

  .art-button {
    width: 400px;
    height: 84px;
    font-size: 22px;
  }

  .lobby__credit {
    margin-top: 14px;
  }
}

/* No iPhone, segurar uma imagem abre o menu/arraste nativo e cancela o
   gesto (era o que impedia puxar a força). As artes do jogo não recebem
   toque; quem recebe é o elemento por baixo. */
.app img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.game img,
.lobby img {
  pointer-events: none;
}

.power-meter__hint {
  position: absolute;
  left: 50%;
  top: -4%;
  display: none;
  padding: 2px 7px;
  border: 1px solid #f2b632;
  border-radius: 999px;
  background: rgb(17 9 5 / 92%);
  color: #ffe3a5;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  animation: puxe 1.1s ease-in-out infinite alternate;
  pointer-events: none;
}

.hint-horizontal {
  display: none;
}

@media (pointer: coarse) {
  .power-meter.is-ready .power-meter__hint {
    display: block;
  }
}

@keyframes puxe {
  from {
    transform: translate(-50%, -100%);
  }

  to {
    transform: translate(-50%, -70%);
  }
}

.game__hint--touch {
  display: none;
}

@media (pointer: coarse) {
  .game__hint--mouse {
    display: none;
  }

  .game__hint--touch {
    display: block;
  }

  .app {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
  }

  .app.is-ios-browser .fullscreen-tip {
    display: inline-block;
  }
}

.fullscreen-tip {
  display: none;
  margin-top: 6px;
  border: 1px solid rgb(228 170 79 / 58%);
  border-radius: 20px;
  padding: 6px 14px;
  background: rgb(20 10 4 / 86%);
  color: #ffd787;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.fullscreen-dialog ol {
  margin: 0 0 12px;
  padding-left: 20px;
  color: #ffe6ad;
  text-align: left;
  line-height: 1.5;
}

/* Celular deitado (plataforma principal): faixa fina de HUD em cima e a
   mesa ocupando o resto da tela, com força à esquerda e canaleta à direita,
   como no 8 Ball Pool. */
@media (orientation: landscape) and (height <= 540px) {
  /* A mesa usa a altura inteira; o HUD vai para as faixas laterais que
     sobram (a tela do celular é mais comprida que a mesa). */
  :root {
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --gap: 8px;
    --table-w: min(
      calc(100dvw - 2 * 58px - 2 * var(--gap) - var(--safe-l) - var(--safe-r)),
      calc((100dvh - 4px) * 1.817)
    );
    --side: calc(
      (100dvw - var(--table-w) - 2 * var(--gap) - var(--safe-l) - var(--safe-r)) /
        2
    );
    --hud-btn: min(38px, calc(var(--side) - 12px));
  }

  html,
  body {
    min-width: 0;
    height: 100dvh;
  }

  .app,
  .lobby,
  .game {
    height: 100dvh;
  }

  .game {
    background-size: cover;
  }

  .game::before {
    background: rgb(4 2 1 / 62%);
  }

  /* HUD por cima de tudo, sem ocupar espaço: cada jogador vira um painel
     na faixa do seu lado (menu e jogador 1 à esquerda, efeito e jogador 2
     à direita). A barra de HUD desenhada fica só no PC. */
  .hud {
    position: absolute;
    z-index: 5;
    inset: 0;
    display: block;
    height: auto;
    padding: 0;
    pointer-events: none;
  }

  .hud__bar {
    position: static;
    aspect-ratio: auto;
  }

  .hud__bar > img,
  .hud__versus {
    display: none;
  }

  .hud__menu,
  .hud__spin {
    position: absolute;
    top: 4px;
    width: var(--hud-btn);
    pointer-events: auto;
  }

  .hud__menu {
    left: calc(var(--safe-l) + (var(--side) - var(--hud-btn)) / 2);
  }

  .hud__spin {
    right: calc(var(--safe-r) + (var(--side) - var(--hud-btn)) / 2);
  }

  .player {
    inset: auto;
    top: calc(var(--hud-btn) + 10px);
    display: flex;
    width: calc(var(--side) - 4px);
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 5px 2px 6px;
    border: 1px solid rgb(201 142 50 / 70%);
    border-radius: 12px;
    background: rgb(16 9 5 / 88%);
  }

  .player--one {
    left: calc(var(--safe-l) + 2px);
  }

  .player--two {
    right: calc(var(--safe-r) + 2px);
  }

  .player.is-active {
    border-color: #f2b632;
    box-shadow: 0 0 10px rgb(242 182 50 / 45%);
  }

  .player__timer {
    position: relative;
    left: auto;
    top: auto;
    order: -1;
    width: min(42px, calc(var(--side) - 14px));
    border: 2px solid #c98e32;
    background: radial-gradient(circle, #2b170b, #0b0604);
    transform: none;
  }

  .player__info {
    position: static;
    display: flex;
    width: 100%;
    height: auto;
    flex-direction: column;
    align-items: center;
    gap: 3px;
  }

  .player strong {
    position: static;
    display: block;
    width: 100%;
    height: auto;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
    transform: none;
  }

  .ball-slots {
    position: static;
    flex-wrap: wrap;
    gap: 2px;
    width: 100%;
    transform: none;
  }

  .slot-ball {
    width: 9px;
    height: 9px;
    border-width: 1px;
    font-size: 0;
    box-shadow: inset -2px -2px 4px rgb(0 0 0 / 38%);
  }

  .game__stage {
    grid-template-columns: var(--side) var(--table-w) var(--side);
    gap: var(--gap);
    height: 100dvh;
    padding: 2px var(--safe-r) 2px var(--safe-l);
  }

  .table-shell {
    width: var(--table-w);
  }

  .table-art {
    filter: drop-shadow(0 8px 14px rgb(0 0 0 / 70%));
  }

  /* Proporção da arte (195×545), para o preenchimento cair dentro do tubo. */
  .power-meter {
    width: min(54px, 100%);
    height: auto;
    place-self: end center;
    margin-bottom: 8px;
    aspect-ratio: 195 / 545;
    touch-action: none;
    cursor: grab;
  }

  /* Área de toque maior que o desenho, para não errar o dedo. */
  .power-meter::after {
    position: absolute;
    inset: -14% -40%;
    content: "";
  }

  .power-meter.is-pulling {
    cursor: grabbing;
    filter: drop-shadow(0 0 10px rgb(242 182 50 / 70%));
  }

  #power-value {
    min-width: 34px;
    padding: 2px 4px;
    font-size: 10px;
  }

  /* Trilho na altura da mesa; 15 bolas cabem empilhadas. */

  /* Canaleta embaixo do painel do jogador 2; 15 bolas cabem empilhadas. */
  .tray {
    /* Altura do trilho menos moldura/folga, dividida por 15 bolas + vãos. */
    --tray-ball: min(14px, calc((100dvh - 160px - 20px) / 15 - 2px));

    height: calc(100dvh - 160px);
    align-self: end;
    margin-bottom: 8px;
  }

  .message {
    top: 7%;
    min-width: 0;
    padding: 5px 14px;
    font-size: 13px;
    white-space: nowrap;
  }

  .game__hint {
    display: none !important;
  }

  dialog {
    max-height: 94dvh;
    overflow: auto;
  }

  .game-menu,
  .spin-dialog {
    padding: 14px 18px;
  }

  .spin-dialog h2,
  .game-menu h2 {
    font-size: 20px;
  }

  .spin-dialog p,
  .room-dialog p {
    margin-bottom: 8px;
    font-size: 13px;
  }

  .spin-ball {
    width: min(150px, 46dvh);
    height: min(150px, 46dvh);
    margin-bottom: 10px;
    border-width: 7px;
  }

  .game-menu button,
  .spin-reset {
    margin-top: 6px;
    padding: 8px 14px;
  }

  /* Lobby em duas colunas: nome à esquerda, botões à direita. */
  .lobby__content {
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: center;
    gap: 0 clamp(20px, 5dvw, 56px);
    width: 100%;
    padding: 0 calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
  }

  .lobby__coin {
    width: clamp(56px, 20dvh, 96px);
    margin-bottom: -8px;
  }

  .lobby h1 {
    font-size: clamp(40px, 15dvh, 72px);
  }

  .lobby__subtitle {
    margin: 8px 0 0;
    font-size: 14px;
  }

  .lobby__actions {
    gap: 4px;
  }

  .art-button {
    width: clamp(220px, 38dvw, 330px);
    height: clamp(44px, 14.5dvh, 66px);
    font-size: clamp(14px, 4.4dvh, 19px);
  }

  .art-button:hover {
    transform: none;
  }

  .difficulty {
    margin: -2px 0 2px;
  }

  .difficulty button {
    padding: 4px 13px;
    font-size: 13px;
  }

  .lobby__credit {
    grid-column: 1 / -1;
    margin-top: 6px;
    font-size: 11px;
  }
}

/* Celular em pé (plataforma principal): placar numa faixa fina em cima e a
   mesa girada -90° (branca embaixo, tacando para cima) no maior tamanho que
   cabe. Força e canaleta ficam por cima da madeira das cabeceiras, então a
   mesa não divide espaço com elas. Todas as medidas saem da tela e das
   áreas seguras, então nada corta em aparelho nenhum. */
@media (orientation: portrait) and (width <= 900px) {
  :root {
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --hud-h: 44px;

    /* Largura da mesa na tela (= altura da arte), limitada pela largura e
       pela altura disponíveis; 1.817 é a proporção de mesa.png. */
    --table-w: min(
      calc(100dvw - var(--safe-l) - var(--safe-r) - 4px),
      calc(
        (100dvh - var(--safe-t) - var(--safe-b) - var(--hud-h) - 6px) / 1.817
      )
    );
    --table-h: calc(var(--table-w) * 1.817);

    /* Madeira das cabeceiras na arte girada: entre as caçapas de canto
       (21% a 79% da largura) e a ~1,3% da ponta da mesa. */
    --rail-x: 21%;
    --rail-w: 58%;
    --rail-gap: calc(var(--table-h) * 0.013);
    --rail-h: calc(var(--table-h) * 0.034);
  }

  html,
  body {
    min-width: 0;
    height: 100dvh;
  }

  .app,
  .lobby,
  .game {
    height: 100dvh;
  }

  .game::before {
    background: rgb(4 2 1 / 62%);
  }

  .hud {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 32px;
    gap: 5px;
    height: calc(var(--hud-h) + var(--safe-t));
    padding: calc(var(--safe-t) + 3px) calc(var(--safe-r) + 5px) 2px
      calc(var(--safe-l) + 5px);
  }

  .hud__bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    height: 100%;
    aspect-ratio: auto;
  }

  .hud__bar > img,
  .hud__versus {
    display: none;
  }

  .hud__menu,
  .hud__spin {
    width: 32px;
  }

  .hud__menu:hover,
  .hud__spin:hover {
    transform: none;
  }

  .player {
    position: static;
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 4px;
    padding: 2px 5px;
    border: 1px solid rgb(201 142 50 / 70%);
    border-radius: 10px;
    background: rgb(16 9 5 / 88%);
  }

  .player.is-active {
    border-color: #f2b632;
    box-shadow: 0 0 10px rgb(242 182 50 / 45%);
  }

  .player__timer {
    position: relative;
    left: auto;
    top: auto;
    width: 32px;
    flex: 0 0 32px;
    border: 2px solid #c98e32;
    background: radial-gradient(circle, #2b170b, #0b0604);
    transform: none;
  }

  .player__info {
    position: static;
    display: flex;
    min-width: 0;
    height: auto;
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: 3px;
  }

  .player strong {
    position: static;
    display: block;
    width: 100%;
    height: auto;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
    transform: none;
  }

  .ball-slots {
    position: static;
    gap: 2px;
    width: 100%;
    transform: none;
  }

  .slot-ball {
    width: 9px;
    height: 9px;
    border-width: 1px;
    font-size: 0;
    box-shadow: inset -2px -2px 4px rgb(0 0 0 / 38%);
  }

  /* Uma célula só: mesa, com canaleta e força por cima das cabeceiras. */
  .game__stage {
    grid-template-columns: var(--table-w);
    grid-template-rows: var(--table-h);
    align-content: center;
    gap: 0;
    height: calc(100dvh - var(--hud-h) - var(--safe-t));
    padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  }

  .table-shell {
    grid-column: 1;
    grid-row: 1;
    width: var(--table-w);
    height: var(--table-h);
    aspect-ratio: auto;
  }

  .table-rotor {
    inset: auto;
    left: 50%;
    top: 50%;
    width: var(--table-h);
    height: var(--table-w);
    transform: translate(-50%, -50%) rotate(-90deg);
  }

  .table-art {
    filter: drop-shadow(0 8px 14px rgb(0 0 0 / 70%));
  }

  /* Força bem fina no meio da madeira de baixo: só mostra a força de quem
     puxa o taco (e ainda aceita puxar para a esquerda, como reserva). */
  .power-meter {
    grid-column: 1;
    grid-row: 1;
    width: calc(var(--rail-w) * 0.7);
    height: calc(var(--rail-h) * 0.45);
    place-self: end start;
    margin: 0 0 calc(var(--rail-gap) + var(--rail-h) * 0.275)
      calc(var(--rail-x) + var(--rail-w) * 0.15);
    border: 1px solid rgb(201 142 50 / 75%);
    border-radius: 999px;
    background: linear-gradient(#0b0604, #2b170b 50%, #0b0604);
    box-shadow:
      inset 0 0 10px #000,
      0 0 0 1px #5a2a0d,
      0 8px 16px rgb(0 0 0 / 62%);
    filter: none;
    z-index: 1;
    touch-action: none;
    cursor: grab;
  }

  .power-meter > img {
    display: none;
  }

  /* Área de toque maior que o desenho fino, mais para baixo (fora do
     pano) do que para cima. */
  .power-meter::after {
    position: absolute;
    inset: -110% -4% -200%;
    content: "";
  }

  .power-meter.is-pulling {
    cursor: grabbing;
    box-shadow:
      inset 0 0 10px #000,
      0 0 12px rgb(242 182 50 / 70%);
  }

  .power-meter__track {
    inset: 1px;
    width: auto;
    height: auto;
    background: none;
  }

  #power-level {
    background: linear-gradient(to left, #d33b1f, #f2b632 62%, #fff2b0);
    transform: scaleX(var(--power, 0));
    transform-origin: right;
  }

  /* Discreta: sem número e sem aviso piscando (a dica de puxar o taco
     aparece na primeira partida). */
  #power-value,
  .power-meter.is-ready .power-meter__hint {
    display: none;
  }

  /* Canaleta fininha sobre a madeira de cima; 15 bolas lado a lado. */
  .tray {
    --tray-ball: min(
      calc(var(--rail-h) * 0.62 - 4px),
      calc((var(--table-w) * 0.58 * 0.8 - 10px) / 15 - 1px)
    );

    display: block;
    grid-column: 1;
    grid-row: 1;
    width: calc(var(--rail-w) * 0.8);
    height: calc(var(--rail-h) * 0.62);
    place-self: start start;
    margin: calc(var(--rail-gap) + var(--rail-h) * 0.19) 0 0
      calc(var(--rail-x) + var(--rail-w) * 0.1);
    z-index: 1;
    pointer-events: none;
  }

  .tray__balls {
    width: 100%;
    height: 100%;
    flex-direction: row;
    gap: 1px;
    padding: 0 3px;
    border-width: 1px;
  }

  .message {
    top: 7%;
    min-width: 0;
    padding: 5px 14px;
    font-size: 13px;
    white-space: nowrap;
  }

  .game__hint {
    display: none !important;
  }

  dialog {
    max-width: calc(100vw - 24px);
    max-height: 92dvh;
    overflow: auto;
  }

  .game-menu,
  .spin-dialog {
    padding: 18px;
  }

  .spin-ball {
    width: min(200px, 54vw);
    height: min(200px, 54vw);
  }

  .lobby__content {
    width: 100%;
    padding: 0 calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
  }

  .lobby__coin {
    width: 84px;
    margin-bottom: -10px;
  }

  .lobby h1 {
    font-size: clamp(48px, 16vw, 72px);
  }

  .lobby__subtitle {
    margin: 10px 0 20px;
    font-size: 15px;
  }

  .lobby__actions {
    gap: 6px;
  }

  .art-button {
    width: min(340px, calc(100vw - 40px));
    height: clamp(58px, 9dvh, 76px);
    font-size: 19px;
  }

  .art-button:hover {
    transform: none;
  }

  .difficulty {
    margin: -2px 0 2px;
  }

  .difficulty button {
    padding: 6px 14px;
    font-size: 14px;
  }

  .lobby__credit {
    margin-top: 14px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
