:root {
  --bg: #0b0a1a;
  --bg-2: #131030;
  --card: rgba(255, 255, 255, 0.045);
  --card-solid: #151232;
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #f3f0ff;
  --text-dim: #a89fce;
  --gold: #ffc54d;
  --gold-2: #ffb020;
  --violet: #8b5cf6;
  --magenta: #ec4899;
  --cyan: #22d3ee;
  --green: #34d399;
  --red: #f87171;
  --danger: #ef4444;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  /* compensação para deixar o número (e não o bloco) no centro da roda */
  --num-raise: 13px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 50% -10%, #1c1440 0%, var(--bg) 55%);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

.glow-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(600px 400px at 15% 85%, rgba(139, 92, 246, 0.16), transparent 60%),
    radial-gradient(700px 500px at 90% 20%, rgba(236, 72, 153, 0.12), transparent 60%),
    radial-gradient(500px 400px at 70% 90%, rgba(34, 211, 238, 0.08), transparent 60%);
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ===================== estrutura geral ===================== */
.page {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 14px calc(18px + env(safe-area-inset-bottom));
}

/* ===================== topbar ===================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 2px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-badge {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 12px rgba(255, 197, 77, 0.4));
  animation: floaty 4s ease-in-out infinite;
  flex: 0 0 auto;
}
.brand-text { min-width: 0; }
.brand h1 {
  font-size: 1.12rem;
  letter-spacing: 0.03em;
  line-height: 1.1;
  background: linear-gradient(90deg, #fff, #ffd98a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}
.tagline { font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--card);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex: 0 0 auto;
  transition: border-color 0.3s, color 0.3s, box-shadow 0.3s;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #56506e;
  transition: background 0.3s, box-shadow 0.3s;
}
.status-pill[data-state="listening"] { color: var(--text); border-color: rgba(52, 211, 153, 0.5); }
.status-pill[data-state="listening"] .dot {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: pulse-dot 1.4s infinite;
}
.status-pill[data-state="listening"] #micPillText { color: var(--green); }
.status-pill[data-state="error"] { color: #ffd7d7; border-color: rgba(248, 113, 113, 0.6); }
.status-pill[data-state="error"] .dot { background: var(--red); }

/* ===================== configuração (recolhível) ===================== */
.config {
  position: relative;
  z-index: 3;
  margin: 8px 0 4px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  overflow: hidden;
}
.config-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}
.config-toggle .cfg-gear { font-size: 1rem; }
.config-toggle .cfg-text { color: var(--text-dim); flex: 0 0 auto; }
.config-toggle .cfg-brief {
  margin-left: auto;
  font-weight: 700;
  color: var(--gold);
  font-size: 0.95rem;
}
.chev {
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.25s;
  flex: 0 0 auto;
}
.config.open .config-toggle .chev { transform: rotate(-135deg) translateY(-2px); }
.config-body {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 6px 14px 16px;
}
.config.open .config-body { display: flex; }
.interval-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.config-body input {
  width: 84px;
  padding: 9px 6px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.config-body input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 197, 77, 0.18);
}
.range-sep { color: var(--text-dim); font-size: 0.9rem; }

/* ---------- seletor de voz ---------- */
.voice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.voice-label {
  font-size: 0.86rem;
  color: var(--text);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
#voiceSelect {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 320px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  outline: none;
}
#voiceSelect:focus { border-color: var(--gold); }
#voiceSelect option { background: #1a1638; color: var(--text); }
.voice-test { padding: 8px 12px; font-size: 0.82rem; flex: 0 0 auto; }
.voice-note {
  margin: 0;
  font-size: 0.78rem;
  color: #ffd7a0;
  line-height: 1.4;
}

/* ===================== palco: roda concêntrica ===================== */
.stage-zone {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* espaço acima e abaixo para o número não encostar em nada */
  padding: 8px 0 0;
}

