:root {
  --felt: #13693a;
  --felt-dark: #0b4426;
  --wood: #5a3418;
  --wood-light: #8a5a2e;
  --gold: #f2c14e;
  --ink: #1d1d1d;
  --die: #fbfaf5;
  --die-held: #fff3c4;
  --text: #f4f1e6;
  --muted: rgba(244, 241, 230, .65);
  --die-size: min(17vw, 76px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--felt-dark);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  overscroll-behavior: none; -webkit-touch-callout: none;
}

/* ---------- Abertura ---------- */
#splash {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 40%, #1c8a4c 0%, var(--felt) 45%, var(--felt-dark) 100%);
  transition: opacity .45s, transform .45s;
}
#splash.out { opacity: 0; transform: scale(1.06); pointer-events: none; }
.logo { width: 132px; height: 132px; filter: drop-shadow(0 12px 24px rgba(0,0,0,.45)); animation: pop .7s .1s both cubic-bezier(.2,1.5,.4,1); }
.logo .d { transform-box: fill-box; transform-origin: center; animation: dropIn .6s calc(.3s + var(--i) * .12s) both cubic-bezier(.2,1.4,.4,1); }
@keyframes dropIn { from { transform: translateY(-60px) rotate(-200deg); opacity: 0; } to { opacity: 1; } }
.wordmark { margin: 0; font-size: 64px; line-height: 1.05; text-align: center; font-weight: 900; letter-spacing: .5px; color: var(--gold); text-shadow: 0 3px 0 #8a6414, 0 8px 18px rgba(0,0,0,.4); animation: rise .5s .7s both cubic-bezier(.2,.8,.2,1); }
.tagline { margin: -12px 0 0; font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--muted); animation: rise .5s .85s both cubic-bezier(.2,.8,.2,1); }
.loadbar { width: 120px; height: 4px; border-radius: 4px; background: rgba(0,0,0,.3); overflow: hidden; margin-top: 18px; animation: rise .4s .9s both; }
.loadbar i { display: block; height: 100%; width: 100%; background: var(--gold); transform-origin: left; animation: load 1.1s 1s both ease-in-out; }
@keyframes load { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- Interruptor ---------- */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 12px; background: rgba(0,0,0,.25); font-size: 15px; cursor: pointer; }
.switch small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch input { display: none; }
.switch .knob { flex: none; width: 46px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.25); position: relative; transition: background .2s; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: transform .2s; }
.switch input:checked + .knob { background: var(--gold); }
.switch input:checked + .knob::after { transform: translateX(18px); }
.drawer .switch { background: #ece3cc; color: var(--ink); padding: 8px 12px; margin-bottom: 8px; font-size: 14px; }
.drawer .switch .knob { background: #cfc4a8; }
.drawer .switch input:checked + .knob { background: #2f7d4a; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:disabled { cursor: default; }

/* ---------- Feltro ---------- */
.felt {
  position: fixed; inset: 0;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .35 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    radial-gradient(ellipse at 50% 40%, #1c8a4c 0%, var(--felt) 45%, var(--felt-dark) 100%);
}

/* ---------- Layout do jogo ---------- */
#game {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
}
header { display: flex; flex-direction: column; gap: 10px; }
.players { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.players::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 6px 12px; border-radius: 999px;
  background: rgba(0,0,0,.22); color: var(--muted); font-size: 14px;
  border: 1px solid transparent; transition: all .2s;
}
.chip.active { background: rgba(0,0,0,.4); color: var(--text); border-color: var(--gold); font-weight: 600; }
.turn-info { display: flex; align-items: baseline; justify-content: space-between; }
.turn-info h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.rolls { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.pip-ind { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--gold); transition: background .2s; }
.pip-ind.used { background: var(--gold); }

/* área onde os dados rolados ficam */
.table { flex: 1; position: relative; margin: 8px 0; }
.table .die { position: absolute; left: 0; top: 0; }
.hint { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-size: 14px; color: var(--muted); pointer-events: none; }

/* bandeja dos dados guardados */
.tray-wrap { margin-bottom: 14px; }
.tray-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 0 0 6px 4px; }
.tray {
  min-height: calc(var(--die-size) + 24px);
  display: flex; gap: 8px; justify-content: center; align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--wood) 0%, #3e220e 100%);
  box-shadow: inset 0 3px 8px rgba(0,0,0,.55), 0 1px 0 rgba(255,255,255,.12);
  border: 2px solid var(--wood-light);
}
.tray { position: relative; }
.tray .die { --die-size-local: calc(var(--die-size) * .82); touch-action: none; cursor: grab; }
.die.dragging { z-index: 3; cursor: grabbing; scale: 1.12; }
.die.dragging .shadow { opacity: .8; transform: translateY(18%) scale(1.05); }
.tray:empty::before { content: attr(data-empty); font-size: 13px; color: rgba(255,255,255,.45); }

/* ---------- Dado (cubo 3D) ---------- */
.die {
  --s: var(--die-size-local, var(--die-size));
  width: var(--s); height: var(--s); padding: 0; background: none;
  flex: 0 0 auto; position: relative;
  perspective: 520px;
  transition: opacity .2s, left .2s ease-out, top .2s ease-out;
}
.die.physics, .die.dragging { transition: opacity .2s; }
.cube {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .35s cubic-bezier(.2,.8,.2,1);
}
.die.physics .cube, .die.physics .shadow { transition: none; }
.face {
  position: absolute; inset: 0;
  background: var(--die);
  border-radius: 14%;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 14%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), inset 0 -3px 6px rgba(0,0,0,.12), inset 0 3px 4px rgba(255,255,255,.8);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  transition: background .2s, box-shadow .2s;
}
.f1 { transform: translateZ(calc(var(--s) / 2)); }
.f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.f3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.f4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.f2 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.f5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.face span { width: 70%; height: 70%; margin: auto; border-radius: 50%; background: var(--ink); visibility: hidden; box-shadow: inset 0 2px 2px rgba(0,0,0,.6); }
.face span.on { visibility: visible; }
.shadow {
  position: absolute; inset: 6%; border-radius: 28%;
  background: rgba(0,0,0,.5); filter: blur(5px);
  transform: translateY(14%); transition: transform .35s, opacity .35s;
}
.die.held .face { background: var(--die-held); box-shadow: inset 0 0 0 3px var(--gold), inset 0 -3px 6px rgba(0,0,0,.1); }
.die.blank { opacity: 0; pointer-events: none; }

