:root {
  --felt: #0f3d2e;
  --felt-2: #145a43;
  --ink: #f4f1e8;
  --muted: #b9c9bf;
  --panel: rgba(0, 0, 0, .28);
  --accent: #ffd34d;
  --r: #e2403a;
  --y: #f2b81c;
  --g: #2fa651;
  --b: #2f6fd8;
  --k: #1d1d24;
  /* Largura da carta: escala com a tela, limitada também pela altura (paisagem). */
  --cw: clamp(48px, min(17vw, 12vh), 104px);
  --ch: calc(var(--cw) * 1.48);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 40%, var(--felt-2), var(--felt) 70%);
  background-color: var(--felt);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- topo */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; gap: 8px;
}
.topbar h1 { margin: 0; font-size: clamp(16px, 4.5vw, 22px); letter-spacing: .5px; }
.topbar h1 span { color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.pill { font-size: 13px; color: var(--muted); background: var(--panel); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.icon-btn { background: var(--panel); border: 0; border-radius: 10px; width: 40px; height: 40px; font-size: 18px; }

/* ---------------------------------------------------------------- mesa */
.table {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: 0 16px 8px;
  gap: 6px;
}

.opponents { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.opp {
  background: var(--panel); border-radius: 14px; padding: 6px 10px 8px;
  min-width: 92px; text-align: center; border: 2px solid transparent;
  transition: border-color .2s, transform .2s;
}
.opp.turn { border-color: var(--accent); transform: translateY(2px); }
.opp .name { font-size: 13px; color: var(--muted); }
.opp .count { font-size: 20px; font-weight: 700; }
.opp .mini { display: flex; justify-content: center; height: 22px; margin-top: 2px; }
.opp .mini i {
  width: 14px; height: 20px; border-radius: 3px; margin-left: -7px;
  background: var(--k); border: 1.5px solid var(--ink);
}
.opp .mini i:first-child { margin-left: 0; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; background: var(--accent); color: #222; border-radius: 6px; padding: 1px 6px; margin-top: 3px; }

.center {
  display: flex; align-items: center; justify-content: center;
  gap: clamp(16px, 6vw, 48px); position: relative; min-height: calc(var(--ch) + 20px);
}
.pile { background: none; border: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pile small { color: var(--muted); font-size: 12px; }
.pile.can .card { box-shadow: 0 0 0 3px var(--accent), 0 6px 14px rgba(0,0,0,.4); }
.discard { position: relative; width: var(--cw); height: var(--ch); }
.discard .card { position: absolute; inset: 0; animation: drop .25s ease-out; }
@keyframes drop { from { transform: translateY(-30px) scale(1.1); opacity: 0; } }
.color-dot { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--ink); box-shadow: 0 0 12px currentColor; }
.dir { position: absolute; font-size: 28px; opacity: .25; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(4); pointer-events: none; }

.status { margin: 0; text-align: center; min-height: 1.4em; font-size: clamp(14px, 3.8vw, 17px); }

/* ---------------------------------------------------------------- mão */
.me { background: var(--panel); border-radius: 16px; padding: 8px 8px 10px; }
.me.turn { box-shadow: 0 0 0 2px var(--accent); }
.me-bar { display: flex; align-items: center; gap: 8px; padding: 0 4px 6px; }
.me-name { flex: 1; font-weight: 600; }
.hand {
  display: flex; justify-content: safe center; overflow-x: auto; overflow-y: visible;
  padding: 14px 8px 4px; scrollbar-width: thin;
}
.hand .card { flex: none; margin-left: calc(var(--cw) * -0.38); transition: transform .15s; }
.hand .card:first-child { margin-left: 0; }
.hand .card.ok { transform: translateY(-12px); cursor: pointer; }
.hand .card.ok:hover, .hand .card.ok:focus-visible { transform: translateY(-20px); outline: none; z-index: 2; }
.hand .card.no { filter: brightness(.55) saturate(.7); opacity: .8; }
.hand.idle .card.no { filter: none; }

/* ---------------------------------------------------------------- cartas (desenho original) */
.card {
  width: var(--cw); height: var(--ch);
  border-radius: calc(var(--cw) * .12);
  background: var(--c, var(--k));
  border: calc(var(--cw) * .05) solid #fff;
  box-shadow: 0 4px 10px rgba(0,0,0,.4);
  position: relative; overflow: hidden;
  display: grid; place-items: center;
  color: #fff; font-weight: 800;
}
.card::before { /* faixa diagonal decorativa */
  content: ""; position: absolute; width: 140%; height: 46%;
  background: rgba(255,255,255,.92); transform: rotate(-28deg); border-radius: 50%;
}
.card .big {
  position: relative; font-size: calc(var(--cw) * .44); color: var(--c, var(--k));
  text-shadow: 1px 1px 0 rgba(0,0,0,.25); line-height: 1;
}
.card .tl, .card .br { position: absolute; font-size: calc(var(--cw) * .2); line-height: 1; }
.card .tl { top: 6%; left: 9%; }
.card .br { bottom: 6%; right: 9%; transform: rotate(180deg); }
.card.c-r { --c: var(--r); } .card.c-y { --c: var(--y); }
.card.c-g { --c: var(--g); } .card.c-b { --c: var(--b); }
.card.c-k { --c: var(--k); }
.card.c-k::before {
  background: conic-gradient(var(--r) 0 25%, var(--y) 0 50%, var(--g) 0 75%, var(--b) 0);
  width: 70%; height: 52%; transform: rotate(-28deg);
}
.card.c-k .big { color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,.6); }
.card.back { background: var(--k); }
.card.back::before { background: var(--r); width: 80%; height: 50%; }
.card.back span { position: relative; font-size: calc(var(--cw) * .28); color: var(--accent); text-shadow: 0 2px 2px rgba(0,0,0,.5); transform: rotate(-28deg); }

/* ---------------------------------------------------------------- botões e diálogos */
.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600;
  background: rgba(255,255,255,.14); min-height: 40px;
}
.btn.primary { background: var(--accent); color: #222; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.3); }
.btn.last[aria-pressed="true"] { background: var(--accent); color: #222; box-shadow: 0 0 12px var(--accent); }

.dlg {
  border: 0; border-radius: 18px; padding: 20px; width: min(92vw, 420px);
  background: #183a2f; color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.dlg::backdrop { background: rgba(0,0,0,.55); }
.dlg h2 { margin: 0 0 14px; font-size: 20px; }
.dlg label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.dlg select { font: inherit; padding: 6px 8px; border-radius: 8px; background: #0f2b22; color: var(--ink); border: 1px solid rgba(255,255,255,.25); }
.dlg .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.rules { font-size: 14px; color: var(--muted); }
.rules summary { cursor: pointer; color: var(--ink); }
.rules ul { padding-left: 18px; margin: 8px 0 0; }
.rules li { margin-bottom: 4px; }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.cbtn { height: 72px; border-radius: 14px; border: 3px solid #fff; }
.cbtn.r { background: var(--r); } .cbtn.y { background: var(--y); }
.cbtn.g { background: var(--g); } .cbtn.b { background: var(--b); }
.scores { width: 100%; border-collapse: collapse; }
.scores td { padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,.1); }
.scores td:last-child { text-align: right; font-weight: 700; }
.scores tr.win td { color: var(--accent); }

/* ---------------------------------------------------------------- online: sala, chat, balões */
.net { font-size: 12px; }
body:not(.online) .net, .net[data-st=""] { display: none; }
.net[data-st="online"] { color: #8be3a8; }
.net[data-st="offline"] { color: #ff9b8f; }

.table { position: relative; }
.opp { position: relative; }
.opp.away { opacity: .6; }
.bubble {
  position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: #fffdf5; color: #1d1d24; border-radius: 12px; padding: 6px 10px;
  font-size: 13px; font-weight: 600; width: max-content; max-width: min(220px, 60vw);
  white-space: normal; z-index: 6; box-shadow: 0 6px 18px rgba(0,0,0,.45); animation: pop .2s ease-out;
}
.bubble::before { content: ""; position: absolute; top: -6px; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top: 0; border-bottom-color: #fffdf5; }
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }

.room-panel {
  position: absolute; inset: 8px 16px; margin: auto; height: fit-content; max-height: calc(100% - 16px);
  overflow: auto; max-width: 440px; z-index: 5; background: #183a2f; border-radius: 18px;
  padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.room-panel[hidden] { display: none; }
.room-panel h2 { margin: 0 0 6px; font-size: 20px; }
.room-panel h3 { margin: 14px 0 6px; font-size: 15px; }
.room-panel label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.room-panel select, .dlg input, .share input {
  font: inherit; font-size: 16px; padding: 7px 10px; border-radius: 8px; background: #0f2b22; color: var(--ink);
  border: 1px solid rgba(255,255,255,.25); min-width: 0;
}
.room-players { list-style: none; padding: 0; margin: 0; }
.room-players li { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.room-players small { color: var(--muted); }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 3px; color: var(--accent); }
.dlg input.code-in { text-transform: uppercase; letter-spacing: 3px; width: 9ch; }
.share { display: flex; gap: 8px; }
.share input { flex: 1; font-size: 13px; }
.sub { color: var(--muted); font-size: 14px; margin: 6px 0; }
.tc { text-align: center; }
.err { color: #ff9b8f; min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.dlg input { width: 58%; }
.dlg hr { border: 0; border-top: 1px solid rgba(255,255,255,.14); margin: 16px 0; }
.row.split .btn { flex: 1; }
.room-panel .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* Chat: no celular fica preso embaixo (recolhível); em telas largas, coluna à direita. */
.side { flex: none; display: flex; flex-direction: column; min-height: 0; }
.chat { display: flex; flex-direction: column; min-height: 0; background: rgba(0,0,0,.34); border-top: 1px solid rgba(255,255,255,.12); }
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px 4px 14px; }
.chat-title { white-space: nowrap; font-size: 13px; color: var(--muted); }
.chat-title b { color: var(--accent); letter-spacing: 1px; }
.chat.unread .chat-title::after { content: " ●"; color: var(--accent); }
.chat-last {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; color: var(--ink);
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; visibility: hidden;
}
.chat-last b { color: var(--accent); margin-right: 6px; }
body.chat-min .chat-last { visibility: visible; }
body.chat-min .chat-list, body.chat-min .chat-quick { display: none; }
.mini-btn { background: rgba(255,255,255,.1); border: 0; border-radius: 8px; width: 34px; height: 30px; font-size: 15px; flex: none; }
.chat-list { list-style: none; margin: 0; padding: 4px 14px; overflow-y: auto; height: 26vh; min-height: 70px; user-select: text; -webkit-user-select: text; }
.msg { margin: 0 0 6px; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.msg b { color: var(--accent); margin-right: 6px; }
.msg.mine b { color: #9fd3ff; }
.msg.sys { color: var(--muted); font-style: italic; font-size: 12px; }
.msg audio { display: block; height: 34px; width: 100%; max-width: 280px; margin-top: 3px; }
.snd { cursor: pointer; background: rgba(255,255,255,.1); border-radius: 8px; padding: 1px 7px; }
.chat-quick { padding: 0 6px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 3px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; background: rgba(255,255,255,.12); border: 0; border-radius: 99px; padding: 6px 11px; font-size: 13px; }
.chip:active { transform: scale(.94); }
.chips.sounds .chip { font-size: 19px; padding: 3px 9px; }
.chat-form { display: flex; gap: 6px; padding: 6px 8px 8px; align-items: center; }
.chat-form[hidden] { display: none; }
.chat-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 9px 14px; border-radius: 99px;
  border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.3); color: var(--ink);
}
.mic, .send { flex: none; width: 42px; height: 42px; min-height: 0; border-radius: 50%; border: 0; padding: 0; font-size: 18px; }
.mic { background: rgba(255,255,255,.14); }
.mic.off { opacity: .45; }
.rec { display: flex; align-items: center; gap: 8px; padding: 6px 10px 10px; font-size: 14px; }
.rec[hidden] { display: none; }
.rec-txt { flex: 1; color: var(--muted); }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #ff4d4d; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* Histórico de jogadas: escondido em telas pequenas, coluna lateral em telas largas. */
.log { display: none; }
@media (min-width: 1000px) and (min-height: 600px) {
  body { display: grid; grid-template-columns: 1fr 270px; grid-template-rows: auto 1fr; }
  body.online { grid-template-columns: 1fr 360px; }
  .topbar { grid-column: 1 / -1; }
  .side { margin: 0 16px 16px 0; gap: 12px; }
  .chat { flex: 1 1 65%; border: 0; border-radius: 14px; background: var(--panel); }
  .chat-list { height: auto; flex: 1; }
  body.chat-min .chat { flex: none; }
  .log {
    display: block; flex: 1 1 35%; margin: 0; padding: 10px 14px 10px 30px; min-height: 0;
    background: var(--panel); border-radius: 14px; overflow-y: auto;
    font-size: 13px; color: var(--muted); list-style: decimal;
  }
  body:not(.online) .log { flex: 1; }
  .log li { margin-bottom: 4px; }
}
/* Paisagem baixa (celular deitado): compacta a mesa. */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { padding: 4px 16px; }
  .opp { padding: 2px 8px; min-width: 70px; }
  .opp .mini { display: none; }
  .me-bar { padding-bottom: 2px; }
  .hand { padding-top: 12px; }
  .chat-list { height: 22vh; }
  .chat-quick .chips:first-child { display: none; }
}

/* Celular em pé com o chat aberto: compacta a mesa para tudo caber. */
.topbar h1 { white-space: nowrap; }
@media (max-width: 999px) {
  body.online .table { overflow: hidden; }
  body.online:not(.chat-min) { --cw: clamp(42px, min(15vw, 8vh), 80px); }
  body.online:not(.chat-min) .opp .mini { display: none; }
  body.online:not(.chat-min) .chat-list { height: 16vh; }
  body.online:not(.chat-min) .hand { padding-top: 10px; }
}
@media (max-width: 999px) and (max-height: 740px) {
  body.online:not(.chat-min) .chat-quick .chips:first-child { display: none; }
}
@media (max-width: 420px) {
  .topbar { padding: 8px 12px; }
  .pill { padding: 4px 8px; font-size: 12px; }
  .icon-btn { width: 36px; height: 36px; }
}
/* Online antes de a partida começar: só a sala de espera (e o chat). */
body.no-game .table > :not(.room-panel):not(.status) { visibility: hidden; }
body.no-game #round-info { display: none; }

/* Modo zueira e placar por rodada */
.zueira-opt { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.dlg label.check { display: flex; align-items: center; gap: 8px; justify-content: flex-start; margin: 0; }
.dlg label.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.dlg label.check small { color: var(--muted); }
.zueira-list { list-style: none; padding: 0; margin: 8px 0; max-height: 55vh; overflow-y: auto; }
.zueira-list li { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.zq { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.zrow { display: flex; gap: 6px; align-items: center; }
.dlg .zrow input { flex: 1; width: auto; font-size: 15px; padding: 6px 9px; }
.zinfo { font-size: 12px; color: var(--muted); margin-top: 3px; }
.mini-btn.rec-on { background: #c33; animation: blink 1s infinite; }
.mini-btn[disabled] { opacity: .4; }
.scores.rounds { margin-top: 12px; font-size: 14px; }
.scores.rounds caption { text-align: left; color: var(--muted); font-size: 13px; padding-bottom: 4px; }
.scores.rounds td { padding: 5px 4px; color: var(--muted); }
