/* 
   Sum Runner - Modern CSS Styles
    */

/* CSS Custom Properties for easy theming */
:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --background-color: #ffffff;
  --surface-color: #f8fafc;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --transition-fast: 0.15s ease-out;
  --transition-normal: 0.25s ease-out;
  --transition-slow: 0.35s ease-out;
}

/* Dark theme variables */
[data-theme="dark"] {
  --primary-color: #3b82f6;
  --primary-dark: #2563eb;
  --background-color: #0f172a;
  --surface-color: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border-color: #334155;
}

/* High contrast theme */
[data-contrast="high"] {
  --primary-color: #000000;
  --primary-dark: #333333;
  --success-color: #006600;
  --error-color: #cc0000;
  --text-primary: #000000;
  --background-color: #ffffff;
  --border-color: #000000;
}

/* Large text mode */
[data-large-text="true"] {
  font-size: 18px;
}

/* 
   Base Styles & Reset
    */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--background-color);
  transition: background-color var(--transition-normal),
    color var(--transition-normal);
  overflow-x: hidden;
  position: relative;
  min-height: 100vh;
}

/* 
   Screen Management
    */

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--transition-normal),
    transform var(--transition-normal);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  transform: translateY(0);
  position: relative;
  z-index: 2;
}

.screen.hidden {
  display: none;
}

.overlay {
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 1000;
}

.container {
  max-width: 600px;
  width: 100%;
  text-align: center;
}

/* 
   Typography
    */

h1,
h2,
h3 {
  margin-bottom: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

h1 {
  font-size: 2.5rem;
}

h2 {
  font-size: 2rem;
}

h3 {
  font-size: 1.5rem;
}

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

/* 
   Loading Screen
    */

.loading-container {
  text-align: center;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 2rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 
   Game Header & Title
    */

.game-header {
  margin-bottom: 3rem;
}

.game-title {
  margin-bottom: 0.5rem;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--primary-dark)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titlePulse 3s ease-in-out infinite;
}

.title-sum {
  font-weight: 800;
}

.title-runner {
  font-weight: 300;
}

.game-subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 0;
}

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

/* 
   Buttons
    */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
  min-width: 120px;
}

.btn:before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.btn:hover:before {
  left: 100%;
}

.btn-primary {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--primary-dark)
  );
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--error-color);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  min-width: 200px;
}

.btn-small {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  min-width: auto;
}

.btn-icon {
  font-size: 1.2em;
}

.btn:active {
  transform: translateY(0);
}

.btn:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* 
   Menu & Navigation
    */

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
}

.back-btn {
  position: absolute;
  top: 2rem;
  left: 2rem;
  padding: 0.5rem 1rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  transition: all var(--transition-fast);
  z-index: 10;
}

.back-btn:hover {
  background: var(--border-color);
  transform: translateX(-2px);
}

/* 
   Instructions
    */

.instructions {
  text-align: left;
  margin-top: 2rem;
}

.instruction-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  transition: transform var(--transition-fast);
}

.instruction-item:hover {
  transform: translateY(-2px);
}

.instruction-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.instruction-item h3 {
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.instruction-item p {
  margin-bottom: 0;
  font-size: 0.95rem;
}

/* 
   High Scores
    */

.high-scores-list {
  margin: 2rem 0;
  text-align: left;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  margin-bottom: 0.5rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  transition: all var(--transition-fast);
}

.score-item:hover {
  transform: translateX(4px);
  border-color: var(--primary-color);
}

.score-item.personal-best {
  background: linear-gradient(
    135deg,
    var(--primary-color) 15,
    var(--surface-color)
  );
  border-color: var(--primary-color);
}

.score-rank {
  font-weight: 700;
  color: var(--primary-color);
  font-size: 1.2rem;
  min-width: 2rem;
}

.score-details {
  flex: 1;
  margin-left: 1rem;
}

.score-points {
  font-weight: 600;
  color: var(--text-primary);
}

.score-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.no-scores {
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
  padding: 3rem 1rem;
}

/* 
   Settings
    */

.settings-grid {
  display: grid;
  gap: 1.5rem;
  margin: 2rem 0;
  text-align: left;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.setting-item label {
  font-weight: 500;
  color: var(--text-primary);
}

.toggle-btn {
  position: relative;
  width: 60px;
  height: 30px;
  background: var(--border-color);
  border: none;
  border-radius: 15px;
  cursor: pointer;
  transition: background-color var(--transition-normal);
}

.toggle-btn.active {
  background: var(--primary-color);
}

.toggle-btn:before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-normal);
}

.toggle-btn.active:before {
  transform: translateX(30px);
}

.toggle-text {
  position: absolute;
  left: 70px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* 
   Custom Settings
    */

.custom-settings {
  text-align: left;
  margin: 2rem 0;
}

.setting-group {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.setting-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.checkbox-group {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: normal;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast);
}

.checkbox-item:hover {
  background: var(--border-color);
}

.checkbox-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color);
}

.slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-color);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-sm);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* 
   Countdown Screen
    */

.countdown-display {
  text-align: center;
}

.countdown-number {
  font-size: 6rem;
  font-weight: 800;
  color: var(--primary-color);
  margin-bottom: 1rem;
  animation: countdownPulse 1s ease-in-out;
}

.countdown-text {
  font-size: 1.5rem;
  color: var(--text-secondary);
  font-weight: 500;
}

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

/* 
   Game Screen
    */

.game-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

