:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a2e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #5b7fff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f5);
  --section-bg: var(--tg-theme-section-bg-color, var(--bg));

  --correct: #34c759;
  --wrong: #ff3b30;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 16px rgba(0,0,0,0.08);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Screens */
.screen {
  display: none;
  min-height: 100vh;
  padding: 16px;
  animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; flex-direction: column; }

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

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

/* Loader */
#screen-loading {
  justify-content: center;
  align-items: center;
  gap: 16px;
}
.loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--btn);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--hint); font-size: 15px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--btn);
  color: var(--btn-text);
}
.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
}
.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  border-radius: var(--radius);
}

/* Intro */
#screen-intro {
  justify-content: center;
  align-items: center;
  overflow-y: auto;
}
.intro-content {
  text-align: center;
  max-width: 400px;
  width: 100%;
  padding: 20px 0;
}
.intro-image-wrap {
  margin-bottom: 24px;
}
.intro-image-wrap img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow);
}
.intro-title {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
  line-height: 1.2;
}
.intro-desc {
  font-size: 18px;
  color: var(--text);
  margin-bottom: 32px;
  line-height: 1.6;
  text-align: center;
}
.resumed-badge {
  background: var(--secondary-bg);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--hint);
}

/* Question screen */
#screen-question {
  padding-top: 8px;
  gap: 0;
}
.q-header {
  margin-bottom: 16px;
}
.q-progress-bar {
  height: 4px;
  background: var(--secondary-bg);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}
.q-progress-fill {
  height: 100%;
  background: var(--btn);
  border-radius: 2px;
  transition: width 0.4s ease;
  width: 0%;
}
.q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.q-counter {
  font-size: 14px;
  color: var(--hint);
  font-weight: 500;
}
.q-score {
  font-size: 14px;
  font-weight: 600;
  color: var(--btn);
}

.q-card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: slideInRight 0.35s ease;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.q-image-wrap {
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.q-image {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-sm);
}

.q-text {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 20px;
}

/* Choice options */
.q-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.q-option-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--secondary-bg);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 16px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.q-option-btn:active { transform: scale(0.98); }
.q-option-btn .option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--secondary-bg);
  font-weight: 700;
  font-size: 13px;
  margin-right: 12px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.q-option-btn .option-text {
  flex: 1;
}
.q-option-btn.selected {
  border-color: var(--btn);
  background: color-mix(in srgb, var(--btn) 8%, var(--bg));
}
.q-option-btn.selected .option-letter {
  background: var(--btn);
  color: var(--btn-text);
}
.q-option-btn.disabled {
  pointer-events: none;
  opacity: 0.6;
}
.q-option-btn.correct {
  border-color: var(--correct);
  background: color-mix(in srgb, var(--correct) 10%, var(--bg));
}
.q-option-btn.correct .option-letter {
  background: var(--correct);
  color: #fff;
}
.q-option-btn.wrong {
  border-color: var(--wrong);
  background: color-mix(in srgb, var(--wrong) 10%, var(--bg));
}
.q-option-btn.wrong .option-letter {
  background: var(--wrong);
  color: #fff;
}

/* Open question */
.q-open {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.q-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--secondary-bg);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.q-input:focus {
  border-color: var(--btn);
}
.q-input::placeholder {
  color: var(--hint);
}

/* Feedback */
#screen-feedback {
  justify-content: center;
  align-items: center;
}
.fb-card {
  text-align: center;
  max-width: 360px;
  width: 100%;
  padding: 20px 0;
}
.fb-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: popIn 0.4s ease;
}
.fb-text {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}
.fb-correct {
  font-size: 15px;
  color: var(--hint);
  margin-bottom: 8px;
}
.fb-points {
  font-size: 16px;
  color: var(--btn);
  font-weight: 600;
  margin-bottom: 28px;
}

/* Results */
#screen-results {
  padding-top: 24px;
}
.results-content {
  max-width: 440px;
  margin: 0 auto;
  width: 100%;
}
.results-header {
  text-align: center;
  margin-bottom: 28px;
}
.confetti-emoji {
  font-size: 56px;
  animation: popIn 0.5s ease;
  margin-bottom: 8px;
}
.results-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 16px;
}
.results-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-bottom: 12px;
}
.res-score-value {
  font-size: 48px;
  font-weight: 800;
  color: var(--btn);
  line-height: 1;
}
.res-score-max {
  font-size: 20px;
  color: var(--hint);
  font-weight: 600;
}
.res-final-text {
  font-size: 15px;
  color: var(--hint);
  line-height: 1.5;
}

/* Leaderboard */
.leaderboard {
  margin-bottom: 24px;
}
.lb-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lb-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: var(--secondary-bg);
  border-radius: var(--radius-sm);
  gap: 12px;
  transition: all 0.2s;
}
.lb-row.you {
  background: color-mix(in srgb, var(--btn) 12%, var(--secondary-bg));
  outline: 2px solid var(--btn);
}
.lb-rank {
  font-size: 16px;
  font-weight: 700;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}
.lb-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--hint) 20%, transparent);
  color: var(--hint);
}
.lb-score {
  font-size: 15px;
  font-weight: 700;
  color: var(--btn);
  flex-shrink: 0;
}

.hidden { display: none !important; }

/* Final Results */
#screen-final {
  padding-top: 16px;
}
#screen-final .results-content {
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}
.fq-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.fq-header {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  line-height: 1.4;
}
.fq-num {
  color: var(--hint);
  font-weight: 700;
}
.fq-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  flex-wrap: wrap;
  max-width: 100%;
}
.fq-option-text {
  word-break: break-word;
  overflow-wrap: break-word;
}
.fq-option.correct .fq-option-text {
  color: var(--correct);
  font-weight: 600;
}
.fq-option.wrong .fq-option-text {
  color: var(--hint);
}
.fq-avatars {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.fq-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.fq-open-answer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 13px;
}
.fq-open-answer.correct {
  color: var(--correct);
}
.fq-open-answer.wrong {
  color: var(--hint);
}
.fq-divider {
  height: 1px;
  background: color-mix(in srgb, var(--hint) 20%, transparent);
  margin: 4px 0;
}
.btn-lock {
  background: #ff9500;
  color: #fff;
  margin-top: 12px;
}

/* Leaderboard photos */
.lb-photo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.fq-avatar {
  object-fit: cover;
}


/* Kick button */
.lb-kick {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--wrong) 15%, transparent);
  color: var(--wrong);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.lb-kick:active {
  background: color-mix(in srgb, var(--wrong) 30%, transparent);
}

.btn-reg-toggle,
.intro-reg-toggle {
  margin-top: 10px;
}
.btn-lock {
  margin-bottom: 0;
}
.results-content .btn + .btn {
  margin-top: 10px;
}

.intro-reg-toggle,
.intro-view-results {
  margin-bottom: 10px;
}
