/* ============================================================
   Sorteador · Roleta da Sorte
   Design tokens + layout responsivo
   ============================================================ */

:root {
  /* Tema escuro (padrão) */
  --bg: #0b0d17;
  --bg-2: #10132140;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.07);
  --surface-strong: #171a2b;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #eef0fb;
  --text-dim: #a2a7c4;
  --text-faint: #6f75a0;

  --accent: #7c5cff;
  --accent-2: #ff4d8d;
  --accent-3: #22d3ee;
  --accent-contrast: #ffffff;

  --ring: rgba(124, 92, 255, 0.55);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 4px 16px -6px rgba(0, 0, 0, 0.5);

  --radius: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --wheel-stroke: rgba(255, 255, 255, 0.9);
  --hub-bg: linear-gradient(160deg, #ffffff, #d9dcf5);
  --hub-text: #171a2b;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-2: #ffffff80;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-2: rgba(15, 18, 40, 0.045);
  --surface-strong: #ffffff;
  --border: rgba(15, 18, 40, 0.1);
  --border-strong: rgba(15, 18, 40, 0.18);
  --text: #14172b;
  --text-dim: #565b7d;
  --text-faint: #8a8fae;

  --shadow-lg: 0 24px 50px -24px rgba(20, 23, 43, 0.35);
  --shadow-sm: 0 4px 14px -8px rgba(20, 23, 43, 0.4);

  --wheel-stroke: rgba(255, 255, 255, 0.95);
  --hub-bg: linear-gradient(160deg, #ffffff, #eceefb);
  --hub-text: #14172b;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Brilhos de fundo */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60vw 60vw at 12% -10%, rgba(124, 92, 255, 0.28), transparent 60%),
    radial-gradient(50vw 50vw at 92% 8%, rgba(255, 77, 141, 0.22), transparent 60%),
    radial-gradient(55vw 55vw at 50% 110%, rgba(34, 211, 238, 0.16), transparent 60%);
  filter: saturate(120%);
}

html[data-theme="light"] .bg-glow { opacity: 0.55; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------ Topbar ------------------------------ */
.topbar {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 4vw, 32px) 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  font-size: 24px;
  border-radius: 14px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px -12px var(--accent);
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.topbar-actions { display: flex; gap: 10px; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
  backdrop-filter: blur(12px);
}

.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); transform: translateY(-1px); }
.icon-btn .icon-off { display: none; }
.icon-btn[aria-pressed="false"] .icon-on { display: none; }
.icon-btn[aria-pressed="false"] .icon-off { display: block; }
html[data-theme="light"] #themeToggle .icon-on { display: none; }
html[data-theme="light"] #themeToggle .icon-off { display: block; }

/* ------------------------------ Layout ------------------------------ */
.layout {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 12px clamp(16px, 4vw, 32px) 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: clamp(16px, 2.2vw, 24px);
  align-items: start;
  flex: 1;
}

.side { display: grid; gap: clamp(16px, 2.2vw, 24px); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 2.4vw, 24px);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  min-width: 26px;
  text-align: center;
}

/* ------------------------------ Roleta ------------------------------ */
.wheel-card {
  display: grid;
  gap: 18px;
  justify-items: center;
  position: sticky;
  top: 18px;
}

.wheel-stage { width: 100%; display: grid; place-items: center; }

