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

:root {
  --navy: #061936;
  --navy-light: #0c2f60;
  --blue: #38bdf8;
  --blue-light: #dff6ff;
  --cyan: #67e8f9;
  --gold: #f2be45;
  --gold-light: #fff1a8;
  --theme-bg-a: rgba(56, 189, 248, 0.48);
  --theme-bg-b: rgba(103, 232, 249, 0.32);
  --theme-bg-c: rgba(223, 246, 255, 0.30);
  --theme-bg-d: rgba(56, 189, 248, 0.36);
  --theme-linear: linear-gradient(105deg, #061936 0%, #092553 34%, #0a4278 66%, #5fc8ff 100%);
  --white: #ffffff;
  --off-white: #f5f5f5;
  --gray: #666;
  --gray-light: #999;
  --red: #d32f2f;
  --red-light: #ff6659;
  --shadow: 0 2px 8px rgba(0,0,0,0.15);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.2);
  --radius: 12px;
  --radius-sm: 8px;
}

body.theme-green {
  --navy: #052318;
  --navy-light: #0b4a32;
  --blue: #34d399;
  --blue-light: #dcfce7;
  --cyan: #86efac;
  --gold: #bef264;
  --gold-light: #ecfccb;
  --theme-bg-a: rgba(52, 211, 153, 0.48);
  --theme-bg-b: rgba(134, 239, 172, 0.32);
  --theme-bg-c: rgba(220, 252, 231, 0.30);
  --theme-bg-d: rgba(34, 197, 94, 0.36);
  --theme-linear: linear-gradient(105deg, #052318 0%, #0d3f2a 34%, #0f766e 66%, #86efac 100%);
}

body.theme-purple {
  --navy: #1a103d;
  --navy-light: #3b2376;
  --blue: #a78bfa;
  --blue-light: #ede9fe;
  --cyan: #c084fc;
  --gold: #f0abfc;
  --gold-light: #fae8ff;
  --theme-bg-a: rgba(167, 139, 250, 0.48);
  --theme-bg-b: rgba(216, 180, 254, 0.32);
  --theme-bg-c: rgba(237, 233, 254, 0.30);
  --theme-bg-d: rgba(168, 85, 247, 0.36);
  --theme-linear: linear-gradient(105deg, #1a103d 0%, #33206d 34%, #6d28d9 66%, #d8b4fe 100%);
}

body.theme-orange-red {
  --navy: #351105;
  --navy-light: #6b2411;
  --blue: #fb923c;
  --blue-light: #ffedd5;
  --cyan: #fca5a5;
  --gold: #facc15;
  --gold-light: #fef3c7;
  --theme-bg-a: rgba(251, 146, 60, 0.48);
  --theme-bg-b: rgba(252, 165, 165, 0.32);
  --theme-bg-c: rgba(255, 237, 213, 0.30);
  --theme-bg-d: rgba(239, 68, 68, 0.36);
  --theme-linear: linear-gradient(105deg, #351105 0%, #7f1d1d 34%, #c2410c 66%, #fdba74 100%);
}

body.theme-mono {
  --navy: #09090b;
  --navy-light: #27272a;
  --blue: #d4d4d8;
  --blue-light: #fafafa;
  --cyan: #e4e4e7;
  --gold: #a1a1aa;
  --gold-light: #f4f4f5;
  --theme-bg-a: rgba(212, 212, 216, 0.28);
  --theme-bg-b: rgba(250, 250, 250, 0.20);
  --theme-bg-c: rgba(244, 244, 245, 0.22);
  --theme-bg-d: rgba(161, 161, 170, 0.28);
  --theme-linear: linear-gradient(105deg, #09090b 0%, #18181b 34%, #3f3f46 66%, #e4e4e7 100%);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1200px 520px at -10% 22%, var(--theme-bg-a), transparent 58%),
    radial-gradient(900px 520px at 108% 58%, var(--theme-bg-b), transparent 62%),
    var(--theme-linear);
  min-height: 100vh;
  color: var(--white);
  display: flex;
  justify-content: center;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: '';
  position: fixed;
  left: -10vw;
  right: -10vw;
  height: 360px;
  pointer-events: none;
  z-index: -1;
  opacity: 0.48;
}

body::before {
  top: 12%;
  background: radial-gradient(60% 72% at 26% 48%, var(--theme-bg-c), transparent 62%);
  transform: rotate(-7deg);
}

body::after {
  bottom: -120px;
  background: radial-gradient(72% 86% at 70% 30%, var(--theme-bg-d), transparent 64%);
  transform: rotate(8deg);
}

#app {
  width: 100%;
  max-width: 500px;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: flex;
}

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

.container {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.header {
  text-align: center;
  padding: 30px 0 20px;
}

.logo {
  height: 100px;
  border-radius: 18px;
  object-fit: cover;
  margin-bottom: 10px;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,0.22));
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
  color: var(--blue-light);
  font-size: 1rem;
  margin-top: 4px;
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 0;
  flex: 1;
}

.level-card {
  background: rgba(6,25,54,0.48);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(223,246,255,0.22);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 16px;
}

.level-card:hover:not(.locked) {
  background: rgba(12,47,96,0.68);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.level-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.level-card.passed {
  border-color: var(--cyan);
  background: rgba(56,189,248,0.18);
}

.level-number {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(223,246,255,0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.level-card.passed .level-number {
  background: var(--blue-light);
  color: var(--navy);
}

.level-card.locked .level-number {
  background: rgba(255,255,255,0.05);
}

.level-info {
  flex: 1;
}

.level-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.level-desc {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  margin-top: 2px;
}

.level-lock, .level-check {
  font-size: 1.3rem;
}

.level-best {
  font-size: 0.75rem;
  color: var(--cyan);
  margin-top: 2px;
}

.progress-info {
  text-align: center;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  padding-bottom: 10px;
}

.name-container {
  justify-content: center;
}

.name-header {
  padding-top: 10px;
}

.name-card,
.leaderboard-panel {
  background: rgba(6,25,54,0.54);
  border: 2px solid rgba(223,246,255,0.22);
  border-radius: 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.24);
  backdrop-filter: blur(12px);
  padding: 22px;
  text-align: center;
}

.name-label {
  display: block;
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 10px;
  text-align: center;
}

.name-input {
  width: 100%;
  border: 2px solid rgba(223,246,255,0.28);
  border-radius: 14px;
  background: rgba(255,255,255,0.94);
  color: var(--navy);
  font-size: 1.1rem;
  font-weight: 700;
  outline: none;
  padding: 14px 16px;
}

.name-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(103,232,249,0.18);
}

.name-help {
  color: rgba(255,255,255,0.68);
  font-size: 0.85rem;
  margin: 6px 0 2px;
  text-align: center;
}

.name-error {
  color: #ffb4ad;
  font-size: 0.9rem;
  font-weight: 800;
  min-height: 20px;
  margin-bottom: 6px;
  text-align: center;
}

.name-card .btn {
  margin-left: auto;
  margin-right: auto;
}

.home-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 8px;
}

.player-greeting {
  color: var(--blue-light);
  font-size: 0.95rem;
  font-weight: 800;
}

.player-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.switch-name-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--cyan);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 900;
  padding: 0;
  text-decoration: underline;
}

