/* --- Dado Aleatório --- */
.random-dice {
  background: #fffbe7;
  border: 2px solid var(--accent);
  padding: 10px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.08);
  transition: box-shadow 0.2s, transform 0.2s;
}

.random-dice:active {
  transform: scale(0.95);
}

.random-dice .dice-svg {
  display: flex;
  align-items: center;
  justify-content: center;
}

.random-dice.rolling .dice-svg {
  animation: dice-roll 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes dice-roll {
  0% {
    transform: rotate(0deg) scale(1);
  }

  20% {
    transform: rotate(90deg) scale(1.1);
  }

  40% {
    transform: rotate(180deg) scale(0.95);
  }

  60% {
    transform: rotate(270deg) scale(1.1);
  }

  80% {
    transform: rotate(360deg) scale(1);
  }

  100% {
    transform: rotate(360deg) scale(1);
  }
}

/* styles.css - Modern Mobile-First UI */
:root {
  --bg-color: #f3f4f6;
  --card-bg: #ffffff;
  --accent: #4f46e5;
  --accent-light: #e0e7ff;
  --accent-hover: #4338ca;
  --text-main: #111827;
  --text-muted: #6b7280;
  --success: #10b981;
  --success-bg: #d1fae5;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --border-color: #e5e7eb;
  --radius-lg: 20px;
  --radius-md: 12px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  /* Remove aquele brilho azul nativo ao tocar no ecrã */
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  /* Centra em ecrãs maiores */
}

/* O contentor principal simula o ecrã do telemóvel */
.app {
  width: 100%;
  max-width: 480px;
  /* Largura ideal para simular app mobile */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}

/* --- Cabeçalho --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding: 0 4px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.score {
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--card-bg);
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--accent-light);
}

/* Tag que mostra o tema atualmente selecionado */
.theme-tag {
  display: inline-block;
  margin: 8px 0 16px 0;
  padding: 6px 10px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
  align-self: flex-start;
}

/* --- Ecrãs / Cartões --- */
.screen {
  background: var(--card-bg);
  padding: 24px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.hidden {
  display: none !important;
}

/* --- Tela Inicial (Temas) --- */
#intro p {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

.theme-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
  position: relative;
}

.random-dice {
  grid-column: 1 / -1;
  margin-top: 10px;
  margin-bottom: 0;
  justify-self: center;
}

.theme-card {
  appearance: none;
  background: #f9fafb;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.theme-card:active {
  transform: scale(0.96);
  /* Efeito de "apertar" o botão real */
}

.theme-card.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3);
}

.setting-hint {
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: auto;
}

/* --- Ecrã de Perguntas --- */
.status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.progress-left {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-muted);
  min-width: 40px;
}

.progress-bar {
  flex: 1;
  height: 10px;
  background: var(--bg-color);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  border-radius: 999px;
  width: 0%;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.question {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 24px;
}

/* --- Botões de Resposta --- */
.choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn.choice {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 16px 14px;
  background: #fff;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.btn.choice:active:not(:disabled) {
  transform: scale(0.98);
  background: #f9fafb;
}

.choice-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-color);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
  margin-right: 12px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.choice-text {
  flex: 1;
  line-height: 1.4;
}

/* Estados de Resposta */
.btn.choice.correct {
  background: var(--success-bg);
  border-color: var(--success);
  color: #064e3b;
}

.btn.choice.correct .choice-label {
  background: var(--success);
  color: #fff;
}

.btn.choice.wrong {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: #7f1d1d;
  animation: shake 0.4s ease;
}

.btn.choice.wrong .choice-label {
  background: var(--danger);
  color: #fff;
}

/* --- Explicação e Ações --- */
.explanation {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--accent-light);
  color: #3730a3;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5;
  animation: slideUp 0.3s ease;
}

.actions {
  margin-top: auto;
  /* Empurra o botão para o fundo do cartão */
  padding-top: 24px;
}

.btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

#nextBtn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

#nextBtn:disabled {
  background: var(--border-color);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

#nextBtn:active:not(:disabled) {
  transform: translateY(2px);
}

/* --- Ecrã Final --- */
#finalScreen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

#finalScreen h2 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text-main);
}

#finalScreen p {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

#finalScreen span {
  font-weight: 800;
  color: var(--accent);
  font-size: 1.4rem;
}

#restartBtn {
  background: var(--accent);
  color: #fff;
  margin-top: 20px;
}

/* --- Rodapé --- */
footer {
  text-align: center;
  padding: 20px 0 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

/* --- Animações --- */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

/* Adaptação para tablets ou PC */
@media (min-width: 600px) {
  .app {
    padding: 40px 16px;
  }

  .screen {
    padding: 32px 40px;
  }
}

/* Mobile-specific improvements for small screens */
@media (max-width: 420px) {
  .app {
    padding: 14px 12px;
  }

  .screen {
    padding: 18px 14px;
  }

  header h1 {
    font-size: 1.2rem;
  }

  /* Use single-column theme cards for narrow screens */
  .theme-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .theme-card {
    padding: 14px 12px;
    font-size: 1rem;
  }

  .question {
    font-size: 1.15rem;
  }

  .btn {
    padding: 14px;
    font-size: 1rem;
  }

  .choices {
    gap: 10px;
  }

  .choice-label {
    width: 36px;
    height: 36px;
    margin-right: 10px;
  }
}

/* Reintroduce 2-column theme grid on wider small screens */
@media (min-width: 420px) and (max-width: 599px) {
  .theme-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}
