@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=Inter:wght@400;600&display=swap");

:root {
  --bg: #050308;
  --text: #f5f2fa;
  --text-faint: #c9c0d6;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 {
  font-family: "Space Grotesk", system-ui, sans-serif;
  margin: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
}

.screen.active {
  display: block;
}

.bg-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* ---------- Écran de sélection ---------- */

.selection-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 4vh, 32px);
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.logo-utopia {
  width: min(70vw, 320px);
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.5));
}

.welcome-text {
  width: min(86vw, 380px);
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: var(--text-faint);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.pseudo-row {
  display: flex;
  gap: 10px;
  width: min(86vw, 380px);
}

#pseudo-input {
  flex: 1;
  min-width: 0;
  padding: 0 16px;
  height: 48px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 15px;
}

#pseudo-input::placeholder {
  color: var(--text-faint);
}

#pseudo-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.lock-note {
  width: min(86vw, 380px);
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rename-feedback {
  width: min(86vw, 380px);
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--text-faint);
}

#play-btn {
  padding: 0 28px;
  height: 48px;
  border-radius: 24px;
  background: var(--text);
  color: #1a1320;
  font-weight: 700;
  font-family: "Space Grotesk", system-ui, sans-serif;
  transition: opacity 160ms ease, transform 160ms ease;
}

#play-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

#play-btn:active {
  transform: scale(0.96);
}

/* ---------- Écran de jeu ---------- */

#screen-game {
  background: #000;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 2;
  pointer-events: none;
}

.score-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 110px;
  height: 88px;
}

.score-panel img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.score-panel span {
  position: relative;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: #262626;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

#pause-btn {
  width: 52px;
  height: 52px;
  pointer-events: auto;
}

#pause-btn img {
  width: 100%;
  height: 100%;
}

#tap-hint {
  position: absolute;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 2;
  pointer-events: none;
  animation: tap-hint-pulse 1.6s ease-in-out infinite;
}

#tap-hint img {
  width: 64px;
}

#tap-hint p {
  margin: 0;
  font-size: 13px;
  color: var(--text-faint);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

@keyframes tap-hint-pulse {
  0%, 100% { opacity: 0.55; transform: translateX(-50%) translateY(0); }
  50% { opacity: 1; transform: translateX(-50%) translateY(-6px); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 3, 8, 0.72);
}

.overlay__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px;
}

.overlay__panel button {
  width: 220px;
  height: 48px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-weight: 600;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--text);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.settings-icon {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 2;
}

#settings-overlay {
  z-index: 4;
}

.settings-panel {
  width: min(86vw, 320px);
}

.settings-panel h2 {
  margin-bottom: 6px;
}

.volume-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  font-size: 13px;
  color: var(--text-faint);
}

.volume-row input[type="range"] {
  width: 100%;
  accent-color: var(--text);
}

/* ---------- Écran de fin de partie ---------- */

.gameover-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3vh, 26px);
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.gameover-panel {
  position: relative;
  width: min(86vw, 360px);
  aspect-ratio: 3 / 4;
  flex-shrink: 0;
  margin-top: 28px;
}

.gameover-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.5));
}

.gameover-inner {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16% 14%;
}

.gameover-label {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6b6275;
}

.gameover-score {
  margin: 0 0 8px;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 48px;
  font-weight: 700;
  color: #262626;
  text-shadow:
    0 0 8px rgba(255, 221, 0, 0.9),
    0 0 20px rgba(255, 221, 0, 0.65);
}

.btn-retry {
  position: relative;
  width: 100%;
  max-width: 220px;
  aspect-ratio: 3 / 1;
}

.btn-retry img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.btn-retry span {
  position: relative;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: #262626;
}

.link-btn {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-faint);
  text-decoration: underline;
}

.leaderboard-panel {
  position: relative;
  width: min(86vw, 360px);
  flex-shrink: 0;
}

.leaderboard-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.leaderboard-inner {
  padding: 10% 9% 22% 9%;
}

.leaderboard-inner h2 {
  font-size: 15px;
  text-align: center;
  color: #2b2b2b;
  margin-bottom: 10px;
}

#leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

#leaderboard-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #2b2b2b;
}

#leaderboard-list .rank {
  width: 20px;
  font-weight: 700;
  text-align: right;
  flex-shrink: 0;
}

#leaderboard-list .pseudo {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

#leaderboard-list .score {
  font-weight: 700;
  flex-shrink: 0;
}

#leaderboard-list .empty {
  color: var(--text-faint);
  font-weight: 400;
  text-align: center;
  width: 100%;
}

.personal-rank {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #2b2b2b;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(58, 31, 62, 0.3);
}

.personal-rank .rank {
  width: 20px;
  font-weight: 700;
  text-align: right;
  flex-shrink: 0;
}

.personal-rank .pseudo {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.personal-rank .score {
  font-weight: 700;
  flex-shrink: 0;
}
