:root {
  color-scheme: light;
  --bg: linear-gradient(135deg, #f4fbff 0%, #eef7ff 45%, #e8f8ef 100%);
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --border: rgba(10, 60, 120, 0.12);
  --text: #16324f;
  --text-muted: #5b728c;
  --primary: #1f6feb;
  --primary-strong: #164db9;
  --accent: #2bcf76;
  --danger: #ef4d4d;
  --shadow: 0 18px 45px rgba(13, 48, 95, 0.16);
  --transition: 240ms ease;
}

body.dark {
  color-scheme: dark;
  --bg: linear-gradient(135deg, #071425 0%, #10253a 45%, #0d1d22 100%);
  --surface: rgba(8, 20, 36, 0.82);
  --surface-strong: #11263c;
  --border: rgba(154, 228, 255, 0.16);
  --text: #f2f8ff;
  --text-muted: #96b1c5;
  --primary: #4ea7ff;
  --primary-strong: #2c7ed2;
  --accent: #38d98d;
  --danger: #ff718d;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

body.home-scroll-locked {
  overflow: hidden;
}

.background-layer {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(6, 24, 44, 0.76), rgba(6, 24, 44, 0.48)),
    url('https://images.unsplash.com/photo-1521295121783-8a321d551ad2?auto=format&fit=crop&w=1600&q=80') center/cover no-repeat;
  transform: translate3d(var(--bg-offset-x, 0px), var(--bg-offset-y, 0px), 0);
  transition: transform 180ms ease-out;
  z-index: -2;
}

.background-layer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top left, rgba(79, 194, 255, 0.16), transparent 34%), rgba(0, 0, 0, 0.16);
  z-index: -1;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 20px 20px 72px;
}

.topbar,
.card,
.footer,
.overlay-card {
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  margin: 0 auto 20px;
  max-width: 1220px;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
}

.brand p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.brand-icon,
.hero-badge {
  font-size: 1.4rem;
}

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

.icon-btn,
.btn,
.mode-card button,
.answer-btn {
  border: 0;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), color var(--transition);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 8px 16px rgba(12, 36, 71, 0.08);
}

.icon-btn:hover,
.btn:hover,
.mode-card:hover,
.answer-btn:hover {
  transform: translateY(-2px);
}

main {
  max-width: 1220px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  align-items: center;
}

.hero-copy h2 {
  font-size: clamp(2rem, 3vw, 3rem);
  margin: 8px 0 14px;
  line-height: 1.1;
}

.hero-text,
.hero-card p,
.feedback,
.footer p,
.setting-row span,
.question-head p,
.result-stat p {
  color: var(--text-muted);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 8px;
}

.hero-actions,
.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.btn {
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(16, 77, 154, 0.16);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
}

.btn-secondary {
  background: rgba(18, 72, 136, 0.12);
  color: var(--text);
}

.btn-danger {
  background: rgba(239, 77, 77, 0.16);
  color: #a31414;
}

.hero-card-play {
  width: min(100%, 460px);
  min-width: 0;
  padding: 36px 48px;
  font-size: 1.95rem;
  font-weight: 800;
  border-radius: 24px;
}

.hero-illustration {
  position: relative;
  min-height: 190px;
  display: grid;
  place-items: center;
}

.hero-glow {
  display: none;
}

.hero-card {
  position: relative;
  width: fit-content;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.player-card {
  grid-column: 1 / -1;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 18px;
  padding: 14px;
}

.player-card label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

.player-input-row {
  display: flex;
  gap: 10px;
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.player-input-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-strong);
  color: var(--text);
}

.player-card p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.continent-grid,
.mode-grid,
.stats-grid,
.result-grid {
  display: grid;
  gap: 16px;
}

.continent-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mode-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.continent-card,
.mode-card {
  padding: 20px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.continent-card {
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.14);
  color: black;
  text-align: left;
  padding: 18px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 92px;
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 34px rgba(0,0,0,0.16);
  transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
}

.continent-card:hover,
.continent-card.active {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 0 20px 40px rgba(0,0,0,0.22);
  border-color: rgba(255,255,255,0.38);
}