.switch-warning {
  color: rgba(255,255,255,0.58);
  font-size: 0.74rem;
  line-height: 1.1;
}

.side-btn {
  border: 2px solid rgba(223,246,255,0.28);
  border-radius: 999px;
  background: rgba(6,25,54,0.44);
  color: var(--blue-light);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 9px 14px;
  transition: all 0.2s;
}

.side-btn:hover {
  background: rgba(56,189,248,0.18);
  border-color: rgba(223,246,255,0.58);
}

.home-action-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.submit-side-btn {
  background: linear-gradient(135deg, var(--blue-light), var(--blue));
  border-color: rgba(223,246,255,0.74);
  color: var(--navy);
  box-shadow: 0 8px 22px rgba(56,189,248,0.22);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0 10px;
  gap: 10px;
}

.back-btn {
  border: 2px solid rgba(223,246,255,0.28);
  border-radius: 999px;
  background: rgba(6,25,54,0.44);
  color: var(--blue-light);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 7px 13px;
  transition: all 0.2s;
}

.back-btn:hover {
  background: rgba(56,189,248,0.18);
  border-color: rgba(223,246,255,0.58);
}

.level-badge {
  background: var(--blue-light);
  color: var(--navy);
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
}

.question-counter {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.8);
  font-weight: 600;
}

