:root {
  --night: #141b3d;
  --night-2: #222b5c;
  --sky: #9fd0f5;
  --gold: #f6d33c;
  --gold-ink: #3a2410;
  --red: #dc4a52;
  --blue: #5b87c7;
  --paper: #ffffff;
  --ink: #15131f;
  --muted: #5d6280;
  --board-w: min(100vw, 760px);
  --hud-h: 132px;
  --px: 3px; /* espessura do "pixel" das bordas */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Montserrat", system-ui, sans-serif;
  color: var(--ink);
  background: var(--night);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- tipografia ---------- */
.pixel-title {
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  color: var(--gold);
  font-size: clamp(2.6rem, 11vw, 4rem);
  line-height: .95;
  margin: 0;
  letter-spacing: .01em;
  text-shadow:
    3px 0 0 var(--gold-ink), -3px 0 0 var(--gold-ink), 0 3px 0 var(--gold-ink), 0 -3px 0 var(--gold-ink),
    3px 3px 0 var(--gold-ink), -3px 3px 0 var(--gold-ink), 3px -3px 0 var(--gold-ink), -3px -3px 0 var(--gold-ink),
    0 7px 0 var(--gold-ink);
}
.pixel-title.small { font-size: 2.2rem; }
.pixel-h {
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  margin: 0;
}
.muted { color: var(--muted); margin: 0; font-size: .95rem; line-height: 1.45; }
.center { text-align: center; }
.label { font-weight: 700; font-size: .85rem; margin: 0 0 .4rem; }
.error { color: #ffd2d4; min-height: 1.2em; margin: 0; font-weight: 600; }

/* ---------- botões: blocos com borda de pixel ---------- */
.btn {
  border: var(--px) solid var(--ink);
  border-radius: 0;
  padding: .85rem 1.2rem;
  font-weight: 800;
  font-size: 1rem;
  box-shadow: inset 0 calc(-1 * var(--px)) 0 rgba(0,0,0,.25), 0 var(--px) 0 var(--ink);
  transition: transform .06s;
}
.btn:active { transform: translateY(var(--px)); box-shadow: inset 0 calc(-1 * var(--px)) 0 rgba(0,0,0,.25); }
.btn:disabled { filter: grayscale(1) opacity(.55); cursor: not-allowed; transform: none; }
.btn-gold { background: var(--gold); color: var(--gold-ink); }
.btn-blue { background: var(--blue); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); }
.btn-link { background: none; border: 0; color: var(--muted); font-weight: 700; text-decoration: underline; padding: .4rem; }

/* ---------- tela inicial ---------- */
.screen { min-height: 100%; }
#home {
  position: relative;
  display: grid;
  place-items: center;
  padding: 2rem 1rem 3rem;
  overflow: hidden;
}
.home-sky {
  position: fixed; top: 0; bottom: 0; left: 50%;
  width: min(100vw, 760px); transform: translateX(-50%);
  background: url("/tabuleiro-mini.webp") center top / 100% auto no-repeat;
}
@media (min-width: 761px) {
  .home-sky { -webkit-mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); }
}
.home-sky::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,27,61,0) 18%, rgba(20,27,61,.72) 42%, var(--night) 70%);
}
.home-panel {
  position: relative;
  width: min(100%, 420px);
  margin-top: min(30vh, 260px);
  display: grid;
  gap: 1rem;
}
.home-lede { color: #fff; font-weight: 600; line-height: 1.5; margin: .2rem 0 .6rem; text-shadow: 0 2px 0 rgba(0,0,0,.4); }
.field { display: grid; gap: .35rem; flex: 1; }
.field span { color: #fff; font-weight: 700; font-size: .85rem; }
.field input {
  font: inherit; font-weight: 700; font-size: 1.1rem;
  padding: .8rem .9rem;
  border: var(--px) solid var(--ink);
  border-radius: 0;
  background: #fff;
  width: 100%;
}
#codeInput { font-family: "Pixelify Sans", sans-serif; letter-spacing: .25em; font-size: 1.3rem; }
.join-row { display: flex; gap: .6rem; align-items: end; }

/* ---------- tabuleiro ---------- */
#room { background: var(--night); }
#boardWrap {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: calc(var(--hud-h) + 16px + env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at top, var(--night-2), var(--night) 70%);
}
#board { position: relative; width: var(--board-w); }
#boardImg { display: block; width: 100%; height: auto; }
#hotspots, #pawns { position: absolute; inset: 0; }
#pawns { pointer-events: none; }
.hotspot {
  position: absolute;
  width: 7.1%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: transparent; border: 0; padding: 0;
}
.hotspot:hover, .hotspot:focus-visible { outline: 3px solid var(--gold); outline-offset: -3px; }

.pawn {
  position: absolute;
  width: 5.2%;
  aspect-ratio: 8 / 10;
  transform: translate(-50%, -78%);
  transition: left .14s linear, top .14s linear;
  z-index: 2;
}
.pawn.jump { transition: left .6s cubic-bezier(.4,0,.2,1), top .6s cubic-bezier(.4,0,.2,1); }
.pawn.active { z-index: 3; animation: bob .9s steps(2) infinite; }
.pawn svg, .pawn-icon svg { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
@keyframes bob { 50% { transform: translate(-50%, -88%); } }
@media (prefers-reduced-motion: reduce) {
  .pawn, .pawn.jump { transition: none; }
  .pawn.active { animation: none; }
}
.pawn-icon { display: inline-block; width: 22px; height: 28px; flex: none; }
.pawn-icon.big { width: 64px; height: 80px; }

/* ---------- painel inferior ---------- */
#hud {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: var(--paper);
  border-top: var(--px) solid var(--ink);
  padding: .5rem .8rem calc(.4rem + env(safe-area-inset-bottom));
  display: grid; gap: .45rem;
  max-width: 760px; margin: 0 auto;
}
@media (min-width: 761px) { #hud { border-left: var(--px) solid var(--ink); border-right: var(--px) solid var(--ink); } }
#playersStrip { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; }
.chip {
  display: flex; align-items: center; gap: .35rem;
  padding: .2rem .5rem .2rem .3rem;
  border: 2px solid #d7d9e6;
  font-size: .78rem; font-weight: 700; white-space: nowrap;
  background: #f4f5fb;
}
.chip.turn { border-color: var(--ink); background: #fff7cf; }
.chip.off { opacity: .45; }
.chip .pawn-icon { width: 14px; height: 18px; }
.chip small { font-weight: 600; color: var(--muted); }
.hud-main { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .7rem; }
#turnInfo { display: flex; align-items: center; gap: .55rem; min-width: 0; }
#turnInfo div { display: grid; min-width: 0; }
#turnText { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#statusText { font-size: .78rem; color: var(--muted); font-weight: 600; line-height: 1.3; }
#rollBtn { min-width: 96px; font-size: 1.05rem; }
#logToggle { justify-self: start; font-size: .78rem; padding: 0; }

/* dados em pixel */
#dice { display: flex; gap: .35rem; }
.die {
  width: 40px; height: 40px;
  background: #fff;
  border: var(--px) solid var(--ink);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 4px;
  box-shadow: 0 var(--px) 0 var(--ink);
}
.die i { width: 7px; height: 7px; background: var(--ink); place-self: center; visibility: hidden; }
.die i.on { visibility: visible; }
.die.rolling { animation: shake .09s steps(2) infinite; }
@keyframes shake { 50% { transform: translate(2px, -2px) rotate(8deg); } }

/* ---------- camadas ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: 1rem;
  background: rgba(20, 27, 61, .62);
}
.sheet {
  width: min(100%, 420px);
  max-height: 88vh; overflow: auto;
  background: #fff;
  border: var(--px) solid var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  padding: 1.3rem;
  display: grid; gap: 1rem;
}
.code { font-family: "Pixelify Sans", sans-serif; letter-spacing: .12em; color: var(--blue); }
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.player-list li { display: flex; align-items: center; gap: .6rem; font-weight: 700; }
.player-list li small { color: var(--muted); font-weight: 600; }
.color-pick { display: flex; gap: .5rem; flex-wrap: wrap; }
.color-pick button {
  width: 46px; height: 52px; padding: 4px 8px;
  background: #f4f5fb; border: var(--px) solid transparent;
}
.color-pick button[aria-pressed="true"] { border-color: var(--ink); background: #fff7cf; }
.color-pick button:disabled { opacity: .25; cursor: not-allowed; }
#logList { margin: 0; padding-left: 1.2rem; display: grid; gap: .35rem; font-size: .9rem; line-height: 1.4; }

/* carta de efeito: a casa do tabuleiro ampliada */
.card-overlay { background: rgba(20,27,61,.35); }
.fx-card {
  width: min(78vw, 300px); aspect-ratio: 1;
  border: 6px solid var(--ink);
  box-shadow: 0 8px 0 var(--ink);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; padding: 1.2rem; gap: .6rem;
  color: #fff;
  position: relative;
  animation: pop .22s steps(3);
}
.fx-card.good { background: var(--blue); }
.fx-card.bad { background: var(--red); }
.fx-card.neutral { background: #fff; color: var(--ink); }
.fx-card.final { background: var(--gold); color: var(--gold-ink); }
.fx-num { position: absolute; top: .5rem; left: .7rem; font-family: "Pixelify Sans", sans-serif; font-size: 1rem; opacity: .8; }
.fx-title { margin: 0; font-weight: 800; font-size: 1.35rem; line-height: 1.15; }
.fx-text { margin: 0; font-weight: 500; font-size: 1.05rem; line-height: 1.35; }
.fx-who { margin: 0; font-size: .8rem; font-weight: 700; opacity: .85; }
@keyframes pop { from { transform: scale(.6); } }

.choice-options { display: grid; gap: .5rem; }
.choice-options button {
  display: flex; align-items: center; gap: .7rem;
  padding: .7rem .8rem;
  background: #f4f5fb;
  border: var(--px) solid #d7d9e6;
  font-weight: 700; text-align: left;
}
.choice-options button[aria-pressed="true"] { border-color: var(--ink); background: #fff7cf; }
.choice-options small { color: var(--muted); font-weight: 600; margin-left: auto; }

#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%);
  z-index: 60;
  background: var(--ink); color: #fff;
  padding: .55rem .9rem; font-weight: 700; font-size: .9rem;
  max-width: 92vw; text-align: center;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }
