* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-family: Arial, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 45%, #fb923c 100%);
  color: #f9fafb;
  touch-action: none;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

#gameContainer {
  position: relative;
  width: min(96vw, 456px);
  padding: clamp(12px, 3.2vw, 18px);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(8px);
}

canvas {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  height: auto;
  background: transparent;
  border-radius: 20px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
}

#score {
  display: none;
}

.overlay {
  position: absolute;
  inset: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(29, 78, 216, 0.96));
  color: #fff;
  padding: 24px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.overlay.hidden {
  display: none;
}

.overlay h1,
.overlay h2 {
  margin-bottom: 12px;
  font-size: 28px;
  letter-spacing: 2px;
}

.overlay p {
  margin-bottom: 10px;
  font-size: 16px;
}

.menu-stats {
  display: grid;
  gap: 8px;
  margin: 14px 0 8px;
  min-width: 240px;
}

.menu-stats .stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: rgba(255,255,255,0.9);
}

.game-over-form,
.leaderboard-panel {
  width: min(92vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-over-form label,
.leaderboard-panel label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 14px;
}

.game-over-form input,
.game-over-form select,
.leaderboard-panel input,
.leaderboard-panel select {
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #ffd166, #ff7f50);
  color: #1d3557;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

button.secondary {
  background: linear-gradient(135deg, #dbeafe, #93c5fd);
  color: #0f172a;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #ffd166;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.form-status,
.leaderboard-status {
  min-height: 20px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 28px 1fr 1fr auto 20px 60px;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.10);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
}

.leaderboard-item.leaderboard-top {
  display: grid;
  grid-template-columns: 28px 1fr 1fr auto 20px 60px;
  grid-template-rows: auto auto;
}

.lb-email {
  grid-column: 2 / -1;
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  padding-top: 2px;
}

.leaderboard-item.leaderboard-top {
  background: rgba(251, 146, 60, 0.22);
  border: 1px solid rgba(251,146,60,0.4);
}

.lb-rank { font-size: 16px; }
.lb-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-school { color: rgba(255,255,255,0.6); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-score { font-weight: 700; text-align: right; color: #ffd166; }
.lb-date { color: rgba(255,255,255,0.45); font-size: 11px; text-align: right; }

.export-btn {
  margin-top: 12px;
  width: 100%;
  font-size: 13px;
}

.gameover-link {
  display: block;
  margin-top: 14px;
  text-align: center;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  text-decoration: none;
  letter-spacing: 0.5px;
}

.gameover-link:hover {
  color: #fff;
  text-decoration: underline;
}

.debug-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255,255,255,0.16);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.5;
  z-index: 20;
}

.debug-panel.hidden {
  display: none;
}

.overlay::before {
  content: '';
  position: absolute;
  inset: 18px;
  border-radius: 18px;
  background: radial-gradient(circle at top center, rgba(255,255,255,0.18), transparent 60%);
  pointer-events: none;
}

.overlay h1,
.overlay h2 {
  position: relative;
  z-index: 1;
}

.overlay p,
.overlay .stats,
.overlay button {
  position: relative;
  z-index: 1;
}

.stats {
  margin-top: 12px;
  font-size: 14px;
}

#gameOverScore {
  font-size: 44px;
  font-weight: 700;
  margin: 12px 0;
}

.stats-panel {
  display: none;
}