/* ---------- Rodapé ---------- */
footer { display: flex; gap: 10px; }
.btn {
  height: 56px; border-radius: 14px; font-size: 18px; font-weight: 700;
  transition: transform .08s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; }
footer .btn-roll { flex: 1; }
.btn-roll { background: var(--gold); color: #3a2a00; box-shadow: 0 4px 0 #b88a1d; }
.btn-end { padding: 0 18px; background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.25); font-size: 16px; }

/* ---------- Ficha lateral ---------- */
.sheet-tab {
  position: fixed; right: 0; top: 50%; transform: translateY(-50%);
  writing-mode: vertical-rl; text-orientation: mixed;
  padding: 14px 8px; border-radius: 10px 0 0 10px;
  background: var(--wood); border: 2px solid var(--wood-light); border-right: 0;
  font-size: 13px; font-weight: 700; letter-spacing: 2px;
  box-shadow: -2px 2px 8px rgba(0,0,0,.4); z-index: 5;
}
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 9; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(88vw, 380px);
  background: #f7f1e1; color: var(--ink);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  z-index: 10; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  box-shadow: -6px 0 20px rgba(0,0,0,.4);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.close { width: 36px; height: 36px; border-radius: 50%; background: rgba(0,0,0,.08); font-size: 20px; }
