/*
  Times Tables Blitz — App Styles
  Loaded after papupa.css; relies on --pa- design tokens.
  All selectors prefixed with ttb- to avoid collisions.
*/

/* ── Leaderboard theme ───────────────────────────────────────────── */
:root {
  --lb-primary:   #f97316;
  --lb-secondary: #3b82f6;
  --lb-bg:        #fff7ed;
  --lb-gold:      #fbbf24;
  --lb-silver:    #94a3b8;
  --lb-bronze:    #c97438;
  --lb-row-hover: rgba(249, 115, 22, 0.08);
  --lb-row-me:    rgba(249, 115, 22, 0.15);
}

/* ── Page background ─────────────────────────────────────────────── */
body {
  background-color: #fff7ed;
  background-image:
    radial-gradient(at 0% 0%, rgba(249, 115, 22, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(59, 130, 246, 0.05) 0px, transparent 50%);
}

/* ── Root container ──────────────────────────────────────────────── */
#ttb-app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  font-family: var(--font-body);
  color: var(--pa-color-text);
  padding: var(--space-sm);
  box-sizing: border-box;
}

/* ═══════════════════════════════════════════════════════════════════
   WELCOME SCREEN
   ═══════════════════════════════════════════════════════════════════ */

.ttb-welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md) 0;
}

.ttb-title {
  font-family: var(--font-heading);
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 800;
  background: linear-gradient(135deg, #f97316, #fb923c, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin: 0;
  line-height: 1.15;
}

.ttb-subtitle {
  color: var(--pa-color-text-muted);
  font-size: var(--font-size-md);
  text-align: center;
  margin: 0;
}

/* Level selection */
.ttb-level-selection-card {
  width: 100%;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  padding: var(--space-lg);
  box-sizing: border-box;
}

.ttb-level-card-header {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #f97316;
  text-align: center;
  margin-bottom: var(--space-md);
}

.ttb-level-cards-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
}

.ttb-level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-xs);
  border: 2px solid #e5e7eb;
  border-radius: 14px;
  background: #f9fafb;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  font-family: inherit;
}

.ttb-level-card:hover {
  border-color: #fdba74;
  background: #fff7ed;
}

.ttb-level-card.ttb-active {
  border-color: #f97316;
  background: #fff7ed;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.18);
}

.ttb-level-card-icon {
  font-size: 1.6rem;
}

.ttb-level-card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #1f2937;
}

.ttb-level-card-desc {
  font-size: 0.7rem;
  color: #6b7280;
  text-align: center;
}

/* Badges row */
.ttb-badges-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  width: 100%;
  align-items: center;
}

.ttb-badges-row {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
  justify-content: center;
}

.ttb-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: #ffffff;
  border: 1.5px solid #fed7aa;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #374151;
  white-space: nowrap;
}

.ttb-badge-highlight {
  font-weight: 700;
  color: #f97316;
}

/* Start button */
.ttb-actions-row {
  width: 100%;
  display: flex;
  justify-content: center;
}

.ttb-start-btn {
  padding: 14px 48px;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #f97316, #3b82f6);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.35);
  transition: opacity 0.15s ease, transform 0.15s ease;
  font-family: inherit;
}

.ttb-start-btn:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-1px);
}

.ttb-start-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════════════════════════════════════ */

.ttb-card {
  background: #ffffff;
  border-radius: 22px;
  box-shadow: 0 7px 24px rgba(0, 0, 0, 0.1);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  position: relative;
  overflow: hidden;
  max-width: 420px;
  margin: 0 auto var(--space-xl);
  transition: transform 0.15s ease;
}

/* Flash states */
.ttb-correct-flash {
  animation: ttb-bounce 0.4s ease;
  box-shadow: 0 7px 24px rgba(34, 197, 94, 0.3);
}

.ttb-wrong-flash {
  animation: ttb-shake 0.4s ease;
  box-shadow: 0 7px 24px rgba(239, 68, 68, 0.3);
}

@keyframes ttb-bounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes ttb-shake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

/* Top bar */
.ttb-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.ttb-progress-pill,
.ttb-timer-pill,
.ttb-score-pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.ttb-progress-pill {
  background: #f3f4f6;
  color: #374151;
}

