:root {
  --bg: #120a2a;
  --bg-2: #1d1145;
  --panel: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f3ff;
  --muted: #a99fd0;
  --accent: #ff4fa3;
  --accent-2: #ffd23f;
  --B: #3b82f6;
  --I: #ef4444;
  --N: #e2e8f0;
  --G: #22c55e;
  --O: #f59e0b;
  --display: 'Bungee', 'Arial Black', system-ui, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 79, 163, 0.25), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(59, 130, 246, 0.25), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

button, input, select { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.6em 1em;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: scale(0.97); }
.btn[aria-pressed="true"] { background: rgba(255, 210, 63, 0.18); border-color: var(--accent-2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-color: transparent;
  font-size: 1.15em;
  padding: 0.7em 1.6em;
  box-shadow: 0 8px 30px rgba(255, 79, 163, 0.35);
}
.btn kbd {
  font-family: inherit;
  font-size: 0.75em;
  opacity: 0.7;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 0.35em;
}

/* ---------- Sorteador ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1.5vh;
  padding: 2vh 2vw;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.top h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.4rem, 3.4vw, 3rem);
  line-height: 1.05;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.count {
  font-family: var(--display);
  font-size: clamp(1rem, 2.4vw, 2rem);
  color: var(--muted);
  white-space: nowrap;
}
.count b { color: var(--text); font-weight: 400; }

.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.6fr);
  gap: 2vw;
  align-items: center;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5vh;
  min-width: 0;
}

.ball {
  --c: var(--accent);
  --size: min(44vh, 30vw);
  width: var(--size);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75), transparent 28%),
    radial-gradient(circle at 50% 50%, var(--c) 55%, color-mix(in srgb, var(--c), #000 45%) 100%);
  box-shadow:
    0 30px 80px color-mix(in srgb, var(--c), transparent 55%),
    inset -12px -18px 40px rgba(0, 0, 0, 0.35);
}
.ball[data-letter="B"] { --c: var(--B); }
.ball[data-letter="I"] { --c: var(--I); }
.ball[data-letter="N"] { --c: var(--N); }
.ball[data-letter="G"] { --c: var(--G); }
.ball[data-letter="O"] { --c: var(--O); }

.ball-face {
  width: 64%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff, #e9e6f5);
  color: #1b1236;
  display: grid;
  place-content: center;
  text-align: center;
  box-shadow: inset 0 -6px 16px rgba(0, 0, 0, 0.15);
}
.ball-letter {
  font-family: var(--display);
  font-size: calc(var(--size) * 0.11);
  line-height: 1;
  opacity: 0.7;
  min-height: 1em;
}
.ball-num {
  font-family: var(--display);
  font-size: calc(var(--size) * 0.3);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.ball.rolling { animation: wobble 0.14s linear infinite; }
.ball.pop { animation: pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes wobble {
  0% { transform: rotate(-4deg) translateY(0); }
  50% { transform: rotate(4deg) translateY(-6px); }
  100% { transform: rotate(-4deg) translateY(0); }
}
@keyframes pop {
  0% { transform: scale(0.6); }
  100% { transform: scale(1); }
}

.who {
  min-height: 1.3em;
  margin-bottom: -1.5vh;
  font-family: var(--display);
  font-size: clamp(0.9rem, 1.6vw, 1.5rem);
  color: var(--accent);
}

.phrase {
  margin: 0;
  max-width: 34ch;
  min-height: 1.4em;
  font-size: clamp(1rem, 2.4vw, 2.1rem);
  font-weight: 800;
  text-align: center;
  color: var(--accent-2);
}

.recent {
  display: flex;
  gap: 0.6vw;
  justify-content: center;
  min-height: clamp(2.2rem, 3.6vw, 4rem);
}
.mini {
  --c: var(--accent);
  width: clamp(2.2rem, 3.6vw, 4rem);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: clamp(0.8rem, 1.3vw, 1.4rem);
  color: #1b1236;
  background: radial-gradient(circle, #fff 50%, var(--c) 52%);
}
.mini.B { --c: var(--B); }
.mini.I { --c: var(--I); }
.mini.N { --c: var(--N); }
.mini.G { --c: var(--G); }
.mini.O { --c: var(--O); }

.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 0.5cqi;
  padding: 1.2cqi;
  border-radius: 2cqi;
  background: var(--panel);
  border: 1px solid var(--line);
}
.board .cell {
  aspect-ratio: 1;
  border-radius: 1cqi;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 2.6cqi;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
  transition: background 0.3s, color 0.3s;
}
.board .head {
  font-size: 3.6cqi;
  color: #1b1236;
  border-radius: 50%;
}
.board .cell.on { color: #fff; }
.board .B.head, .board .B.on { background: var(--B); }
.board .I.head, .board .I.on { background: var(--I); }
.board .N.head, .board .N.on { background: var(--N); color: #1b1236; }
.board .G.head, .board .G.on { background: var(--G); }
.board .O.head, .board .O.on { background: var(--O); }
.board .cell.new { animation: flash 1.2s ease-out 2; outline: 0.4cqi solid var(--accent-2); }
@keyframes flash { 0%, 100% { filter: none; } 50% { filter: brightness(1.6); } }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  align-items: center;
}
.controls .sep { flex: 0 0 1px; height: 1.6rem; background: var(--line); }

:fullscreen .controls { opacity: 0.15; transition: opacity 0.3s; }
:fullscreen .controls:hover, :fullscreen .controls:focus-within { opacity: 1; }

@media (max-width: 900px) {
  .app { height: auto; min-height: 100%; padding: 16px; }
  .stage { grid-template-columns: 1fr; }
  .ball { --size: min(70vw, 340px); }
  .recent { gap: 8px; }
  .board { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .board .cell { font-size: 4.8cqi; }
  .board .head { font-size: 6cqi; grid-column: 1 / -1; aspect-ratio: auto; border-radius: 1cqi; padding: 0.5cqi 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ball.rolling, .ball.pop, .board .cell.new { animation: none; }
}

/* ---------- Diálogos ---------- */

dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  color: var(--text);
  background: var(--bg-2);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(8, 4, 20, 0.7); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 16px; font-family: var(--display); font-weight: 400; font-size: 1.5rem; }
