/* TypeRacer Arena - Main Styles */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ==================== Layout ==================== */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  padding: 2rem 0;
  animation: fadeIn var(--transition-normal);
}

.screen.active {
  display: flex;
}

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

/* ==================== Reusable Components ==================== */

/* Centered screen layout - for screens with a single centered card */
.centered-screen {
  display: flex;
  flex: 1;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

/* Generic card component */
.card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.card--sm { max-width: 420px; }
.card--md { max-width: 540px; }
.card--lg { max-width: 600px; }

.card__title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
}

.card__actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.card__actions .btn {
  width: 100%;
}

.card__actions .keyboard-hint {
  margin-top: 0.5rem;
  text-align: center;
}

/* ==================== Header ==================== */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  margin-bottom: 2rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-icon {
  font-size: 2rem;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ==================== Buttons ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

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

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

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.btn-primary:hover {
  box-shadow: var(--shadow-lg), 0 0 30px rgba(233, 69, 96, 0.4);
}

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

.btn-secondary:hover {
  background: var(--accent-secondary);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--border-radius-full);
  font-size: 1.25rem;
}

.btn-lg {
  padding: 1rem 2.5rem;
  font-size: 1.125rem;
}

/* ==================== Title Screen ==================== */

/* Uses .centered-screen utility */

.title-screen {
  text-align: center;
}

.title-content {
  max-width: 600px;
}

.title-logo {
  font-size: 4rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: pulse 2s ease-in-out infinite;
}

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

.title-tagline {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 3rem;
}

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

.keyboard-hint {
  margin-top: 3rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

kbd {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: var(--bg-surface);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  margin: 0 0.25rem;
}

/* ==================== Player Setup ==================== */

/* Uses .centered-screen and .card utilities */

.setup-card {
  padding: 2.5rem;
}

.player-count {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.player-count .btn {
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  min-width: 100px;
}

.player-count .btn.active {
  background: var(--gradient-primary);
  color: white;
}

.player-inputs {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}

.player-input-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.player-number {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-primary);
  color: white;
  font-weight: 700;
  border-radius: var(--border-radius-full);
  font-size: 0.875rem;
}

.input {
  flex: 1;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-primary);
  border: 2px solid transparent;
  border-radius: var(--border-radius-md);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.2);
}

.input::placeholder {
  color: var(--text-muted);
}

/* ==================== Mode Select ==================== */

.mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.mode-card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: 2px solid transparent;
  position: relative;
}

.mode-card:hover,
.mode-card:focus {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-primary);
  outline: none;
}