.ttb-timer-pill {
  background: #fff7ed;
  color: #f97316;
  border: 1.5px solid #fed7aa;
  min-width: 56px;
  text-align: center;
  transition: color 0.3s ease, border-color 0.3s ease;
}

.ttb-score-pill {
  background: #eff6ff;
  color: #3b82f6;
}

/* Timer track */
.ttb-timer-track {
  width: 100%;
  height: 7px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: var(--space-md);
}

.ttb-timer-bar {
  height: 100%;
  background: #22c55e;
  border-radius: 4px;
  transition: width 1s linear, background 0.4s ease;
}

.ttb-timer-bar--amber { background: #f59e0b; }
.ttb-timer-bar--red   { background: #ef4444; }

/* Question display */
.ttb-question-card {
  margin: var(--space-md) 0;
}

.ttb-question-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 3vw, 20px);
  flex-wrap: wrap;
}

.ttb-operand {
  font-size: clamp(2.4rem, 10vw, 3.8rem);
  font-weight: 900;
  color: #3b82f6;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ttb-operator {
  font-size: clamp(1.8rem, 7vw, 3rem);
  font-weight: 700;
  color: #f97316;
  line-height: 1;
}

.ttb-answer-slot {
  font-size: clamp(2.4rem, 10vw, 3.8rem);
  font-weight: 900;
  color: #d1d5db;
  line-height: 1;
  min-width: 60px;
  text-align: center;
}

/* Input row */
.ttb-input-form {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-md) 0 var(--space-sm);
}

.ttb-answer-input {
  width: 100px;
  padding: 12px 16px;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  border: 2.5px solid #3b82f6;
  border-radius: 12px;
  background: #eff6ff;
  color: #1d4ed8;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  /* Hide number input spinners */
  -moz-appearance: textfield;
}

.ttb-answer-input::-webkit-inner-spin-button,
.ttb-answer-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.ttb-answer-input:focus {
  border-color: #f97316;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.ttb-answer-input:disabled {
  background: #f9fafb;
  border-color: #e5e7eb;
  color: #9ca3af;
}