/* ---------- roda (a "figura de fundo") ---------- */
.wheel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(86vw, 62vh, 620px);
  height: min(86vw, 62vh, 620px);
  border-radius: 50%;
  pointer-events: none;
}
.wheel-disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 40%, rgba(139, 92, 246, 0.22), rgba(236, 72, 153, 0.08) 48%, rgba(11, 10, 26, 0) 72%);
  box-shadow: inset 0 0 60px rgba(11, 10, 26, 0.55);
  animation: breathe 5s ease-in-out infinite;
}
.wheel::before {           /* anel externo fino */
  content: "";
  position: absolute;
  inset: 1.5%;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 26px rgba(139, 92, 246, 0.25);
}
.wheel-rings {
  position: absolute;
  inset: 0;
}
.wheel-rings::before,
.wheel-rings::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px dashed rgba(255, 197, 77, 0.28);
}
.wheel-rings::before { inset: 8%; animation: spin 26s linear infinite; }
.wheel-rings::after  { inset: 21%; animation: spin-rev 20s linear infinite; }
.wheel-rings .ring3 { position: absolute; inset: 33%; border-radius: 50%; border: 1px dashed rgba(34, 211, 238, 0.2); animation: spin 34s linear infinite; }
.wheel-orbs {
  position: absolute;
  inset: 0;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
  background: radial-gradient(circle at 32% 28%, #fff, var(--c, var(--violet)) 55%, rgba(0, 0, 0, 0.55));
  animation: orb-drift var(--dur, 3.5s) ease-in-out infinite alternate;
}
@keyframes orb-drift { to { transform: translate(var(--dx, 4px), var(--dy, -5px)); } }

/* "fervura" durante o sorteio */
.wheel.boiling .wheel-rings::before { animation: spin 0.7s linear infinite; }
.wheel.boiling .wheel-rings::after  { animation: spin-rev 0.5s linear infinite; }
.wheel.boiling .ring3               { animation: spin 0.9s linear infinite; }
.wheel.boiling .wheel-orbs          { animation: shake-soft 0.2s infinite; }
.wheel.boiling .wheel-disc          { filter: saturate(1.5) brightness(1.15); }

/* ---------- número ---------- */
.number-wrap {
  position: relative;
  z-index: 2;
  text-align: center;
  transform: translateY(calc(-1 * var(--num-raise)));
  max-width: 100%;
}
.number-label {
  font-size: 0.8rem;
  line-height: 1.15;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
  white-space: nowrap;
}
.number-big {
  font-family: inherit;
  line-height: 1;
  font-weight: 900;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff, #ffd98a 60%, var(--gold-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 12px 34px rgba(0, 0, 0, 0.6));
  transition: filter 0.2s;
}
/* tamanho por quantidade de algarismos (para o número caber na roda) */
.number-big { font-size: clamp(4.2rem, 27vh, 11rem); }            /* 1 dígito (padrão) */
.number-big.dc-2 { font-size: clamp(3.7rem, 22vh, 9.5rem); }
.number-big.dc-3 { font-size: clamp(3.1rem, 18vh, 7.6rem); }
.number-big.dc-4 { font-size: clamp(2.7rem, 15vh, 6.4rem); }
.number-big.dc-5 { font-size: clamp(2.3rem, 12.5vh, 5.4rem); }
.number-big.dc-6 { font-size: clamp(2rem, 10.5vh, 4.7rem); }

.number-big.idle { opacity: 0.16; }
.number-big.spinning {
  opacity: 0.85;
  filter: blur(3px) drop-shadow(0 12px 34px rgba(0, 0, 0, 0.6));
}
.number-big.revealed { animation: pop 0.7s cubic-bezier(0.2, 1.6, 0.35, 1); }

/* ===================== dock (controle) ===================== */
.dock {
  flex: 0 0 auto;
  padding-top: 6px;
}
.progress {
  margin-bottom: 12px;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--violet), var(--magenta), var(--gold));
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.5);
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}
.btn {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--card-border);
  border-radius: 15px;
  background: var(--card);
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  transition: transform 0.12s, box-shadow 0.2s, filter 0.2s, border-color 0.2s, background 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn .btn-icon { display: inline-block; margin-right: 5px; }

.btn-big {
  flex: 1 1 auto;
  border: none;
  color: #241500;
  font-weight: 800;
  font-size: 1.35rem;
  padding: 16px 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  box-shadow: 0 12px 34px rgba(255, 176, 32, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn-big:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn-big.busy { opacity: 0.85; cursor: wait; }

.act-side {
  flex: 0 0 auto;
  min-width: 84px;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 12px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
}
.act-side .btn-icon { margin-right: 0; font-size: 1.15rem; }
.act-side .mic-icon { font-size: 1.15rem; }

.btn-mic { border: 1px solid rgba(139, 92, 246, 0.5); background: rgba(139, 92, 246, 0.14); }
.btn-mic[aria-pressed="true"] {
  border-color: var(--green);
  background: rgba(52, 211, 153, 0.16);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.16);
}
.btn-danger { border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.1); }
.btn-danger.armed { border-color: var(--danger); background: rgba(239, 68, 68, 0.35); animation: shake 0.5s; }

.last-note {
  min-height: 1.4em;
  margin-top: 12px;
  color: var(--text-dim);
  font-size: 0.86rem;
  text-align: center;
}