.mode-card.selected {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.mode-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.mode-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.mode-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.mode-key {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ==================== Category Select ==================== */

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

.category-card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-md);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.category-card:hover:not(.locked) {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
}

.category-card.selected {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.category-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.category-card.locked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
}

.category-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.category-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.category-unlock {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.lock-icon {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 1rem;
}

/* ==================== Difficulty Select ==================== */

.difficulty-options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 2rem;
}

.difficulty-btn {
  padding: 1rem 2rem;
  background: var(--bg-surface);
  border: 2px solid transparent;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.difficulty-btn:hover {
  border-color: var(--accent-secondary);
}

.difficulty-btn.selected {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.difficulty-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.difficulty-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.difficulty-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* ==================== Game Screen ==================== */

.game-screen {
  padding: 1rem 0;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

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

.info-item {
  text-align: center;
}

.info-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.info-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.info-value.wpm {
  color: var(--accent-primary);
}

.info-value.accuracy {
  color: var(--success);
}

.current-player {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-surface);
  padding: 0.75rem 1.25rem;
  border-radius: var(--border-radius-full);
}

.player-avatar {
  width: 36px;
  height: 36px;
  background: var(--gradient-primary);
  border-radius: var(--border-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
}

.player-name {
  font-weight: 600;
}

.player-turn-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==================== Typing Area ==================== */

.typing-container {
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.text-display {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  line-height: 2;
  margin-bottom: 2rem;
  min-height: 150px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.char {
  position: relative;
  transition: color var(--transition-fast);
}

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

.char.incorrect {
  color: var(--error);
  text-decoration: underline;
  text-decoration-style: wavy;
}

.char.current {
  position: relative;
}

.char.current::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 2px;
  height: 100%;
  background: var(--accent-primary);
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.char.untyped {
  color: var(--text-muted);
}

.typing-input {
  width: 100%;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 1.25rem;
  background: var(--bg-primary);
  border: 2px solid transparent;
  border-radius: var(--border-radius-md);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.typing-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.typing-input.error {
  border-color: var(--error);
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Progress bar */
.progress-container {
  margin-top: 1.5rem;
}

.progress-bar {
  height: 8px;
  background: var(--bg-primary);
  border-radius: var(--border-radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: var(--border-radius-full);
  transition: width var(--transition-fast);
  width: 0%;
}

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

/* ==================== Countdown Overlay ==================== */

.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.countdown-overlay.active {
  display: flex;
}

.countdown-number {
  font-size: 12rem;
  font-weight: 800;
  color: var(--accent-primary);
  animation: countPop 1s ease-out;
}

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

/* ==================== Results Screen ==================== */

/* Uses .centered-screen and .card utilities */

.results-card {
  padding: 2.5rem;
  text-align: center;
}

.results-title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.results-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.scoreboard {
  margin-bottom: 2rem;
}

.score-row {
  display: flex;
  align-items: center;
  padding: 1rem;
  background: var(--bg-primary);
  border-radius: var(--border-radius-md);
  margin-bottom: 0.75rem;
  transition: all var(--transition-fast);
}

.score-row.winner {
  background: var(--gradient-primary);
  color: white;
  transform: scale(1.02);
}

.score-rank {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border-radius: var(--border-radius-full);
  font-weight: 700;
  margin-right: 1rem;
}

.score-row.winner .score-rank {
  background: rgba(255, 255, 255, 0.2);
}

.score-player {
  flex: 1;
  text-align: left;
  font-weight: 600;
}

.score-stats {
  display: flex;
  gap: 1.5rem;
  font-family: var(--font-mono);
}

.score-wpm, .score-accuracy {
  font-size: 0.875rem;
}

.score-total {
  font-weight: 700;
  font-size: 1.25rem;
}

/* XP Gain */
.xp-gain {
  background: var(--bg-primary);
  border-radius: var(--border-radius-md);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.xp-title {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.xp-amount {
  font-size: 2rem;
  font-weight: 800;
  color: var(--warning);
}

.xp-bar {
  height: 8px;
  background: var(--bg-surface);
  border-radius: var(--border-radius-full);
  margin-top: 1rem;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: var(--gradient-success);
  border-radius: var(--border-radius-full);
  transition: width 1s ease-out;
}

.results-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ==================== Theme Toggle ==================== */

.theme-toggle {
  position: relative;
  width: 44px;
  height: 44px;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle label {
  position: absolute;
  inset: 0;
  background: var(--bg-surface);
  border-radius: var(--border-radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all var(--transition-fast);
}

.theme-toggle label:hover {
  background: var(--bg-elevated);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  position: absolute;
  transition: all var(--transition-fast);
}

.theme-toggle .icon-sun {
  opacity: 0;
  transform: rotate(-90deg);
}

.theme-toggle .icon-moon {
  opacity: 1;
  transform: rotate(0);
}

[data-theme="light"] .theme-toggle .icon-sun {
  opacity: 1;
  transform: rotate(0);
}

[data-theme="light"] .theme-toggle .icon-moon {
  opacity: 0;
  transform: rotate(90deg);
}

/* ==================== Confetti ==================== */

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

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

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

/* ==================== Game Prompt ==================== */

.game-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--bg-primary);
  border-radius: var(--border-radius-md);
  color: var(--text-secondary);
  animation: pulse 2s ease-in-out infinite;
}

.game-prompt.hidden {
  display: none;
}

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

.prompt-text {
  font-size: 1rem;
  font-weight: 500;
}

.source-text {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ==================== Modal ==================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 200;
  padding: 1rem;
  animation: fadeIn var(--transition-normal);
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease-out;
}

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

.modal-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--gradient-success);
  border-radius: var(--border-radius-full);
  color: white;
}

.modal-icon.winner {
  background: var(--gradient-primary);
  font-size: 2.5rem;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.modal-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Stats Breakdown */
.stats-breakdown {
  background: var(--bg-primary);
  border-radius: var(--border-radius-md);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
}

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

.stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

.stat-row.highlight .stat-value {
  color: var(--accent-primary);
}

.stat-row.total {
  padding-top: 0.75rem;
}

.stat-row.total .stat-label {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1rem;
}

.stat-row.total .stat-value {
  font-size: 1.25rem;
  color: var(--success);
}

.stat-divider {
  height: 1px;
  background: var(--bg-surface);
  margin: 0.5rem 0;
}

/* XP Mini Display */
.xp-gain-mini {
  text-align: center;
  margin-bottom: 1.5rem;
}

.xp-label {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  background: var(--bg-primary);
  border-radius: var(--border-radius-full);
  font-weight: 700;
  color: var(--warning);
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-actions .btn {
  width: 100%;
}

.modal-hint {
  text-align: center;
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ==================== Settings Modal ==================== */

.settings-modal {
  max-width: 480px;
}

.settings-list {
  margin-bottom: 1.5rem;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--bg-primary);
  border-radius: var(--border-radius-md);
  margin-bottom: 0.75rem;
  gap: 1rem;
}

.setting-info {
  flex: 1;
}

.setting-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.setting-select {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-surface);
  border: 2px solid var(--bg-elevated);
  border-radius: var(--border-radius-md);
  color: var(--text-primary);
  cursor: pointer;
  min-width: 140px;
}

.setting-select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* ==================== Utilities ==================== */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.hidden { display: none !important; }

/* ==================== Responsive ==================== */

@media (max-width: 768px) {
  .title-logo {
    font-size: 2.5rem;
  }

  .text-display {
    font-size: 1.125rem;
  }

  .typing-input {
    font-size: 1rem;
  }

  .game-info {
    gap: 1rem;
  }

  .info-value {
    font-size: 1.25rem;
  }

  .mode-cards {
    grid-template-columns: 1fr;
  }

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

  .difficulty-options {
    flex-direction: column;
    align-items: stretch;
  }

  .difficulty-btn {
    width: 100%;
  }
}