.sheet-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 0 -6px; }
.sheet { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 15px; }
.sheet col.lbl { width: 40%; }
.sheet th, .sheet td { border-bottom: 1px solid #e3d9c2; height: 42px; padding: 3px; text-align: center; }
.sheet th { position: sticky; top: 0; background: #f7f1e1; z-index: 1; font-size: 11px; font-weight: 700; line-height: 1.1; overflow-wrap: anywhere; }
.sheet th.cur { color: #9a6a00; }
.sheet td.cur { background: rgba(242,193,78,.16); }
.sheet td.label { text-align: left; padding-left: 6px; line-height: 1.15; }
.label b { display: block; font-size: 13px; }
.label small { color: #8a8070; font-size: 11px; }
.label .ico { font-size: 22px; vertical-align: -3px; margin-right: 4px; }
.sheet tr.section td { height: auto; padding: 14px 6px 4px; text-align: left; font-size: 11px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; color: #7a7262; border: 0; }
.sheet tr.sum td { font-weight: 700; background: #efe6cf; }
.sheet tr.sum td.cur { background: #f0dfae; }
.sheet tr.grand td { font-size: 17px; font-weight: 800; background: #e6d9b8; }
.sheet tr.grand td.cur { background: #ead08a; }
.sheet .zero { color: #b0a690; }
.sheet .muted { color: #a59c88; font-size: 12px; font-weight: 400; }
/* ponto já marcado: número forte, com tinta de caneta */
.sheet .marked { font-weight: 800; font-size: 17px; color: #1b3f8f; }
.sheet .marked.zero { color: #b0a690; text-decoration: line-through; }
/* sugestão: só uma prévia, ainda não marcada */
.cell-btn {
  width: 100%; height: 100%; border-radius: 8px; background: none; border: 0;
  color: #6aa47c; font-size: 13px; font-weight: 600; font-style: italic;
}
.cell-btn.zero { color: #c9bfa8; }
/* sem sugestões: só um espaço tocável */
.cell-btn.empty:not(.sel) { border: 1.5px dashed #d6ccb4; height: 70%; width: 70%; }
.sheet.picking .cell-btn:not(.sel) { opacity: .45; }
.cell-btn.sel { background: var(--gold); color: #3a2a00; font-size: 16px; font-weight: 800; font-style: normal; opacity: 1; box-shadow: 0 0 0 2px #b88a1d; }
.sheet-hint { margin: 0 0 8px; padding: 8px 10px; border-radius: 10px; background: #e9f2e6; color: #2f6a43; font-size: 13px; line-height: 1.3; }
.confirm { flex: none; margin-top: 12px; width: 100%; }

/* colunas dos outros jogadores ficam apagadas */
.sheet .other { opacity: .35; }

/* ---------- Vez do jogador ---------- */
#turnIntro {
  position: fixed; inset: 0; z-index: 25;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: radial-gradient(circle at 50% 45%, rgba(10,60,32,.75), rgba(3,20,10,.94));
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
#turnIntro.show { opacity: 1; pointer-events: auto; }
#turnIntro .lbl { font-size: 15px; letter-spacing: 3px; text-transform: uppercase; color: var(--muted); }
#turnIntro .who {
  font-size: clamp(36px, 12vw, 64px); font-weight: 900; color: var(--gold); text-align: center; padding: 0 16px;
  text-shadow: 0 4px 20px rgba(0,0,0,.5); overflow-wrap: anywhere;
}
#turnIntro .round { font-size: 14px; color: var(--muted); }
#turnIntro .tap { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 32px); font-size: 13px; color: rgba(255,255,255,.4); }
#turnIntro.show .lbl { animation: rise .45s .05s both cubic-bezier(.2,.8,.2,1); }
#turnIntro.show .who { animation: pop .6s .15s both cubic-bezier(.2,1.5,.4,1); }
#turnIntro.show .round { animation: rise .45s .35s both cubic-bezier(.2,.8,.2,1); }
#turnIntro .dice-row { font-size: 34px; letter-spacing: 6px; margin-bottom: 8px; }
#turnIntro.show .dice-row span { display: inline-block; animation: spin .7s both cubic-bezier(.2,.8,.2,1); }
#turnIntro.show .dice-row span:nth-child(2) { animation-delay: .08s; }
#turnIntro.show .dice-row span:nth-child(3) { animation-delay: .16s; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes spin { from { transform: translateY(-40px) rotate(-360deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Fim de partida ---------- */
#results { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 24px; background: rgba(5,30,16,.88); }
#results h1 { margin: 0 0 8px; text-align: center; font-size: 30px; }
.rank { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; background: rgba(255,255,255,.08); font-size: 18px; }
.rank.first { background: var(--gold); color: #3a2a00; font-weight: 800; }
.rank .pos { width: 28px; font-weight: 800; }
.rank .name { flex: 1; }
.rank .pts { font-weight: 800; }
#ranking { display: flex; flex-direction: column; gap: 10px; }
.rank .badge { display: block; font-size: 12px; font-weight: 700; color: #8a5a00; }
.rank:not(.first) .badge { color: var(--gold); }

/* ---------- Menu e janelas ---------- */
#menuBtn {
  position: fixed; z-index: 21; top: calc(env(safe-area-inset-top) + 10px); right: 12px;
  width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,.3);
  display: grid; place-items: center;
}
#menuBtn svg { width: 22px; height: 22px; }
.players { padding-right: 48px; }
#modal {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .25s;
}
#modal.open { opacity: 1; pointer-events: auto; }
.panel {
  width: 100%; max-width: 520px; max-height: 86vh; display: flex; flex-direction: column;
  background: #f7f1e1; color: var(--ink); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
#modal.open .panel { transform: none; }
.panel .grip { width: 40px; height: 5px; border-radius: 3px; background: #d6ccb4; margin: 0 auto 10px; }
.panel-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel h3 { margin: 18px 0 6px; font-size: 16px; }
.panel p, .panel li { font-size: 14px; line-height: 1.45; color: #3d3a33; }
.panel ul { padding-left: 18px; margin: 4px 0; }
.menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; border-radius: 14px; background: #ece3cc; color: var(--ink); font-size: 17px; font-weight: 600; text-align: left; }
.menu-item .ic { font-size: 22px; width: 26px; text-align: center; }
.menu-item.danger { color: #a3271b; }
.menu-item .menu-val { margin-left: auto; font-size: 14px; font-weight: 500; color: #8a8070; }
.menu-item.sel { box-shadow: inset 0 0 0 2px var(--gold); }
.menu-item .check { margin-left: auto; color: #9a6a00; font-weight: 800; }
.rules-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0; }
.rules-table td { padding: 7px 4px; border-bottom: 1px solid #e3d9c2; }
.rules-table td:last-child { text-align: right; font-weight: 700; white-space: nowrap; }
.hs-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid #e3d9c2; font-size: 16px; }
.hs-row .pos { width: 30px; font-weight: 800; color: #9a6a00; }
.hs-row .name { flex: 1; font-weight: 600; }
.hs-row .name small { display: block; font-weight: 400; font-size: 12px; color: #8a8070; }
.hs-row .pts { font-weight: 800; font-size: 18px; }
.hs-empty { text-align: center; color: #8a8070; padding: 28px 0; }
.link-btn { background: none; color: #a3271b; font-size: 14px; padding: 14px; width: 100%; }

/* ---------- Tela inicial ---------- */
#setup {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  display: flex; flex-direction: column; justify-content: safe center; gap: 18px;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
}
.setup-brand { display: flex; align-items: center; justify-content: center; gap: 12px; }
.setup-brand .logo { width: 52px; height: 52px; animation: none; }
.setup-brand .logo g { animation: none; }
.setup-brand .logo .d { animation: none; }
#setup h1 { margin: 0; font-size: 44px; line-height: 1.05; text-align: left; color: var(--gold); font-weight: 900; }
#setup .sub { margin: 6px 0 4px; text-align: center; color: var(--muted); }
.count { display: flex; gap: 10px; }
.count button { flex: 1; height: 52px; border-radius: 12px; background: rgba(0,0,0,.25); font-size: 20px; font-weight: 700; border: 2px solid transparent; }
.count button.sel { border-color: var(--gold); background: rgba(0,0,0,.4); }
.names { display: flex; flex-direction: column; gap: 10px; }
.names input {
  height: 48px; border-radius: 12px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25); color: var(--text); padding: 0 14px; font-size: 16px; outline: none;
  user-select: text; -webkit-user-select: text;
}
.names input:focus { border-color: var(--gold); }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; }
.name-row .kind {
  width: 72px; flex: none; border-radius: 12px; background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.25);
  font-size: 20px; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.name-row .kind small { font-size: 11px; font-weight: 700; color: var(--muted); }
.name-row.bot .kind { border-color: var(--gold); background: rgba(242,193,78,.15); }
.name-row.bot .kind small { color: var(--gold); }
.hidden { display: none !important; }

/* ---------- Abas da tela inicial ---------- */
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: rgba(0,0,0,.3); }
.tab { flex: 1; height: 42px; border-radius: 10px; background: none; color: var(--muted); font-size: 15px; font-weight: 700; transition: background .2s, color .2s; }
.tab.sel { background: var(--gold); color: #3a2a00; }
.pane { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 700; color: var(--muted); padding-left: 4px; }
.field input {
  height: 48px; border-radius: 12px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25); color: var(--text); padding: 0 14px; font-size: 16px; outline: none;
  user-select: text; -webkit-user-select: text;
}
.field input:focus { border-color: var(--gold); }
.lan-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 16px; background: rgba(0,0,0,.22); }
.lan-card h3 { margin: 0; font-size: 17px; }
.lan-card p { margin: -6px 0 2px; font-size: 13px; color: var(--muted); }
.lan-card .btn { width: 100%; }
.ip-boxes { display: flex; align-items: center; gap: 4px; }
.ip-boxes b { font-size: 26px; color: var(--muted); line-height: 1; }
.ip-boxes input {
  flex: 1; min-width: 0; height: 52px; border-radius: 12px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.3); color: var(--text); font-size: 22px; font-weight: 700; text-align: center; outline: none;
  user-select: text; -webkit-user-select: text; font-variant-numeric: tabular-nums;
}
.ip-boxes input:focus { border-color: var(--gold); }
.lan-note { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.3); color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Sala de espera ---------- */
#lobby, #room {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; justify-content: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
}
#lobby h2, #room h2 { margin: 0; text-align: center; font-size: 24px; color: var(--gold); }
.ip-card { padding: 16px; border-radius: 16px; background: rgba(0,0,0,.35); border: 2px dashed rgba(242,193,78,.6); text-align: center; }
.ip-card small { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.ip-card .ip { font-size: 34px; font-weight: 900; letter-spacing: 1px; color: var(--text); user-select: text; -webkit-user-select: text; }
.lobby-status { margin: 0; text-align: center; color: var(--muted); font-size: 15px; }
.lobby-list { display: flex; flex-direction: column; gap: 8px; }
.lobby-player { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: rgba(0,0,0,.25); font-size: 17px; }
.lobby-player .dot { width: 10px; height: 10px; border-radius: 50%; background: #4cd964; box-shadow: 0 0 8px #4cd964; }
.lobby-player small { margin-left: auto; color: var(--muted); font-size: 12px; }
.lobby-player.waiting { opacity: .45; border: 1px dashed rgba(255,255,255,.25); background: none; }
.lobby-player.waiting .dot { background: none; border: 1px solid var(--muted); box-shadow: none; }

/* ---------- Partida em rede ---------- */
.chip .you { font-size: 11px; opacity: .8; }
.chip.gone { text-decoration: line-through; opacity: .45; }
.chip.offline { opacity: .6; border-style: dashed; }
.rank.gone { opacity: .55; }
.rank.gone .badge { color: var(--muted); }

/* aba da ficha: pula quando as rolagens acabam e fica brilhando até marcar */
.sheet-tab { transition: background .3s, color .3s; }
.sheet-tab.ready { background: var(--gold); color: #3a2a00; border-color: #ffe08a; box-shadow: -2px 2px 14px rgba(242,193,78,.7); }
.sheet-tab.nudge { animation: tab-hop .9s cubic-bezier(.3,1.6,.5,1) 2; }
@keyframes tab-hop {
  0%, 100% { transform: translateY(-50%) translateX(0); }
  25% { transform: translateY(-50%) translateX(-14px); }
  45% { transform: translateY(-50%) translateX(0); }
  65% { transform: translateY(-50%) translateX(-6px); }
}

/* reconectando à partida */
#reconnect {
  position: fixed; inset: 0; z-index: 42; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; background: rgba(5,30,16,.88); backdrop-filter: blur(4px);
}
#reconnect .ic { font-size: 46px; }
#reconnect h2 { margin: 0; font-size: 22px; }
#reconnect p { margin: 0; color: var(--muted); max-width: 300px; }
#reconnect .spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--gold); animation: spin 1s linear infinite; }
#reconnect.failed .spin { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.die.locked { cursor: default; }
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 64px); z-index: 45;
  transform: translate(-50%, -20px); opacity: 0; transition: transform .3s, opacity .3s;
  padding: 10px 16px; border-radius: 999px; background: rgba(0,0,0,.8); color: var(--text); font-size: 14px; white-space: nowrap;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }


/* arrastar a ficha: segue o dedo sem animação; o gesto horizontal fica com o jogo, a rolagem vertical continua */
.drawer.dragging, .scrim.dragging { transition: none; }
.scrim.dragging { pointer-events: auto; }
#game, .drawer, .scrim, .sheet-tab { touch-action: pan-y; }

/* ---------- Versão web: tela inicial ---------- */
#setup { align-items: center; }
#setup > * { width: 100%; max-width: 440px; }
.opponents { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.opp {
  padding: 8px 14px; border-radius: 999px; font-size: 15px; font-weight: 600;
  background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.2);
}
.opp.me { border-color: var(--gold); color: var(--gold); }
button.opp:active { transform: scale(.96); }
.opp-hint { width: 100%; text-align: center; font-size: 12px; color: var(--muted); }
.lan-card.soon { text-align: center; align-items: center; }
.soon-ic { font-size: 40px; }
.install-help ol { margin: 0; padding-left: 22px; line-height: 1.6; font-size: 16px; }
.install-help li { margin-bottom: 8px; }
.ios-share { display: inline-block; padding: 0 6px; border-radius: 6px; background: #ece3cc; font-weight: 800; }

/* ---------- Tela larga: ficha fixa ao lado da mesa ---------- */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .drawer { width: 400px; transform: none; box-shadow: -2px 0 18px rgba(0,0,0,.35); }
  #game { right: 400px; padding-left: 32px; padding-right: 32px; }
  .scrim, .sheet-tab, #closeSheet, #end { display: none !important; }
  #menuBtn, #menuBtn.hidden { display: grid !important; right: 412px; }
  /* fora da partida (tela inicial, sala) a ficha some e o menu volta para o canto */
  #game.hidden ~ .drawer { display: none; }
  #game.hidden ~ #menuBtn { right: 12px; }
}

/* ---------- Conta: entrar, criar conta, código ---------- */
#auth {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  display: flex; flex-direction: column; justify-content: safe center; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
}
#auth > * { width: 100%; max-width: 400px; }
#auth .setup-brand h1 { margin: 0; font-size: 44px; color: var(--gold); font-weight: 900; }
.auth-view { display: flex; flex-direction: column; gap: 14px; }
.auth-view.hidden { display: none; }
.auth-view h2 { margin: 0; text-align: center; font-size: 22px; }
.field small { font-size: 12px; color: var(--muted); padding-left: 4px; }
.field input[type=email], .field input[type=password] { text-transform: none; }
.nick-status.good { color: #7ee2a0; }
.nick-status.bad { color: #ff9b8a; }
.auth-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(163,39,27,.35); color: #ffd9d3; font-size: 14px; }
.auth-sub { margin: 0; text-align: center; color: var(--muted); }
.code-input {
  height: 64px; border-radius: 14px; border: 2px solid var(--gold); background: rgba(0,0,0,.3); color: var(--text);
  text-align: center; font-size: 32px; font-weight: 800; letter-spacing: 12px; outline: none;
  user-select: text; -webkit-user-select: text;
}
.auth-link, .auth-guest { color: var(--gold); font-weight: 600; padding: 8px; }
.auth-guest { color: var(--muted); font-weight: 500; }
.signed-in { margin: 0; text-align: center; font-size: 16px; }
.signed-in b { color: var(--gold); }

/* ---------- Partida online ---------- */
#room > * { width: 100%; max-width: 440px; margin-inline: auto; }
#room .ip { letter-spacing: 6px; }
#room .ip-card { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#room .ip-card .btn { width: 100%; }
.online-card { gap: 12px; }
.online-card h3 { margin: 0; text-align: center; }
.online-card .sub { margin: 0; text-align: center; color: var(--muted); }
.code-join { display: flex; gap: 8px; }
.code-join input {
  flex: 1; min-width: 0; height: 48px; border-radius: 12px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25); color: var(--text); padding: 0 14px; font-size: 18px; font-weight: 700;
  letter-spacing: 3px; text-transform: uppercase; outline: none; user-select: text; -webkit-user-select: text;
}
.code-join input::placeholder { letter-spacing: 0; font-weight: 400; text-transform: none; }
.code-join input:focus { border-color: var(--gold); }
.code-join .btn { height: 48px; flex: none; width: auto; padding: 0 20px; }
.signed-in { margin-top: -8px; }
.or-robots { margin: 4px 0 -6px; text-align: center; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.train-title { margin: 0; text-align: center; font-size: 22px; }
#paneOnline .auth-link { align-self: center; margin-top: 4px; }

/* ---------- Banner "Instale o 5D6" ---------- */
.install-banner {
  position: fixed; z-index: 25; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px);
  max-width: 480px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px;
  border-radius: 18px; background: #f7f1e1; color: var(--ink);
  border: 2px solid var(--gold); box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: bannerUp .45s .3s both cubic-bezier(.2,1.2,.4,1);
}
@keyframes bannerUp { from { transform: translateY(140%); opacity: 0; } }
.install-ic { width: 46px; height: 46px; border-radius: 12px; flex: none; }
.install-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.install-txt b { font-size: 16px; }
.install-txt small { font-size: 12.5px; color: #6b6352; line-height: 1.25; }
.install-go { flex: none; height: 44px; padding: 0 18px; font-size: 16px; }
.install-x { position: absolute; top: -10px; right: -8px; width: 28px; height: 28px; border-radius: 50%; background: #3a2a00; color: #fff; font-size: 17px; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
/* só nas telas de início e de login: some na partida, na sala e nos resultados */
#game:not(.hidden) ~ .install-banner, #room:not(.hidden) ~ .install-banner,
#lobby:not(.hidden) ~ .install-banner, #results:not(.hidden) ~ .install-banner { display: none; }
/* espaço para o banner não cobrir o último botão */
body.install-on #setup, body.install-on #auth { padding-bottom: calc(env(safe-area-inset-bottom) + 110px); }

/* ---------- Amigos e convites ---------- */
.setup-links { display: flex; justify-content: center; gap: 4px 18px; flex-wrap: wrap; }
.badge-n { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 6px; border-radius: 999px; background: #c0392b; color: #fff !important; font-size: 12px; font-weight: 800; text-align: center; }
.friend-add { display: flex; gap: 8px; margin-bottom: 8px; }
.friend-add input { flex: 1; min-width: 0; height: 46px; border-radius: 12px; border: 1px solid #d8ccb0; background: #fff; padding: 0 12px; font-size: 16px; outline: none; user-select: text; -webkit-user-select: text; }
.friend-add input:focus { border-color: var(--gold); }
.friend-add .btn { height: 46px; padding: 0 16px; font-size: 16px; }
.friend-msg { margin: 0 0 8px; font-size: 14px; }
.friend-msg.good { color: #2f7d4a; }
.friend-msg.bad { color: #a3271b; }
#friendsBody h3, .room-friends h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; color: #7a7262; }
.room-friends h3 { color: var(--muted); }
.friend-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #ece3cc; margin-bottom: 6px; }
.room-friends .friend-row { background: rgba(0,0,0,.25); }
.friend-row .dot { width: 10px; height: 10px; border-radius: 50%; background: #b8ae98; flex: none; }
.friend-row .dot.on { background: #4cd964; box-shadow: 0 0 8px #4cd964; }
.friend-row .fname { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.friend-row .fname small { margin-left: 6px; font-weight: 500; color: #2f7d4a; font-size: 12px; }
.room-friends .fname small { color: #7ee2a0; }
.mini { padding: 7px 12px; border-radius: 10px; background: rgba(0,0,0,.08); font-size: 14px; font-weight: 600; }
.mini.ok { background: var(--gold); color: #3a2a00; }
.room-friends .mini:not(.ok) { background: rgba(255,255,255,.12); }
.muted-tag { color: #8a8070; font-size: 12px; }
.room-friends .muted-tag { color: var(--muted); }
.invite-pop {
  position: fixed; z-index: 46; left: 12px; right: 12px; top: calc(env(safe-area-inset-top) + 12px);
  max-width: 480px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: 16px; background: #f7f1e1; color: var(--ink); border: 2px solid var(--gold);
  box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: popDown .4s both cubic-bezier(.2,1.2,.4,1);
}
@keyframes popDown { from { transform: translateY(-140%); opacity: 0; } }
.invite-txt { flex: 1; font-size: 15px; }
.invite-pop .btn { height: 42px; padding: 0 16px; font-size: 16px; flex: none; }
.invite-pop .install-x { top: -10px; right: -8px; }
.setup-links .link-btn { width: auto; padding-inline: 6px; }
