/* Base Styles - Applied to all themes */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s, color 0.3s;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  width: 100%;
}

.top-controls {
  display: flex;
  width: 100%;
  max-width: 800px;
  margin-bottom: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #ddd;
  justify-content: center;
  gap: 1.5rem;
}

.top-controls label {
  margin-right: 0.5rem;
  font-weight: 500;
}

.top-controls select {
  padding: 0.6rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  min-width: 180px;
  font-size: 0.95rem;
}

.theme-selector,
.language-selector {
  padding: 0.5rem;
  border-radius: 4px;
}

.container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  padding: 2rem;
  border-radius: 12px;
  width: 100%;
}

.settings-card {
  display: block;
}

.problem-card {
  display: none;
  text-align: center;
  position: relative;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

h3 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
}

/* Back button */
.back-btn {
  position: absolute;
  top: 1rem;
  left: 1rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: #e9ecef;
  color: #495057;
  transition: all 0.2s;
}

.back-btn:hover {
  background: #dee2e6;
}

/* Timer display */
.timer-display {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.5rem;
  font-weight: bold;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: #fff3cd;
  color: #856404;
}

.timer-display.warning {
  background: #f8d7da;
  color: #721c24;
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Streak display */
.streak-display {
  margin-bottom: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  background: linear-gradient(135deg, #ff6b6b, #ffa500);
  color: white;
  font-weight: bold;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  animation: streakPop 0.3s ease-out;
}

.streak-fire {
  font-size: 1.3rem;
}

@keyframes streakPop {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* Progress bar */
.progress-container {
  margin-top: 1.5rem;
  position: relative;
  height: 24px;
  background: #e9ecef;
  border-radius: 12px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #4361ee, #3f37c9);
  border-radius: 12px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.85rem;
  font-weight: bold;
  color: #495057;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

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

.modal-content {
  background: white;
  padding: 2.5rem;
  border-radius: 16px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: slideUp 0.3s ease;
}

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

.modal-content h2 {
  margin-bottom: 1.5rem;
  color: #212529;
}

.summary-score {
  font-size: 3rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.summary-score .summary-number:first-child {
  color: #28a745;
}

.summary-score #summary-separator {
  color: #6c757d;
  margin: 0 0.25rem;
}

.summary-message {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  color: #6c757d;
}

.summary-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.btn-primary, .btn-secondary {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: #4361ee;
  color: white;
}

.btn-primary:hover {
  background: #3f37c9;
}

.btn-secondary {
  background: #e9ecef;
  color: #495057;
}

.btn-secondary:hover {
  background: #dee2e6;
}

/* Confetti */
#confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0;
  animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

/* Session settings */
.session-options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.session-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.session-option label {
  cursor: pointer;
}

.session-option select,
.session-option input[type="number"] {
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 1rem;
}

.timed-option {
  margin-left: 1.5rem;
  padding-left: 1rem;
  border-left: 2px solid #ddd;
}

/* Problem and answer styling */
.problem {
  font-size: 2.5rem;
  font-weight: bold;
  margin: 2rem 0;
}

.answer-input {
  font-size: 1.5rem;
  padding: 1rem;
  width: 100%;
  max-width: 200px;
  text-align: center;
  border: 2px solid #ddd;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.answer-input:focus {
  outline: none;
  border-color: #4361ee;
}

.feedback {
  font-size: 1.2rem;
  font-weight: bold;
  min-height: 2rem;
  margin: 1rem 0;
}

.feedback.correct {
  color: #28a745;
}

.feedback.incorrect {
  color: #dc3545;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: bold;
}

.correct-count {
  color: #28a745;
}

.incorrect-count {
  color: #dc3545;
}

/* Settings styling */
.setting-group {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #eee;
}

.setting-group:last-child {
  border-bottom: none;
}

.operations {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.operation-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.operation-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.operation-checkbox label {
  cursor: pointer;
  font-size: 1rem;
}

.range-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.range-input {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.range-input input {
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.tables-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.tables-mode input[type="radio"] {
  margin-right: 0.25rem;
}

.tables-container {
  margin-top: 1rem;
}

.tables-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
}

.table-checkbox {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.table-checkbox input {
  width: 18px;
  height: 18px;
}

.table-checkbox label {
  font-size: 0.9rem;
  cursor: pointer;
}

.force-visible {
  display: block !important;
}

#start-btn,
#action-btn {
  padding: 1rem 2rem;
  font-size: 1.2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 1rem;
  transition: all 0.2s;
}

/* ===== THEME: DEFAULT ===== */
.theme-default {
  font-family: "Quicksand", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #212529;
}

.theme-default h1 {
  color: #ffffff;
}

.theme-default header p {
  color: rgba(255, 255, 255, 0.9);
}

.theme-default .card {
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.theme-default .answer-input {
  background: #f8f9fa;
}

.theme-default #start-btn,
.theme-default #action-btn {
  background: #4361ee;
  color: white;
}

.theme-default #start-btn:hover,
.theme-default #action-btn:hover {
  background: #3f37c9;
  transform: translateY(-2px);
}

.theme-default .top-controls {
  border-top-color: rgba(255, 255, 255, 0.3);
}

.theme-default .top-controls select {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background-color: rgba(255, 255, 255, 0.9);
  color: #212529;
}

/* ===== THEME: ACCESSIBLE ===== */
.theme-accessible {
  font-family: Arial, Helvetica, sans-serif;
  background: #ffffff;
  color: #000000;
}

.theme-accessible h1,
.theme-accessible header p {
  color: #000000;
}

.theme-accessible .card {
  background: #ffffff;
  border: 3px solid #000000;
  box-shadow: none;
}

.theme-accessible .problem {
  font-size: 3rem;
}

.theme-accessible .answer-input {
  border: 3px solid #000000;
  font-size: 1.75rem;
}

.theme-accessible .answer-input:focus {
  outline: 4px solid #0056b3;
  outline-offset: 2px;
}

.theme-accessible #start-btn,
.theme-accessible #action-btn {
  background: #000000;
  color: #ffffff;
  border: 3px solid #000000;
  font-size: 1.3rem;
}

.theme-accessible #start-btn:hover,
.theme-accessible #action-btn:hover,
.theme-accessible #start-btn:focus,
.theme-accessible #action-btn:focus {
  background: #ffffff;
  color: #000000;
  outline: 4px solid #0056b3;
}

.theme-accessible .back-btn {
  border: 2px solid #000;
  font-weight: bold;
}

.theme-accessible .top-controls {
  border-top-color: #000000;
  margin-top: 3rem;
  padding-top: 2rem;
}

.theme-accessible .top-controls select {
  border: 2px solid #000000;
  background-color: #ffffff;
  color: #000000;
  font-size: 1.1rem;
  padding: 0.8rem 1.2rem;
}

/* ===== THEME 1: Playful/Kids ===== */
.theme-1 {
  font-family: "Comic Neue", cursive;
  background: linear-gradient(180deg, #ffd6e0 0%, #c1f0f6 50%, #d4f0c0 100%);
  color: #333;
}

.theme-1 h1 {
  color: #ff6b9d;
  text-shadow: 3px 3px 0 #fff;
}

.theme-1 header p {
  color: #7b68ee;
}

.theme-1 .card {
  background: #ffffff;
  border: 4px dashed #8338ec;
  border-radius: 20px;
  box-shadow: 8px 8px 0 rgba(131, 56, 236, 0.2);
}

.theme-1 .problem {
  color: #ff6b9d;
}

.theme-1 .answer-input {
  border: 3px solid #8338ec;
  border-radius: 15px;
  background: #fff9e6;
}

.theme-1 #start-btn,
.theme-1 #action-btn {
  background: linear-gradient(135deg, #ff6b9d, #c56cf0);
  color: white;
  border-radius: 25px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
}

.theme-1 #start-btn:hover,
.theme-1 #action-btn:hover {
  transform: translateY(-3px) rotate(-1deg);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.15);
}

.theme-1 .streak-display {
  background: linear-gradient(135deg, #ff6b9d, #ffd93d);
}

.theme-1 .top-controls {
  border-top-color: #8338ec;
  border-top-style: dashed;
  border-top-width: 3px;
  margin-top: 2.5rem;
}

.theme-1 .top-controls select {
  border: 2px dashed #8338ec;
  border-radius: 10px;
  background-color: #ffffff;
  font-family: "Comic Neue", cursive;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.1);
}

/* ===== THEME 2: Calm/Nature ===== */
.theme-2 {
  font-family: "Quicksand", sans-serif;
  background: linear-gradient(180deg, #e8f5e9 0%, #b2dfdb 100%);
  color: #2d6e65;
}

.theme-2 h1 {
  color: #2d6e65;
}

.theme-2 header p {
  color: #4a9e91;
}

.theme-2 .card {
  background: #ffffff;
  border: 2px solid #b1dad3;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(45, 110, 101, 0.1);
}

.theme-2 .problem {
  color: #2d6e65;
}

.theme-2 .answer-input {
  border: 2px solid #b1dad3;
  background: #f0f9f7;
}

.theme-2 #start-btn,
.theme-2 #action-btn {
  background: #4a9e91;
  color: white;
}

.theme-2 #start-btn:hover,
.theme-2 #action-btn:hover {
  background: #3d8578;
}

.theme-2 .streak-display {
  background: linear-gradient(135deg, #4a9e91, #81c784);
}

.theme-2 .progress-bar {
  background: linear-gradient(90deg, #4a9e91, #81c784);
}

.theme-2 .top-controls {
  border-top-color: #b1dad3;
}

.theme-2 .top-controls select {
  border: 2px solid #b1dad3;
  border-radius: 6px;
  background-color: #ffffff;
  color: #2d6e65;
  font-family: "Quicksand", sans-serif;
  font-weight: 500;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  body {
    padding: 1rem 0.5rem;
  }

  h1 {
    font-size: 1.8rem;
  }

  .card {
    padding: 1.5rem 1rem;
  }

  .problem {
    font-size: 2rem;
    margin: 1.5rem 0;
  }

  .operations {
    grid-template-columns: 1fr;
  }

  .range-inputs {
    grid-template-columns: 1fr;
  }

  .tables-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .top-controls {
    flex-direction: column;
    gap: 0.75rem;
  }

  .top-controls select {
    width: 100%;
  }

  .back-btn {
    position: static;
    margin-bottom: 1rem;
    width: 100%;
  }

  .timer-display {
    position: static;
    margin-bottom: 1rem;
  }

  .summary-buttons {
    flex-direction: column;
  }

  .stats {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* ===== CHALLENGE STYLES ===== */

.challenge-banner {
  background: linear-gradient(135deg, #ffd93d, #ff6b6b);
  color: #333;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-weight: bold;
  margin-bottom: 1rem;
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.challenge-icon {
  font-size: 1.5rem;
}

.small-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  transition: all 0.2s;
}

.small-btn:hover {
  background: #fff;
  transform: scale(1.05);
}

.button-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 1.5rem;
}

.button-row button {
  flex: 1;
  min-width: 150px;
}

/* Nickname input */
.nickname-section {
  margin: 1.5rem 0;
  text-align: center;
}

.nickname-section label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
}

.nickname-input {
  padding: 0.75rem 1rem;
  font-size: 1.1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  width: 100%;
  max-width: 250px;
  text-align: center;
}

.nickname-input:focus {
  outline: none;
  border-color: #4361ee;
}

/* Challenge form */
.challenge-form {
  margin: 1.5rem 0;
  text-align: center;
}

.challenge-form label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
}

.form-hint {
  font-size: 0.85rem;
  color: #888;
  margin-top: 0.75rem;
}

/* Share link */
.share-link-container {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

.share-link-input {
  flex: 1;
  padding: 0.75rem;
  font-size: 0.9rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #f8f9fa;
}

.copy-feedback {
  font-size: 0.9rem;
  color: #28a745;
  min-height: 1.5rem;
}

/* Leaderboard */
.modal-wide {
  max-width: 500px;
}

.leaderboard-content {
  max-height: 300px;
  overflow-y: auto;
  margin: 1rem 0;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid #eee;
}

.leaderboard-table th {
  font-weight: 600;
  color: #666;
  font-size: 0.85rem;
  text-transform: uppercase;
}

.leaderboard-table tr.is-you {
  background: #fff9e6;
}

.leaderboard-table .rank {
  width: 40px;
  font-weight: bold;
}

.leaderboard-table .rank-1 { color: #ffd700; }
.leaderboard-table .rank-2 { color: #c0c0c0; }
.leaderboard-table .rank-3 { color: #cd7f32; }

.leaderboard-empty {
  text-align: center;
  color: #888;
  padding: 2rem;
}

/* Responsive */
@media (max-width: 600px) {
  .button-row {
    flex-direction: column;
  }
  
  .button-row button {
    width: 100%;
  }
  
  .share-link-container {
    flex-direction: column;
  }
  
  .challenge-banner {
    flex-wrap: wrap;
    text-align: center;
  }
}
