*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fff5e6;
  --bg-gradient: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 50%, #ffd166 100%);
  --card: #ffffff;
  --primary: #ff6b6b;
  --primary-dark: #e85555;
  --secondary: #ffd166;
  --success: #06d6a0;
  --error: #ef476f;
  --text: #2d3748;
  --text-light: #718096;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  --radius: 20px;
}

body {
  font-family: "Fredoka", sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text);
  line-height: 1.5;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.header {
  text-align: center;
  margin-bottom: 28px;
  color: white;
}

.header-top {
  text-align: left;
  margin-bottom: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.22);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 99px;
  text-decoration: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s, transform 0.2s;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.32);
  transform: translateX(-3px);
}

.back-link:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.logo {
  font-size: 2.4rem;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.tagline {
  font-size: 1.05rem;
  opacity: 0.95;
  margin-top: 4px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.card h1 {
  font-size: 1.8rem;
  text-align: center;
  margin-bottom: 8px;
}

.subtitle {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}

.field span {
  font-weight: 500;
  font-size: 0.95rem;
}

.field input {
  font-family: inherit;
  font-size: 1.1rem;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: var(--primary);
}

.mode-label {
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
}

.mode-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.mode-btn {
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 12px;
  border: 3px solid #e2e8f0;
  border-radius: 16px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.mode-btn.selected {
  border-color: var(--primary);
  background: #fff0f0;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.25);
}

.mode-icon {
  font-size: 2rem;
}

.mode-title {
  font-weight: 600;
  font-size: 1rem;
}

.mode-desc {
  font-size: 0.75rem;
  color: var(--text-light);
  text-align: center;
}

.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  margin-bottom: 20px;
}

.toggle-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-title {
  font-weight: 600;
  font-size: 1rem;
}

.toggle-desc {
  font-size: 0.82rem;
  color: var(--text-light);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e0;
  border-radius: 999px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.toggle-switch input:focus-visible + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.35);
}

.btn {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 14px 28px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-secondary {
  background: #edf2f7;
  color: var(--text);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}

.progress-info {
  flex: 1;
}

.progress-info span {
  font-size: 0.9rem;
  color: var(--text-light);
  font-weight: 500;
}

.progress-bar {
  height: 8px;
  background: #edf2f7;
  border-radius: 99px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 5%;
}

.game-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.score-badge {
  background: var(--secondary);
  padding: 8px 16px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.timer-badge {
  background: var(--primary);
  color: white;
  padding: 8px 14px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  transition: background 0.2s;
  font-variant-numeric: tabular-nums;
}

.timer-badge.warning {
  background: var(--error);
  animation: pulse 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.question-area {
  text-align: center;
  margin-bottom: 28px;
}

.question-prompt {
  color: var(--text-light);
  font-size: 1rem;
  margin-bottom: 4px;
}

.question-text {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
  letter-spacing: 0.02em;
}

.answer-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  align-items: stretch;
}

.answer-input {
  flex: 1;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 600;
  padding: 14px 20px;
  border: 3px solid #e2e8f0;
  border-radius: 14px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s;
  min-width: 0;
}

.answer-input:focus {
  border-color: var(--primary);
}

.answer-input:disabled {
  background: #f7fafc;
  color: var(--text-light);
}

.btn-inline {
  width: auto;
  padding: 14px 24px;
  white-space: nowrap;
}

.feedback {
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.feedback.correct-msg {
  background: #d4faf0;
  color: #047857;
  animation: pop 0.3s ease-out;
}

.feedback.wrong-msg {
  background: #fde8ed;
  color: #be123c;
  animation: pop 0.3s ease-out;
}

@keyframes pop {
  0% { transform: scale(0.85); }
  100% { transform: scale(1); }
}

.hidden {
  display: none !important;
}

.results-card {
  text-align: center;
}

.results-emoji {
  font-size: 4rem;
  margin-bottom: 8px;
}

.results-name {
  color: var(--text-light);
  margin-bottom: 20px;
}

.results-score-box {
  background: linear-gradient(135deg, #ff9a56, #ff6b6b);
  color: white;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 16px;
}

.results-label {
  display: block;
  font-size: 0.95rem;
  opacity: 0.85;
}

.final-score {
  display: block;
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.results-max {
  font-size: 0.9rem;
  opacity: 0.85;
}

.results-message {
  color: var(--text-light);
  margin-bottom: 24px;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.save-confirmation {
  color: var(--success);
  font-weight: 600;
  font-size: 0.95rem;
}

.leaderboard-section {
  margin-top: 28px;
}

.leaderboards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.leaderboard-card h2 {
  text-align: center;
  margin-bottom: 16px;
  font-size: 1.15rem;
}

.leaderboard-card.highlight {
  box-shadow: 0 0 0 3px var(--primary), var(--shadow);
}

.leaderboard-empty {
  text-align: center;
  color: var(--text-light);
  padding: 12px;
  font-size: 0.9rem;
}

.leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f7fafc;
  border-radius: 12px;
  font-size: 0.9rem;
}

.leaderboard-item:first-child {
  background: linear-gradient(135deg, #fff9db, #ffe06633);
  border: 2px solid var(--secondary);
}

.rank {
  font-weight: 700;
  color: var(--primary);
  text-align: center;
}

.lb-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 700;
  color: var(--primary);
}

@media (max-width: 720px) {
  .leaderboards-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .mode-buttons {
    grid-template-columns: 1fr;
  }

  .question-text {
    font-size: 2.2rem;
  }

  .answer-row {
    flex-direction: column;
  }

  .btn-inline {
    width: 100%;
  }
}