.wheel-wrap {
  position: relative;
  width: min(100%, 480px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

#wheel {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 22px 40px rgba(0, 0, 0, 0.45));
  touch-action: manipulation;
}

html[data-theme="light"] #wheel { filter: drop-shadow(0 18px 32px rgba(20, 23, 43, 0.25)); }

.hub {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 23%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: none;
  background: var(--hub-bg);
  color: var(--hub-text);
  font-family: inherit;
  font-weight: 800;
  font-size: clamp(0.65rem, 1.9vw, 0.95rem);
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 -3px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  display: grid;
  place-items: center;
}

.hub:hover:not(:disabled) { transform: translate(-50%, -50%) scale(1.06); }
.hub:active:not(:disabled) { transform: translate(-50%, -50%) scale(0.97); }
.hub:disabled { cursor: not-allowed; opacity: 0.75; }
.hub-label { pointer-events: none; }

.status {
  margin: 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
  min-height: 1.2em;
}

.wheel-actions {
  display: grid;
  gap: 14px;
  justify-items: center;
  width: 100%;
}

.speed-group {
  display: inline-flex;
  gap: 6px;
  padding: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.chip {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.chip:hover { color: var(--text); }

.chip.is-active {
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px -8px var(--accent);
}

html[data-theme="light"] .chip.is-active { color: #fff; }

/* ------------------------------ Botões ------------------------------ */
.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 11px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, filter 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 12px 28px -14px var(--accent);
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-soft:hover { border-color: var(--border-strong); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-sm { padding: 7px 12px; font-size: 0.8rem; }

.btn-lg {
  padding: 15px 34px;
  font-size: 1.02rem;
  border-radius: var(--radius-pill);
  width: min(100%, 320px);
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* ------------------------------ Formulário ------------------------------ */
.add-form { display: flex; gap: 8px; margin-bottom: 12px; }

.input, .textarea {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input::placeholder, .textarea::placeholder { color: var(--text-faint); }

.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

:where(button, a, input, textarea, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.textarea { width: 100%; resize: vertical; display: block; }

.bulk { margin-bottom: 14px; }

.bulk summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-dim);
  list-style: none;
  padding: 4px 0;
  user-select: none;
}

.bulk summary::-webkit-details-marker { display: none; }
.bulk summary::before { content: "＋ "; color: var(--accent); font-weight: 700; }
.bulk summary:hover { color: var(--text); }
.bulk[open] summary::before { content: "− "; }
.bulk .textarea { margin: 8px 0; }

/* ------------------------------ Listas ------------------------------ */
.list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: grid;
  gap: 7px;
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  animation: pop-in 0.25s ease both;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 1.05rem;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.remove:hover { color: #ff6b8a; background: rgba(255, 77, 141, 0.12); }

.empty {
  margin: 4px 0 14px;
  font-size: 0.84rem;
  color: var(--text-faint);
  text-align: center;
  padding: 18px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.empty[hidden] { display: none; }

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.history li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.86rem;
}

.history li:first-child {
  border-color: rgba(124, 92, 255, 0.45);
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.14), rgba(255, 77, 141, 0.1));
}

.history .h-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .h-time { color: var(--text-faint); font-size: 0.74rem; flex: 0 0 auto; }

/* ------------------------------ Switch ------------------------------ */
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--text-dim);
  user-select: none;
}

.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch-track {
  width: 40px; height: 23px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.25s ease, border-color 0.25s ease;
  flex: 0 0 auto;
}

.switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.25s cubic-bezier(0.3, 1.4, 0.5, 1), background 0.25s ease;
}

.switch input:checked + .switch-track {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(17px);
  background: #fff;
}

.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--ring); }

/* ------------------------------ Footer ------------------------------ */
.footer {
  text-align: center;
  padding: 6px 20px 26px;
  color: var(--text-faint);
  font-size: 0.76rem;
}

.footer code {
  font-size: 0.72rem;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

/* ------------------------------ Modal ------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 7, 16, 0.72);
  backdrop-filter: blur(8px);
  animation: fade-in 0.25s ease both;
}

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.modal-box {
  position: relative;
  width: min(440px, 100%);
  text-align: center;
  padding: clamp(26px, 5vw, 38px) clamp(20px, 4vw, 32px);
  border-radius: 24px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: zoom-in 0.35s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoom-in {
  from { opacity: 0; transform: translateY(14px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

.modal-kicker {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.winner-name {
  margin: 0 0 24px;
  font-size: clamp(1.7rem, 6vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
  background: linear-gradient(120deg, var(--accent-3), var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* ------------------------------ Toast ------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(12px);
  z-index: 60;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------ Responsivo ------------------------------ */
@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; }
  .wheel-card { position: static; }
  .side { grid-template-columns: 1fr; }
}

@media (min-width: 560px) and (max-width: 940px) {
  .side { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 560px) {
  .topbar { padding-top: 16px; }
  .brand-mark { width: 40px; height: 40px; font-size: 21px; }
  .wheel-wrap { width: min(100%, 360px); }
  .btn-lg { width: 100%; }
  .add-form { flex-wrap: wrap; }
  .add-form .btn { width: 100%; }
  .modal-actions .btn { flex: 1 1 140px; }
}

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