:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1d1b16;
  --muted: #6f6a5d;
  --line: #e2ddd0;
  --accent: #c8452c;
  --accent-ink: #ffffff;
  --good: #2e7d4f;
  --bad: #b3372a;
  --gold: #b7791f;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --card: #221f17;
    --ink: #f1ede2;
    --muted: #a39d8c;
    --line: #38342a;
    --accent: #e2634a;
    --accent-ink: #1a0d09;
    --good: #5bbf85;
    --bad: #ee7d6e;
    --gold: #e8b04a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; padding: 24px 16px 40px; }

.title { font-size: 1.6rem; text-align: center; margin: 0 0 16px; letter-spacing: -0.01em; }
.h2 { font-size: 1.2rem; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 12px; }
.lead { margin: 0 0 14px; }

/* ---------- barra do usuário ---------- */
.userbar {
  display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.userbar-info { display: flex; flex-direction: column; min-width: 0; }
.userbar-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbar-stats { color: var(--muted); font-size: 0.85rem; }
.coins { color: var(--gold); font-weight: 700; }
.userbar-nav { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn {
  padding: 6px 12px; font-size: 0.85rem; font-weight: 600; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.chip-btn:hover { border-color: var(--muted); }

/* ---------- avatar ---------- */
.avatar {
  --s: 44px;
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: var(--s); height: var(--s); border-radius: 50%;
  font-size: calc(var(--s) * 0.58); line-height: 1; flex: none;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
}
.avatar .acc { position: absolute; top: calc(var(--s) * -0.2); right: calc(var(--s) * -0.12); font-size: calc(var(--s) * 0.38); transform: rotate(14deg); }
.avatar-preview { display: flex; justify-content: center; margin: 8px 0 18px; padding-top: 10px; }

.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.pick {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 42px; height: 42px; padding: 0 6px; font-size: 1.4rem;
  background: transparent; border: 2px solid var(--line); border-radius: 10px; cursor: pointer;
}
.pick:hover { border-color: var(--muted); }
.pick[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pick.swatch { width: 38px; min-width: 38px; height: 38px; border-radius: 50%; }
.pick.none { font-size: 0.8rem; font-weight: 600; color: var(--muted); }

/* ---------- campos e botões ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span, .field .label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.field small { color: var(--muted); }

input[type="text"] {
  width: 100%; padding: 12px 14px; font-size: 1rem; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select {
  padding: 8px 10px; font-size: 0.9rem; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px;
}

.actions { display: grid; gap: 10px; }
.actions.row { grid-auto-flow: column; grid-auto-columns: 1fr; }

.btn {
  padding: 13px 16px; font-size: 1rem; font-weight: 600; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.btn small { font-weight: 400; color: var(--muted); }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 8px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .move:focus-visible, .link:focus-visible, .chip-btn:focus-visible,
.pick:focus-visible, .seg button:focus-visible, .emote:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 52px; padding: 10px 6px; font-size: 0.95rem; font-weight: 600; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.seg button[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }

.login-box { text-align: center; padding: 4px 0 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.google-btn { display: flex; justify-content: center; min-height: 0; margin-bottom: 8px; }
.daily {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; margin-bottom: 16px; border: 1px dashed var(--gold); border-radius: 10px; color: var(--gold); font-weight: 600;
}

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.85rem; margin: 22px 0 16px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.join { display: flex; gap: 10px; }
.join input { text-transform: uppercase; letter-spacing: 0.2em; text-align: center; font-weight: 700; }

.error { color: var(--bad); font-size: 0.92rem; margin: 14px 0 0; }

/* ---------- ranking ---------- */
.rank-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rank-list { list-style: none; margin: 0 0 14px; padding: 0; }
.rank-row {
  display: grid; grid-template-columns: 28px auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px 6px; border-bottom: 1px solid var(--line);
}
.rank-row.me { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 8px; }
.rank-pos { font-weight: 800; text-align: center; color: var(--muted); }
.rank-row:nth-child(-n+3) .rank-pos { color: var(--gold); }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank-stat { text-align: right; font-size: 0.85rem; color: var(--muted); }
.rank-stat b { color: var(--ink); }
.rank-me { margin: 0 0 14px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; font-size: 0.9rem; }

/* ---------- jogo ---------- */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted);
}
.pill.gold { color: var(--gold); border-color: var(--gold); }
.link { background: none; border: 0; color: var(--muted); font-size: 0.9rem; cursor: pointer; text-decoration: underline; }

.waiting { text-align: center; padding: 18px 0 8px; }
.code-big { font-size: 2.6rem; font-weight: 800; letter-spacing: 0.25em; margin: 6px 0 14px; padding-left: 0.25em; }

.scores { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px; text-align: center; }
.side { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.avwrap { position: relative; padding-top: 8px; }
.side .name { max-width: 100%; font-size: 0.9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .points { font-size: 2.4rem; font-weight: 800; line-height: 1.05; }
.points.bump { animation: bump 0.5s ease; }
.vs { align-self: center; text-align: center; font-size: 0.85rem; color: var(--muted); }
.vs small { display: block; font-size: 0.75rem; }

/* balão de emote */
.bubble {
  position: absolute; left: 50%; top: -14px; transform: translateX(-50%);
  font-size: 2.2rem; line-height: 1; padding: 4px 8px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  animation: bubble-pop 2.4s ease forwards; pointer-events: none; z-index: 3;
}

/* ---------- arena: animações da rodada ---------- */
.arena {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; align-items: center;
  height: 118px; margin: 14px 0 0; overflow: hidden;
}
.fighter { display: flex; justify-content: center; transition: transform 0.28s ease; }
.hand { position: relative; width: 4.2rem; height: 4.2rem; font-size: 3.6rem; line-height: 4.2rem; text-align: center; }
.hand .glyph { position: relative; width: 100%; height: 100%; }
.fighter.right .glyph { transform: scaleX(-1); }
.hand .half { position: absolute; inset: 0; text-align: center; }
.hand .half.a { clip-path: inset(0 50% 0 0); }
.hand .half.b { clip-path: inset(0 0 0 50%); }

.arena.shaking .fighter { animation: shake 0.3s ease-in-out 3; }
.arena.clash .fighter.left { transform: translateX(14%); }
.arena.clash .fighter.right { transform: translateX(-14%); }

/* efeitos: perdedor quebrado / cortado / embrulhado */
.hand.broken .half.a { animation: break-left 0.75s ease-in forwards; }
.hand.broken .half.b { animation: break-right 0.75s ease-in forwards; }
.hand.cut .half.a { animation: cut-left 0.8s ease-in forwards; }
.hand.cut .half.b { animation: cut-right 0.8s ease-in forwards; }
.hand.wrapped { animation: squish 0.7s ease forwards; }
.hand.smash { animation: smash 0.5s ease; }
.hand.snip { animation: snip 0.6s ease; }
.hand.cover { animation: cover 0.7s ease forwards; }
.hand.drawn { animation: bounce 0.6s ease; }

.spark {
  position: absolute; left: 50%; top: 50%; font-size: 3rem; line-height: 1;
  transform: translate(-50%, -50%) scale(0); pointer-events: none; z-index: 2;
}
.spark.show { animation: spark 0.75s ease forwards; }

.result { text-align: center; font-weight: 700; font-size: 1rem; min-height: 1.5em; margin-top: 6px; }
.result.win { color: var(--good); }
.result.lose { color: var(--bad); }
.result.draw { color: var(--muted); }
.result.pop { animation: result-pop 0.4s ease; }

.status { text-align: center; min-height: 1.5em; margin: 10px 0; color: var(--muted); }

.moves { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.move {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px 6px; font-size: 0.95rem; font-weight: 600; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.move .emoji { font-size: 2.2rem; }
.move:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.move:disabled { opacity: 0.45; cursor: default; }
.move.chosen { border-color: var(--accent); opacity: 1; background: color-mix(in srgb, var(--accent) 12%, transparent); }

#btn-claim { display: block; margin: 0 auto 12px; }

.emotes { display: flex; justify-content: center; gap: 5px; margin-top: 14px; }
.emote {
  font-size: 1.2rem; width: 38px; height: 38px; line-height: 1; cursor: pointer; padding: 0;
  background: transparent; border: 1px solid var(--line); border-radius: 50%;
}
.emote:hover:not(:disabled) { border-color: var(--accent); transform: scale(1.08); }
.emote:disabled { opacity: 0.4; cursor: default; }

.finished { text-align: center; margin-top: 18px; }
.finished-text { font-size: 1.4rem; font-weight: 800; margin: 0 0 4px; }
.finished-text.win { color: var(--good); }
.finished-text.lose { color: var(--bad); }

.foot { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-size: 0.9rem; font-weight: 600; z-index: 10;
}

/* ---------- keyframes ---------- */
@keyframes shake { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-22px) rotate(-6deg); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes bubble-pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.4); }
  12% { opacity: 1; transform: translate(-50%, -4px) scale(1.15); }
  22% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -22px) scale(0.9); }
}
@keyframes break-left { to { transform: translate(-46px, 22px) rotate(-52deg); opacity: 0; } }
@keyframes break-right { to { transform: translate(46px, 22px) rotate(52deg); opacity: 0; } }
@keyframes cut-left { 30% { transform: translate(-6px, 4px) rotate(-4deg); } to { transform: translate(-26px, 40px) rotate(-26deg); opacity: 0; } }
@keyframes cut-right { 30% { transform: translate(6px, 4px) rotate(4deg); } to { transform: translate(26px, 40px) rotate(26deg); opacity: 0; } }
@keyframes squish { 40% { transform: scale(0.8, 0.55); } to { transform: scale(0.55, 0.35); opacity: 0.35; } }
@keyframes smash { 30% { transform: scale(1.35); } 60% { transform: scale(0.95); } 100% { transform: scale(1); } }
@keyframes snip { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-16deg); } 40% { transform: rotate(14deg); } 60% { transform: rotate(-12deg); } 80% { transform: rotate(8deg); } }
@keyframes cover { 50% { transform: scale(1.55); } to { transform: scale(1.3); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 30% { transform: translateY(-18px); } 60% { transform: translateY(0); } 80% { transform: translateY(-6px); } }
@keyframes spark {
  0% { transform: translate(-50%, -50%) scale(0) rotate(-20deg); opacity: 1; }
  45% { transform: translate(-50%, -50%) scale(1.5) rotate(8deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.9) rotate(0); opacity: 0; }
}
@keyframes result-pop { 0% { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }

@media (max-width: 400px) {
  .emotes { display: grid; grid-template-columns: repeat(4, 1fr); justify-items: center; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .move, .fighter { transition: none; }
  .arena.shaking .fighter, .bubble, .spark.show, .points.bump, .result.pop,
  .hand.broken .half, .hand.cut .half, .hand.wrapped, .hand.smash, .hand.snip, .hand.cover, .hand.drawn { animation: none; }
  .hand.broken .half, .hand.cut .half { opacity: 0.25; }
  .hand.wrapped { opacity: 0.45; }
}
