:root {
  --go: #1faa4b;
  --go-dark: #12783a;
  --go-glow: rgba(31,170,75,.55);
  --ink: #1b120c;
  --ink-2: #2a1d14;
  --cream: #f7ecd7;
  --cream-dim: #d9c9ac;
  --mustard: #f2b705;
  --mustard-dark: #c48f00;
  --red: #d9412b;
  --red-dark: #9e2a19;
  --green: #3f9b55;
  --us: #3b82c4;
  --them: #d9412b;
  --glass: rgba(27, 18, 12, .78);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--cream); font-family: 'Nunito', system-ui, sans-serif; font-weight: 800; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ink); font-family: 'Bungee', sans-serif; color: var(--mustard); z-index: 50; transition: opacity .5s; }
#loading.gone { opacity: 0; pointer-events: none; }

/* ─────────── botões ─────────── */
.btn { border: 0; border-radius: 12px; padding: 12px 18px; background: var(--ink-2); color: var(--cream); box-shadow: inset 0 -3px 0 rgba(0,0,0,.35), 0 2px 0 rgba(255,255,255,.04); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(0,0,0,.35); }
.btn:disabled { opacity: .45; cursor: default; filter: none; transform: none; }
.btn-primary { background: var(--mustard); color: var(--ink); box-shadow: inset 0 -4px 0 var(--mustard-dark); font-weight: 900; }
.btn-small { padding: 8px 12px; font-size: 14px; }
.btn-ghost { background: rgba(247,236,215,.12); backdrop-filter: blur(6px); border: 2px solid rgba(247,236,215,.35); }
.btn-ghost.on { background: var(--cream); color: var(--ink); }
.btn-truco { background: var(--go); color: #fff; font-family: 'Bungee', sans-serif; font-size: 30px; padding: 18px 38px; border-radius: 18px; letter-spacing: 1px; text-shadow: 0 2px 0 rgba(0,0,0,.25); box-shadow: inset 0 -6px 0 var(--go-dark), 0 0 0 3px rgba(255,255,255,.25), 0 8px 26px var(--go-glow); animation: pulse 1.5s ease-in-out infinite; }
.btn-truco:hover { filter: brightness(1.08); }
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: inset 0 -6px 0 var(--go-dark), 0 0 0 3px rgba(255,255,255,.25), 0 8px 22px var(--go-glow); }
  50% { transform: scale(1.045); box-shadow: inset 0 -6px 0 var(--go-dark), 0 0 0 5px rgba(255,255,255,.35), 0 10px 38px var(--go-glow); }
}
.icon-btn { border: 0; background: var(--glass); border-radius: 999px; min-width: 42px; height: 42px; padding: 0 12px; font-size: 16px; backdrop-filter: blur(6px); }

