/* Identidade: noite de jabuticaba (roxo-vinho) com o amarelo do botão CAFUFA
   como única cor forte. Bungee (letreiro/placar) para marca, número e botões;
   Nunito para os textos. Visual escuro de propósito, nos dois temas do sistema. */
:root {
  --bg: #2a0f33;
  --surface: #3b1a47;
  --fg: #fff4e3;
  --muted: #c4a9cf;
  --accent: #ffc93c;
  --accent-dark: #c98a12;
  --on-accent: #2a0f33;
  --hot: #ff6b9a;
  --ok: #3ddc97;
  --bad: #ff4b4b;
  --font-display: "Bungee", "Arial Black", Impact, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-weight: 500;
  /* sem zoom por toque duplo ao apertar rápido */
  touch-action: manipulation;
}

main {
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- placar ---------- */

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
/* na partida o topo mostra o placar; fora dela, o jogador e as Rinhas */
.hud.playing .off-game,
.hud:not(.playing) .in-game { display: none; }

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 58%;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.95rem;
}
.player-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 0.9rem;
  background: var(--muted);
  color: var(--on-accent);
}
.player-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-tag { flex: none; font-size: 0.75rem; color: var(--muted); }
.player-chip[data-kind="google"] .player-avatar { background: var(--accent); }
.player-chip[data-kind="google"] .player-tag { color: var(--ok); font-size: 0.95rem; }
/* sem sessão: o chip vira convite para entrar */
.player-chip[data-kind="none"] { background: none; box-shadow: inset 0 0 0 2px var(--accent); }
.player-chip[data-kind="none"] .player-avatar { background: none; color: var(--accent); font-family: var(--font-body); font-weight: 800; font-size: 1.1rem; }

.rinhas-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}
.badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 400;
}
/* Rinha aberta em que o jogador ainda não jogou */
.badge.dot { width: 10px; height: 10px; padding: 0; background: var(--hot); }

.stat strong {
  margin-left: 6px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

/* ---------- telas ---------- */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 20px;
}
.hidden { display: none !important; }

p { line-height: 1.5; margin: 0; }
strong { font-weight: 800; }
.hint { color: var(--muted); font-size: 0.9rem; max-width: 32ch; }

/* ---------- tela inicial ---------- */

.brand {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.brand-mark { width: 96px; height: 96px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(3rem, 15vw, 4.2rem);
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 4px 0 var(--accent-dark);
}
.tagline {
  font-size: 1.25rem;
  font-weight: 800;
  text-wrap: balance;
}

.rule {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border-radius: 20px;
  background: var(--surface);
  max-width: 360px;
}
.rule p { text-wrap: pretty; }

.examples {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.chip {
  min-width: 44px;
  padding: 6px 8px;
  border-radius: 12px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}
.chip.yes { background: var(--accent); color: var(--on-accent); }
.chip.no {
  color: var(--muted);
  border: 2px dashed var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

/* atalhos da tela inicial: Rinha e Ranking, já com a posição */
.home-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}
.home-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--fg);
  text-align: left;
  box-shadow: inset 0 0 0 2px transparent;
}
/* Rinha aberta: o cartão ganha a borda amarela */
.home-card.live { box-shadow: inset 0 0 0 2px var(--accent); }
.home-card-label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.home-card strong { font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; line-height: 1.2; }
.home-card.live strong { color: var(--accent); }
.home-card strong,
.home-card-sub { max-width: 100%; overflow-wrap: anywhere; }
.home-card-sub { color: var(--muted); font-size: 0.85rem; }
.home-card-sub:empty { display: none; }

/* ---------- jogo ---------- */

