:root {
  --bg: #fbf5ec;
  --card: #ffffff;
  --ink: #2a1d17;
  --muted: #7a6a60;
  --line: #eadfd2;
  --red: #b3122e;
  --red-dark: #8c0d23;
  --green: #1d6b47;
  --green-soft: #e3f1e9;
  --gold: #d9a441;
  --gold-soft: #fbf0d9;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(60, 30, 10, 0.06), 0 8px 24px rgba(60, 30, 10, 0.08);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 240px;
  background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
  z-index: -1;
}

.snow {
  position: fixed;
  inset: 0 0 auto 0;
  height: 240px;
  z-index: -1;
  background-image:
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,.55) 50%, transparent 51%),
    radial-gradient(2px 2px at 80px 120px, rgba(255,255,255,.4) 50%, transparent 51%),
    radial-gradient(3px 3px at 150px 60px, rgba(255,255,255,.35) 50%, transparent 51%),
    radial-gradient(2px 2px at 220px 180px, rgba(255,255,255,.45) 50%, transparent 51%),
    radial-gradient(2px 2px at 300px 90px, rgba(255,255,255,.4) 50%, transparent 51%);
  background-size: 340px 220px;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* ---------- topo ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: Fraunces, Georgia, serif;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex: none;
}

.brand .gift { font-size: 24px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px 6px 4px 4px;
  border-radius: 999px;
  font-size: 14px;
  min-width: 0;
}

.user-chip .name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-btn {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-size: 13px;
  opacity: 0.85;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 999px;
}
.link-btn:hover { opacity: 1; background: rgba(255,255,255,.12); }

/* ---------- cartões ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

.hero {
  text-align: center;
  padding: 36px 24px 32px;
}

.hero .big-gift {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 12px;
}

h1, h2, h3 {
  font-family: Fraunces, Georgia, serif;
  font-weight: 800;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
  line-height: 1.15;
}

h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

p { margin: 0 0 12px; }

.room-title {
  color: #fff;
  margin-bottom: 20px;
}
.room-title h1 { font-size: 32px; color: #fff; overflow-wrap: anywhere; }
.room-title .meta { color: rgba(255,255,255,.85); font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

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

.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 600;
  border-radius: 12px;
  padding: 13px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .06s ease, background .15s ease, opacity .15s ease;
  text-decoration: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }

.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { background: #155236; }

.btn-ghost { background: #f3ece3; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: #eadfd2; }

.btn-whats { background: #25d366; color: #0b3d20; }
.btn-whats:hover { background: #1fbe5b; }

.btn-danger-ghost { background: none; color: var(--red); padding: 10px 12px; font-size: 14px; }
.btn-danger-ghost:hover { background: #fbe9ec; }

.btn-draw {
  font-size: 18px;
  padding: 18px 20px;
  border-radius: 14px;
}
.btn-draw:disabled {
  background: #ece5dc;
  color: #9b8b80;
}

.hint {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

/* ---------- formulário ---------- */

.input {
  width: 100%;
  font: inherit;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fffdfa;
  color: var(--ink);
  outline: none;
}
.input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(179,18,46,.12); }

.row { display: flex; gap: 10px; }
.row .input { flex: 1; min-width: 0; }

/* ---------- lista de salas ---------- */

.room-list { list-style: none; margin: 0; padding: 0; }
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}
.room-item:first-child { border-top: 0; }
.room-item .ico {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--gold-soft);
  font-size: 20px;
}
.room-item .info { flex: 1; min-width: 0; }
.room-item .info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item .chev { color: var(--muted); font-size: 20px; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #8a6010;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: #fbe9ec; color: var(--red); }
.badge.light { background: rgba(255,255,255,.18); color: #fff; }

/* ---------- avatares / sala ---------- */

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--gold-soft);
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  color: #8a6010;
  flex: none;
  overflow: hidden;
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 18px 10px;
  margin-top: 16px;
}

.player {
  text-align: center;
  position: relative;
  animation: pop .35s ease both;
}
.player .avatar {
  width: 68px; height: 68px;
  font-size: 24px;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--line);
}
.player.owner .avatar { box-shadow: 0 0 0 2px var(--gold); }
.player.me .avatar { box-shadow: 0 0 0 2px var(--green); }
.player .pname {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.player .tag { font-size: 11px; color: var(--muted); }
.player .crown {
  position: absolute;
  top: -8px; left: 50%;
  transform: translateX(14px) rotate(18deg);
  font-size: 18px;
}
.player .remove {
  position: absolute;
  top: -4px; right: calc(50% - 44px);
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 0;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  color: var(--red);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.waiting-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #7dffb0;
  animation: pulse 1.6s infinite;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.invite-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #faf6f0;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
  margin: 12px 0;
}
.invite-box code {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-box .btn { padding: 8px 12px; font-size: 14px; }

.stack { display: grid; gap: 10px; }

/* ---------- resultado ---------- */

.result {
  text-align: center;
  padding: 32px 24px;
}

.reveal {
  margin: 20px auto 8px;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 4 / 5;
  perspective: 1000px;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  display: block;
}
.reveal-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .7s cubic-bezier(.2,.8,.2,1);
  transform-style: preserve-3d;
}
.reveal.open .reveal-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.face.front {
  background:
    linear-gradient(90deg, transparent 44%, var(--gold) 44%, var(--gold) 56%, transparent 56%),
    linear-gradient(0deg, transparent 44%, var(--gold) 44%, var(--gold) 56%, transparent 56%),
    linear-gradient(160deg, var(--red) 0%, var(--red-dark) 100%);
  color: #fff;
  box-shadow: 0 14px 34px rgba(140, 13, 35, .35);
}
.face.front .tap {
  background: rgba(255,255,255,.95);
  color: var(--red);
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 15px;
  animation: bob 2s ease-in-out infinite;
}
.face.back {
  background: linear-gradient(180deg, #fff 0%, var(--gold-soft) 100%);
  border: 2px solid var(--gold);
  transform: rotateY(180deg);
}
.face.back .avatar {
  width: 128px; height: 128px;
  font-size: 46px;
  border: 5px solid #fff;
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
}
.face.back .match-name {
  font-family: Fraunces, Georgia, serif;
  font-weight: 800;
  font-size: 26px;
  margin-top: 16px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

/* ---------- login ---------- */

.google-slot {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin-top: 20px;
}

.dev-login {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
}

.notice {
  background: var(--gold-soft);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  color: #6b4b0c;
  margin-top: 16px;
}

/* ---------- diálogo / toast ---------- */

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(420px, calc(100vw - 32px));
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  color: var(--ink);
}
dialog::backdrop { background: rgba(30, 10, 5, .45); }
.dialog-body { padding: 24px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { display: grid; place-items: center; min-height: 60vh; }
.spinner {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
}

.footer-actions { text-align: center; margin-top: 8px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

@media (max-width: 420px) {
  h1 { font-size: 26px; }
  .room-title h1 { font-size: 28px; }
  .card { padding: 20px; }
  .row { flex-direction: column; }
}
