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

:root {
  --bg: #0e0e10;
  --surface: #18181b;
  --surface-alt: #1f1f23;
  --border: #2a2a2e;
  --purple: #9147ff;
  --purple-dim: #772ce8;
  --text: #efeff1;
  --text-dim: #adadb8;
  --text-muted: #6b6b7b;
  --green: #00c474;
  --red: #eb0400;
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding: 32px 16px 80px;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

header {
  padding: 4px 0 8px;
}

h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

header p {
  color: var(--text-dim);
  margin-top: 4px;
  font-size: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.fields {
  display: flex;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

input[type="text"] {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 15px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input[type="text"]:focus {
  border-color: var(--purple);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn {
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  padding: 9px 20px;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--purple);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--purple-dim);
}

.btn-primary.stop {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-primary.stop:hover:not(:disabled) {
  background: var(--border);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm:hover:not(:disabled) {
  background: var(--border);
}

.btn-purple {
  background: var(--purple) !important;
  color: #fff !important;
  border-color: transparent !important;
}

.btn-purple:hover:not(:disabled) {
  background: var(--purple-dim) !important;
}

.btn-ghost {
  background: transparent !important;
  color: var(--text-muted) !important;
  border-color: transparent !important;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-alt) !important;
  color: var(--text-dim) !important;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 14px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}

.dot.connecting {
  background: #ffab00;
  animation: pulse 1s ease-in-out infinite;
}

.dot.live {
  background: var(--green);
}

.dot.error {
  background: var(--red);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.timer {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
}

.timer.urgent {
  color: var(--red);
  border-color: var(--red);
}

.channel-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  margin-left: auto;
  flex-shrink: 0;
}

.stream-info {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Settings card ─────────────────────────────────────────────────────────── */

details.card {
  padding: 0;
  gap: 0;
}

details.card > summary {
  padding: 14px 20px;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

details.card > summary::-webkit-details-marker {
  display: none;
}

details.card > summary::after {
  content: "▾";
  font-size: 12px;
  transition: transform 0.2s;
}

details[open].card > summary::after {
  transform: rotate(-180deg);
}

.settings-grid {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--border);
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr 68px;
  align-items: center;
  gap: 16px;
}

.setting-row > label {
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
}

.setting-hint {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

.setting-row-check {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  grid-column: 1 / -1;
}

.setting-row-check label {
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  cursor: pointer;
}

.setting-input {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 6px 10px;
  outline: none;
  width: 68px;
  text-align: center;
  transition: border-color 0.15s;
}

.setting-input:focus {
  border-color: var(--purple);
}

.setting-input[type="number"]::-webkit-inner-spin-button,
.setting-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.setting-input[type="number"] {
  -moz-appearance: textfield;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--purple);
  cursor: pointer;
  flex-shrink: 0;
}

.label-optional {
  font-weight: 400;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

.oauth-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.oauth-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.oauth-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.oauth-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.oauth-connected {
  display: flex;
  align-items: center;
  gap: 10px;
}

.oauth-user {
  font-size: 13px;
  color: var(--green);
  font-weight: 600;
}

.oauth-user::before {
  content: "✓ Connected as ";
  font-weight: 400;
  color: var(--text-muted);
}

.badge-img {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  flex-shrink: 0;
  display: block;
}

.badge-fol {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
  background: rgba(0, 196, 116, 0.15);
  color: var(--green);
  border: 1px solid rgba(0, 196, 116, 0.3);
}

/* ── Results ───────────────────────────────────────────────────────────────── */

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.count-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}

.count {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--purple);
  min-width: 32px;
  text-align: center;
}

.count-gold {
  color: #f5a623;
}

.hidden {
  display: none !important;
}

.winner-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: rgba(245, 166, 35, 0.08);
  border: 1px solid rgba(245, 166, 35, 0.25);
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.12s ease-out;
}

.winner-item .num {
  color: #f5a623;
  font-size: 12px;
  width: 24px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: flex;
  gap: 6px;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 56px;
  max-height: 420px;
  overflow-y: auto;
}

.empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 12px 0;
  text-align: center;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface-alt);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  animation: slideIn 0.12s ease-out;
}

.user-item.winner {
  background: rgba(145, 71, 255, 0.15);
  border-color: rgba(145, 71, 255, 0.5);
  color: #fff;
}

.user-item .num {
  color: var(--text-muted);
  font-size: 12px;
  width: 24px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease-out;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: popIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  width: 520px;
  max-width: 90vw;
}

.modal-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--purple);
}

.modal-username {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  transition: color 0.1s;
  min-height: 1.2em;
}

.modal-username.rolling {
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 8px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 480px) {
  .fields {
    flex-direction: column;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .settings-grid {
    gap: 16px;
  }

  .setting-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .setting-row-check {
    flex-direction: row;
  }
}
