:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --secondary: #ec4899;
  --bg-body: linear-gradient(135deg, #f3f4f6 0%, #e0e7ff 100%);
  --bg-card: rgba(255, 255, 255, 0.95);
  --text-main: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.1);
  --input-bg: #f9fafb;
  --success: #059669;
  --app-radius: 24px;
}

[data-theme="dark"] {
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: rgba(99, 102, 241, 0.15);
  --secondary: #f472b6;
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
  --input-bg: #0f172a;
  --success: #34d399;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden; /* Evita scroll lateral */
}

/* Wrapper para centralizar no Desktop e encher no Mobile */
.main-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 20px;
}

.container {
  background: var(--bg-card);
  width: 100%;
  max-width: 480px;
  border-radius: var(--app-radius);
  box-shadow: var(--shadow);
  padding: 2.5rem;
  position: relative;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  min-height: 400px; /* Altura mínima consistente */
}

/* --- Cabeçalhos --- */
.brand-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 5px;
}
.brand-icon {
  font-size: 2rem;
  color: var(--primary);
}
h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}
h2 {
  font-size: 1.4rem;
  font-weight: 700;
}
.subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 1.5rem;
}
.btn-icon-back {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text-main);
  cursor: pointer;
  padding: 10px;
  border-radius: 12px;
  display: flex;
  align-items: center;
}

/* --- Menu Grid --- */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.menu-card {
  background: var(--input-bg);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.menu-card:active {
  transform: scale(0.96);
}
.icon-box {
  background: var(--primary-light);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.menu-card .material-icons-round {
  font-size: 1.8rem;
  color: var(--primary);
}
.menu-title {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 4px;
}
.menu-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Inputs --- */
.input-group-row {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
}
.input-wrapper {
  flex: 1;
}
.input-wrapper label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

textarea,
input[type="number"],
.input-select {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--border);
  background: var(--input-bg);
  color: var(--text-main);
  border-radius: 12px;
  outline: none;
  font-size: 1rem;
  appearance: none;
}
textarea {
  height: 140px;
  resize: none;
  margin-bottom: 15px;
}
textarea:focus,
input:focus {
  border-color: var(--primary);
}

.file-upload-area {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  background: var(--input-bg);
  padding: 10px;
  border-radius: 12px;
  border: 1px dashed var(--border);
}
.file-instruction {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

/* --- Botões --- */
.btn-primary,
.btn-secondary,
.btn-ghost {
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s;
}
.btn-primary {
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-hover) 100%
  );
  color: white;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.3);
}
.btn-primary:active {
  transform: scale(0.97);
}
.btn-primary:disabled {
  background: var(--border);
  box-shadow: none;
  opacity: 0.7;
}
.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
}
.btn-secondary.small {
  width: auto;
  font-size: 0.85rem;
  padding: 8px 16px;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.bottom-action {
  margin-top: 20px;
}

/* --- Resultado --- */
.result-box {
  background: var(--input-bg);
  border-radius: 20px;
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
}
.winner-display {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--success);
  line-height: 1;
  word-break: break-word;
}
.winner-display.small-text {
  font-size: 1.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* --- Stats & Histórico --- */
.stats-row {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  padding: 15px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.stat-item {
  text-align: center;
}
.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
}
.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
}

.history-grid-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 100px;
  overflow-y: auto;
}
.ball {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}
.ball.latest {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
  transform: scale(1.1);
}

.list-container {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 140px;
  overflow-y: auto;
  margin-top: 10px;
}
.list-container.active {
  display: flex;
}
.name-tag {
  background: var(--input-bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
}
.name-tag.winner {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
}

/* --- Tabs --- */
.history-tabs {
  display: flex;
  background: var(--input-bg);
  padding: 4px;
  border-radius: 12px;
  gap: 5px;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-radius: 8px;
}
.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* --- Botão Settings --- */
.btn-settings {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--input-bg);
  color: var(--text-muted);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  z-index: 10;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- MODAL (Overlay) --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.modal-overlay:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}

/* Card Padrão Desktop */
.modal-card {
  background: var(--bg-card);
  width: 90%;
  max-width: 400px;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
.modal-overlay:not(.hidden) .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.btn-close-modal {
  background: none;
  border: none;
  font-size: 1.5rem;
  padding: 5px;
}
.modal-drag-handle {
  display: none;
} /* Só aparece no mobile */
.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* Switch Toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  transition: 0.3s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
}
input:checked + .slider {
  background-color: var(--primary);
}
input:checked + .slider:before {
  transform: translateX(22px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 900;
}
.hidden {
  display: none !important;
}

/* ==========================================================================
   MEDIA QUERIES (RESPONSIVIDADE MOBILE)
   ========================================================================== */
@media (max-width: 600px) {
  /* Ajustes Gerais de Container */
  .main-wrapper {
    padding: 0;
    height: 100vh;
    align-items: flex-end; /* Colar no fundo se precisar */
  }

  body {
    align-items: flex-start;
  } /* Permite scroll se o conteudo for maior */

  .container {
    max-width: 100%;
    min-height: 100vh; /* Ocupa a tela toda */
    border-radius: 0; /* Remove bordas arredondadas nos cantos */
    padding: 1.5rem;
    padding-top: 4rem; /* Espaço para o botão de settings */
    box-shadow: none;
    border: none;
  }

  /* Ajuste do botão de Settings no mobile */
  .btn-settings {
    top: 15px;
    right: 15px;
    background: transparent;
  }

  /* Tipografia Mobile */
  h1 {
    font-size: 1.6rem;
  }
  .winner-display {
    font-size: 3rem;
  }

  /* Input adjustments para teclado */
  textarea {
    height: 100px;
  } /* Menor para caber teclado */

  /* MODAL: BOTTOM SHEET STYLE (Estilo iPhone/Android) */
  .modal-overlay {
    align-items: flex-end;
  } /* Alinha no fundo */

  .modal-card {
    width: 100%;
    max-width: 100%;
    border-radius: 24px 24px 0 0; /* Só arredonda em cima */
    padding: 20px;
    padding-bottom: 40px; /* Area segura iPhone */
    transform: translateY(100%); /* Começa escondido em baixo */
    margin: 0;
  }

  .modal-overlay:not(.hidden) .modal-card {
    transform: translateY(0);
  }

  /* Visual de "Puxador" do modal */
  .modal-drag-handle {
    display: block;
    width: 40px;
    height: 5px;
    background: var(--border);
    margin: 0 auto 20px auto;
    border-radius: 10px;
  }

  .btn-close-modal {
    display: none;
  } /* No mobile, geralmente se clica fora ou arrasta */
}