.ttb-submit-btn {
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #ffffff;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.ttb-submit-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.ttb-submit-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Feedback banner */
.ttb-feedback {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  border-radius: 0 0 22px 22px;
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.ttb-feedback.ttb-show {
  opacity: 1;
  transform: translateY(0);
}

.ttb-feedback--correct { background: #dcfce7; color: #15803d; }
.ttb-feedback--wrong   { background: #fee2e2; color: #b91c1c; }
.ttb-feedback--timeout { background: #fef3c7; color: #92400e; }

/* Bonus popups */
.ttb-bonus-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  background: #f97316;
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 800;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  z-index: 10;
}

.ttb-bonus-popup--streak {
  background: #f59e0b;
  top: 40%;
}

.ttb-bonus-popup.ttb-show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  animation: ttb-pop 1.2s ease forwards;
}

@keyframes ttb-pop {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70%  { opacity: 1; transform: translate(-50%, -70%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(0.9); }
}

/* ═══════════════════════════════════════════════════════════════════
   RESULT SCREEN
   ═══════════════════════════════════════════════════════════════════ */

.ttb-result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ttb-result-scroll {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.ttb-result-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

/* Stars */
.ttb-stars-display {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.ttb-star {
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1;
  transition: transform 0.2s ease;
}

.ttb-star--earned {
  color: #fbbf24;
  text-shadow: 0 2px 8px rgba(251, 191, 36, 0.5);
  animation: ttb-star-pop 0.4s ease;
}

.ttb-star--empty {
  color: #e5e7eb;
}

@keyframes ttb-star-pop {
  0%   { transform: scale(0.5); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.ttb-result-heading {
  font-family: var(--font-heading);
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
}

.ttb-result-heading--win  { color: #f97316; }
.ttb-result-heading--loss { color: #6b7280; }

.ttb-result-subheading {
  color: var(--pa-color-text-muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Metrics */
.ttb-metrics-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
}

.ttb-metric-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #ffffff;
  border-radius: 14px;
  padding: var(--space-md) var(--space-xs);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ttb-metric-icon { font-size: 1.4rem; }

.ttb-metric-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: #1f2937;
  line-height: 1;
}

.ttb-metric-value--text { font-size: 1rem; }

.ttb-metric-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #9ca3af;
}

/* Try again card */
.ttb-try-again-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #fff7ed, #fffbeb);
  border: 2px solid #fed7aa;
  border-radius: 16px;
  padding: var(--space-md);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
  box-sizing: border-box;
}

.ttb-try-again-card:hover:not(:disabled) {
  border-color: #f97316;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.2);
}

.ttb-try-again-card:disabled { opacity: 0.6; cursor: not-allowed; }

.ttb-try-again-icon  { font-size: 1.8rem; }
.ttb-try-again-title { font-size: 1.1rem; font-weight: 800; color: #f97316; }
.ttb-try-again-note  { font-size: 0.8rem; color: #6b7280; }

/* Sign-in prompt */
.ttb-signin-prompt {
  text-align: center;
  font-size: 0.85rem;
  color: var(--pa-color-text-muted);
  margin: 0;
}

.ttb-signin-link {
  background: none;
  border: none;
  color: #f97316;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

/* Leaderboard card */
.ttb-leaderboard-card {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: var(--space-md);
}

.ttb-leaderboard-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
  font-size: 1.2rem;
}

.ttb-leaderboard-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: #1f2937;
}

.ttb-leaderboard-message {
  display: block;
  font-size: 0.85rem;
  color: var(--pa-color-text-muted);
  text-align: center;
  margin: 0;
}

.ttb-leaderboard-message--link {
  background: none;
  border: none;
  color: #f97316;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.ttb-leaderboard-message--link:hover { opacity: 0.8; }

/* Result footer */
.ttb-result-footer {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}

.ttb-footer-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.ttb-footer-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.ttb-footer-btn--play  { background: linear-gradient(135deg, #f97316, #fb923c); color: #ffffff; }
.ttb-footer-btn--games { background: #f3f4f6; color: #374151; }
.ttb-footer-btn-icon   { font-size: 1rem; }

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE  (≤ 480px)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  #ttb-app {
    padding: var(--space-xs);
  }

  .ttb-title {
    font-size: 1.6rem;
  }

  .ttb-level-cards-container {
    gap: 6px;
  }

  .ttb-level-card {
    padding: 10px 4px;
  }

  .ttb-level-card-icon { font-size: 1.3rem; }
  .ttb-level-card-title { font-size: 0.78rem; }
  .ttb-level-card-desc  { font-size: 0.62rem; }

  .ttb-start-btn {
    padding: 12px 32px;
    font-size: 0.95rem;
  }

  .ttb-card {
    padding: var(--space-md) var(--space-sm);
    border-radius: 16px;
  }

  .ttb-operand     { font-size: 2.2rem; }
  .ttb-operator    { font-size: 1.6rem; }
  .ttb-answer-slot { font-size: 2.2rem; }

  .ttb-answer-input {
    width: 80px;
    font-size: 1.3rem;
    padding: 10px 12px;
  }

  .ttb-submit-btn {
    padding: 10px 18px;
    font-size: 0.9rem;
  }

  .ttb-metrics-row {
    gap: 8px;
  }

  .ttb-metric-value { font-size: 1.2rem; }

  .ttb-result-footer {
    flex-direction: column;
  }

  .ttb-star { font-size: 1.8rem; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET  (481px – 768px)
   ═══════════════════════════════════════════════════════════════════ */
@media (min-width: 481px) and (max-width: 768px) {
  .ttb-title {
    font-size: 2rem;
  }

  .ttb-start-btn {
    padding: 13px 40px;
  }

  .ttb-operand     { font-size: 3rem; }
  .ttb-operator    { font-size: 2.2rem; }
  .ttb-answer-slot { font-size: 3rem; }

  .ttb-answer-input {
    width: 90px;
    font-size: 1.4rem;
  }

  .ttb-submit-btn {
    padding: 11px 20px;
  }

  .ttb-metrics-row { gap: var(--space-sm); }

  .ttb-star { font-size: 2.4rem; }

  /* Larger touch targets for tablets */
  .ttb-footer-btn  { padding: 14px; }
  .ttb-level-card  { padding: var(--space-sm); }
}