/* ===================== painéis / chips (dentro do histórico) ===================== */
.panel {
  margin: 12px 0;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
}
.panel h2 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-bottom: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count {
  background: rgba(139, 92, 246, 0.25);
  color: #d9ccff;
  font-size: 0.7rem;
  padding: 2px 9px;
  border-radius: 999px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  --c: var(--violet);
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.92rem;
  color: #fff;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.95) 0 4%, transparent 5%),
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.9), var(--c) 40%, color-mix(in srgb, var(--c) 55%, black));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 -2px 6px rgba(0, 0, 0, 0.3);
  animation: chip-in 0.35s ease-out backwards;
}
.remaining .chip {
  --c: var(--violet);
  background: rgba(139, 92, 246, 0.16);
  color: #cfc4ff;
  border: 1px solid rgba(139, 92, 246, 0.4);
  box-shadow: none;
}
.remaining .chip:hover { background: rgba(139, 92, 246, 0.32); transform: scale(1.08); }
.remaining .chip.picked { animation: pick-out 0.5s forwards; }
.drawn .chip {
  --c: var(--gold);
  animation: chip-in 0.5s cubic-bezier(0.2, 1.6, 0.35, 1) backwards;
}
.empty-note { color: var(--text-dim); font-size: 0.9rem; }

.round {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 9px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.84rem;
  color: var(--text-dim);
}
.round:first-child { border-top: none; }
.round .nums { display: flex; flex-wrap: wrap; gap: 6px; }
.round .mini {
  min-width: 25px;
  height: 25px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  color: #332200;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
}

.voice-hint {
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.6;
  padding: 4px 6px 8px;
}

/* ===================== histórico (drawer no mobile) ===================== */
.history {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  max-width: 560px;
  margin: 0 auto;
  background: linear-gradient(180deg, #1a1636, #131030);
  border: 1px solid var(--card-border);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.history-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
}
.history-toggle .h-title { font-weight: 700; }
.history-toggle .h-badges { margin-left: auto; display: inline-flex; gap: 6px; }
.pillb {
  font-size: 0.68rem;
  font-weight: 700;
  color: #e8e0ff;
  background: rgba(139, 92, 246, 0.22);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.history-body {
  max-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: max-height 0.32s ease;
}
.history-body::-webkit-scrollbar { width: 6px; }
.history-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }
.history.open .history-body { max-height: min(64vh, 620px); }
.history.open .history-toggle .chev { transform: rotate(-135deg) translateY(-2px); }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  transition: opacity 0.25s;
}
.sheet-backdrop[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(92vw, 520px);
  padding: 12px 20px;
  background: #1a1638;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.95rem;
  animation: toast-in 0.3s ease-out;
}
.toast.error { border-color: rgba(248, 113, 113, 0.6); }
.toast[hidden] { display: none; }

/* ===================== keyframes ===================== */
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.02); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-rev { to { transform: rotate(-360deg); } }
@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,0.6); } 70% { box-shadow: 0 0 0 9px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } }
@keyframes shake-soft {
  0%,100% { transform: translate(0, 0); }
  25% { transform: translate(-1.6px, 1px); }
  75% { transform: translate(1.6px, -1px); }
}
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; filter: blur(12px); }
  60% { transform: scale(1.15); opacity: 1; filter: blur(0); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes chip-in { from { transform: scale(0) rotate(-30deg); opacity: 0; } }
@keyframes pick-out { to { transform: scale(0); opacity: 0; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes toast-in { from { transform: translate(-50%, 20px); opacity: 0; } }

/* ============================================================
   DESKTOP — aproveita o espaço: controle à esquerda,
   histórico como coluna fixa à direita (sempre visível)
   ============================================================ */
@media (min-width: 900px) {
  .page {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 22px;
    align-items: start;
    padding: 18px 22px 40px;
  }
  .app {
    max-width: 760px;
    min-height: calc(100vh - 40px);
    margin: 0;
    padding: 0;
  }
  /* config sempre aberta no desktop */
  .config { margin-top: 10px; }
  .config-toggle { display: none; }
  .config-body { display: flex; }
  .config.open .config-body { display: flex; }

  .wheel {
    width: min(56vh, 640px);
    height: min(56vh, 640px);
  }

  /* histórico como coluna lateral */
  .history {
    position: sticky;
    top: 18px;
    max-width: none;
    border-radius: var(--radius);
    border: 1px solid var(--card-border);
    background: linear-gradient(180deg, #151232, #111028);
    box-shadow: var(--shadow);
  }
  .history-toggle { display: none; }
  .history-body {
    max-height: none !important;
    overflow: visible;
    padding: 16px;
  }
  .history-body .panel:first-child { margin-top: 0; }
  .history-body .panel:last-of-type { margin-bottom: 0; }
  .sheet-backdrop { display: none !important; }
}

/* mobile muito estreito: ajusta roda e controles */
@media (max-height: 640px) and (max-width: 899px) {
  .wheel { width: min(78vw, 58vh); height: min(78vw, 58vh); }
  .number-big { font-size: clamp(3.4rem, 24vh, 8rem); }
  .brand h1 { font-size: 1rem; }
  .status-pill { display: none; }
  .tagline { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
}