.game-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.game-stats {
  display: flex;
  gap: 2rem;
}

.stat {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Timer Bar */
.timer-bar {
  width: 100%;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  margin-bottom: 3rem;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--success-color),
    var(--warning-color),
    var(--error-color)
  );
  border-radius: 4px;
  transition: width 0.1s linear;
  width: 100%;
}

/* Question Area */
.question-area {
  text-align: center;
  margin-bottom: 2rem;
}

.question-text {
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3rem;
  padding: 2rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-color);
  animation: questionSlideIn 0.5s ease-out;
}

@keyframes questionSlideIn {
  0% {
    transform: translateY(20px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.answer-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.answer-btn {
  padding: 1.5rem 2rem;
  font-size: 1.5rem;
  font-weight: 600;
  background: var(--surface-color);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.answer-btn:hover {
  transform: translateY(-4px);
  border-color: var(--primary-color);
  box-shadow: var(--shadow-lg);
}

.answer-btn:active {
  transform: translateY(-2px);
}

.answer-btn.correct {
  background: var(--success-color);
  border-color: var(--success-color);
  color: white;
  animation: correctAnswer 0.6s ease-out;
}

.answer-btn.incorrect {
  background: var(--error-color);
  border-color: var(--error-color);
  color: white;
  animation: incorrectAnswer 0.6s ease-out;
}

@keyframes correctAnswer {
  0% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.05);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes incorrectAnswer {
  0%,
  20%,
  40%,
  60%,
  80% {
    transform: translateX(-5px);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(5px);
  }
  100% {
    transform: translateX(0);
  }
}

/* Feedback Area */
.feedback-area {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  pointer-events: none;
}

.feedback-text {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  animation: feedbackPop 0.8s ease-out;
}

.feedback-text.correct {
  color: var(--success-color);
}

.feedback-text.incorrect {
  color: var(--error-color);
}

.points-animation {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary-color);
  animation: pointsFloat 1s ease-out;
}

@keyframes feedbackPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes pointsFloat {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-50px);
    opacity: 0;
  }
}

/* 
   Pause Screen
    */

.pause-container {
  background: var(--background-color);
  padding: 3rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
}

.pause-stats {
  margin: 2rem 0;
  text-align: left;
}

.pause-stats .stat {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
}

/* 
   End Screen
    */

.end-game-content {
  text-align: center;
}

.new-high-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--warning-color);
  margin-bottom: 2rem;
  animation: celebrate 2s ease-in-out;
}

@keyframes celebrate {
  0%,
  100% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.1) rotate(-5deg);
  }
  75% {
    transform: scale(1.1) rotate(5deg);
  }
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.stat-card {
  padding: 1.5rem 1rem;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  text-align: center;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.stat-card .stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.end-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
}

/* Floating Animations */

.floating-animations {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

.floating-point {
  position: absolute;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  animation: floatUp 2s ease-out forwards;
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-100px) scale(1.5);
  }
}

/* Background Elements */

.background-elements {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.bg-shape {
  position: absolute;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color) 10, transparent);
  animation: float 20s ease-in-out infinite;
}

.bg-shape-1 {
  width: 200px;
  height: 200px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.bg-shape-2 {
  width: 150px;
  height: 150px;
  top: 60%;
  right: 10%;
  animation-delay: 5s;
}

.bg-shape-3 {
  width: 100px;
  height: 100px;
  top: 30%;
  right: 30%;
  animation-delay: 10s;
}

.bg-shape-4 {
  width: 250px;
  height: 250px;
  bottom: 10%;
  left: 20%;
  animation-delay: 15s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-20px) rotate(90deg);
  }
  50% {
    transform: translateY(-40px) rotate(180deg);
  }
  75% {
    transform: translateY(-20px) rotate(270deg);
  }
}

/* Responsive Design */

/* Tablet */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }

  .game-stats {
    gap: 1rem;
  }

  .question-text {
    font-size: 2.5rem;
    padding: 1.5rem;
  }

  .answer-buttons {
    grid-template-columns: 1fr;
  }

  .answer-btn {
    padding: 1.25rem 1.5rem;
    font-size: 1.25rem;
  }

  .final-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .back-btn {
    top: 1rem;
    left: 1rem;
    font-size: 0.875rem;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .screen {
    padding: 0.5rem;
  }

  .game-header-bar {
    flex-direction: column;
    gap: 1rem;
  }

  .game-stats {
    justify-content: center;
  }

  .question-text {
    font-size: 2rem;
    padding: 1rem;
  }

  .countdown-number {
    font-size: 4rem;
  }

  .instruction-item {
    flex-direction: column;
    text-align: center;
  }

  .mode-buttons .btn {
    flex-direction: column;
    text-align: center;
  }

  .final-stats {
    grid-template-columns: 1fr;
  }

  .bg-shape {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .bg-shape {
    animation: none;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
  }
}

/* Focus styles for keyboard navigation */
.btn:focus-visible,
.answer-btn:focus-visible,
.back-btn:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* High contrast focus indicators */
[data-contrast="high"] .btn:focus-visible,
[data-contrast="high"] .answer-btn:focus-visible {
  outline: 3px solid #000000;
  outline-offset: 3px;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media print {
  .background-elements,
  .floating-animations,
  .btn,
  .back-btn {
    display: none !important;
  }

  .screen {
    position: static;
    min-height: auto;
    page-break-inside: avoid;
  }

  body {
    background: white;
    color: black;
  }
}