.continent-card h3,
.mode-card h3 {
  margin: 0;
}

.continent-card p,
.mode-card p {
  margin: 0;
  color: var(--text-muted);
}

.mode-card button {
  align-self: flex-start;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
}

.continent-icon {
  font-size: 1.4rem;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255,255,255,0.16);
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0;
}

.game-topbar {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr 0.8fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.progress-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(18, 72, 136, 0.12);
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width var(--transition);
}

.timer-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.timer-ring {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  position: relative;
  background: conic-gradient(var(--primary) 0deg, rgba(148, 184, 255, 0.2) 0deg);
  color: var(--text);
}

.timer-ring::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--surface-strong);
}

.timer-ring span {
  position: relative;
  z-index: 1;
}

.timer-caption {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.score-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-strong);
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--text);
  font-weight: 700;
}

.question-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-card.correct {
  border-color: rgba(43, 207, 118, 0.4);
  animation: pop 320ms ease;
}

.question-card.incorrect {
  border-color: rgba(239, 77, 77, 0.35);
  animation: shake 320ms ease;
}

.question-body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 188px;
}

.flag-display-card,
.flag-question-head {
  width: min(100%, 360px);
  text-align: center;
  animation: fadeIn 280ms ease;
}

.capital-question-head {
  width: min(100%, 360px);
  text-align: center;
  animation: fadeIn 280ms ease;
}

.flag-image {
  width: min(100%, 320px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(13, 48, 95, 0.18);
  border: 1px solid rgba(255,255,255,0.3);
}

.flag-question-head h4 {
  margin: 6px 0 0;
  font-size: clamp(1.3rem, 2vw, 1.8rem);
}

.capital-question-head strong {
  display: block;
  margin: 6px 0 0;
  font-size: clamp(1.3rem, 2vw, 1.8rem);
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.answer-btn {
  padding: 14px;
  border-radius: 16px;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--border);
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
}

.answer-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}

.answer-btn.flag-option {
  padding: 6px;
  min-height: 84px;
  overflow: hidden;
  border-radius: 16px;
  display: grid;
  place-items: center;
}

.answer-btn.flag-option img {
  width: 100%;
  max-width: 112px;
  height: 64px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.92);
  padding: 2px;
}

.answer-btn.correct {
  background: rgba(0, 255, 115, 0.16);
  color: #00953d;
  border: 3px solid #00e65c;
  box-shadow: 0 0 0 3px rgba(0, 230, 92, 0.24);
}

.answer-btn.incorrect {
  background: rgba(255, 42, 42, 0.16);
  color: #b30000;
  border: 3px solid #ff2a2a;
  box-shadow: 0 0 0 3px rgba(255, 42, 42, 0.24);
}

.feedback-wrap {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feedback {
  min-height: 24px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feedback-info {
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 600;
}

.feedback-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.combo-burst {
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.24), rgba(255, 107, 107, 0.2));
  color: #b96a00;
  font-weight: 800;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.combo-burst.show {
  opacity: 1;
  transform: translateY(0);
}

.hero-mode {
  min-height: 320px;
}

.hero-portrait-frame {
  width: min(100%, 360px);
  padding: 10px;
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255,255,255,0.7), rgba(255,255,255,0.2));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: fadeIn 320ms ease;
}

.hero-portrait {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 20px;
  box-shadow: 0 14px 34px rgba(13, 48, 95, 0.16);
  transition: transform 220ms ease, box-shadow 220ms ease;
}

.hero-portrait:hover {
  transform: scale(1.03);
  box-shadow: 0 20px 42px rgba(13, 48, 95, 0.24);
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
  padding: 16px;
  background: var(--surface-strong);
  border-radius: 18px;
  border: 1px solid var(--border);
}

.stat-card strong {
  display: block;
  font-size: 1.2rem;
  margin-top: 6px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 18, 35, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}

.overlay-card {
  width: min(100%, 580px);
  text-align: center;
}

.result-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 18px 0;
}

.result-stat {
  text-align: left;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.result-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.settings-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 8px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mini-progress {
  margin-top: 8px;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(18, 72, 136, 0.12);
}

.mini-progress > div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.achievements-card {
  grid-column: 1 / -1;
}

.leaderboard-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.leaderboard-tabs .btn.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
}