/* ─────────── lobby ─────────── */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 10; background: radial-gradient(ellipse at center, rgba(27,18,12,.25), rgba(27,18,12,.85)); overflow-y: auto; }
.panel { width: min(440px, 100%); background: var(--glass); backdrop-filter: blur(10px); border: 1px solid rgba(242,183,5,.25); border-radius: 22px; padding: 26px 22px; box-shadow: var(--shadow); }
.logo { text-align: center; margin-bottom: 22px; line-height: 1; }
.logo-top { display: block; font-family: 'Bungee', sans-serif; color: var(--cream); font-size: 20px; letter-spacing: 2px; }
.logo-main { display: block; font-family: 'Bungee', sans-serif; color: var(--mustard); font-size: clamp(46px, 13vw, 64px); text-shadow: 0 4px 0 var(--red-dark), 0 10px 26px rgba(242,183,5,.35); }
.logo-sub { display: block; margin-top: 10px; color: var(--cream-dim); font-size: 14px; letter-spacing: 1px; text-transform: uppercase; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--cream-dim); margin-bottom: 6px; }
.field input, .row input, #chatInput { width: 100%; padding: 13px 14px; border-radius: 12px; border: 2px solid rgba(247,236,215,.18); background: rgba(0,0,0,.35); color: var(--cream); outline: none; }
.field input:focus, .row input:focus, #chatInput:focus { border-color: var(--mustard); }
#home .btn-primary, #btnStart { width: 100%; font-size: 18px; padding: 15px; }
.or { text-align: center; margin: 18px 0 12px; color: var(--cream-dim); font-size: 13px; position: relative; }
.or::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid rgba(247,236,215,.15); }
.or span { position: relative; background: #241811; padding: 0 10px; border-radius: 6px; }
.row { display: flex; gap: 8px; }
.row input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-family: 'Bungee', sans-serif; }
.err { color: #ff8a73; text-align: center; min-height: 1.2em; margin: 12px 0 0; font-size: 14px; }
.hint { color: var(--cream-dim); font-size: 13px; text-align: center; margin: 12px 0; font-weight: 600; }

.room-line { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }
.room-line b { font-family: 'Bungee', sans-serif; font-size: 30px; color: var(--mustard); letter-spacing: 4px; }
.teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.vs { font-family: 'Bungee', sans-serif; color: var(--cream-dim); font-size: 22px; }
.team h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; text-align: center; }
.team-a h3 { color: var(--us); }
.team-b h3 { color: var(--them); }
.seat { display: block; width: 100%; min-height: 52px; margin-bottom: 8px; padding: 8px; border-radius: 12px; border: 2px dashed rgba(247,236,215,.22); background: rgba(0,0,0,.25); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat.filled { border-style: solid; background: rgba(247,236,215,.08); cursor: default; }
.team-a .seat.filled { border-color: rgba(59,130,196,.7); }
.team-b .seat.filled { border-color: rgba(217,65,43,.7); }
.seat.me { background: rgba(242,183,5,.18); border-color: var(--mustard) !important; }
.seat small { display: block; color: var(--cream-dim); font-size: 11px; font-weight: 600; }

/* ─────────── HUD ─────────── */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#hud #toast, #hud #bubbles, #hud #turnInfo { pointer-events: none; }

#scoreboard { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; align-items: stretch; background: var(--glass); backdrop-filter: blur(8px); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.sc { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.sc b { font-family: 'Bungee', sans-serif; font-size: 28px; line-height: 1; min-width: 1.2em; text-align: center; }
.sc-us { background: linear-gradient(90deg, rgba(59,130,196,.55), rgba(59,130,196,.15)); }
.sc-them { background: linear-gradient(270deg, rgba(217,65,43,.55), rgba(217,65,43,.15)); }
.sc-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--cream-dim); }
.sc-mid { padding: 6px 12px; text-align: center; display: flex; flex-direction: column; justify-content: center; gap: 5px; }
#handValue { font-family: 'Bungee', sans-serif; font-size: 13px; color: var(--mustard); white-space: nowrap; }
#handValue.hot { color: #fff; background: var(--red); border-radius: 6px; padding: 1px 6px; }
#roundDots { display: flex; gap: 6px; justify-content: center; }
#roundDots i { width: 11px; height: 11px; border-radius: 50%; border: 2px solid rgba(247,236,215,.35); }
#roundDots i.us { background: var(--us); border-color: var(--us); }
#roundDots i.them { background: var(--them); border-color: var(--them); }
#roundDots i.tie { background: var(--cream-dim); border-color: var(--cream-dim); }

