@import url('https://fonts.googleapis.com/css2?family=Red+Hat+Display:wght@400;500;700;900&family=Red+Hat+Text:wght@400;500;700&family=Red+Hat+Mono:wght@400;700&display=swap');

/* ─── CSS Variables ─── */
:root {
  --rh-red: #EE0000;
  --rh-red-dark: #A30000;
  --rh-red-light: #FF4D4D;
  --rh-black: #151515;
  --rh-dark: #1A1A1A;
  --rh-gray-900: #212427;
  --rh-gray-800: #2D2D2D;
  --rh-gray-700: #3C3F42;
  --rh-gray-500: #6A6E73;
  --rh-gray-300: #B8BBBE;
  --rh-gray-100: #E0E0E0;
  --rh-white: #FFFFFF;
  --rh-gold: #F0AB00;
  --rh-green: #3E8635;
  --rh-blue: #0066CC;
  --rh-cyan: #009596;

  --bg-primary: var(--rh-black);
  --bg-card: var(--rh-gray-900);
  --bg-card-hover: var(--rh-gray-800);
  --text-primary: var(--rh-white);
  --text-secondary: var(--rh-gray-300);
  --text-muted: var(--rh-gray-500);
  --accent: var(--rh-red);
  --accent-glow: rgba(238, 0, 0, 0.3);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Red Hat Text', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Subtle Background Pattern ─── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(238, 0, 0, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(238, 0, 0, 0.04) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ─── App Shell ─── */
#app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--rh-gray-800);
  margin-bottom: 24px;
  flex-shrink: 0;
}

.app-header .logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header .logo-group img {
  height: 36px;
  width: auto;
  filter: drop-shadow(0 2px 8px var(--accent-glow));
}

.app-header .logo-group h1 {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 900;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--rh-white) 0%, var(--rh-gray-300) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--rh-gray-700);
  color: var(--text-secondary);
  font-family: 'Red Hat Text', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.nav-btn:hover, .nav-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--rh-white);
}

/* ─── Screens ─── */
.screen {
  display: none;
  flex: 1;
  animation: fadeSlideIn 0.35s ease-out;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

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

/* ─── Welcome / Name Screen ─── */
.welcome-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 32px;
  padding-bottom: 20vh;
}

.welcome-logo {
  width: 100px;
  height: auto;
  filter: drop-shadow(0 4px 24px var(--accent-glow));
  animation: floatLogo 3s ease-in-out infinite;
}

@keyframes floatLogo {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-screen h2 {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 900;
  font-size: 2rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.welcome-screen h2 span {
  color: var(--accent);
}

.welcome-screen p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 300px;
}

/* ─── Forms / Inputs ─── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.input-field {
  font-family: 'Red Hat Text', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 2px solid var(--rh-gray-700);
  border-radius: var(--radius);
  padding: 14px 16px;
  outline: none;
  transition: all var(--transition);
  width: 100%;
}

.input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

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

/* ─── Buttons ─── */
.btn {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 28px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--accent);
  color: var(--rh-white);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--rh-red-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 2px solid var(--rh-gray-700);
}

.btn-secondary:hover {
  border-color: var(--rh-gray-500);
  background: var(--bg-card-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 16px;
  font-size: 0.85rem;
}

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

.btn-block {
  width: 100%;
}

/* ─── Subject Screen ─── */
.subject-screen {
  gap: 24px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--rh-gray-700);
  border-radius: 100px;
  padding: 6px 14px 6px 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.user-badge .avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.7rem;
  color: white;
}

.subject-card {
  background: var(--bg-card);
  border: 1px solid var(--rh-gray-800);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.subject-card h2 {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 900;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.subject-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}

.multiplier-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--rh-gold);
  background: rgba(240, 171, 0, 0.08);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(240, 171, 0, 0.15);
}

.multiplier-hint .icon {
  font-size: 1.1rem;
}

/* ─── Loading / Fun GIF Screen ─── */
.loading-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 24px;
  padding-bottom: 10vh;
}

.loading-gif-container {
  width: 220px;
  height: 220px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
  border: 2px solid var(--rh-gray-800);
  box-shadow: var(--shadow-lg);
}

.loading-gif-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.loading-text {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
}

.loading-dots::after {
  content: '';
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

.loading-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ─── Quiz Screen ─── */
.quiz-screen {
  gap: 20px;
  padding-bottom: 100px;
}

.quiz-progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--rh-gray-800);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.progress-text {
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--rh-gray-800);
  border-radius: var(--radius-lg);
  padding: 24px;
  animation: fadeSlideIn 0.35s ease-out;
}

.question-number {
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
}

.question-text {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.4;
  margin-bottom: 20px;
}

.multiplier-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(240, 171, 0, 0.12);
  color: var(--rh-gold);
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: 'Red Hat Mono', monospace;
  margin-bottom: 16px;
}

