:root {
  --bg: #0b1f17;
  --felt: #13573a;
  --felt-dark: #0c3d28;
  --ink: #f4efe2;
  --muted: #a9c2b5;
  --tile: #f8f4e9;
  --tile-edge: #d9d0bb;
  --pip: #1d1a16;
  --us: #f2c14e;
  --them: #ff8a6b;
  --accent: #f2c14e;
  --danger: #ff7b7b;
  --panel: rgba(8, 24, 17, 0.82);
  --radius: 14px;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- Botões e campos ---------- */

.btn {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s, background 0.2s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #2a1f00; border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: #ffd36b; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 7px 12px; font-size: 14px; white-space: nowrap; }

input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
input:focus { border-color: var(--accent); }

/* ---------- Tela inicial ---------- */

#home {
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, var(--felt), var(--felt-dark) 60%, var(--bg));
}
.home-card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  padding: 28px 24px;
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.logo { display: flex; align-items: center; gap: 14px; justify-content: center; }
.logo h1 { margin: 0; font-size: 40px; letter-spacing: -0.02em; }
.logo-tile {
  width: 30px; height: 58px; border-radius: 6px; background: var(--tile);
  display: flex; flex-direction: column; padding: 4px; gap: 3px; transform: rotate(-12deg);
  box-shadow: 0 4px 0 var(--tile-edge);
}
.logo-tile span { flex: 1; display: grid; place-items: center; }
.logo-tile span::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--pip); }
.logo-tile span:first-child { border-bottom: 2px solid var(--tile-edge); }
.tagline { text-align: center; margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input { color: var(--ink); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.15); }
.join-row { display: flex; gap: 8px; }
.step { display: flex; flex-direction: column; gap: 14px; }
.modes { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
  display: flex; flex-direction: column; gap: 10px; padding: 14px;
  border-radius: 16px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.08);
}
.mode-head { display: flex; gap: 12px; align-items: flex-start; }
.mode-icon {
  flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-size: 22px; background: rgba(0, 0, 0, 0.3);
}
.mode-head h2 { margin: 0; font-size: 17px; }
.mode-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); line-height: 1.35; }
.fine { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.invite {
  margin: 0; padding: 10px 14px; border-radius: 12px; text-align: center;
  background: rgba(242, 193, 78, 0.12); border: 1px solid rgba(242, 193, 78, 0.35);
}
.invite strong { color: var(--accent); letter-spacing: 0.15em; }
.greeting { display: flex; align-items: center; gap: 12px; padding: 4px 0 6px; }
.hello { font-size: 20px; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 13px; }
.link:hover { color: var(--ink); }

/* Mesas abertas */
.rooms-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rooms-head h2 { margin: 0; font-size: 17px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); animation: live 2s infinite; }
@keyframes live { 70% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }
.rooms-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rooms-empty { font-size: 13px; color: var(--muted); text-align: center; padding: 6px 0; }
.room-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
}
.room-seats { flex: none; display: grid; grid-template-columns: repeat(2, 22px); gap: 3px; }
.avatar.mini { width: 22px; height: 22px; font-size: 11px; border-width: 1.5px; }
.avatar.mini.bot { font-size: 12px; background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.2); }
.room-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.room-text strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-text small { font-size: 12px; color: var(--muted); }
.room-item .btn { flex: none; }

/* Avatar com inicial */
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  background: #2b4a3c; color: var(--ink); border: 2px solid var(--muted);
}
.avatar[data-side="us"], .avatar[data-side="0"] { background: #4a3c12; border-color: var(--us); color: var(--us); }
.avatar[data-side="them"] { background: #4a2219; border-color: var(--them); color: var(--them); }
.avatar.big { width: 48px; height: 48px; font-size: 22px; }
.empty-avatar { border-style: dashed; background: transparent; color: var(--muted); }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 0.2em; text-align: center; }

/* ---------- Barra de topo ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: rgba(0, 0, 0, 0.35);
  z-index: 5;
}
.room-code strong { letter-spacing: 0.2em; color: var(--accent); }

/* ---------- Saguão ---------- */

#lobby { background: radial-gradient(ellipse at 50% 40%, var(--felt), var(--felt-dark) 70%, var(--bg)); }
.lobby-body {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  gap: 18px; padding: 16px;
}
.lobby-body > * { flex-shrink: 0; }
.spacer { width: 60px; }
.invite-card {
  width: min(420px, 100%); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel); border-radius: 18px; padding: 14px 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.small-caps { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; }
.big-code { font-size: 34px; font-weight: 800; letter-spacing: 0.25em; color: var(--accent); line-height: 1.1; }
.seat-table { position: relative; width: min(420px, 100%); aspect-ratio: 1.15; }
.felt-mini {
  position: absolute; inset: 24% 20%; border-radius: 24px;
  background: radial-gradient(ellipse, var(--felt), var(--felt-dark));
  box-shadow: inset 0 0 0 6px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.35);
  display: grid; place-items: center; text-align: center; padding: 10px;
}
.felt-mini span { font-size: 12px; color: var(--muted); }
.seat {
  position: absolute; width: 42%; min-height: 58px; padding: 8px 10px;
  border-radius: var(--radius); border: 2px solid transparent;
  background: var(--panel); display: flex; align-items: center; gap: 10px; text-align: left;
  transform: translate(-50%, -50%);
  cursor: default; transition: transform 0.15s, opacity 0.2s;
}
.seat-text { display: flex; flex-direction: column; min-width: 0; }
.seat strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat small { color: var(--muted); font-size: 12px; }
.seat.me { box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.18); }
.seat.empty:hover { transform: translate(-50%, -50%) scale(1.03); }
.team-legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; font-size: 13px; }
.chip { padding: 3px 10px; border-radius: 999px; border: 1.5px solid; font-size: 12px; }
.chip.us { color: var(--us); border-color: var(--us); }
.chip.them { color: var(--them); border-color: var(--them); }
.btn.wide { min-width: 240px; }
.hint, #lobby-status { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
.seat.team-us { border-color: var(--us); }
.seat.team-them { border-color: var(--them); }
.seat.empty { border-style: dashed; opacity: 0.75; cursor: pointer; }
.seat.empty:hover { opacity: 1; }
.seat.offline { opacity: 0.5; }
.seat.bottom { left: 50%; top: 90%; }
.seat.top { left: 50%; top: 10%; }
.seat.left { left: 22%; top: 50%; }
.seat.right { left: 78%; top: 50%; }

/* ---------- Mesa ---------- */

#table { background: var(--bg); }
.scoreboard { display: flex; align-items: center; gap: 16px; }
.team { display: flex; flex-direction: column; gap: 4px; min-width: 96px; }
.team-line { display: flex; align-items: baseline; gap: 6px; }
.team.us .team-line { justify-content: flex-start; }
.team.them .team-line { justify-content: flex-end; }
.team strong { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1; display: inline-block; }
.team strong.bump { animation: bump 0.5s ease-out; }
@keyframes bump { 30% { transform: scale(1.35); } }
.bar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width 0.6s ease; }
.team.us .bar i { background: var(--us); }
.team.them .bar i { background: var(--them); margin-left: auto; }
.team.them .bar { display: flex; justify-content: flex-end; }
.team .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.team.us strong { color: var(--us); }
.team.them strong { color: var(--them); }
.team .wins { font-size: 10px; letter-spacing: 2px; }
.team.us .wins { color: var(--us); }
.team.them .wins { color: var(--them); }
.match-info { display: flex; flex-direction: column; align-items: center; font-size: 12px; line-height: 1.3; white-space: nowrap; }

.felt {
  position: relative; flex: 1; min-height: 0;
  margin: 6px 8px; border-radius: 28px;
  border: 9px solid #6b4426;
  outline: 2px solid #2c1a0e; outline-offset: -1px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "left board right";
  background:
    repeating-radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 4px),
    radial-gradient(ellipse at center, #17663f 0%, var(--felt) 45%, var(--felt-dark) 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35), inset 0 0 70px rgba(0, 0, 0, 0.55), 0 12px 30px rgba(0, 0, 0, 0.45);
  background-clip: padding-box;
}
#table { background: radial-gradient(ellipse at 50% 0%, #1b2a20, #0a120d 70%); }