.question-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 0;
}

.player-photo-wrapper {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 4px solid var(--blue-light);
  overflow: hidden;
  background: linear-gradient(145deg, rgba(223,246,255,0.22), rgba(56,189,248,0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 16px 40px rgba(0,0,0,0.24), 0 0 0 8px rgba(56,189,248,0.12);
}

.player-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

.player-photo-wrapper.missing-photo::before {
  content: attr(data-initials);
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #071d42;
  color: var(--gold-light);
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.question-prompt {
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  color: var(--white);
}

.options {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  width: 100%;
  padding: 14px 20px;
  border: 2px solid rgba(223,246,255,0.22);
  border-radius: var(--radius-sm);
  background: rgba(6,25,54,0.46);
  color: var(--white);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.option-btn:hover:not(.disabled) {
  background: rgba(56,189,248,0.18);
  border-color: rgba(223,246,255,0.55);
}

.option-btn.correct {
  background: #0891b2;
  border-color: #67e8f9;
}

.option-btn.incorrect {
  background: var(--red);
  border-color: var(--red);
}

.option-btn.disabled {
  cursor: default;
  opacity: 0.7;
}

.results-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.results-icon {
  font-size: 4rem;
}

h2 {
  font-size: 1.8rem;
  font-weight: 800;
}

.results-score {
  font-size: 3rem;
  font-weight: 800;
  color: var(--blue-light);
}

.results-message {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.8);
}

.btn {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  max-width: 280px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue-light), var(--blue));
  color: var(--navy);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #ffffff, var(--cyan));
  transform: translateY(-2px);
}

.btn:disabled {
  background: rgba(173,183,196,0.64);
  color: rgba(6,25,54,0.58);
  cursor: not-allowed;
  transform: none;
}

.btn:disabled:hover {
  background: rgba(173,183,196,0.64);
  transform: none;
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: var(--white);
  border: 2px solid rgba(255,255,255,0.2);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.2);
}

.leaderboard-panel {
  margin-top: 24px;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.leaderboard-row {
  align-items: center;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(223,246,255,0.18);
  border-radius: 14px;
  display: grid;
  gap: 10px;
  grid-template-columns: 38px 1fr auto;
  padding: 12px 14px;
}

.leaderboard-row.top-1 {
  background: linear-gradient(135deg, rgba(255,241,168,0.24), rgba(56,189,248,0.10));
  border-color: rgba(255,241,168,0.58);
}

.leaderboard-row.top-2 {
  background: linear-gradient(135deg, rgba(226,232,240,0.22), rgba(56,189,248,0.10));
  border-color: rgba(226,232,240,0.52);
}

.leaderboard-row.top-3 {
  background: linear-gradient(135deg, rgba(205,127,50,0.22), rgba(56,189,248,0.10));
  border-color: rgba(205,127,50,0.52);
}

.leaderboard-rank {
  color: var(--cyan);
  font-weight: 900;
}

.leaderboard-name {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-note-hidden {
  display: none;
}

.leaderboard-score {
  color: var(--blue-light);
  font-weight: 900;
}

.empty-leaderboard {
  color: rgba(255,255,255,0.72);
  padding: 12px 0;
  text-align: center;
}

@media (max-width: 500px) {
  #app {
    padding: 12px;
  }
  h1 {
    font-size: 1.6rem;
  }
  .player-photo-wrapper {
    width: 130px;
    height: 130px;
  }
  .option-btn {
    padding: 12px 16px;
    font-size: 0.9rem;
  }
  .home-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .switch-name-btn {
    align-self: center;
  }
  .switch-warning,
  .player-greeting {
    text-align: center;
  }
  .home-action-buttons {
    width: 100%;
  }
  .home-action-buttons .side-btn {
    flex: 1;
  }
}
