:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #8a8a93;
  --line: #ececee;
  --soft: #f4f4f5;
  --accent: #18181b;
  --on-accent: #ffffff;
  --good: #16a34a;
  --good-soft: #ecfdf3;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --turn: #6366f1;
  --turn-soft: #eef0ff;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e;
    --surface: #151518;
    --text: #f4f4f5;
    --muted: #7c7c86;
    --line: #232328;
    --soft: #1c1c20;
    --accent: #f4f4f5;
    --on-accent: #0c0c0e;
    --good: #4ade80;
    --good-soft: #10241a;
    --bad: #f87171;
    --bad-soft: #2a1414;
    --turn: #818cf8;
    --turn-soft: #1b1c33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

h1, h2, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent); }
input::placeholder { color: var(--muted); }

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  cursor: pointer;
  background: var(--accent);
  color: var(--on-accent);
  transition: opacity .15s, transform .05s;
  white-space: nowrap;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .35; cursor: default; transform: none; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.link { background: none; color: var(--muted); padding: 6px 0; font-weight: 500; }
button.link:hover { color: var(--text); }
button.tiny { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.row { display: flex; gap: 8px; }
.row > input { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- home ---------- */
.home {
  max-width: 380px;
  margin: 10vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand { text-align: center; }
.brand h1 { font-size: 40px; font-weight: 800; letter-spacing: -0.04em; }
.brand p { color: var(--muted); margin-top: 6px; }
.or {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 13px;
}
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 600; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px;
}
.room-code { font-weight: 700; letter-spacing: .25em; font-size: 14px; }
.room-code span { color: var(--muted); letter-spacing: 0; font-weight: 500; margin-right: 8px; }

/* ---------- lobby ---------- */
.lobby { max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.big-code {
  text-align: center;
  padding: 28px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.big-code .label { color: var(--muted); font-size: 13px; }
.big-code .code { font-size: 48px; font-weight: 800; letter-spacing: .25em; margin: 4px 0 10px; padding-left: .25em; }
.big-code.choose { padding: 32px 16px; }
.big-code .target {
  font-size: 40px; font-weight: 800; letter-spacing: -0.03em;
  margin: 2px 0 6px; color: var(--turn); word-break: break-word;
}
.section-title { font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 10px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }
.hint.ok { color: var(--good); }

.plist { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.plist li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.plist li + li { border-top: 1px solid var(--line); }
.plist .name { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--good); }
.tag { font-size: 12px; color: var(--muted); }

/* ---------- game ---------- */
.turn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}
.turn.mine { border-color: var(--turn); box-shadow: 0 0 0 3px var(--turn-soft); }
.turn-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.turn-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.secs { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 22px; }
.secs.low { color: var(--bad); }
.bar { height: 4px; background: var(--soft); border-radius: 4px; margin-top: 14px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--turn); border-radius: 4px; width: 100%; }
.bar.low > i { background: var(--bad); }
.turn-sub { color: var(--muted); margin-top: 10px; font-size: 14px; }
.guess-form { margin-top: 16px; }
button.skip {
  width: 100%;
  margin-top: 10px;
  padding: 15px 18px;
  font-size: 17px;
  font-weight: 700;
  background: var(--turn);
  color: #fff;
  box-shadow: 0 6px 20px -8px var(--turn);
}
button.skip:hover { opacity: .92; }

.votes { display: inline-flex; gap: 8px; }
button.vote {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  font-size: 14px; font-variant-numeric: tabular-nums;
}
button.vote .ic { font-size: 16px; font-weight: 800; line-height: 1; }
button.vote.yes .ic { color: var(--good); }
button.vote.no .ic { color: var(--bad); }
button.vote.yes.on { background: var(--good-soft); border-color: var(--good); }
button.vote.no.on { background: var(--bad-soft); border-color: var(--bad); }
button.vote:disabled { opacity: .6; }

.last {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  font-size: 14px; color: var(--muted);
  margin-bottom: 20px; min-height: 30px; text-align: center;
}
.last b { color: var(--text); font-weight: 600; }
.last .yes { color: var(--good); font-weight: 600; }
.last .no { color: var(--bad); font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  min-height: 112px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  transition: border-color .2s, opacity .2s, box-shadow .2s;
}
.card .who { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; gap: 8px; }
.card .who .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .char { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; word-break: break-word; }
.card.me .char { color: var(--muted); font-size: 32px; }
.card.turn-on { border-color: var(--turn); box-shadow: 0 0 0 3px var(--turn-soft); }
.card.solved { background: var(--good-soft); border-color: transparent; }
.card.solved .badge { color: var(--good); }
.card.loser .badge { color: var(--bad); }
.badge { font-size: 12px; font-weight: 600; }

/* ---------- end ---------- */
.end-head { text-align: center; margin: 8px 0 28px; }
.end-head h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.end-head p { color: var(--muted); margin-top: 6px; }
.end-actions { display: flex; justify-content: center; margin-top: 28px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--accent); color: var(--on-accent);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  #app { padding-top: 20px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { min-height: 96px; padding: 14px; }
  .card .char { font-size: 17px; }
  .big-code .code { font-size: 40px; }
}

/* ---------- home: escolha do jogo ---------- */
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.game-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  text-align: left; white-space: normal;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; font-weight: 500;
}
button.game-opt .g-name { font-weight: 700; font-size: 16px; }
button.game-opt .g-desc { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
button.game-opt.on { border-color: var(--turn); box-shadow: 0 0 0 3px var(--turn-soft); }

/* ---------- stop: lobby ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 500;
}
.chip button { background: none; color: var(--muted); padding: 0 0 0 2px; font-size: 16px; line-height: 1; }
.chip button:hover { color: var(--bad); }

/* ---------- stop: rodada ---------- */
.stop-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.stop-top .right { text-align: right; }
.stop-top .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.letter {
  font-size: 64px; font-weight: 800; line-height: 1;
  width: 96px; height: 96px; display: grid; place-items: center;
  border-radius: 20px; background: var(--turn-soft); color: var(--turn);
}
.cat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px;
  margin-bottom: 16px;
}
.card.cat { min-height: 0; cursor: text; gap: 6px; }
.card.cat:focus-within { border-color: var(--text); }
.card.cat.ok { border-color: color-mix(in srgb, var(--good) 55%, transparent); }
.card.cat.bad { border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.card.cat input {
  border: 0; padding: 0; background: transparent; box-shadow: none;
  font-size: 19px; font-weight: 700; text-transform: uppercase; letter-spacing: -0.01em;
}
.card.cat input::placeholder { text-transform: none; font-weight: 500; }
.card.cat input:focus { box-shadow: none; }
button.stop-btn {
  width: 100%; padding: 18px; font-size: 22px; font-weight: 800; letter-spacing: .08em;
  background: var(--bad); color: #fff; box-shadow: 0 8px 24px -10px var(--bad);
}

/* ---------- stop: STOP! ---------- */
.stop-center { text-align: center; padding: 48px 0 28px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.stop-center h2 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stop-word { font-size: 64px; font-weight: 800; color: var(--bad); letter-spacing: .04em; line-height: 1; animation: pop .4s ease-out; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pills { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--soft); color: var(--muted); }
.pill.on { background: var(--good-soft); color: var(--good); }

/* ---------- stop: validação ---------- */
.ans-wrap { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 8px 0 20px; min-height: 48px; }
button.ans {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; font-size: 17px; font-weight: 700;
}
button.ans .x { font-size: 13px; color: var(--bad); font-weight: 700; }
button.ans.mine { border-color: var(--bad); }
button.ans.invalid { background: var(--bad-soft); color: var(--bad); border-color: transparent; text-decoration: line-through; }
button.ans.off { opacity: .45; }
.dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 16px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--turn); }
.dots i.done { background: color-mix(in srgb, var(--turn) 40%, transparent); }
.center-row { display: flex; justify-content: center; }

/* ---------- stop: placar ---------- */
.score-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.plist .rank { width: 28px; text-align: center; color: var(--muted); font-weight: 700; flex: none; }
.plist .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.plist .pts.plus { color: var(--good); }
.ready-box { max-width: 380px; margin: 24px auto 0; }

/* ---------- stop: anticheat e painel secreto ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(6px);
}
.overlay.show { display: flex; }
.overlay-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.overlay-title { font-size: 24px; font-weight: 800; color: var(--bad); }
.cheat {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; display: none;
  width: 260px; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 12px 40px -12px rgba(0, 0, 0, .35);
}
.cheat.show { display: block; }
.cheat input { padding: 8px 10px; width: 80px; flex: none; }

@media (max-width: 520px) {
  .games { grid-template-columns: 1fr; }
  .letter { width: 76px; height: 76px; font-size: 48px; }
  .stat { font-size: 20px; }
  .cat-grid { grid-template-columns: 1fr 1fr; }
  .card.cat input { font-size: 16px; }
  .score-cols { grid-template-columns: 1fr; }
  .stop-word { font-size: 52px; }
}
