:root {
  --bg: #e9f4ff;
  --water: #2b70ff;
  --stone: #aeb6c1;
  --lava: #ff6a00;
  --gate: #2ecc71;
  --gate-2: #ffffff;
  --goal-a: #111;
  --goal-b: #eee;
  --duck: #ffc300;
  --ui: #0b284f;
  --shadow: 0 10px 30px rgba(0,0,0,.12);
  --radius: 18px;
  --cellGap: clamp(4px, .6vw, 10px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
  background: linear-gradient(180deg, var(--bg), #ffffff 60%);
  color: #0e1a2b;
}

.app {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.screen {
  display: none;
  width: min(1200px, 100%);
  padding: 20px;
}
.screen--active {
  display: block;
  animation: fadeIn .35s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* -------- Titre -------- */
.title-hero {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2vw, 24px);
  justify-content: center;
}
.title-hero .earth {
  width: min(40vw, 320px);
  aspect-ratio: 1/1;
  overflow: hidden;
  border-radius: 50%;
  box-shadow: var(--shadow);
}
.title-hero .earth img { width: 140%; transform: translateX(-30%); }
.title-hero .duck { width: min(36vw, 260px); }
.title-hero .duck img { width: 100%; filter: drop-shadow(0 18px 24px rgba(0,0,0,.16)); }

.game-title {
  font-size: clamp(28px, 6vw, 56px);
  text-align: center;
  margin: .2em 0 .6em;
}
.title-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 10px;
}

/* -------- Boutons -------- */
.btn {
  appearance: none;
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  background: #ffffff;
  color: #0b284f;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 700;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: #0b284f; color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; font-size: 24px; }
.round {
  border-radius: 50%;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  padding: 0;
}

/* -------- HUD -------- */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.hud-right { justify-self: end; display: flex; gap: 8px; align-items: center; }
.hud-left { display: flex; gap: 8px; }
.hud-center { justify-self: center; }
.badge {
  background: #0b284f;
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 800;
}

/* -------- Plateau -------- */
.playfield-wrap {
  width: 100%;
  display: grid;
  place-items: center;
  padding: clamp(8px, 2vw, 18px);
}
.playfield {
  width: min(92vw, 92vh);
  height: min(92vw, 92vh);
  max-width: 780px;
  max-height: 780px;
  background: radial-gradient(120% 120% at 50% 20%, #d9eeff, #c9e5ff 60%, #b9ddff);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  perspective: 1600px;
  position: relative;
  overflow: hidden;
}

.grid3d {
  --rotX: 24deg;
  --rotZ: 0deg;
  position: absolute;
  inset: clamp(8px, 2vw, 20px);
  transform: rotateX(var(--rotX)) rotateZ(var(--rotZ));
  transform-style: preserve-3d;
  transition: transform var(--rotateMs, 420ms) cubic-bezier(.2,.8,.2,1);
}

.grid {
  display: grid;
  width: 100%; height: 100%;
  gap: var(--cellGap);
}

.cell {
  position: relative;
  border-radius: 12px;
  background: linear-gradient(#f7fbff,#eef6ff);
  box-shadow: inset 0 -2px 0 rgba(255,255,255,.6), inset 0 6px 10px rgba(0,0,0,.04);
  overflow: hidden;
}

/* Relief */
.cell::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.24), rgba(0,0,0,.06));
  mix-blend-mode: overlay;
}

/* Tuiles */
.tile { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; }
.tile--stone { background: linear-gradient(#c7cdd6,#a6afbb); border:1px solid rgba(0,0,0,.05); }
.tile--lava { background: radial-gradient(circle at 30% 20%, #ffd2a6, #ff6a00 60%, #b73f00); color:white; }
.tile--goal {
  background:
    conic-gradient(from 45deg, var(--goal-a) 0 25%, var(--goal-b) 0 50%, var(--goal-a) 0 75%, var(--goal-b) 0 100%);
  background-size: 24px 24px;
}

/* -------- Nouveaux tunnels -------- */
.tile--tunnel-h {
  background: repeating-linear-gradient(90deg, #2ecc71, #2ecc71 10px, #ffffff 10px, #ffffff 20px);
}
.tile--tunnel-v {
  background: repeating-linear-gradient(180deg, #2ecc71, #2ecc71 10px, #ffffff 10px, #ffffff 20px);
}

/* Eau animée */
.water-layer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(43,112,255,.85), rgba(43,112,255,.95));
  box-shadow: 0 -6px 16px rgba(43,112,255,.35);
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  height: 0%;
  transition: height 0.8s cubic-bezier(.25,.8,.25,1);
  z-index: 5;
  overflow: hidden;
}
.water-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 30%, rgba(255,255,255,.3) 0 20%, transparent 60%);
  opacity: .4;
  animation: waveMove 6s infinite linear;
}
.water-marker {
  position: absolute;
  left: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #0b284f;
  background: rgba(255,255,255,.8);
  padding: 2px 4px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transform: translateY(50%);
  z-index: 20;
  pointer-events: none;
}
@keyframes waveMove {
  from { transform: translateX(-20%); }
  to { transform: translateX(20%); }
}

/* Canard dans la grille */
.duck {
  width: 90%;
  height: 90%;
  object-fit: contain;
  justify-self: center;
  align-self: center;
  z-index: 10;
  /* rotation et flottement gérés par JS via variables CSS */
  transform: rotate(var(--duck-rot, 0deg)) translateY(var(--duck-dy, 0px));
  transition: transform 0.6s cubic-bezier(.25,.8,.25,1);
}

/* Toast */
.toast {
  position: absolute;
  inset: auto 0 8% 0;
  margin-inline: auto;
  width: min(90%, 520px);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  color: #0b284f;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 18px;
  display: none;
  text-align: center;
  font-size: clamp(18px, 3.4vw, 28px);
  font-weight: 900;
}
.toast--show { display: block; animation: pop .28s ease both; }
@keyframes pop { from{transform:translateY(14px) scale(.96); opacity:0} to{transform:none; opacity:1} }

/* Score */
.level-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(68px,1fr)); gap: 10px; }
.level-card {
  display: grid; place-items: center;
  aspect-ratio: 1/1;
  border-radius: 12px;
  box-shadow: var(--shadow);
  background: #fff;
  font-weight: 800;
  cursor: not-allowed;
  color: #779;
}
.level-card--open { cursor: pointer; color: #0b284f; }
.level-card--done { background: #fff; color: #000; }
.level-card--locked { opacity: .5; }

.tiny { opacity: .6; font-size: 12px; text-align: center; margin-top: 10px; }

/* Petits écrans */
@media (max-width:560px) {
  .hud { grid-template-columns: 1fr; gap: 6px; }
  .hud-right, .hud-left, .hud-center { justify-self: center; }
}

																			/* ===== Animation du canard ===== */

.duck {
  transition: none; /* Géré par JS */
  will-change: transform;
}

/* Animation de victoire */
.duck--win {
  animation: duck-win 1.4s ease-in-out;
}

@keyframes duck-win {
  0% { transform: rotate(var(--duck-rot, 0deg)) scale(1); }
  25% { transform: rotate(calc(var(--duck-rot, 0deg) + 360deg)) scale(1.3); }
  50% { transform: rotate(calc(var(--duck-rot, 0deg) + 720deg)) scale(1.2); }
  75% { transform: rotate(calc(var(--duck-rot, 0deg) + 1080deg)) scale(1.1); }
  100% { transform: rotate(calc(var(--duck-rot, 0deg) + 1440deg)) scale(1); }
}

/* Animation de défaite */
.duck--lose {
  animation: duck-lose 0.5s ease-in-out;
}

@keyframes duck-lose {
  0%, 100% { transform: rotate(var(--duck-rot, 0deg)) translateX(0); }
  20% { transform: rotate(var(--duck-rot, 0deg)) translateX(-8px); }
  40% { transform: rotate(var(--duck-rot, 0deg)) translateX(8px); }
  60% { transform: rotate(var(--duck-rot, 0deg)) translateX(-6px); }
  80% { transform: rotate(var(--duck-rot, 0deg)) translateX(6px); }
}

/* ===== Eau avec animation smooth ===== */

.water-layer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    rgba(30, 144, 255, 0.7) 0%,
    rgba(100, 180, 255, 0.5) 60%,
    rgba(135, 206, 250, 0.3) 100%
  );
  pointer-events: none;
  z-index: 5;
  transition: height 0.4s ease-out;
  border-top: 3px solid rgba(255, 255, 255, 0.6);
}

/* Effet de vagues sur l'eau */
.water-layer::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 0;
  right: 0;
  height: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 10'%3E%3Cpath d='M0 5 Q25 0 50 5 T100 5 V10 H0Z' fill='rgba(100,180,255,0.4)'/%3E%3C/svg%3E") repeat-x;
  background-size: 100px 16px;
  animation: waves 3s linear infinite;
}

@keyframes waves {
  0% { background-position-x: 0; }
  100% { background-position-x: 100px; }
}

/* ===== Marqueurs d'eau ===== */

.water-marker {
  position: absolute;
  right: 5px;
  font-size: 10px;
  font-weight: bold;
  color: #fff;
  background: rgba(30, 144, 255, 0.8);
  padding: 2px 6px;
  border-radius: 3px;
  z-index: 6;
  pointer-events: none;
}