/* ─── Answer Options ─── */
.answers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--rh-gray-800);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.answer-option:hover {
  background: var(--rh-gray-700);
  border-color: var(--rh-gray-500);
}

.answer-option.selected {
  background: rgba(238, 0, 0, 0.08);
  border-color: var(--accent);
}

.answer-option .radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--rh-gray-500);
  flex-shrink: 0;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.answer-option.selected .radio {
  border-color: var(--accent);
}

.answer-option.selected .radio::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.answer-option .answer-text {
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Submit fixed at bottom */
.quiz-submit-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
  display: flex;
  justify-content: center;
  z-index: 10;
}

.quiz-submit-bar .btn {
  max-width: 480px;
  width: calc(100% - 32px);
}

/* ─── Results Screen ─── */
.results-screen {
  gap: 24px;
  padding-bottom: 32px;
}

.score-hero {
  text-align: center;
  padding: 32px 24px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--rh-gray-800);
  position: relative;
  overflow: hidden;
}

.score-hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--rh-gold), var(--accent));
}

.score-label {
  font-family: 'Red Hat Text', sans-serif;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.score-value {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 900;
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 8px;
}

.score-value.positive { color: var(--rh-green); }
.score-value.negative { color: var(--accent); }
.score-value.neutral { color: var(--text-secondary); }

.score-breakdown {
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.result-detail {
  background: var(--bg-card);
  border: 1px solid var(--rh-gray-800);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-detail .q-label {
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-detail .q-text {
  font-weight: 600;
  font-size: 0.95rem;
}

.result-answer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.result-answer.correct {
  background: rgba(62, 134, 53, 0.12);
  border: 1px solid rgba(62, 134, 53, 0.25);
  color: var(--rh-green);
}

.result-answer.wrong {
  background: rgba(238, 0, 0, 0.08);
  border: 1px solid rgba(238, 0, 0, 0.2);
  color: var(--rh-red-light);
}

.result-answer.doubtful {
  background: rgba(240, 171, 0, 0.08);
  border: 1px solid rgba(240, 171, 0, 0.15);
  color: var(--rh-gold);
}

.result-answer .points {
  font-family: 'Red Hat Mono', monospace;
  font-weight: 700;
  margin-left: auto;
  white-space: nowrap;
}

.result-correct-answer {
  font-size: 0.82rem;
  color: var(--rh-green);
  padding: 6px 0 0;
}

.result-explanation {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Leaderboard ─── */
.leaderboard-screen {
  gap: 20px;
  padding-bottom: 32px;
}

.leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.leaderboard-header h2 {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 900;
  font-size: 1.5rem;
}

.refresh-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--rh-gray-800);
}

.refresh-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rh-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.leaderboard-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--rh-gray-800);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.lb-row.header {
  background: transparent;
  border-color: transparent;
  padding: 8px 16px;
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.lb-row.top-1 { border-color: var(--rh-gold); background: rgba(240, 171, 0, 0.06); }
.lb-row.top-2 { border-color: var(--rh-gray-300); background: rgba(184, 187, 190, 0.04); }
.lb-row.top-3 { border-color: #CD7F32; background: rgba(205, 127, 50, 0.04); }
.lb-row.is-you { border-color: var(--accent); background: rgba(238, 0, 0, 0.06); }

.lb-rank {
  font-family: 'Red Hat Display', sans-serif;
  font-weight: 900;
  font-size: 1.1rem;
  text-align: center;
  color: var(--text-muted);
}

.lb-row.top-1 .lb-rank { color: var(--rh-gold); }
.lb-row.top-2 .lb-rank { color: var(--rh-gray-300); }
.lb-row.top-3 .lb-rank { color: #CD7F32; }

.lb-name {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-name .you-tag {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 700;
  margin-left: 6px;
}

.lb-score-block {
  text-align: right;
}

.lb-total {
  font-family: 'Red Hat Mono', monospace;
  font-weight: 700;
  font-size: 1.05rem;
}

.lb-meta {
  font-family: 'Red Hat Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.lb-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.lb-empty .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

/* ─── Admin row ─── */
.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px dashed var(--rh-gray-700);
  border-radius: var(--radius);
  margin-top: 8px;
}

.admin-row span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-danger {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  font-size: 0.8rem;
  padding: 6px 14px;
}

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

/* ─── Toast Notifications ─── */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  width: calc(100% - 32px);
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  animation: toastIn 0.3s ease-out;
  box-shadow: var(--shadow);
}

.toast.success {
  background: var(--rh-green);
  color: white;
}

.toast.error {
  background: var(--accent);
  color: white;
}

.toast.info {
  background: var(--rh-blue);
  color: white;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Utility ─── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-auto { margin-top: auto; }
.gap-sm { gap: 8px; }

/* ─── Desktop / wider screens ─── */
@media (min-width: 600px) {
  #app {
    max-width: 520px;
    padding: 0 24px;
  }

  .question-card {
    padding: 32px;
  }

  .score-value {
    font-size: 4.5rem;
  }
}