/* partida valendo pela Rinha */
.champ-banner {
  max-width: 100%;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#game-screen { position: relative; user-select: none; -webkit-user-select: none; }

.number {
  font-family: var(--font-display);
  font-size: clamp(6rem, 35vw, 10rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: color 0.15s;
}
.number.ok { color: var(--ok); }
.number.bad { color: var(--bad); }
.number.countdown { color: var(--muted); }
.number.pop { animation: pop 160ms ease-out; }
.number.hit { animation: hit 260ms ease-out; }

@keyframes pop {
  from { transform: scale(0.8); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes hit {
  40% { transform: scale(1.25); }
  to { transform: scale(1); }
}

#game-screen.shake { animation: shake 400ms ease-in-out; }
@keyframes shake {
  20%, 60% { transform: translateX(-12px); }
  40%, 80% { transform: translateX(12px); }
}

.timer {
  width: 40%;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  background: var(--muted);
  opacity: 0.35;
  transform-origin: left;
}

.toast {
  position: absolute;
  top: 8%;
  left: 0;
  right: 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--hot);
  opacity: 0;
  pointer-events: none;
}
.toast.show { animation: toast 1100ms ease-out; }
/* fantasma do recorde: mais abaixo, para não cobrir o "MAIS RÁPIDO!" se vierem juntos */
.ghost-toast { top: 17%; font-size: 1.1rem; }
.ghost-toast.show { animation-duration: 1600ms; }
/* recorde do topo passa a acompanhar os pontos depois que o fantasma fica para trás */
.stat strong.beaten { color: var(--hot); }
@keyframes toast {
  15% { opacity: 1; transform: translateY(0) scale(1.1); }
  70% { opacity: 1; transform: translateY(-6px) scale(1); }
  to { opacity: 0; transform: translateY(-16px); }
}

.notice {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 200ms ease-out, transform 200ms ease-out;
  pointer-events: none;
}
.notice.show { opacity: 1; transform: translate(-50%, 0); }

.particle {
  position: fixed;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  pointer-events: none;
  animation: fly 600ms ease-out forwards;
}
@keyframes fly {
  to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

.flash {
  position: fixed;
  inset: 0;
  background: var(--bad);
  opacity: 0;
  pointer-events: none;
}
.flash.on { animation: flash 500ms ease-out; }
@keyframes flash {
  from { opacity: 0.45; }
  to { opacity: 0; }
}

/* ---------- fim de jogo ---------- */

.new-record {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--on-accent);
  background: var(--hot);
  padding: 6px 16px;
  border-radius: 999px;
  animation: hit 500ms ease-out;
}
.reason {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.3;
  text-wrap: balance;
}
.result {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.result-score {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--accent);
}
.result-score strong {
  font-weight: 400;
  font-size: 4rem;
  line-height: 1;
  display: block;
}
.result-number { color: var(--muted); }

.tutorial-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.tutorial-label {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.result-number strong { color: var(--fg); }

/* ---------- botões ---------- */

button {
  font: inherit;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn {
  background: none;
  font-size: 1.3rem;
  padding: 4px 8px;
}

/* botão amarelo de "apertar": Jogar, Jogar de novo e o CAFUFA */
.primary,
.cafufa {
  width: 100%;
  max-width: 320px;
  font-family: var(--font-display);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 4px 0 var(--accent-dark);
}
.primary:active,
.cafufa:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }

.primary { min-height: 60px; font-size: 1.4rem; }
.cafufa { min-height: 70px; font-size: 1.6rem; user-select: none; }

/* número centralizado no espaço livre; botão embaixo, na zona do polegar */
#game-screen .number { margin-top: auto; }
#game-screen .cafufa { margin-top: auto; margin-bottom: 24px; }

.share {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.share-btn {
  background: none;
  border: 2px solid var(--muted);
  border-radius: 16px;
  color: var(--fg);
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
}
/* bateu o recorde: compartilhar ganha destaque */
.share-btn.highlight { border-color: var(--hot); background: var(--hot); color: var(--on-accent); }

/* ação secundária discreta, como "Jogar sem valer" */
.link-btn {
  background: none;
  color: var(--muted);
  padding: 6px 12px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.share-text {
  width: 100%;
  max-width: 360px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font: inherit;
}
.share-text[hidden] { display: none; }

/* ---------- conta ---------- */

.hud-actions { display: flex; gap: 2px; }

.account-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.8rem;
  color: var(--accent);
}
.account-status { max-width: 34ch; text-wrap: balance; }

.nickname-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 360px;
  text-align: left;
}
.nickname-form label {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
/* o botão (até 320px) é mais estreito que o formulário (360px): centraliza como nas outras telas */
.nickname-form > .primary { align-self: center; margin-top: 8px; }
.nickname-row { display: flex; gap: 8px; }
.text-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 16px;
  border: 2px solid var(--muted);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-weight: 800;
}
.text-input:focus-visible { border-color: var(--accent); outline: none; }
.text-input:read-only { opacity: 0.6; }

/* salvando o apelido: botão travado com um anel girando */
.share-btn:disabled { cursor: default; opacity: 0.75; }
.share-btn.busy { display: inline-flex; align-items: center; gap: 8px; }
.share-btn.busy::before {
  content: "";
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* salvou: o botão pisca verde */
.share-btn.saved { animation: saved 900ms ease-out; }
@keyframes saved {
  0%, 40% { border-color: var(--ok); color: var(--ok); }
}
#nickname-msg[data-kind="ok"] { color: var(--ok); font-weight: 800; }
#nickname-msg[data-kind="bad"] { color: var(--bad); font-weight: 800; }
/* apelido recusado: o campo balança de lado */
.text-input.shake-x { animation: shake-x 320ms ease-in-out; border-color: var(--bad); }
@keyframes shake-x {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.google-btn { min-height: 44px; }
/* o iframe do Google é claro; com o color-scheme escuro da página ele ganharia fundo branco */
.google-btn iframe { color-scheme: light; }
.share-btn.danger { border-color: var(--bad); color: var(--bad); }
.hint a { color: var(--fg); }

/* ---------- Rinha ---------- */

.section-label {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
a.hint { color: var(--muted); }

/* central "Suas Rinhas" */
#rinhas-screen { gap: 14px; }
.champ-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.champ-cards:empty { display: none; }
.champ-card {
  display: grid;
  grid-template-columns: 3.2em 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--fg);
  text-align: left;
}
.champ-card-pos { font-family: var(--font-display); font-size: 1.6rem; color: var(--accent); text-align: center; }
.champ-card-body { display: flex; flex-direction: column; min-width: 0; }
.champ-card-body strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.champ-card-body span { color: var(--muted); font-size: 0.9rem; }
.champ-card.ended { opacity: 0.75; }
.champ-card.ended .champ-card-pos { color: var(--muted); }

/* posição em destaque no fim de jogo */
.big-pos {
  font-family: var(--font-display);
  font-size: 3rem;
  line-height: 1;
  color: var(--accent);
}
.big-pos small { font-family: var(--font-body); font-size: 1rem; font-weight: 800; color: var(--muted); }

#rinha-screen { gap: 14px; }
.rinha-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.6rem, 8vw, 2.2rem);
  line-height: 1.1;
  color: var(--accent);
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.rinha-info { color: var(--muted); }
.rinha-champion {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--on-accent);
  background: var(--hot);
  padding: 8px 16px;
  border-radius: 16px;
  text-wrap: balance;
}
.rinha-ranking {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rank-row {
  display: grid;
  grid-template-columns: minmax(2.2em, auto) 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
}
.rank-row.me { outline: 2px solid var(--accent); }
.rank-pos { font-family: var(--font-display); color: var(--muted); }
.rank-nick { font-weight: 800; overflow-wrap: anywhere; }
.rank-best { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.rinha-msg { color: var(--hot); font-weight: 800; }

.rinha-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--surface);
  max-width: 360px;
  text-wrap: balance;
}

/* ---------- Ranking global ---------- */

#ranking-screen { gap: 14px; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface); }
.tab {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }
.rank-gap { text-align: center; color: var(--muted); list-style: none; }

@media (prefers-reduced-motion: reduce) {
  .number.pop, .number.hit, #game-screen.shake, .new-record { animation: none; }
  .particle { display: none; }
  .notice { transition: none; }
  .text-input.shake-x, .share-btn.saved { animation: none; }
  .share-btn.busy::before { animation-duration: 2s; }
}