#viraBox { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px; display: flex; gap: 16px; align-items: stretch; background: #ffffff; color: var(--ink); padding: 10px 18px 12px 12px; border-radius: 18px; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.vira-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.vira-lbl { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: #6b5a4a; font-weight: 900; }
#viraBox .mini-card { width: 56px; height: 80px; font-size: 22px; border-radius: 8px; background: #fffaf0; border: 2px solid #d9cdb5; box-shadow: 0 3px 8px rgba(0,0,0,.18); }
.vira-man { justify-content: flex-start; }
#manilhaTxt { font-family: 'Bungee', sans-serif; font-size: 46px; line-height: 1; color: var(--ink); }
.suit-order { display: flex; gap: 4px; font-size: 18px; font-style: normal; line-height: 1; }
.suit-order i { font-style: normal; }
.suit-order .red { color: #c0261b; }
.suit-order .blk { color: #1a1a1a; }

/* ─────────── cartas jogadas ─────────── */
#playedPanel { position: absolute; bottom: calc(70px + env(safe-area-inset-bottom)); left: 12px; width: 214px; background: var(--glass); backdrop-filter: blur(8px); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.pp-head { width: 100%; border: 0; background: rgba(0,0,0,.25); display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--cream-dim); }
.pp-head b { color: var(--mustard); font-family: 'Bungee', sans-serif; font-size: 12px; letter-spacing: .5px; }
#ppBody { padding: 8px 10px 10px; }
.pp-cross { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto auto; gap: 2px 4px; justify-items: center; align-items: center; }
.pp-slot { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.pp-slot[data-r="2"] { grid-column: 2; grid-row: 1; }
.pp-slot[data-r="3"] { grid-column: 1; grid-row: 2; }
.pp-slot[data-r="1"] { grid-column: 3; grid-row: 2; }
.pp-slot[data-r="0"] { grid-column: 2; grid-row: 3; }
.pp-slot small { font-size: 10px; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--cream-dim); }
.pp-slot small.us { color: #8fc3f0; }
.pp-slot small.them { color: #ff9e8c; }
.pc { width: 38px; height: 54px; border-radius: 6px; display: grid; place-items: center; text-align: center; font-family: 'Bungee', sans-serif; font-size: 15px; line-height: 1; background: #fffaf0; color: #1a1a1a; border: 2px solid transparent; box-shadow: 0 2px 6px rgba(0,0,0,.35); position: relative; }
.pc.red { color: #c0261b; }
.pc.empty { background: transparent; border: 2px dashed rgba(247,236,215,.25); box-shadow: none; }
.pc.back { background: repeating-linear-gradient(45deg, #8f1d14 0 5px, #a8291d 5px 10px); border-color: #f2b705; color: transparent; }
.pc.man::after { content: '★'; position: absolute; top: -7px; right: -6px; font-size: 13px; color: #f2b705; text-shadow: 0 1px 2px rgba(0,0,0,.6); font-family: serif; }
.pc.best { border-color: #f2b705; box-shadow: 0 0 0 2px rgba(242,183,5,.45), 0 0 14px rgba(242,183,5,.6); }
#ppHistory { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
#ppHistory:empty { display: none; }
.pp-row { display: flex; align-items: center; gap: 4px; font-size: 11px; }
.pp-row > span:first-child { width: 22px; color: var(--cream-dim); }
.pp-row .chip { min-width: 30px; padding: 2px 3px; border-radius: 5px; background: #fffaf0; color: #1a1a1a; font-family: 'Bungee', sans-serif; font-size: 11px; text-align: center; border-bottom: 3px solid transparent; }
.pp-row .chip.red { color: #c0261b; }
.pp-row .chip.us { border-bottom-color: var(--us); }
.pp-row .chip.them { border-bottom-color: var(--them); }
.pp-row .chip.cov { background: #8f1d14; color: #f2b705; }
.pp-row .res { margin-left: auto; font-weight: 900; font-size: 10px; text-transform: uppercase; }
.pp-row .res.us { color: #8fc3f0; } .pp-row .res.them { color: #ff9e8c; } .pp-row .res.tie { color: var(--cream-dim); }
#playedPanel.collapsed #ppBody { display: none; }

/* ─────────── seletor de personagem ─────────── */
#avatarBox { margin-bottom: 16px; }
.picker-label { display: block; font-size: 13px; color: var(--cream-dim); margin-bottom: 6px; }
#avatarPicker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.av { border: 2px solid rgba(247,236,215,.15); background: radial-gradient(circle at 50% 35%, #4a3426, #24180f); border-radius: 12px; padding: 2px 2px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--cream-dim); overflow: hidden; }
.av img { width: 100%; aspect-ratio: 1; display: block; }
.av.on { border-color: var(--mustard); color: var(--cream); background: radial-gradient(circle at 50% 35%, #6a4a20, #2a1c10); }
.av span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.seat .seat-av { width: 34px; height: 34px; border-radius: 50%; vertical-align: middle; margin-right: 6px; background: #3a2a1e; float: left; }
.mini-card { width: 34px; height: 50px; border-radius: 5px; background: #fffaf0; color: #1a1a1a; display: grid; place-items: center; font-family: 'Bungee', sans-serif; font-size: 14px; line-height: 1; text-align: center; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.mini-card.red { color: #c0261b; }

#topRight { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
#btnRoom { font-family: 'Bungee', sans-serif; font-size: 13px; color: var(--mustard); }

#turnInfo { position: absolute; left: 50%; bottom: calc(24vh + 14px + env(safe-area-inset-bottom)); transform: translateX(-50%); font-size: 15px; background: var(--glass); padding: 6px 14px; border-radius: 999px; white-space: nowrap; transition: opacity .2s; }
#turnInfo:empty { opacity: 0; }
#turnInfo.mine { background: var(--mustard); color: var(--ink); }

#actions { position: absolute; right: 14px; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }

#chatBar { position: absolute; left: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column-reverse; align-items: flex-start; gap: 8px; }
#chatPanel { width: min(300px, calc(100vw - 24px)); background: var(--glass); backdrop-filter: blur(8px); padding: 10px; border-radius: 14px; box-shadow: var(--shadow); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.quick button { border: 0; background: rgba(247,236,215,.12); border-radius: 999px; padding: 6px 10px; font-size: 13px; }
.quick button:hover { background: rgba(247,236,215,.24); }
#chatForm { display: flex; gap: 6px; }
#chatInput { padding: 9px 10px; }

#prompt { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.35); padding: 16px; }
.prompt-card { width: min(380px, 100%); background: var(--ink-2); border: 2px solid var(--mustard); border-radius: 20px; padding: 20px; text-align: center; box-shadow: var(--shadow); animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#promptTitle { font-family: 'Bungee', sans-serif; font-size: 26px; color: var(--mustard); line-height: 1.15; margin-bottom: 8px; }
#promptBody { color: var(--cream-dim); font-size: 15px; margin-bottom: 16px; font-weight: 700; }
#promptBody .cards { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
#promptBody .mini-card { width: 46px; height: 66px; font-size: 17px; }
#promptBtns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#promptBtns .btn { flex: 1 1 100px; }
.btn-run { background: #4a3a2e; }
.btn-raise { background: var(--go); color: #fff; box-shadow: inset 0 -4px 0 var(--go-dark), 0 4px 18px var(--go-glow); font-family: 'Bungee', sans-serif; font-size: 18px; animation: pulse 1.5s ease-in-out infinite; }

#toast { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%) scale(.8); font-family: 'Bungee', sans-serif; font-size: clamp(30px, 8vw, 64px); color: var(--mustard); text-shadow: 0 4px 0 var(--red-dark), 0 0 30px rgba(0,0,0,.8); opacity: 0; transition: opacity .25s, transform .25s; text-align: center; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#toast.small { font-size: clamp(20px, 5vw, 34px); }
#toast.good { color: #8fd3ff; text-shadow: 0 4px 0 #1d4f7a, 0 0 30px rgba(0,0,0,.8); }
#toast.bad { color: #ffb3a6; text-shadow: 0 4px 0 #6b1c10, 0 0 30px rgba(0,0,0,.8); }

#bubbles { position: absolute; inset: 0; }
.bubble { position: absolute; transform: translate(-50%, -100%); background: var(--cream); color: var(--ink); padding: 7px 12px; border-radius: 14px; font-size: 15px; max-width: 200px; text-align: center; box-shadow: 0 4px 14px rgba(0,0,0,.4); animation: pop .2s ease-out; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -7px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: var(--cream); }
.bubble.shout { background: var(--red); color: #fff; font-family: 'Bungee', sans-serif; font-size: 20px; }
.bubble.shout::after { border-top-color: var(--red); }

@media (max-width: 640px) {
  #viraBox { top: calc(62px + env(safe-area-inset-top)); left: 8px; gap: 10px; padding: 8px 12px 8px 8px; border-radius: 14px; }
  #viraBox .mini-card { width: 40px; height: 58px; font-size: 16px; }
  #manilhaTxt { font-size: 32px; }
  .suit-order { font-size: 14px; gap: 2px; }
  .vira-lbl { font-size: 10px; letter-spacing: 1px; }
  .mini-card { width: 28px; height: 42px; font-size: 12px; }
  #playedPanel { top: calc(62px + env(safe-area-inset-top)); bottom: auto; left: auto; right: 8px; width: 150px; }
  #ppBody { padding: 6px; }
  .pc { width: 28px; height: 40px; font-size: 11px; border-radius: 4px; }
  .pp-slot small { font-size: 9px; max-width: 46px; }
  .pp-row .chip { min-width: 0; flex: 1; font-size: 9px; padding: 1px; }
  .pp-row > span:first-child { width: 16px; font-size: 9px; }
  .pp-row .res { font-size: 8px; }
  .pp-head { padding: 6px 8px; font-size: 9px; }
  .pp-head b { font-size: 10px; }
  #avatarPicker { grid-template-columns: repeat(3, 1fr); }
  .sc { padding: 6px 10px; }
  .sc b { font-size: 24px; }
  #scoreboard { left: 12px; transform: none; }
  #turnInfo { bottom: calc(30vh + 10px + env(safe-area-inset-bottom)); font-size: 14px; }
  .btn-truco { font-size: 24px; padding: 14px 26px; }
  #actions { bottom: calc(36vh + env(safe-area-inset-bottom)); right: 10px; }
}

.host-note { color: var(--mustard); }