dialog .row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
dialog .actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 20px; flex-wrap: wrap; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: 0.9rem; color: var(--muted); }
.field small { color: var(--muted); }
.chars {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 12px;
}
.chars label { font-weight: 700; cursor: pointer; }
input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 0.65em 0.8em;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
}
select option { background: var(--bg-2); }
input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
#checkNum { font-family: var(--display); font-size: 1.6rem; width: 9rem; text-align: center; }

.verdict {
  margin: 16px 0 12px;
  font-family: var(--display);
  font-size: 1.4rem;
  text-align: center;
}
.verdict.win { font-size: 2.4rem; color: var(--accent-2); animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
.verdict.lose { color: var(--muted); font-family: var(--body); font-weight: 800; font-size: 1.1rem; }

/* ---------- Cartela (conferência e impressão) ---------- */

.card {
  color: #1b1236;
  background: #fff;
  border-radius: 14px;
  padding: 10px;
  display: grid;
  gap: 6px;
}
.card-title {
  text-align: center;
  font-weight: 800;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.card-grid > div {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--display);
  font-size: 1.35rem;
  border: 2px solid #ddd8ee;
}
.card-grid > .h { border: 0; color: #fff; font-size: 1.5rem; }
.card-grid > .h.B { background: var(--B); }
.card-grid > .h.I { background: var(--I); }
.card-grid > .h.N { background: #9ca3af; }
.card-grid > .h.G { background: var(--G); }
.card-grid > .h.O { background: var(--O); }
.card-grid > .free { font-size: 0.7rem; font-family: var(--body); font-weight: 900; color: var(--accent); }
.card-grid > .hit { background: #ffe9f4; border-color: var(--accent); }
.card-grid > .done { background: var(--accent); border-color: var(--accent); color: #fff; }
.card-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #6b6290;
}