.leaderboard-own-rank {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-weight: 700;
}

.auth-card {
  max-width: 480px;
  text-align: left;
}

.auth-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.auth-tabs .btn.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 600;
}

.auth-form input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-strong);
  color: var(--text);
}

.password-field {
  position: relative;
}

.password-field input {
  width: 100%;
  padding-right: 54px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: rgba(18, 72, 136, 0.08);
  color: var(--text);
  outline: none;
}

.auth-feedback {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--text-muted);
}

.auth-guest-btn {
  margin-top: 12px;
  width: 100%;
}

.auth-feedback.error {
  color: #b30000;
}

.mobile-nav {
  display: none;
}

.social-links {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  z-index: 25;
}

.social-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform var(--transition), background var(--transition), color var(--transition);
}

.social-link:hover {
  transform: translateY(-2px);
}

.leaderboard-list {
  display: grid;
  gap: 10px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: auto 1.5fr auto;
  gap: 12px;
  align-items: center;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

.leaderboard-rank {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: rgba(31, 111, 235, 0.14);
  color: var(--primary-strong);
}

.leaderboard-player strong,
.leaderboard-player span {
  display: block;
}

.leaderboard-player span,
.leaderboard-meta,
.leaderboard-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.leaderboard-points {
  font-weight: 800;
  color: var(--primary-strong);
}

.leaderboard-meta {
  grid-column: 2 / -1;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.setting-row input {
  width: 18px;
  height: 18px;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.confetti-piece {
  position: absolute;
  top: -16px;
  width: 10px;
  height: 16px;
  border-radius: 4px;
  animation: fall 2.2s linear forwards;
}

.hidden {
  display: none !important;
}

.footer {
  text-align: center;
  padding: 16px 0 0;
  max-width: 1220px;
  margin: 0 auto;
}

@keyframes pop {
  0% { transform: scale(0.98); }
  50% { transform: scale(1.01); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

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

@media (max-width: 920px) {
  .hero,
  .game-topbar,
  .continent-grid,
  .mode-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .score-chip-group {
    justify-content: flex-start;
  }

  .hero-card-play {
    width: 100%;
    padding: 24px 20px;
    font-size: 1.5rem;
  }
}

@media (max-width: 720px) {
  body.home-scroll-locked {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-shell {
    padding: 12px 12px 66px;
  }

  #auth-overlay,
  #result-overlay {
    place-items: stretch;
    overflow-y: auto;
    padding: 12px;
  }

  #auth-overlay .overlay-card,
  #result-overlay .overlay-card {
    width: 100%;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    margin: auto 0;
    -webkit-overflow-scrolling: touch;
  }

  .topbar {
    padding: 14px;
    flex-wrap: wrap;
  }

  .brand {
    width: 100%;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .continent-grid,
  .mode-grid,
  .stats-grid,
  .profile-grid,
  .result-grid,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 18px;
  }

  .player-input-row {
    flex-direction: column;
  }

  .player-input-row .btn {
    width: 100%;
  }

  .session-row {
    flex-direction: column;
    align-items: stretch;
  }

  .session-row .btn {
    width: 100%;
  }

  .hero-copy h2 {
    font-size: 1.65rem;
  }

  .leaderboard-row {
    grid-template-columns: auto 1fr;
  }

  .leaderboard-points {
    grid-column: 2;
  }

  .leaderboard-meta {
    grid-column: 1 / -1;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 10px;
    padding: 8px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 20;
  }

  .social-links {
    right: 12px;
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }

  .social-link {
    min-height: 40px;
    padding: 9px 12px;
    font-size: 0.88rem;
  }

  .mobile-nav-btn {
    border: 0;
    border-radius: 12px;
    background: var(--surface-strong);
    color: var(--text);
    min-height: 54px;
    display: grid;
    place-items: center;
    gap: 2px;
    font-size: 0.9rem;
  }

  .mobile-nav-btn span {
    font-size: 0.72rem;
    color: var(--text-muted);
  }

  .password-toggle {
    width: 44px;
    height: 44px;
    right: 6px;
  }
}
