:root {
  --sky: #4ec0ca;
  --ink: #1f2933;
  --card: #ffffff;
  --line: #e3e8ef;
  --accent: #f7c948;
  --accent-d: #f0a500;
  --green: #2f9e44;
  --muted: #6b7280;
  --shadow: 0 10px 30px rgba(31, 41, 51, .15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(165deg, #4ec0ca 0%, #71d0d9 38%, #eef4f8 38%, #eef4f8 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 14px 40px;
}

/* --- Barre du haut : marque à gauche, joueur à droite --- */
.topbar {
  width: 100%;
  max-width: 760px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.brand h1 {
  margin: 0;
  font-size: 2.1rem;
  letter-spacing: -.5px;
  color: #fff;
  text-shadow: 0 2px 0 var(--accent-d), 0 4px 12px rgba(0,0,0,.2);
}
.brand h1 span { color: var(--accent); }
.brand h1 .bird-emoji { text-shadow: none; }
.tagline { margin: 4px 0 0; color: #fff; opacity: .92; font-weight: 500; font-size: .9rem; }

/* --- Widget joueur (pseudo persistant) --- */
.player {
  background: rgba(255,255,255,.92);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}
.player-label { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.player-set, .player-form { display: flex; align-items: center; gap: 6px; }
.player-set.hidden, .player-form.hidden { display: none; }
.player-name { font-weight: 800; font-size: 1.05rem; color: var(--ink); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-input {
  width: 130px;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-size: .95rem;
  outline: none;
}
#player-input:focus { border-color: var(--accent); }
.mini-btn {
  border: none;
  background: var(--accent);
  color: #5a3e00;
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.player-set .mini-btn { background: #eef2f7; }
.mini-btn:active { transform: translateY(1px); }

.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 760px;
}

/* --- Carte de jeu --- */
.game-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.canvas-wrap { position: relative; line-height: 0; }
canvas {
  display: block;
  width: 360px;
  max-width: 78vw;
  height: auto;
  aspect-ratio: 360 / 640;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  background: var(--sky);
}
.hint {
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
  margin: 10px 0 2px;
}

/* --- Overlay Game Over --- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  border-radius: 12px;
  background: rgba(31, 41, 51, .78);
  color: #fff;
  text-align: center;
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }
.overlay h2 { margin: 0; font-size: 2rem; letter-spacing: 1px; }
.overlay .final { margin: 0; font-size: 1.1rem; }
.overlay .final strong { color: var(--accent); font-size: 1.4rem; }
.save-status { margin: 0; font-size: .9rem; min-height: 1.1em; color: var(--accent); font-weight: 600; }
.save-status.error { color: #ffb4b4; }

/* --- Boutons --- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #5a3e00; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.4); }
.btn-sm { padding: 6px 12px; font-size: .85rem; }

/* --- Leaderboard --- */
.leaderboard {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  width: 280px;
  max-width: 78vw;
}
.leaderboard h2 { margin: 0 0 12px; font-size: 1.15rem; }
.scores { list-style: none; margin: 0 0 12px; padding: 0; counter-reset: rank; }
.scores li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  font-size: .95rem;
}
.scores li::before {
  counter-increment: rank;
  content: counter(rank);
  flex: 0 0 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #eef2f7;
  color: var(--muted);
  font-weight: 700;
  font-size: .8rem;
}
.scores li:nth-child(1)::before { background: #fff3bf; color: var(--accent-d); }
.scores li:nth-child(2)::before { background: #e9ecef; color: #495057; }
.scores li:nth-child(3)::before { background: #ffe8cc; color: #d9480f; }
.scores li .pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores li .pscore { font-weight: 800; color: var(--green); }
.scores li.me { background: #fffbea; border-radius: 8px; }
.scores li.empty { color: var(--muted); justify-content: center; font-style: italic; }
.scores li.empty::before { content: ""; background: none; }
.scores li.error { color: #c92a2a; }
.scores li.error::before { content: "!"; background: #ffe3e3; color: #c92a2a; }

.legend { color: var(--muted); font-size: .78rem; margin: 10px 0 0; line-height: 1.4; }
.legend code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; }

.leaderboard-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.page-footer {
  margin-top: 28px;
  color: #fff;
  opacity: .9;
  font-size: .82rem;
  text-align: center;
  max-width: 620px;
}

@media (max-width: 700px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .brand h1 { font-size: 1.7rem; }
  .player { align-self: flex-end; }
  .leaderboard { width: 360px; }
}

/* ===================== ÉCRAN MENU (landing) ===================== */
.menu-screen.hidden,
.game-screen.hidden { display: none; }

.menu-screen {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.menu-hero { text-align: center; }
.hero-bird {
  font-size: 4.6rem;
  line-height: 1;
  animation: float 2.4s ease-in-out infinite;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .2));
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50%      { transform: translateY(-14px) rotate(4deg); }
}
.menu-title {
  margin: 8px 0 0;
  font-size: 3rem;
  letter-spacing: -1px;
  color: #fff;
  text-shadow: 0 3px 0 var(--accent-d), 0 6px 16px rgba(0, 0, 0, .25);
}
.menu-title span { color: var(--accent); }
.menu-tagline { margin: 6px 0 0; color: #fff; font-weight: 600; opacity: .95; }

/* Le widget pseudo, centré dans le menu */
.menu-player { align-items: center; min-width: 220px; }

/* Gros bouton JOUER, avec ombre "3D" */
.btn-play {
  font-size: 1.4rem;
  padding: 14px 52px;
  border-radius: 14px;
  letter-spacing: .5px;
  box-shadow: 0 6px 0 var(--accent-d), 0 12px 22px rgba(0, 0, 0, .22);
}
.btn-play:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--accent-d), 0 6px 12px rgba(0, 0, 0, .22);
}

.menu-cards {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}
.menu-cards .leaderboard,
.menu-cards .howto {
  flex: 1 1 280px;
  width: auto;
  max-width: 340px;
}

.howto {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.howto h2 { margin: 0 0 12px; font-size: 1.15rem; }
.howto ul { margin: 0; padding-left: 18px; color: var(--ink); }
.howto li { margin: 8px 0; font-size: .92rem; line-height: 1.45; }

/* ===================== ÉCRAN JEU ===================== */
.game-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.back-menu { align-self: center; }
.overlay-actions { display: flex; gap: 10px; }
