* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 17px; }
code, kbd { font-family: var(--font-mono); font-size: 0.9em; }
.muted { color: var(--color-muted); }
.small { font-size: 13px; }
.center { text-align: center; margin-top: 24px; }

/* Botões */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 999px; padding: 10px 20px; border: 1px solid transparent;
  transition: transform .1s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--color-accent); color: var(--color-accent-contrast); }
.btn-ghost { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-surface); }
.btn-on-dark { background: transparent; color: var(--stage-text); border-color: rgba(255,255,255,.3); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 32px; font-size: 17px; }

/* Topo */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 32px; border-bottom: 3px solid var(--color-accent-2); background: var(--color-surface);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 28px; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--color-muted); padding-left: 10px; border-left: 1px solid var(--color-border); }
.badge { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.badge-demo { background: #fff2c6; color: #7a5800; }
.account { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.account-name { font-weight: 600; }
.account-token { font-size: 13px; color: var(--color-muted); }

.main { max-width: 1200px; margin: 0 auto; padding: 32px; }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 20px; }
.section-head { margin-bottom: 24px; }
.section-head p { margin: 4px 0 0; }

/* Conexão */
.connect { max-width: 560px; margin: 40px auto; }
.connect p { color: var(--color-muted); }
.token-form { display: flex; gap: 8px; margin-top: 16px; }
.token-form input { flex: 1; min-width: 0; }
input[type=password], input[type=search], textarea {
  font: inherit; color: inherit; background: var(--color-bg);
  border: 1px solid var(--color-border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { font-family: var(--font-mono); font-size: 13px; resize: vertical; }
.form-error { color: var(--color-danger); font-size: 14px; }

/* Grade de posts */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.post-card {
  text-align: left; font: inherit; color: inherit; cursor: pointer; padding: 0; overflow: hidden;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  transition: transform .15s, box-shadow .15s;
}
.post-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.post-thumb { aspect-ratio: 1; width: 100%; object-fit: cover; display: block; background: var(--color-border); }
.post-body { padding: 12px 14px 14px; }
.post-caption { margin: 0 0 6px; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-meta { font-size: 13px; color: var(--color-muted); display: flex; justify-content: space-between; }

/* Tela de participantes */
.back { margin-bottom: 20px; }
.draw-layout { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
.draw-side { display: grid; gap: 16px; }
.post-summary { padding: 0; overflow: hidden; }
.post-summary .post-body p { margin: 0 0 8px; font-size: 14px; }
.post-summary a { color: var(--color-accent); font-size: 14px; font-weight: 600; }
.rules { display: grid; gap: 14px; }
.rule-fixed { margin: 0; font-weight: 600; }
.toggle { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--color-accent); }
.field { display: grid; gap: 6px; }
.field span { font-weight: 600; font-size: 14px; }

.draw-main { display: grid; gap: 16px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-family: var(--font-display); font-size: 26px; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--color-muted); }
.stat-main { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-contrast); }
.stat-main span { color: inherit; opacity: .8; }
.note { font-size: 13px; color: var(--color-muted); margin: -4px 0 0; }

.participants { padding: 0; overflow: hidden; }
.participants-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--color-border); }
.participants-head input { max-width: 240px; padding: 7px 12px; }
.table-wrap { max-height: 460px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { position: sticky; top: 0; background: var(--color-surface); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-muted); }
th, td { padding: 9px 20px; border-bottom: 1px solid var(--color-border); vertical-align: top; }
td:first-child { color: var(--color-muted); font-variant-numeric: tabular-nums; width: 1%; }
td:nth-child(2) { font-weight: 600; white-space: nowrap; }
td:last-child { white-space: nowrap; color: var(--color-muted); }
tr.excluded td { text-decoration: line-through; opacity: .45; }
tr.reply td:nth-child(3)::before { content: "↳ "; color: var(--color-muted); }
.draw-actions { display: flex; justify-content: flex-end; gap: 12px; align-items: center; }

/* Carregando / avisos */
.loading { position: fixed; inset: 0; background: rgba(246,245,242,.75); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 20; font-weight: 600; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--color-border); border-top-color: var(--color-accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--color-text); color: var(--color-bg); padding: 12px 20px; border-radius: 12px; z-index: 40; max-width: 90vw; }
.toast.error { background: var(--color-danger); color: #fff; }

/* Palco do sorteio */
.stage { position: fixed; inset: 0; z-index: 30; background: var(--stage-bg); color: var(--stage-text); display: flex; align-items: center; justify-content: center; text-align: center; }
.stage-close { position: absolute; top: 16px; right: 20px; background: none; border: 0; color: var(--stage-muted); font-size: 32px; cursor: pointer; }
.stage-inner { width: min(900px, 92vw); display: flex; flex-direction: column; align-items: center; gap: 24px; }
.stage-logo { height: 56px; }
.stage-kicker { margin: 0; color: var(--stage-muted); font-size: 18px; letter-spacing: .08em; text-transform: uppercase; }
.reel {
  --row: 96px;
  height: calc(var(--row) * 3); width: 100%; overflow: hidden; position: relative;
  mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
  -webkit-mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
}
.reel::after { content: ""; position: absolute; left: 10%; right: 10%; top: var(--row); height: var(--row); border-top: 1px solid rgba(255,255,255,.18); border-bottom: 1px solid rgba(255,255,255,.18); pointer-events: none; }
.reel-track { will-change: transform; }
.reel-item { height: var(--row); line-height: var(--row); font-family: var(--font-display); font-size: clamp(32px, 6vw, 64px); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reel.done .reel-item.win { color: var(--stage-highlight); }
.reel.done .reel-item:not(.win) { opacity: 0; transition: opacity .6s; }
.reel-placeholder { color: var(--stage-muted); font-variant-numeric: tabular-nums; }
/* Desfoque de movimento: ninguém fica legível até o giro desacelerar. */
.reel.spinning .reel-track { animation: deblur 7s cubic-bezier(.5,0,.75,1) forwards; }
@keyframes deblur {
  0% { filter: blur(14px); }
  60% { filter: blur(8px); }
  88% { filter: blur(2px); }
  100% { filter: blur(0); }
}
.stage-winner { max-width: 640px; }
.stage-winner .label { color: var(--stage-muted); text-transform: uppercase; letter-spacing: .08em; font-size: 14px; margin: 0 0 8px; }
.stage-winner blockquote { margin: 0; font-size: 20px; }
.stage-meta { color: var(--stage-muted); font-size: 14px; font-family: var(--font-mono); }
.stage-actions { display: flex; gap: 12px; }
.stage-hint { margin: 0; color: var(--stage-muted); font-size: 14px; }
.stage kbd { border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: 1px 6px; }
.pop { animation: pop .6s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Certificado */
.cert-overlay { position: fixed; inset: 0; z-index: 35; background: var(--color-bg); overflow: auto; padding: 0 16px 48px; }
.cert-toolbar { position: sticky; top: 0; display: flex; justify-content: space-between; gap: 8px; max-width: 820px; margin: 0 auto; padding: 16px 0; background: var(--color-bg); }
.cert-toolbar div { display: flex; gap: 8px; }
.certificate { max-width: 820px; margin: 0 auto; background: #fff; color: #17161a; border: 1px solid var(--color-border); border-radius: var(--radius); padding: 56px 64px; }
.cert-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; border-bottom: 3px solid var(--color-accent-2); padding-bottom: 20px; margin-bottom: 28px; }
.cert-head img { height: 40px; }
.cert-head h1 { font-size: 30px; }
.cert-head p { margin: 4px 0 0; color: #6d6a73; }
.cert-winner { text-align: center; padding: 28px; border: 1px solid #e4e1da; border-radius: var(--radius); margin-bottom: 28px; }
.cert-winner .label { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: #6d6a73; margin: 0; }
.cert-winner .name { font-family: var(--font-display); font-size: 40px; font-weight: 700; margin: 6px 0; color: var(--color-accent); }
.cert-winner blockquote { margin: 0; color: #3b3940; }
.cert-grid { display: grid; grid-template-columns: 200px 1fr; gap: 10px 20px; font-size: 14px; margin: 0 0 28px; }
.cert-grid dt { color: #6d6a73; }
.cert-grid dd { margin: 0; overflow-wrap: anywhere; }
.cert-hash { font-family: var(--font-mono); font-size: 12.5px; }
.cert-verify { font-size: 13px; color: #3b3940; background: #f6f5f2; border-radius: 10px; padding: 16px 20px; }
.cert-verify h2 { font-size: 14px; margin-bottom: 6px; }
.cert-verify ol { margin: 0; padding-left: 18px; }
.cert-foot { margin-top: 24px; font-size: 12px; color: #6d6a73; display: flex; justify-content: space-between; }

@media (max-width: 860px) {
  .main { padding: 20px 16px; }
  .topbar { padding: 12px 16px; }
  .draw-layout { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .certificate { padding: 32px 24px; }
  .cert-grid { grid-template-columns: 1fr; gap: 2px; }
  .cert-grid dd { margin-bottom: 10px; }
}

@media print {
  @page { margin: 14mm; }
  body > *:not(.cert-overlay) { display: none !important; }
  .cert-overlay { position: static; padding: 0; background: #fff; }
  .cert-toolbar { display: none; }
  .certificate { border: 0; padding: 0; max-width: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Marcação de teste */
.stage-test { position: absolute; top: 20px; left: 24px; background: #ffd23f; color: #2e0a5e; font-weight: 700; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; padding: 6px 14px; border-radius: 999px; }
.cert-test { margin: 0 0 20px; padding: 12px 16px; border-radius: 10px; background: #fff2c6; color: #7a5800; font-weight: 600; text-align: center; }

/* Login */
.login-page { min-height: 100vh; background: var(--stage-bg); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 32px; }
.login-card h1 { font-size: 24px; margin-top: 4px; }
.login-card .muted { margin: -10px 0 4px; }
.login-logo { height: 36px; justify-self: start; }
.login-card input { font: inherit; color: inherit; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 10px; padding: 10px 12px; width: 100%; }
.login-card .btn { margin-top: 6px; }
