/* CSS Variables for centralized styling */
:root {
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --primary-active: #004494;
  --background-light: #f0f0f0;
  --container-bg: #ffffff;
  --text-color: #333333;
  --correct-color: green;
  --incorrect-color: red;
  --feedback-correct-bg: #c6f7c6;
  --feedback-incorrect-bg: #f7c6c6;
  --transition-speed: 0.3s;
  --modal-bg: rgba(0, 0, 0, 0.5);
  --modal-content-bg: #ffffff;
}

/* Dark mode overrides */
.dark-mode {
  --primary-color: #66b3ff;
  --primary-hover: #3399ff;
  --primary-active: #007fff;
  --background-light: #121212;
  --container-bg: #1e1e1e;
  --text-color: #e0e0e0;
  --feedback-correct-bg: #2e7d32;
  --feedback-incorrect-bg: #c62828;
  --modal-content-bg: #333333;
}

* {
  box-sizing: border-box;
}

/* Utility class to hide elements */
.hidden {
  display: none !important;
}

/* Basic styles for body and container */
body {
  font-family: Arial, sans-serif;
  background-color: var(--background-light);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

.container {
  position: relative;
  background: var(--container-bg);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  padding: 20px;
  text-align: center;
  width: 90%;
  max-width: 600px;
  transition: background-color var(--transition-speed);
}

/* Dark Mode Toggle Button - fixed at the top-right of the window */
#themeToggle {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 900; /* Lower than modal (z-index: 1000) */
  font-size: 20px;
  padding: 8px;
  background: var(--primary-color);
  border: none;
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  transition: background-color var(--transition-speed), transform 0.2s;
}

#themeToggle:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

#themeToggle:active {
  background: var(--primary-active);
  transform: scale(0.95);
}

/* Responsive adjustments for small screens (iPhone) */
@media (max-width: 600px) {
  #themeToggle {
    top: 5px;
    right: 5px;
    font-size: 16px;
    padding: 6px;
  }
  .buttons {
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .option {
    font-size: 16px;
    padding: 10px;
  }
  #clockCanvas {
    width: 150px;
    height: 150px;
  }
}

/* Button styles */
.option {
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 15px;
  margin: 10px 5px;
  font-size: 18px;
  cursor: pointer;
  min-width: 80px;
  transition: background-color var(--transition-speed), transform 0.2s;
}

.option:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.option:active {
  background: var(--primary-active);
  transform: scale(0.95);
}

/* Difficulty Selection Section */
#difficultySelection {
  margin-bottom: 20px;
}

#difficultySelection p {
  margin: 5px 0;
}

/* Canvas styling */
#clockCanvas {
  margin: 20px auto;
  border: 2px solid var(--text-color);
  border-radius: 50%;
  display: block;
}

/* Buttons container with fixed minimum height to avoid layout jumps */
.buttons {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  overflow-x: auto;
  min-height: 60px;
}

/* Timer display styling */
#timerDisplay {
  font-size: 20px;
  font-weight: bold;
  margin-top: 10px;
}

/* Feedback styling with animation */
#feedback {
  margin-top: 10px;
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.5s;
}

.feedback-show {
  opacity: 1;
  animation: feedbackAnim 0.5s;
}

@keyframes feedbackAnim {
  0% { transform: scale(0.9); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Progress Bar styling */
.progress-bar {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 20px;
}

.progress-circle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: gray;
  transition: background-color 0.3s, transform 0.3s;
}

.progress-circle.correct {
  background-color: var(--correct-color);
  transform: scale(1.2);
}

.progress-circle.incorrect {
  background-color: var(--incorrect-color);
  transform: scale(0.8);
}

/* End Game Section */
#endGame {
  margin-top: 20px;
}

/* Modal styles for tutorial */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--modal-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--modal-content-bg);
  padding: 20px;
  border-radius: 8px;
  text-align: left;
  max-width: 500px;
  width: 90%;
  animation: modalIn 0.5s;
}

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

/* Animation on clock change */
.clock-change-anim {
  animation: clockChange 0.5s ease-out;
}
@keyframes clockChange {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

/* Visual effects for correct/incorrect answers */
.correct-effect {
  animation: flashCorrect 0.5s;
}
@keyframes flashCorrect {
  0% { box-shadow: 0 0 0px 0px var(--correct-color); }
  50% { box-shadow: 0 0 20px 10px var(--correct-color); }
  100% { box-shadow: 0 0 0px 0px transparent; }
}

.incorrect-effect {
  animation: flashIncorrect 0.5s;
}
@keyframes flashIncorrect {
  0% { box-shadow: 0 0 0px 0px var(--incorrect-color); }
  50% { box-shadow: 0 0 20px 10px var(--incorrect-color); }
  100% { box-shadow: 0 0 0px 0px transparent; }
}

/* Confetti / Particle Effects */
.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
  /* Randomized animation duration and horizontal offset */
  animation: confetti-fall 2s ease-out forwards;
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateX(var(--x-offset)) translateY(300px) rotate(360deg); }
}
