:root {
  --bg: #16112b;
  --bg2: #221a42;
  --panel: #2a2150;
  --line: #3b3170;
  --text: #f4f0ff;
  --muted: #a89fcc;
  --gold: #ffc83d;
  --gold-dark: #e0a100;
  --coral: #ff5d73;
  --mint: #3ddc97;
  --cream: #fff6df;
  --ink: #1d1638;
  --radius: 18px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -200px, #3a2a7a 0%, transparent 70%),
    radial-gradient(800px 500px at 110% 110%, #3b1747 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

#app { padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

h2 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.label {
  display: block;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: stretch; }
.row > input { flex: 1; min-width: 0; }

/* ---------- logo ---------- */

.logo { display: flex; align-items: center; justify-content: center; gap: 10px; user-select: none; }
.logo-num {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: var(--gold);
  color: var(--ink);
  font-size: 56px;
  font-weight: 900;
  transform: rotate(-6deg);
  box-shadow: 0 6px 0 var(--gold-dark), 0 14px 30px #0006;
}
.logo-word { font-size: 52px; font-weight: 900; letter-spacing: -.02em; }
.logo.small { justify-content: flex-start; gap: 8px; }
.logo.small .logo-num { width: 34px; height: 34px; font-size: 24px; border-radius: 10px; box-shadow: 0 3px 0 var(--gold-dark); }
.logo.small .logo-word { font-size: 22px; }

/* ---------- campos e botões ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field.small { flex: 1; min-width: 120px; }

input, select {
  font: inherit;
  font-size: 18px;
  color: var(--text);
  background: var(--bg2);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s;
}
select { font-size: 16px; padding: 10px 12px; }
input:focus, select:focus { border-color: var(--gold); }
input::placeholder { color: #7d74a6; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; text-align: center; }

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  color: var(--text);
  background: var(--line);
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0005;
  transition: transform .08s, box-shadow .08s, filter .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0005; }
.btn:disabled { opacity: .5; cursor: default; transform: none; filter: none; }
.btn.primary { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 var(--gold-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--gold-dark); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); padding: 8px 12px; }
.btn.ghost:hover { color: var(--text); }
.btn.small { font-size: 14px; }
.btn.big { width: 100%; padding: 16px; font-size: 20px; }

.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.error { margin: 0; color: var(--coral); font-weight: 600; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.waiting { text-align: center; color: var(--muted); font-size: 17px; margin: 14px 0; }

/* ---------- início ---------- */

.home { max-width: 440px; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 20px; }
.tagline { text-align: center; color: var(--muted); margin: -4px 0 4px; font-size: 17px; }
.rules summary { cursor: pointer; font-weight: 700; }
.rules ol { margin: 12px 0 0; padding-left: 20px; color: var(--muted); line-height: 1.55; }
.rules b { color: var(--text); }

/* ---------- sala ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.lobby, .end { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.room-code { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.room-code .code {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: .18em;
  padding-left: .18em;
  color: var(--gold);
  line-height: 1;
}
.count { background: var(--line); color: var(--text); border-radius: 99px; padding: 1px 9px; font-size: 12px; letter-spacing: 0; }
.settings { display: flex; gap: 10px; flex-wrap: wrap; }

.players, .scores, .feed { list-style: none; margin: 0; padding: 0; }
.players li, .scores li { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.players li + li, .scores li + li { border-top: 1px solid #ffffff0d; }
.off { opacity: .4; }
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-weight: 800;
  color: #fff;
  background: hsl(var(--h) 60% 48%);
}
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pname em { color: var(--muted); font-style: normal; font-weight: 400; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink); background: var(--gold); border-radius: 99px; padding: 3px 8px; }

/* ---------- jogo ---------- */

.game {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.game .topbar { margin: 0; }
.round { color: var(--muted); font-weight: 700; }

.timer { position: relative; height: 10px; border-radius: 99px; background: var(--bg2); overflow: hidden; }
.timer-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--gold), #ffe08a);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform .2s linear, background .3s;
}
.timer-fill.low { background: var(--coral); }
#timer-num { position: absolute; right: 0; top: 14px; font-size: 13px; font-weight: 800; color: var(--muted); }

.stage { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 26px 18px; }
.who { margin: 0; font-size: 18px; color: var(--muted); text-align: center; }
.who b { color: var(--text); }
.category { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.category span { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.category b {
  font-size: 22px;
  background: #ffffff12;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 18px;
}

[data-region="clues"] { width: 100%; display: flex; justify-content: center; }
.clues { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 640px; }
.clue {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  display: grid;
  place-items: center;
  padding: 26px 8px 10px;
  border: 2px dashed var(--line);
  background: #ffffff06;
}
.clue-pts {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.clue-text { font-size: clamp(18px, 4.4vw, 30px); font-weight: 900; color: #5d5390; overflow-wrap: anywhere; text-align: center; }
.clue.current { border-color: var(--gold); border-style: solid; animation: pulse 1.4s ease-in-out infinite; }
.clue.current .clue-text { color: var(--gold); }
.clue.filled {
  border: 0;
  background: var(--cream);
  box-shadow: 0 5px 0 #d9c99f, 0 14px 24px #0005;
}
.clue.new { animation: flip .45s cubic-bezier(.2, .9, .3, 1.3) both; }
.clue.filled .clue-pts { color: #9a8a5c; }
.clue.filled .clue-text { color: var(--ink); }

@keyframes pulse { 50% { box-shadow: 0 0 0 6px #ffc83d22; } }
@keyframes flip { from { transform: rotateX(90deg) scale(.9); opacity: 0; } }

.action { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.action .btn.ghost { align-self: center; }
.action .hint { text-align: center; margin: 0; }

.secret, .reveal, .winner {
  text-align: center;
  border-radius: 16px;
  padding: 14px;
  background: #ffc83d14;
  border: 1px solid #ffc83d55;
}
.secret.solved { background: #3ddc9714; border-color: #3ddc9766; }
.secret .word, .reveal .word, .winner .word {
  font-size: clamp(30px, 8vw, 44px);
  font-weight: 900;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .03em;
  overflow-wrap: anywhere;
}
.secret.solved .word { color: var(--mint); }
.reveal { animation: pop .4s cubic-bezier(.2, .9, .3, 1.4) both; }
.reveal p, .winner p { margin: 4px 0 0; color: var(--muted); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

.side { display: flex; flex-direction: column; gap: 16px; }
.scores .me .pname { color: var(--gold); }
.score { font-weight: 900; font-size: 20px; min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }
.st { font-size: 11px; font-weight: 800; border-radius: 99px; padding: 3px 8px; text-transform: uppercase; letter-spacing: .05em; }
.st.giver { background: var(--gold); color: var(--ink); }
.st.hit { background: var(--mint); color: #08321f; }
.st.done { background: var(--line); color: var(--muted); }

.feed { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; font-size: 15px; }
.feed li { color: var(--muted); }
.f-clue { color: var(--text) !important; font-weight: 700; }
.f-hit { color: var(--mint) !important; font-weight: 700; }
.f-miss::before { content: '✗ '; color: var(--coral); }
.f-reveal { color: var(--gold) !important; font-weight: 700; }

.winner { padding: 22px; }
.rank { width: 32px; font-weight: 900; color: var(--muted); }
.final li:first-child .rank { color: var(--gold); }
.end .row .btn.big { flex: 1; }

@media (min-width: 900px) {
  .game { grid-template-columns: 1fr 320px; }
  .game .topbar, .game .timer { grid-column: 1 / -1; }
  .stage { padding: 36px 28px; }
}

/* ---------- avisos ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px);
  opacity: 0;
  pointer-events: none;
  background: var(--cream);
  color: var(--ink);
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: 0 10px 30px #0008;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

body.is-offline::after {
  content: 'Reconectando…';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 6px;
  background: var(--coral);
  color: #fff;
  font-weight: 700;
  z-index: 20;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- placar com as palavras de cada um ---------- */
.pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pclues { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pclues i { font-style: normal; color: var(--text); background: #ffffff12; border-radius: 6px; padding: 0 5px; margin-left: 2px; }
.secret.mini { padding: 10px; background: #ffffff08; border-color: var(--line); }
.secret.mini .word { font-size: 22px; color: var(--text); }
.secret.mini .label + .label { margin-top: 4px; text-transform: none; letter-spacing: 0; }
