:root {
  --felt: #14452b;
  --felt-dark: #0f2a1b;
  --felt-light: #1d6a42;
  --wood: #5a3a1e;
  --gold: #e8c766;
  --paper: #f5ecd4;
  --ink: #1d1a14;
  --danger: #c0392b;
  --ok: #2e9e5b;
  --muted: #a9b8ad;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at top, #1b3d2b, var(--felt-dark) 70%);
  color: var(--paper);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 700; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

.wrap { max-width: 960px; margin: 0 auto; padding: 16px; padding-bottom: 32px; }
.narrow { max-width: 460px; }
.card {
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(232, 199, 102, .25);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.logo { font-size: 3rem; letter-spacing: .25em; text-align: center; color: var(--gold); margin: 12px 0 4px; }
.sub { text-align: center; opacity: .8; margin-bottom: 18px; }
label { display: block; margin: 10px 0 4px; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=number], input[type=tel], input[type=password], select {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #355a45;
  background: #0b1f14; color: var(--paper);
}
input:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1; }
.btn {
  padding: 12px 16px; border: 0; border-radius: 10px; font-weight: 700;
  background: var(--gold); color: var(--ink); min-height: 46px;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #2a4a38; color: var(--paper); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .9rem; }
.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.avatar-pick {
  font-size: 1.7rem; padding: 6px 0; border-radius: 10px; border: 2px solid transparent;
  background: #0b1f14; line-height: 1.2;
}
.avatar-pick[aria-pressed=true] { border-color: var(--gold); background: #24412f; }
.code-box {
  font-size: 2.4rem; letter-spacing: .3em; text-align: center; font-weight: 800;
  color: var(--gold); padding: 8px; border: 2px dashed rgba(232, 199, 102, .5); border-radius: 12px;
}
.players-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.players-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(0, 0, 0, .25); border-radius: 10px; }
.players-list .av { font-size: 1.6rem; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: #2a4a38; color: var(--paper); }
.tag.gold { background: var(--gold); color: var(--ink); }
.muted { color: var(--muted); }
.err { color: #ffb4a8; min-height: 1.2em; margin-top: 6px; }

/* senha com olho */
.pw { position: relative; }
.pw input { padding-right: 7.5rem; }
.eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: #2a4a38; color: var(--paper); border: 0; border-radius: 8px; padding: 8px 10px; font-size: .95rem; font-weight: 700;
}
.linkbtn { background: none; border: 0; color: var(--gold); text-decoration: underline; padding: 10px 0 0; font-size: 1rem; display: block; }

/* ---------- mesa ---------- */
.layout { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: 1fr 320px; align-items: start; }
}
/* tela da mesa: 3 colunas no computador (mesa | painel do jogo | chat), tudo empilhado no celular */
.wrap.wide { max-width: 1600px; }
.layout3, .col-table, .col-panel { display: grid; gap: 14px; align-content: start; }
.col-table, .col-panel { min-width: 0; }
@media (min-width: 1000px) {
  .layout3 { grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr) 300px; align-items: start; }
  .col-table .table-wrap { max-height: 82vh; }
  .layout3 .chat { height: min(520px, 80vh); position: sticky; top: 16px; }
}
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.table-wrap { position: relative; width: 100%; aspect-ratio: 1.45 / 1; max-height: 70vh; }
.table {
  position: absolute; inset: 9% 6%;
  background: radial-gradient(ellipse at center, var(--felt-light), var(--felt) 70%);
  border: 10px solid var(--wood); border-radius: 50%;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .55), 0 8px 24px rgba(0, 0, 0, .5);
  display: grid; place-items: center; text-align: center; padding: 10%;
}
.center-info .bid { font-size: clamp(1.3rem, 5vw, 2.2rem); font-weight: 800; color: var(--gold); line-height: 1.1; }
.center-info .small { font-size: clamp(.7rem, 2.4vw, .95rem); opacity: .9; }
.seat {
  position: absolute; transform: translate(-50%, -50%);
  width: clamp(70px, 17vw, 112px); text-align: center;
  background: rgba(10, 25, 17, .92); border: 2px solid #355a45; border-radius: 12px; padding: 4px 4px 5px;
}
.seat.current { border-color: var(--gold); box-shadow: 0 0 14px rgba(232, 199, 102, .8); }
.seat.dead { opacity: .4; filter: grayscale(1); }
.seat.me { border-color: #6fcf97; }
.seat .av { font-size: clamp(1.3rem, 5vw, 1.9rem); line-height: 1.1; }
.seat .nm { font-size: clamp(.68rem, 2.3vw, .85rem); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .lv { font-size: clamp(.6rem, 2vw, .8rem); letter-spacing: -1px; }
.seat .mk { font-size: .62rem; color: var(--muted); }

.mine { text-align: center; }
.dice { display: flex; gap: 6px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
/* Dados: pintas vermelhas grandes, quase até a borda; o 1 mostra o Ás do baralho (pensado para ler de longe) */
.die {
  --pip: #d10a1f;
  --d: clamp(52px, 15vw, 68px);
  width: var(--d); height: var(--d); font-size: var(--d);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 4px; margin: 0;
  background: #fff; border: 4px solid #cfc7b2; border-radius: 14px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, .5);
}
.die:disabled { opacity: 1; cursor: default; }
.die .pip { background: var(--pip); border-radius: 50%; width: 92%; height: 92%; place-self: center; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18); }
.die .ace {
  grid-area: 1 / 1 / 4 / 4; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--pip); font-family: Georgia, "Times New Roman", serif; font-weight: 900; line-height: .9;
}
.die .ace .a { font-size: .56em; }
.die .ace .s { font-size: .46em; }
.die.shown { border-color: var(--gold); }
.die.keep { border-color: var(--ok); background: #d8f5e1; }
.die.small { width: 46px; height: 46px; font-size: 46px; padding: 3px; border-width: 3px; border-radius: 10px; }
.die.tiny { width: 30px; height: 30px; font-size: 30px; padding: 2px; border-width: 2px; border-radius: 6px; box-shadow: none; }
.die.mini { width: 40px; height: 40px; font-size: 40px; padding: 2px; border-width: 2px; border-radius: 8px; box-shadow: none; }
/* dados abertos: na frente do copo, entre a cadeira e o centro da mesa */
.front {
  position: absolute; transform: translate(-50%, -50%); z-index: 2;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 26%;
}
.front .die { --d: clamp(22px, 6.4vw, 38px); width: var(--d); height: var(--d); font-size: var(--d); border-color: var(--gold); }
.totals h3 { font-size: 1.05rem; }
.tot-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.tot { background: rgba(255, 255, 255, .06); border: 2px solid transparent; border-radius: 10px; padding: 6px 4px; text-align: center; }
.tot.current { border-color: var(--gold); background: rgba(232, 199, 102, .14); }
.tot .l { font-size: .85rem; color: var(--muted); }
.tot .n { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.tot .b { font-size: .78rem; min-height: 1em; opacity: .9; }
.timer { font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.low { color: #ff8a7a; }
.faces { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.face-btn {
  padding: 6px 0; border-radius: 10px; border: 2px solid #355a45; background: #0b1f14; color: var(--paper); line-height: 1.1;
}
.face-btn .d { display: flex; justify-content: center; margin-bottom: 2px; }
.face-btn .t { font-size: .72rem; display: block; }
.face-btn[aria-pressed=true] { border-color: var(--gold); background: #2d4d37; }
.stepper { display: flex; align-items: center; gap: 10px; justify-content: center; margin: 6px 0; }
.stepper .qty { font-size: 1.8rem; font-weight: 800; min-width: 2.5ch; text-align: center; }
.stepper .btn { min-width: 52px; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 8px; }
.waiting-note { text-align: center; padding: 8px; opacity: .85; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 340px; }
.chat h3 { font-size: 1rem; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px; }
.msg { background: rgba(255, 255, 255, .07); border-radius: 10px; padding: 6px 9px; font-size: .92rem; word-wrap: break-word; overflow-wrap: anywhere; }
.msg b { color: var(--gold); }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.chat-form input { flex: 1; }
.chat-form .btn { flex: 0 0 auto; }

/* ---------- resultado ---------- */
.overlay { border: 2px solid var(--gold); background: rgba(0, 0, 0, .55); }
.revealed { display: grid; gap: 6px; margin: 8px 0; }
.revealed .r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.revealed .who { min-width: 8ch; font-weight: 700; }
.delta { font-weight: 800; }
.delta.pos { color: #7be3a4; }
.delta.neg { color: #ff9a8b; }
.podium li { font-size: 1.05rem; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(30px);
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 999px; max-width: 90vw;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--danger); }

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

/* Escolha do sentido da mesa (quem abre a rodada) */
.dir-choice { margin: 8px 0; padding: 10px; border: 2px solid var(--gold, #e8c766); border-radius: 12px; background: rgba(0,0,0,.25); }
.dir-title { margin: 0 0 8px; font-weight: 700; text-align: center; }
.dir-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dir-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 64px; padding: 8px; border-radius: 12px; border: 2px solid #5a8a6e; background: #1f3a2b; color: #fff; font-size: 1rem; font-weight: 700; cursor: pointer; }
.dir-btn .dir-arrow { font-size: 1.8rem; line-height: 1; }
.dir-btn.on { background: #e8c766; color: #1a2a20; border-color: #fff3c4; }
.dir-btn:hover { filter: brightness(1.1); }

/* Resumo das vidas (canto esquerdo) e sentido da mesa, visíveis para todos */
.top-bar { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.life-summary { min-width: 170px; max-width: 60%; padding: 8px 10px; border-radius: 12px; background: rgba(0,0,0,.3); border: 1px solid #3f6a52; }
.ls-title { font-weight: 800; font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px; }
.ls-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 2px 4px; border-radius: 6px; font-size: .9rem; }
.ls-row.turn { background: rgba(232,199,102,.22); }
.ls-row.out { opacity: .5; text-decoration: line-through; }
.ls-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ls-hearts { letter-spacing: -1px; white-space: nowrap; }
.dir-badge { display: flex; flex-direction: column; align-items: center; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--gold); background: rgba(0,0,0,.3); text-align: center; }
.db-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--paper); }
.db-value { font-size: 1.15rem; font-weight: 800; color: var(--gold); }

/* Conferência do resultado: quem já clicou Pronto */
.ready-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.ready-chip { padding: 4px 10px; border-radius: 999px; border: 1px solid #5a8a6e; background: #1f3a2b; font-weight: 700; font-size: .9rem; }
.ready-chip.ok { background: #2f7a4d; border-color: #7bd39b; }

/* Resumo explícito do resultado do DUDO */
.res-summary { display: grid; gap: 6px; margin: 8px 0; padding: 12px; border-radius: 12px; border: 2px solid var(--gold); background: rgba(0,0,0,.3); }
.res-line { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; font-size: 1.05rem; }
.res-k { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #b9c9bd); }
.res-big { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: 1.9rem; line-height: 1.1; color: var(--gold); }
.res-sub { font-size: .95rem; }
.res-win, .res-lose { padding: 8px 10px; border-radius: 8px; font-weight: 800; font-size: 1.1rem; }
.res-win { background: #2f7a4d; color: #fff; }
.res-lose { background: #9b2335; color: #fff; }
.die.counted { outline: 3px solid var(--gold); outline-offset: 1px; }
.die.ignored { opacity: .35; }

/* Resultado do DUDO: tabela, dados dourados caindo em pilhas e soma */
.die.counted { background: linear-gradient(#ffe9a0, #e8c766); border-color: #b8902e; outline: none; box-shadow: 0 0 10px rgba(232,199,102,.8), 0 3px 6px rgba(0,0,0,.5); }
.die.ignored { opacity: .3; }
.conf-table .r { display: flex; align-items: center; gap: 8px; }
.n-badge { margin-left: auto; min-width: 2ch; text-align: center; padding: 2px 8px; border-radius: 999px; background: #e8c766; color: #1a2a20; font-weight: 800; }
.pile { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 10px; margin-top: 4px; border-top: 3px solid #b8902e; background: rgba(0,0,0,.25); border-radius: 0 0 10px 10px; min-height: 70px; }
.pile-col { display: grid; gap: 4px; justify-items: center; }
.pile-head { font-size: .8rem; font-weight: 800; color: var(--gold); }
.pile-dice { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 220px; }
.die.tiny.fall { animation: dieFall .75s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes dieFall {
  0% { transform: translateY(-190px) rotate(-30deg) scale(1.2); opacity: 0; }
  35% { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
.res-tally { animation: tallyIn .5s ease-out both; display: grid; gap: 6px; }
@keyframes tallyIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .die.tiny.fall, .res-tally { animation: none; }
}

/* A escolha do sentido pisca de leve para não passar despercebida */
.dir-choice { animation: dirPulse 1.6s ease-in-out 3; }
@keyframes dirPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(232,199,102,0); } 50% { box-shadow: 0 0 0 6px rgba(232,199,102,.55); } }
@media (prefers-reduced-motion: reduce) { .dir-choice { animation: none; } }

/* Sentido da mesa para todos: escolhido em verde, abandonado em vermelho */
.dir-choice { animation: none; }
.dir-choice.can { animation: dirPulse 1.6s ease-in-out 3; }
.dir-btn.on { background: #2f8f55; border-color: #8be0ad; color: #fff; }
.dir-btn.off { background: #8f2434; border-color: #e07a89; color: #ffe3e7; opacity: .85; }
.dir-btn:disabled { cursor: default; }
.dir-btn:not(:disabled):hover { filter: brightness(1.12); }

/* Dados da mão: os que ficaram à vista na mesa ficam bem dourados */
.die.shown { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,199,102,.6), 0 3px 6px rgba(0,0,0,.5); }
.hand-count { margin: 4px 0 0; font-size: .9rem; font-weight: 700; color: var(--gold); }

/* Mao dividida: dados a vista na mesa x dados escondidos no copo */
.hand-group { margin: 6px 0; padding: 6px 8px; border-radius: 10px; }
.hand-group .dice { margin: 4px 0 0; }
.hand-group.on-table { border: 2px solid #d4af37; background: rgba(212,175,55,.10); }
.hand-group.in-cup { border: 2px dashed #7a7f8a; background: rgba(0,0,0,.18); }
.hand-label { margin: 0; font-size: .85rem; font-weight: 700; }
.hand-group.on-table .hand-label { color: #d4af37; }
.hand-group.in-cup .hand-label { color: #b8bcc6; }
.hand-group .die.shown { box-shadow: none; }

/* Sorteio de quem começa */
.draw { margin: 0; border: 2px solid var(--gold); }
.draw summary { cursor: pointer; font-weight: 800; }
.draw-round { display: grid; gap: 4px; margin: 8px 0; }
.draw-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 6px; border-radius: 8px; border: 1px solid transparent; }
.draw-row.best { border-color: var(--gold); background: rgba(232,199,102,.12); }
.draw-row .who { min-width: 8ch; font-weight: 700; }
.draw .res-win { margin-bottom: 8px; }
.draw-in { animation: tallyIn .4s ease-out both; }
@media (prefers-reduced-motion: reduce) { .draw-in { animation: none; } }

/* Copo de couro: esconde os dados; inclina para tras enquanto o dedo ou o mouse esta nele */
.cup-box { text-align: center; }
.cup-hint { margin: 0 0 4px; font-size: .85rem; }
.cup-hit { position: relative; width: 280px; max-width: 100%; aspect-ratio: 3 / 2; margin: 0 auto; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.cup-art, .cup-art svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.cup-hit .cup-dice { position: absolute; inset: 0; display: block; margin: 0; visibility: hidden; pointer-events: none; }
.cup-hit.seen .cup-dice { visibility: visible; }
.cup-hit .cup-dice .die { position: absolute; width: 10%; height: 15%; min-width: 0; font-size: 19px; padding: 1px; border-width: 2px; border-radius: 6px; box-shadow: none; opacity: 1; }
.cup-hit .cup-dice .die:nth-child(1) { left: 22.7%; top: 73.5%; }
.cup-hit .cup-dice .die:nth-child(2) { left: 33.8%; top: 72%; }
.cup-hit .cup-dice .die:nth-child(3) { left: 45%; top: 71%; }
.cup-hit .cup-dice .die:nth-child(4) { left: 56.2%; top: 72%; }
.cup-hit .cup-dice .die:nth-child(5) { left: 67.3%; top: 73.5%; }
.cup-hit .cup-dice .die { grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr)); }
.cup-hit .cup-dice .die .pip { width: 6px; height: 6px; box-shadow: none; }
.cup-hit .cup-dice .die .ace { line-height: 1; }

/* relatórios de desempenho */
.highlights { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.highlight { display: grid; gap: 4px; align-content: start; padding: 10px; border-radius: 10px; background: rgba(0, 0, 0, .28); border: 1px solid rgba(232, 199, 102, .25); font-size: .9rem; overflow-wrap: anywhere; }
.highlight strong { font-size: 1.05rem; color: var(--gold); }
.rank-row { background: rgba(0, 0, 0, .25); border-radius: 10px; margin-top: 8px; }
.rank-row summary { display: flex; align-items: center; gap: 10px; padding: 10px; cursor: pointer; }
.rank-row .av { font-size: 1.5rem; }
.rank-row .who { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; padding: 4px 12px 12px; font-size: .9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.months { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .85rem; }
.months th, .months td { padding: 6px 4px; text-align: right; border-bottom: 1px solid rgba(232, 199, 102, .15); }
.months th:first-child, .months td:first-child { text-align: left; }