.opponent {
  display: flex; align-items: center; gap: 6px; padding: 8px;
  --u: 11px;
  transition: opacity 0.2s;
}
.opponent.top { grid-area: top; flex-direction: column; justify-self: center; }
.opponent.left { grid-area: left; flex-direction: column; justify-content: center; }
.opponent.right { grid-area: right; flex-direction: column; justify-content: center; }
.opponent.offline { opacity: 0.45; }
.plate {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.38); border: 1.5px solid transparent; max-width: 170px;
  transition: background 0.2s, border-color 0.2s;
}
.plate .avatar { width: 28px; height: 28px; font-size: 13px; }
.plate-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.plate-text strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate-text small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.opponent.active .plate, .plate.active {
  border-color: var(--accent); background: rgba(242, 193, 78, 0.16); animation: pulse 1.2s infinite;
}
.opponent.active .plate small::after, .plate.active small::after { content: ' · jogando'; color: var(--accent); }
.opp-tiles { display: flex; gap: 2px; }
.opponent.left .opp-tiles, .opponent.right .opp-tiles { flex-direction: column; }
.opp-tiles.revealed { --u: 15px; gap: 3px; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 193, 78, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(242, 193, 78, 0); }
}

#board-wrap { grid-area: board; min-width: 0; min-height: 0; position: relative; }
#board { --u: 30px; position: absolute; inset: 0; }
#board > .tile, #board > .slot { position: absolute; }
.board-empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); white-space: nowrap;
  color: var(--muted); padding: 18px 22px; border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius); font-size: 15px;
}
.tile.spinner { box-shadow: 0 0 0 2px var(--accent), 0 3px 0 var(--tile-edge); }
/* Última pedra jogada */
/* Contorno desenhado por dentro da pedra, para não invadir as vizinhas */
.tile.last-us { outline: 3px solid var(--us); outline-offset: -3px; box-shadow: 0 0 10px 1px rgba(242, 193, 78, 0.6); }
.tile.last-them { outline: 3px solid var(--them); outline-offset: -3px; box-shadow: 0 0 10px 1px rgba(255, 138, 107, 0.6); }
#board > .tile { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }
#board > .tile.spinner { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); outline: 2px solid var(--accent); outline-offset: -2px; }
#board > .tile.last-us { z-index: 1; outline: 3px solid var(--us); outline-offset: -3px; box-shadow: 0 0 10px 1px rgba(242, 193, 78, 0.6); }
#board > .tile.last-them { z-index: 1; outline: 3px solid var(--them); outline-offset: -3px; box-shadow: 0 0 10px 1px rgba(255, 138, 107, 0.6); }
.tile.drop { animation: drop-in 0.4s ease-out; }
.last-play {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); border: 1.5px solid var(--us); white-space: nowrap; pointer-events: none;
  font-size: 13px;
}
.last-play.them { border-color: var(--them); }
.last-play .avatar { width: 24px; height: 24px; font-size: 12px; }
.last-play .tile { --u: 14px; }
@keyframes drop-in {
  from { opacity: 0; transform: scale(1.35); }
  to { opacity: 1; transform: none; }
}

.ends-sum {
  position: absolute; left: 12px; top: 10px; z-index: 2; font-size: 13px; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.3);
}
.ends-sum:empty { display: none; }
.ends-sum.scoring { color: #2a1f00; background: var(--accent); font-weight: 700; }

.log {
  position: absolute; right: 10px; top: 8px; z-index: 2; margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-end; pointer-events: none;
  max-width: 55%;
}
.log li { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); white-space: nowrap; }
.log li:not(:first-child) { opacity: 0.6; }
.log li b { font-variant-numeric: tabular-nums; }
.log li.us b { color: var(--us); }
.log li.them b { color: var(--them); }

#toasts {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 4;
}
.your-turn {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  padding: 8px 22px; border-radius: 999px; background: var(--accent); color: #2a1f00;
  font-weight: 800; font-size: 18px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: your-turn 1.4s ease forwards;
}
@keyframes your-turn {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.9); }
  15%, 75% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}
