:root {
  --bg: #0a0a0e;
  --bg-2: #111116;
  --bg-3: #1a1a22;
  --bg-4: #22222c;
  --line: #2a2a36;
  --text: #e8e4dc;
  --text-2: #c4c0b8;
  --muted: #7a7670;
  --ruby: #cc342d;
  --ruby-light: #e04050;
  --ruby-dark: #901a1a;
  --ruby-glow: rgba(204, 52, 45, 0.25);
  --gold: #d4a843;
  --green: #5cb85c;
  --green-bg: rgba(92, 184, 92, 0.12);
  --red: #d86c6c;
  --red-bg: rgba(216, 108, 108, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  background:
    radial-gradient(900px 400px at 20% 0%, rgba(204,52,45,0.06), transparent 60%),
    radial-gradient(600px 500px at 90% 100%, rgba(204,52,45,0.03), transparent 60%),
    var(--bg);
}

.app {
  max-width: 520px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== TOPBAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ruby-light);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
  text-decoration: none;
}
.brand-gem { width: 26px; height: 26px; }

.auth-actions { display: flex; gap: 8px; }

.auth-btn {
  background: var(--ruby);
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.auth-btn:hover { filter: brightness(1.1); }
.auth-btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.auth-btn.ghost:hover { color: var(--text); border-color: var(--ruby); }

/* ===== NOTICE ===== */
.notice {
  padding: 10px 16px;
  font-size: 12px;
  line-height: 1.4;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.notice.ok { background: var(--green-bg); color: var(--green); }
.notice.warn { background: rgba(212,168,67,0.1); color: var(--gold); }
.notice.error { background: var(--red-bg); color: var(--red); }

/* ===== SCREENS ===== */
.screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 16px;
  scroll-behavior: smooth;
}
.screen::-webkit-scrollbar { width: 6px; }
.screen::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* ===== HOME ===== */
.hero {
  text-align: center;
  padding: 32px 0 24px;
}
.hero-gem { width: 90px; height: 90px; margin: 0 auto 16px; }
.hero-gem svg {
  width: 100%; height: 100%;
  filter: drop-shadow(0 4px 24px var(--ruby-glow));
}
.hero-title {
  font-size: 32px;
  font-weight: 800;
  color: var(--ruby-light);
  letter-spacing: 0.5px;
}
.hero-sub {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

.start-btn {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 28px auto 0;
  padding: 16px 24px;
  background: linear-gradient(180deg, var(--ruby), var(--ruby-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 20px var(--ruby-glow);
}
.start-btn:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 6px 28px var(--ruby-glow);
}
.start-btn:active { transform: translateY(0); }
.start-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.how-it-works {
  margin-top: 32px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.how-it-works h3 {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}
.how-it-works ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.how-it-works li {
  font-size: 13px;
  color: var(--text-2);
  padding-left: 20px;
  position: relative;
}
.how-it-works li::before {
  position: absolute;
  left: 0;
  color: var(--ruby-light);
}
.how-it-works li:nth-child(1)::before { content: "1."; }
.how-it-works li:nth-child(2)::before { content: "2."; }
.how-it-works li:nth-child(3)::before { content: "3."; }
.how-it-works li:nth-child(4)::before { content: "4."; }

.leaderboard {
  margin-top: 24px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.leaderboard h3 {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}
.leaderboard ol { list-style: none; }
.leaderboard li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.leaderboard li:last-child { border-bottom: none; }
.lb-rank {
  width: 24px;
  font-weight: 700;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}
.lb-info { flex: 1; }
.lb-score {
  font-weight: 700;
  color: var(--gold);
  font-family: var(--mono);
}
.lb-date {
  font-size: 11px;
  color: var(--muted);
  margin-left: 8px;
}
.lb-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 12px 0;
}

.home-footer {
  text-align: center;
  margin-top: 28px;
  font-size: 11px;
  color: var(--muted);
}
.home-footer a { color: var(--ruby-light); text-decoration: none; }
.home-footer a:hover { text-decoration: underline; }

/* ===== LOADING ===== */
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: 20px;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--ruby);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  color: var(--muted);
  font-size: 14px;
}

/* ===== QUIZ ===== */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.quiz-progress { flex: 1; }
.progress-bar {
  height: 6px;
  background: var(--bg-4);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ruby), var(--ruby-light));
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 10%;
}
.progress-label {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

.quiz-stats { display: flex; gap: 16px; }
.stat { text-align: center; }
.stat-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-value {
  display: block;
  font-size: 20px;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--gold);
}

.q-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.q-category {
  font-size: 11px;
  color: #5b9bd5;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.q-difficulty {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.q-difficulty.easy { background: var(--green-bg); color: var(--green); }
.q-difficulty.medium { background: rgba(212,168,67,0.12); color: var(--gold); }
.q-difficulty.hard { background: var(--red-bg); color: var(--red); }

.q-text {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text);
  margin-bottom: 20px;
}

.q-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.choice-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--bg-3);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.35;
}
.choice-btn:hover:not(:disabled) {
  border-color: var(--ruby);
  background: var(--bg-4);
}
.choice-btn:disabled { cursor: default; }
.choice-btn.correct {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
  font-weight: 600;
}
.choice-btn.wrong {
  border-color: var(--red);
  background: var(--red-bg);
  color: var(--red);
}
.choice-btn.reveal {
  border-color: var(--green);
  opacity: 0.6;
}

.q-feedback {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.q-feedback.correct { background: var(--green-bg); color: var(--green); }
.q-feedback.wrong { background: var(--red-bg); color: var(--red); }
.q-feedback .fb-title { font-weight: 700; margin-bottom: 4px; }
.q-feedback .fb-exp { font-weight: 400; color: var(--text-2); }

.next-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(180deg, var(--ruby), var(--ruby-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
  font-family: inherit;
}
.next-btn:hover { filter: brightness(1.1); }

/* ===== RESULTS ===== */
.results-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}
.results-heading {
  font-size: 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 20px;
}

.results-score {
  font-size: 64px;
  font-weight: 900;
  font-family: var(--mono);
  line-height: 1;
  margin-bottom: 4px;
}
.results-score.perfect { color: var(--gold); }
.results-score.great { color: var(--green); }
.results-score.ok { color: var(--text); }
.results-score.low { color: var(--red); }

.results-out-of {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 8px;
}

.results-grade {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}
.results-grade.perfect { color: var(--gold); }
.results-grade.great { color: var(--green); }
.results-grade.ok { color: var(--text-2); }
.results-grade.low { color: var(--red); }

.results-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.results-stat { text-align: center; }
.results-stat-val {
  display: block;
  font-size: 20px;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--gold);
}
.results-stat-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

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

.btn-share {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px;
  background: var(--bg-4);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-share:hover { border-color: #1d9bf0; color: #1d9bf0; }
.btn-share:hover .share-x-icon { fill: #1d9bf0; }
.share-x-icon { width: 16px; height: 16px; fill: var(--text); transition: fill 0.15s; }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(180deg, var(--ruby), var(--ruby-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
  font-family: inherit;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  width: 100%;
  padding: 13px;
  background: var(--bg-4);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-secondary:hover { border-color: var(--ruby); }

/* ===== RESPONSIVE ===== */
@media (min-width: 520px) {
  .app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}
