:root {
  --felt: #12633f;
  --felt-dark: #0a3d27;
  --wood: #5a3418;
  --gold: #f4c542;
  --red: #c8102e;
  --ink: #1b1b1b;
  --you: #3ddc84;
  --bot: #ff6b6b;
  --cw: clamp(62px, 17vw, 96px);
  --ch: calc(var(--cw) * 1.42);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 30%, #1d1d1d, #050505);
  color: #fff;
  overflow: hidden;
}

#app {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ---------- topo ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}
.topbar h1 { margin: 0; font-size: 1.1rem; letter-spacing: .04em; }
.topbar h1 span { color: var(--gold); }

.scoreboard { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.team { display: flex; align-items: center; gap: 6px; }
.team .label { font-size: .8rem; opacity: .8; }
.team .pts {
  min-width: 2ch; text-align: center; font-size: 1.4rem;
  padding: 2px 8px; border-radius: 8px; background: #ffffff14;
}
.team.you .pts { color: var(--you); }
.team.bot .pts { color: var(--bot); }
.vs { opacity: .5; }

.stake {
  font-size: .85rem; padding: 4px 10px; border-radius: 999px;
  background: #ffffff14; transition: background .3s, color .3s;
}
.stake strong { font-size: 1.1rem; }
.stake.hot { background: var(--gold); color: var(--ink); }

/* ---------- mesa ---------- */
.table {
  position: relative;
  flex: 1;
  margin: 0 10px;
  border-radius: 28px;
  border: 10px solid var(--wood);
  background:
    radial-gradient(ellipse at center, #1a7a4f 0%, var(--felt) 45%, var(--felt-dark) 100%);
  box-shadow: inset 0 0 60px #0008, 0 10px 40px #000a;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 8px;
  min-height: 0;
}

.seat { position: relative; display: flex; justify-content: center; align-items: center; gap: 10px; }
.avatar { font-size: 1.8rem; filter: drop-shadow(0 2px 4px #0006); }

.hand { display: flex; justify-content: center; gap: 8px; min-height: var(--ch); }
.hand.opponent { --cw: clamp(44px, 12vw, 64px); }
.hand.opponent .card:nth-child(1) { rotate: -6deg; }
.hand.opponent .card:nth-child(3) { rotate: 6deg; }

.center { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }

.deck-area { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.deck {
  width: calc(var(--cw) * .7); height: calc(var(--ch) * .7);
  border-radius: 8px;
  background: repeating-linear-gradient(45deg, #8b1e2d 0 6px, #a8293a 6px 12px);
  border: 3px solid #fff;
  box-shadow: 2px 2px 0 #ddd, 4px 4px 0 #bbb, 6px 6px 10px #0007;
}
.vira-slot { min-height: calc(clamp(44px, 12vw, 64px) * 1.42); }
.vira-slot .card { --cw: clamp(44px, 12vw, 64px); rotate: -8deg; }
.manilha-info { font-size: .75rem; opacity: .9; text-align: center; }
.manilha-info strong { color: var(--gold); font-size: 1rem; }

.play-area { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.slot {
  width: var(--cw); height: var(--ch);
  border-radius: 10px; border: 2px dashed #ffffff30;
}

.rounds { display: flex; flex-direction: column; gap: 8px; }
.rounds span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #ffffff60; background: transparent;
  transition: background .3s, border-color .3s;
}
.rounds span.you { background: var(--you); border-color: var(--you); }
.rounds span.bot { background: var(--bot); border-color: var(--bot); }
.rounds span.tie { background: #bbb; border-color: #bbb; }

/* ---------- cartas ---------- */
.card {
  width: var(--cw); height: var(--ch);
  perspective: 800px;
  flex: none;
  transition: translate .2s ease, filter .3s;
  border-radius: 10px;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.3,.7,.3,1);
}
.card.face-down .card-inner { transform: rotateY(180deg); }

.card-front, .card-back {
  position: absolute; inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  box-shadow: 0 3px 8px #0007;
}
.card-front {
  background: linear-gradient(160deg, #fff, #f1ece1);
  color: var(--ink);
  border: 1px solid #0002;
}
.card.red .card-front { color: var(--red); }
.card-back {
  transform: rotateY(180deg);
  border: 3px solid #fff;
  background: repeating-linear-gradient(45deg, #8b1e2d 0 6px, #a8293a 6px 12px);
}

.corner {
  position: absolute; display: flex; flex-direction: column; align-items: center;
  font-weight: 800; line-height: 1; font-size: calc(var(--cw) * .22);
}
.corner small { font-size: .8em; }
.corner.top { top: 5px; left: 6px; }
.corner.bottom { bottom: 5px; right: 6px; transform: rotate(180deg); }
.pip {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--cw) * .5);
}

.card.manilha .card-front::after {
  content: "★";
  position: absolute; top: 4px; right: 6px;
  color: var(--gold); font-size: calc(var(--cw) * .2);
  text-shadow: 0 0 4px #b8860b;
}

.hand.player.my-turn .card.playable { cursor: pointer; }
.hand.player.my-turn .card.playable:hover,
.hand.player.my-turn .card.playable:focus-visible { translate: 0 -14px; outline: none; }
.hand.player.my-turn .card.playable:focus-visible .card-front { box-shadow: 0 0 0 3px var(--gold); }
.hand.player.my-turn { animation: glow 1.6s ease-in-out infinite; border-radius: 14px; }

.card.winner .card-front { animation: winner 1s ease-in-out infinite alternate; }
.card.loser { filter: brightness(.55) saturate(.5); }
.card.tie { filter: grayscale(.6); }

@keyframes glow {
  50% { box-shadow: 0 0 22px 2px #f4c54255; }
}
@keyframes winner {
  from { box-shadow: 0 0 0 2px var(--gold), 0 0 10px var(--gold); }
  to { box-shadow: 0 0 0 3px var(--gold), 0 0 28px var(--gold); }
}

/* ---------- falas e avisos ---------- */
.bubble {
  position: absolute; left: 50%; z-index: 5;
  padding: 6px 12px; border-radius: 14px;
  background: #fff; color: var(--ink); font-weight: 800;
  white-space: nowrap; pointer-events: none;
  opacity: 0; translate: -50% 0; scale: .5;
  transition: opacity .2s, scale .25s cubic-bezier(.3,1.6,.5,1);
}
.seat-bot .bubble { top: 100%; }
.seat-you .bubble { bottom: 100%; }
.bubble.show { opacity: 1; scale: 1; }

.shout {
  position: fixed; inset: 0; display: grid; place-items: center;
  pointer-events: none; z-index: 20;
  font-size: clamp(3rem, 14vw, 6rem); font-weight: 900; letter-spacing: .04em;
  color: var(--gold);
  text-shadow: 0 0 2px #000, 4px 4px 0 var(--red), 0 0 40px #000;
  opacity: 0;
}
.shout.show { animation: shout .9s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes shout {
  0% { opacity: 0; transform: scale(.2) rotate(-12deg); }
  35% { opacity: 1; transform: scale(1.15) rotate(3deg); }
  70% { opacity: 1; transform: scale(1) rotate(0); }
  100% { opacity: 0; transform: scale(1.3); }
}

.toast {
  position: fixed; left: 50%; bottom: 90px; z-index: 15;
  translate: -50% 20px; opacity: 0;
  padding: 10px 18px; border-radius: 999px;
  background: #000c; font-weight: 600;
  transition: opacity .25s, translate .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; translate: -50% 0; }

/* ---------- botões ---------- */
.actions { display: flex; justify-content: center; padding: 14px; }
.btn {
  font: inherit; font-weight: 800; cursor: pointer;
  border: none; border-radius: 12px; padding: 12px 26px;
  transition: transform .1s, filter .2s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.95); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary { background: var(--you); color: var(--ink); }
.btn-truco {
  background: linear-gradient(180deg, #ffd65a, #e0a800);
  color: #4a1500; font-size: 1.2rem; letter-spacing: .06em;
  box-shadow: 0 4px 0 #9a6b00;
}
.btn-truco:not(:disabled):hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: #fff; border: 2px solid #ffffff60; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 20px;
  background: #000b; backdrop-filter: blur(3px);
  animation: fade .25s ease;
}
.panel {
  background: linear-gradient(180deg, #1f2a24, #121815);
  border: 1px solid #ffffff20; border-radius: 20px;
  padding: 24px; max-width: 420px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px #000c;
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
.panel h2 { margin: 0 0 8px; }
.panel .logo { font-size: 3rem; }
.rules { text-align: left; padding-left: 18px; line-height: 1.5; font-size: .92rem; opacity: .9; }
.choices { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
#gameover.won .title { color: var(--gold); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

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

/* ---------- modos ---------- */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 4px; }
.mode {
  font: inherit; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  padding: 14px 10px; border-radius: 14px;
  background: #ffffff0d; border: 2px solid #ffffff25;
  transition: border-color .2s, background .2s, transform .15s;
}
.mode strong { font-size: 1.15rem; }
.mode span { font-size: .78rem; opacity: .75; }
.mode:hover { transform: translateY(-2px); }
.mode[aria-pressed="true"] { border-color: var(--gold); background: #f4c5421f; }

/* ---------- manilhas fixas (Mineiro) ---------- */
.manilha-info .fixed { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; font-weight: 800; font-size: .95rem; }
.manilha-info .fixed span { background: #fff; color: var(--ink); border-radius: 6px; padding: 1px 6px; }
.manilha-info .fixed span:nth-child(2),
.manilha-info .fixed span:nth-child(4) { color: var(--red); }

/* ---------- coringa ---------- */
.card.joker .card-front {
  color: #6b21a8;
  background: linear-gradient(160deg, #fff, #efe4ff);
}
.card.joker .pip { font-size: calc(var(--cw) * .55); }