.toast {
  display: flex; align-items: baseline; gap: 8px; padding: 8px 16px; border-radius: 999px;
  background: var(--panel); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toast 2.8s ease forwards;
}
.toast span { white-space: nowrap; }
.toast strong { font-size: 22px; }
.toast.us strong { color: var(--us); }
.toast.them strong { color: var(--them); }
.toast.big strong { font-size: 34px; }
@keyframes toast {
  0% { opacity: 0; transform: translateY(10px) scale(0.9); }
  10%, 75% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* ---------- Minha área ---------- */

.me-area {
  background: linear-gradient(to top, #120c08, #24180f);
  padding: 8px 12px max(12px, env(safe-area-inset-bottom));
  border-top: 2px solid rgba(255, 255, 255, 0.06);
  transition: border-color 0.3s, background 0.3s;
}
.me-area.my-turn { border-top-color: var(--accent); background: linear-gradient(to top, #160f08, #33250f); }
.me-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 10px; }
.me-bar #sort-hand { justify-self: end; }
.me-bar .plate { justify-self: start; max-width: 200px; }
.status { font-size: 14px; color: var(--muted); text-align: center; }
.me-area.my-turn .status { color: var(--accent); font-weight: 700; }
.hand {
  --u: 46px; position: relative; display: flex; justify-content: center; gap: 14px;
  min-height: calc(var(--u) * 2 + 16px); padding-top: 6px; touch-action: pan-y;
}

/* ---------- Pedras ---------- */

.tile {
  display: flex; flex: none;
  background: var(--tile);
  border-radius: calc(var(--u) * 0.16);
  box-shadow: 0 calc(var(--u) * 0.08) 0 var(--tile-edge), 0 2px 6px rgba(0, 0, 0, 0.35);
  padding: calc(var(--u) * 0.06);
}
.tile.v { flex-direction: column; width: var(--u); height: calc(var(--u) * 2); }
.tile.h { flex-direction: row; width: calc(var(--u) * 2); height: var(--u); }
.half {
  flex: 1; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: calc(var(--u) * 0.1); place-items: center;
}
.tile.v .half:first-child { border-bottom: max(1px, calc(var(--u) * 0.04)) solid var(--tile-edge); }
.tile.h .half:first-child { border-right: max(1px, calc(var(--u) * 0.04)) solid var(--tile-edge); }
.half i { display: block; }
.half i.pip { width: calc(var(--u) * 0.17); height: calc(var(--u) * 0.17); border-radius: 50%; background: var(--pip); }

.tile.back {
  background:
    radial-gradient(circle, rgba(242, 193, 78, 0.55) 0 14%, transparent 16%),
    linear-gradient(135deg, #2e3b52, #1a2233);
  box-shadow: 0 1px 0 #0b1018, inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.tile.in-hand { cursor: grab; transition: transform 0.15s, opacity 0.15s, box-shadow 0.15s; outline: none; touch-action: none; user-select: none; -webkit-user-select: none; }
.tile.in-hand:focus-visible { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.6); }
.tile.in-hand { cursor: pointer; }
.tile.in-hand.dragging {
  transition: none; z-index: 3; cursor: grabbing; opacity: 1;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(255, 255, 255, 0.5);
}
.tile.in-hand:hover, .tile.in-hand:focus-visible { transform: translateY(-6px); }
.hint-bar {
  display: flex; align-items: center; gap: 8px; margin: 0 auto 8px; max-width: 100%;
  padding: 5px 12px; border-radius: 999px; border: 1px solid rgba(160, 110, 255, 0.6);
  background: rgba(120, 60, 200, 0.35); color: #fff; font-size: 13px; cursor: pointer; text-align: left;
}
.hint-bar .tile { --u: 14px; flex: none; }
.hint-label { font-weight: 800; white-space: nowrap; }
.tile.in-hand.hinted { box-shadow: 0 0 0 3px #a06eff, 0 0 18px 4px rgba(160, 110, 255, 0.55); }
.slot.best {
  border-color: #a06eff; background: rgba(160, 110, 255, 0.3);
  display: grid; place-items: center; font-size: calc(var(--u) * 0.6);
}
.tile.in-hand.selected { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--accent), 0 8px 18px rgba(0, 0, 0, 0.5); }

.slot {
  flex: none; border: 2px dashed var(--accent); background: rgba(242, 193, 78, 0.18);
  border-radius: calc(var(--u) * 0.16); cursor: pointer; animation: pulse 1.2s infinite;
}
.slot.h { width: calc(var(--u) * 2); height: var(--u); }
.slot.v { width: var(--u); height: calc(var(--u) * 2); }
.slot:hover { background: rgba(242, 193, 78, 0.4); }
#board > .center-slot { --u: 34px; left: 50%; top: 50%; transform: translate(-50%, -50%); }

/* ---------- Chat ---------- */

.chat {
  position: fixed; right: 10px; top: 56px; width: min(320px, calc(100% - 20px)); height: min(380px, 55%);
  background: var(--panel); backdrop-filter: blur(8px); border-radius: var(--radius);
  display: flex; flex-direction: column; z-index: 6; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 14px; }
#chat-list {
  flex: 1; overflow-y: auto; margin: 0; padding: 12px; list-style: none; font-size: 14px;
  display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
/* Balões: os seus à direita (dourado), os dos outros à esquerda, avisos da sala no meio. */
#chat-list li {
  align-self: flex-start; max-width: 82%; padding: 6px 10px; border-radius: 14px 14px 14px 4px;
  background: rgba(255, 255, 255, 0.08); overflow-wrap: anywhere; line-height: 1.3;
}
#chat-list li b { display: block; font-size: 0.78em; color: var(--accent); margin-bottom: 1px; }
#chat-list li.mine { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: rgba(242, 193, 78, 0.22); }
#chat-list li.mine b { display: none; }
#chat-list .system {
  align-self: center; max-width: 92%; background: none; padding: 2px 6px; text-align: center;
  color: var(--muted); font-style: italic; font-size: 13px;
}
#chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
#chat-form input { flex: 1; min-width: 0; padding: 8px 10px; }
.badge { background: var(--them); color: #2a0c00; border-radius: 999px; padding: 0 6px; font-size: 12px; margin-left: 4px; }

/* ---------- Resultado ---------- */

.modal {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: #10291e; border-radius: 20px; padding: 22px; width: min(460px, 100%);
  max-height: 100%; overflow-y: auto; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.modal-card h2 { margin: 0 0 4px; font-size: 24px; }
.modal-card p { margin: 0 0 12px; }
.events { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 4px; }
.events li.us { color: var(--us); }
.events li.them { color: var(--them); }
.result-hands { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.garage {
  margin: 0 0 16px; padding: 12px 14px; border-radius: 14px;
  background: rgba(242, 193, 78, 0.08); border: 1px solid rgba(242, 193, 78, 0.35);
}
.garage.them { background: rgba(255, 138, 107, 0.08); border-color: rgba(255, 138, 107, 0.35); }
.garage h3 { margin: 0 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.garage-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.garage-name { width: 70px; flex: none; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.garage-row .mini-tiles { flex: 1; }
.garage-row b { font-variant-numeric: tabular-nums; }
.garage-sum { margin: 8px 0 2px !important; font-size: 14px; color: var(--ink); }
.garage-verdict { margin: 0 !important; font-size: 17px; font-weight: 800; }
.garage.us .garage-verdict { color: var(--us); }
.garage.them .garage-verdict { color: var(--them); }
.result-row { display: flex; align-items: center; gap: 10px; padding-left: 10px; border-left: 3px solid var(--us); }
.result-row.them { border-color: var(--them); }
.result-row > span { width: 90px; flex: none; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-tiles { --u: 14px; display: flex; flex-wrap: wrap; gap: 4px; color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.top-actions { display: flex; align-items: center; gap: 2px; }
.btn.icon { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; border-color: rgba(255, 255, 255, 0.18); }
.tagline .link { margin-left: 4px; }

/* ---------- Regras ---------- */

.rules-modal { position: fixed; z-index: 30; }
.rules-card {
  width: min(620px, 100%); max-height: min(860px, 100%); padding: 0;
  display: flex; flex-direction: column; overflow: hidden;
}
.rules-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.rules-head h2 { margin: 0; }
.rules-nav {
  display: flex; gap: 6px; padding: 6px 20px 12px; overflow-x: auto; flex: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); scrollbar-width: none;
}
.rules-nav a {
  flex: none; padding: 5px 11px; border-radius: 999px; font-size: 13px; text-decoration: none;
  color: var(--ink); background: rgba(255, 255, 255, 0.07);
}
.rules-nav a:hover { background: rgba(242, 193, 78, 0.2); color: var(--accent); }
.rules-body { overflow-y: auto; padding: 4px 20px 24px; line-height: 1.5; font-size: 15px; }
.rules-body section { padding-top: 14px; scroll-margin-top: 8px; }
.rules-body h3 { margin: 0 0 6px; font-size: 17px; color: var(--accent); }
.rules-body p { margin: 0 0 8px; }
.rules-body ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 5px; }
.rules-body b { color: #fff; }
.rules-body .tile { --u: 14px; display: inline-flex; vertical-align: middle; margin: 0 2px; }
.example {
  --u: 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 10px 0 14px;
  padding: 14px; border-radius: 12px; background: radial-gradient(ellipse, var(--felt), var(--felt-dark));
}
.example .tile { --u: 20px; margin: 0; }
.ex-eq { margin-left: auto; padding-left: 12px; font-size: 14px; white-space: nowrap; }
.points { width: 100%; border-collapse: collapse; font-size: 14px; }
.points th, .points td { text-align: left; vertical-align: top; padding: 8px 6px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.points th { width: 30%; color: var(--accent); font-weight: 600; }

.queue-list { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; font-size: 13px; }
.chip.queue { color: var(--ink); border-color: rgba(255, 255, 255, 0.3); }
.chip.queue.offline { opacity: 0.5; }
.test-notice {
  position: absolute; left: 12px; top: 72px; z-index: 3; pointer-events: none; max-width: calc(50% - 12px);
  font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 12px;
  background: rgba(120, 60, 200, 0.85); color: #fff;
}
.test-notice.static { position: static; display: inline-block; margin: 0; max-width: none; }
.queue-chip {
  position: absolute; left: 12px; top: 40px; z-index: 2; max-width: 40%;
  font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.4); color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.team .label { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hand > .tile.back { --u: 30px; }

/* ---------- Sorteio da fila ---------- */

.draw-modal { z-index: 12; }
.draw-card { width: min(560px, 100%); text-align: center; }
.draw-status { font-weight: 700; color: var(--accent); min-height: 1.4em; }
.draw-deck { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; justify-items: center; margin-top: 8px; }
.draw-tile {
  position: relative; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 6px;
  --u: 22px; transition: transform 0.15s;
}
.draw-tile:disabled { cursor: default; }
.draw-tile:not(:disabled):hover { transform: translateY(-4px); }
.draw-tile:not(:disabled) .tile { box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.5), 0 4px 10px rgba(0, 0, 0, 0.4); }
.draw-tile.picked .tile { opacity: 0.35; }
.draw-tile .avatar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 26px; height: 26px; font-size: 13px; }
.draw-reveal { display: flex; justify-content: center; gap: 40px; margin-top: 12px; }
.draw-pick { display: flex; flex-direction: column; align-items: center; gap: 10px; --u: 44px; animation: drop-in 0.4s ease-out; transition: opacity 0.3s; }
.draw-pick strong { font-size: 17px; }
.draw-pick span { font-variant-numeric: tabular-nums; color: var(--muted); }
.draw-pick.stays .tile { box-shadow: 0 0 0 3px var(--accent), 0 0 24px 6px rgba(242, 193, 78, 0.45); }
.draw-pick.stays strong { color: var(--accent); }
.draw-pick.leaves { opacity: 0.55; }

.lobby-options { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.turn-limit { display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 4px; font-size: 13px; }
.seg {
  border: 1px solid rgba(255, 255, 255, 0.18); background: transparent; color: var(--ink);
  padding: 5px 10px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.seg.active { background: var(--accent); color: #2a1f00; border-color: var(--accent); font-weight: 700; }
.seg:disabled { cursor: default; }
.seg:disabled:not(.active) { opacity: 0.5; }
.seat.bot-seat { cursor: pointer; }
.seat.bot-seat:hover { transform: translate(-50%, -50%) scale(1.03); }

/* Relógio da vez */
.clock { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.clock.urgent { color: var(--danger); animation: pulse 0.8s infinite; }
.clock[data-offline] { color: var(--them); }

/* Reações */
.chat-reactions { display: flex; justify-content: space-around; padding: 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.react-btn { font-size: 22px; background: none; border: 0; cursor: pointer; padding: 4px 6px; border-radius: 10px; transition: transform 0.1s; }
.react-btn:hover { transform: scale(1.2); background: rgba(255, 255, 255, 0.08); }
.react-tray {
  position: absolute; right: 10px; top: 8px; z-index: 6; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; padding: 6px;
  width: min(290px, calc(100vw - 20px)); max-height: calc(100% - 16px); overflow-y: auto;
  border-radius: 18px; background: var(--panel); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.plate { position: relative; }
.reaction-bubble {
  position: absolute; left: 50%; bottom: 100%; z-index: 8; pointer-events: none;
  font-size: 30px; line-height: 1; animation: float-up 2.6s ease-out forwards;
}
.reaction-bubble.anchored { position: fixed; bottom: auto; }
.reaction-bubble.floating {
  position: fixed; left: 50%; top: 70px; bottom: auto; font-size: 16px; padding: 6px 14px; border-radius: 999px;
  background: var(--panel); white-space: nowrap;
}
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -4px) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -14px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -30px); }
}

.chat-phrases {
  display: flex; flex: none; gap: 6px; padding: 8px; overflow-x: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); -webkit-overflow-scrolling: touch;
}
.phrase-btn {
  flex: none; max-width: 100%; padding: 6px 10px; font-size: 13px; cursor: pointer; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14);
}
.phrase-btn:hover { background: rgba(255, 255, 255, 0.16); }
.react-tray .phrase-btn { margin: 2px; }
.reaction-bubble.phrase-bubble {
  width: max-content; max-width: 150px; font-size: 13px; font-weight: 700; line-height: 1.2; text-align: center;
  padding: 5px 10px; border-radius: 12px; background: var(--panel); color: var(--ink);
}
.reaction-bubble.floating.phrase-bubble { max-width: calc(100vw - 32px); }
.reaction-bubble.pass-bubble {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.75); color: var(--muted); white-space: nowrap;
}
.galo-banner {
  position: absolute; left: 50%; top: 42%; z-index: 7; pointer-events: none;
  font-size: clamp(34px, 9vw, 64px); font-weight: 900; letter-spacing: 0.04em; color: var(--accent);
  text-shadow: 0 4px 0 #6b4426, 0 10px 30px rgba(0, 0, 0, 0.6);
  animation: galo 2.2s cubic-bezier(.2,.8,.2,1) forwards;
}
@keyframes galo {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95); }
}
.modal:not(.hidden) .modal-card { animation: pop-in 0.3s cubic-bezier(.2,.8,.2,1); }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* Janela de confirmação */
.dialog-modal { position: fixed; z-index: 40; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
.dialog-card { width: min(380px, 100%); text-align: center; padding: 26px 22px 20px; }
.dialog-icon {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 18px; display: grid; place-items: center;
  font-size: 28px; background: rgba(242, 193, 78, 0.14); border: 1px solid rgba(242, 193, 78, 0.35);
}
.dialog-card h2 { font-size: 21px; margin: 0 0 6px; }
.dialog-card p { color: var(--muted); margin: 0 0 18px; line-height: 1.4; }
.dialog-input { width: 100%; margin: 0 0 16px; text-align: center; color: var(--ink); font-size: 14px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; white-space: nowrap; padding-left: 10px; padding-right: 10px; }
.btn.primary.danger { background: var(--danger); color: #2a0606; }
.btn.primary.danger:hover:not(:disabled) { background: #ff9696; }

.flash {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2b1d1a; color: var(--ink); border: 1px solid var(--them);
  padding: 10px 16px; border-radius: 999px; z-index: 20; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ---------- Telas pequenas ---------- */

@media (max-width: 600px) {
  .team strong { font-size: 20px; }
  .scoreboard { gap: 8px; }
  .match-info { font-size: 11px; }
  .topbar .btn.small { padding: 6px 8px; font-size: 13px; }
  .topbar .btn.icon { width: 28px; height: 28px; padding: 0; }
  .rules-body { font-size: 14px; }
  .ex-eq { margin-left: 0; padding-left: 0; width: 100%; padding-top: 6px; }
  .opponent { --u: 8px; padding: 4px; }
  .plate { max-width: 92px; padding-right: 8px; gap: 5px; }
  .plate .avatar { width: 22px; height: 22px; font-size: 11px; }
  .plate-text strong { font-size: 11px; }
  .plate-text small { font-size: 10px; }
  .opponent.active .plate small::after, .plate.active small::after { content: ''; }
  .match-info { font-size: 10px; }
  .toast { padding: 6px 12px; }
  .toast strong { font-size: 18px; }
  .status { font-size: 13px; }
  /* Mão compacta no celular: sobra mais altura para a mesa. */
  .hand { --u: 26px; gap: 8px; min-height: calc(var(--u) * 2 + 4px); padding-top: 4px; }
  .hand > .tile.back { --u: 26px; }
  .me-area { padding: 3px 10px max(5px, env(safe-area-inset-bottom)); }
  .me-bar { margin-bottom: 0; gap: 6px; }
  .me-bar .plate { padding-right: 4px; }
  .me-bar .plate .plate-text small { display: none; }
  .me-bar #sort-hand { padding: 3px 8px; font-size: 12px; }
  .status { font-size: 12px; line-height: 1.25; }
  .felt { margin: 4px; border-width: 5px; border-radius: 18px; }
  /* Celular: os três jogadores ficam na faixa de cima e a mesa usa a largura toda. Todos
     mostram só a contagem de pedras. */
  .felt {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas: "left top right" "board board board";
  }
  .opponent.left, .opponent.right { justify-content: flex-start; }
  .opponent.left { align-items: flex-start; }
  .opponent.right { align-items: flex-end; }
  .opponent { padding: 2px 4px; }
  .opponent .opp-tiles:not(.revealed) { display: none; }
  .opponent.left .opp-tiles.revealed, .opponent.right .opp-tiles.revealed { flex-direction: row; flex-wrap: wrap; --u: 11px; }
  .opponent.right .opp-tiles.revealed { justify-content: flex-end; }
  /* Os avisos ficam numa faixa fina no alto da mesa, sem cobrir as pedras. */
  #board-wrap { margin-top: 28px; }
  .ends-sum, .queue-chip { grid-area: board; top: 0; }
  .ends-sum { left: 6px; }
  .queue-chip { left: auto; right: 6px; max-width: 48%; }
  .test-notice { grid-area: board; top: auto; bottom: 52px; left: 6px; font-size: 11px; max-width: 70%; }
  .wide-only { display: none; }
  .topbar { padding-left: 6px; padding-right: 6px; gap: 4px; }
  .scoreboard { gap: 8px; }
  .team { min-width: 56px; }
  .team .label { font-size: 10px; }
  .log { display: none; } /* no celular os avisos aparecem só no centro, na hora */
  /* Chat no celular: quase a tela toda, letras e botões grandes (16px evita o zoom do iPhone) */
  /* Ocupa a parte visível da tela (acima do teclado, quando ele está aberto): --chat-top e
     --chat-height vêm do visualViewport, calculados no app.js. */
  .chat {
    left: 8px; right: 8px; width: auto; bottom: auto;
    top: calc(var(--chat-top, 0px) + max(8px, env(safe-area-inset-top)));
    height: calc(var(--chat-height, 100dvh) - max(8px, env(safe-area-inset-top)) - 8px);
  }
  body.chat-open { overflow: hidden; }
  .chat-head strong { font-size: 18px; }
  .chat-head .btn.icon { width: 40px; height: 40px; font-size: 18px; }
  #chat-list { font-size: 16px; gap: 8px; padding: 14px; }
  #chat-list .system { font-size: 14px; }
  #chat-form { padding: 10px; gap: 8px; }
  #chat-form input { font-size: 16px; padding: 12px 14px; }
  #chat-form .btn { padding: 12px 18px; font-size: 16px; }
  .chat-reactions { padding: 10px 6px; }
  .react-btn { font-size: 28px; padding: 6px 8px; }
  .topbar [data-action="chat"] { width: 36px; height: 36px; padding: 0; font-size: 19px; display: grid; place-items: center; }
  /* Botões de som, reações e chat: grandes o bastante para o dedo (36px). */
  .topbar .top-actions { gap: 6px; }
  .topbar .btn.icon { width: 36px; height: 36px; font-size: 19px; }
  .topbar .scoreboard .team { min-width: 0; }
  .topbar [data-action="chat"] .wide-only { display: none; }
  .topbar [data-action="chat"] { position: relative; border-radius: 999px; border-color: rgba(255, 255, 255, 0.18); }
  .topbar [data-action="chat"] .badge { position: absolute; top: -4px; right: -6px; margin: 0; }
  .team { min-width: 64px; }
  .team strong { font-size: 20px; }
  .wins { display: none; }
  .me-bar { grid-template-columns: auto 1fr auto; }
  .seat { width: 46%; padding: 6px 8px; gap: 6px; min-height: 48px; }
  .seat .avatar { width: 26px; height: 26px; font-size: 12px; }
  /* Sala de espera no celular: tudo cabe na tela sem rolar. */
  .lobby-body { gap: 10px; padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  .invite-card { padding: 10px 14px; border-radius: 14px; }
  .big-code { font-size: 26px; }
  .seat-table { aspect-ratio: 1.6; }
  .felt-mini { inset: 26% 24%; border-radius: 18px; }
  .seat strong { font-size: 14px; }
  .seat small { font-size: 11px; }
  .seat.top { top: 13%; }
  .seat.bottom { top: 87%; }
  .team-legend { gap: 6px; }
  .hint { font-size: 12px; line-height: 1.3; }
  .lobby-options { gap: 8px; }
  .turn-limit .seg { padding: 5px 10px; }
  #lobby .topbar .room-code { font-size: 15px; font-weight: 700; }
  .home-card { padding: 22px 16px; }
}

/* Celulares estreitos (até 380px): botões um pouco menores e placar mais justo para tudo caber. */
@media (max-width: 380px) {
  .topbar .top-actions { gap: 3px; }
  .topbar .btn.icon, .topbar [data-action="chat"] { width: 34px; height: 34px; font-size: 18px; }
  .topbar .scoreboard { gap: 5px; }
  .team .label { display: none; }
}

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