:root {
  --sea:        #38b6c9;
  --sea-deep:   #1f8fa3;
  --sand:       #fbe3a2;
  --sand-deep:  #f3cf78;
  --tile:       #f8efd6;
  --tile-edge:  #e7d3a0;
  --leaf:       #5cb85c;
  --leaf-deep:  #3f9a45;
  --coral:      #ff7a59;
  --coral-deep: #ec5c3a;
  --sun:        #ffc94d;
  --grape:      #7c5cff;
  --ink:        #2c4a52;
  --ink-soft:   #5a767d;
  --paper:      #fffdf6;
  --shadow:     0 8px 0 rgba(0,0,0,.08);
  --radius:     22px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button, [role="button"] { touch-action: manipulation; }

html, body {
  height: 100%;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 100% at 50% -20%, #6fd3e0 0%, var(--sea) 45%, var(--sea-deep) 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(10px, 2vh, 22px) clamp(12px, 3vw, 28px);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(10px, 2vh, 18px);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; flex-shrink: 1; overflow: hidden; }
.brand-badge {
  width: 58px; height: 58px;
  flex: none;
  background: var(--paper);
  border-radius: 50%;
  box-shadow: 0 6px 0 rgba(0,0,0,.12);
  display: grid; place-items: center;
  overflow: hidden;
}
.brand-badge svg { width: 80%; height: 80%; }
.brand-text h1 {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: clamp(20px, 3.2vw, 30px);
  color: var(--paper);
  line-height: 1;
  text-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.brand-text p {
  font-weight: 500;
  font-size: clamp(11px, 1.6vw, 14px);
  color: #d6f5fa;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.level-pill {
  background: var(--paper);
  border-radius: 999px;
  padding: 7px 16px 7px 14px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 5px 0 rgba(0,0,0,.12);
}
.level-pill-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.level-pill-num {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800; font-size: 22px;
  color: var(--coral); line-height: 1;
}
button.level-pill { border: none; cursor: pointer; transition: transform .08s; }
button.level-pill:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.level-pill .ico-grid { width: 16px; height: 16px; opacity: .55; }
.icon-btn {
  width: 44px; height: 44px;
  border: none; cursor: pointer;
  background: var(--paper);
  border-radius: 50%;
  box-shadow: 0 5px 0 rgba(0,0,0,.12);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800; font-size: 20px;
  color: var(--sea-deep);
  display: grid; place-items: center;
  transition: transform .08s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }

/* Pastille de profil */
.profile-chip {
  border: none; cursor: pointer;
  background: var(--paper);
  border-radius: 999px;
  padding: 5px 14px 5px 5px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 5px 0 rgba(0,0,0,.12);
  transition: transform .08s;
  max-width: 170px;
}
.profile-chip:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.profile-name {
  font-weight: 700; font-size: 15px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Avatar genré */
.avatar {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--tile);
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 3px var(--ring, #ccc);
  flex: none;
}
.avatar svg { width: 78%; height: 78%; }
.avatar.avatar-f { --ring: #ff7ab0; background: #ffe6f0; }
.avatar.avatar-g { --ring: #4aa3e8; background: #e2f1ff; }
.avatar[data-badge]::after {
  content: attr(data-badge);
  position: absolute; bottom: -3px; right: -5px;
  font-size: 14px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.2));
}

/* ---------- Play area ---------- */
.play-area {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: clamp(14px, 2.5vw, 26px);
  min-height: 0;
}

/* ---------- Board ---------- */
.board-panel { display: flex; flex-direction: column; min-height: 0; }
.board-frame {
  position: relative;
  flex: 1;
  background: var(--sand);
  border-radius: var(--radius);
  padding: clamp(10px, 1.6vw, 16px);
  box-shadow: inset 0 0 0 6px var(--sand-deep), 0 10px 0 rgba(0,0,0,.12);
  display: grid; place-items: center;
  overflow: hidden;
}
.board-reset {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 7;
  border: none; cursor: pointer;
  background: var(--paper);
  color: var(--sea-deep);
  border-radius: 999px;
  padding: 7px 13px 7px 10px;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700; font-size: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,.14);
  transition: transform .08s;
}
.board-reset:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.14); }
.board-reset .ico-home { width: 16px; height: 16px; }
.board-water {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.25) 0 8px, transparent 9px),
    radial-gradient(circle at 82% 78%, rgba(255,255,255,.18) 0 6px, transparent 7px);
  pointer-events: none;
}
.board {
  position: relative;
  display: grid;
  gap: 4px;
  background: var(--sand-deep);
  padding: 6px;
  border-radius: 16px;
}
.cell {
  position: relative;
  border-radius: 11px;
  background: var(--tile);
  box-shadow: inset 0 -3px 0 var(--tile-edge);
}
.cell.wall {
  background: linear-gradient(180deg, var(--leaf) 0%, var(--leaf-deep) 100%);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18);
}
.cell.wall::after {
  content: "";
  position: absolute; inset: 16%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.45) 0 18%, transparent 20%);
  border-radius: 50%;
}
/* Insectes SVG injectés via JS */
.insect {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
}
.insect svg {
  width: 72%; height: 72%;
  overflow: visible;
}
.mosquito-insect { animation: bob 1.6s ease-in-out infinite; }
.fly-insect      { animation: bob 1.4s ease-in-out infinite; }
.cell.gem.taken .insect { display: none; }
.cell.goal {
  background: radial-gradient(circle at 50% 45%, #ffe6a8 0 45%, var(--tile) 70%);
}
@keyframes bob {
  0%, 100% { transform: translateY(-2px); }
  50%      { transform: translateY(3px); }
}

/* Gecko token */
.gecko {
  position: absolute;
  top: 0; left: 0;
  display: grid; place-items: center;
  pointer-events: none;
  transition: transform .32s cubic-bezier(.34,1.4,.5,1);
  z-index: 5;
  will-change: transform;
}
.gecko svg { width: 78%; height: 78%; overflow: visible; }
.gecko.idle svg { animation: wiggle 2.4s ease-in-out infinite; }
@keyframes wiggle {
  0%,100% { transform: rotate(-3deg); }
  50%     { transform: rotate(3deg); }
}
.gecko.bump svg { animation: bash .38s ease; }
@keyframes bash {
  0%,100% { filter: none; }
  25%     { filter: drop-shadow(0 0 8px #ff3322) brightness(1.35); }
  50%     { filter: drop-shadow(0 0 4px #ff3322) brightness(1.1); }
}
/* Gobe : Bacar croque l'insecte */
.gecko.gobbling svg { animation: chomp .36s ease-in-out !important; }
@keyframes chomp {
  0%   { transform: scale(1) rotate(0deg); }
  35%  { transform: scale(1.32) rotate(8deg); }
  65%  { transform: scale(0.88) rotate(-4deg); }
  100% { transform: scale(1) rotate(0deg); }
}
/* Danses victoire dans la modale */
@keyframes dance-bounce {
  0%,100% { transform: translateY(0) rotate(0deg) scale(1); }
  25%     { transform: translateY(-22px) rotate(-12deg) scale(1.08); }
  75%     { transform: translateY(-10px) rotate(12deg) scale(1.05); }
}
@keyframes dance-spin {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(200deg) scale(1.15); }
  100% { transform: rotate(360deg) scale(1); }
}
@keyframes dance-wiggle {
  0%,100% { transform: rotate(-18deg) scale(1); }
  33%     { transform: rotate(18deg) scale(1.12); }
  66%     { transform: rotate(-10deg) scale(0.96); }
}
@keyframes dance-jump {
  0%,100% { transform: translateY(0) scale(1); }
  20%     { transform: translateY(-28px) scale(1.1); }
  40%     { transform: translateY(0) scale(1); }
  60%     { transform: translateY(-16px) scale(1.05); }
  80%     { transform: translateY(0) scale(1); }
}

.goal-banner {
  margin-top: 12px;
  background: var(--paper);
  border-radius: 16px;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 600;
  font-size: clamp(13px, 1.8vw, 16px);
  box-shadow: 0 5px 0 rgba(0,0,0,.1);
}
.goal-banner .goal-icon::before { content: "🎯"; font-size: 20px; }

/* ---------- Code panel ---------- */
.code-panel {
  background: var(--paper);
  border-radius: var(--radius);
  padding: clamp(14px, 2vw, 20px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 10px 0 rgba(0,0,0,.12);
}
.code-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.code-header h2 {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800; font-size: clamp(17px, 2.4vw, 22px);
  color: var(--ink);
}
.block-count {
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  background: #f0e9d6; padding: 3px 10px; border-radius: 999px;
}

.program {
  flex: 1;
  min-height: 90px;
  background: #f6efdd;
  border: 3px dashed var(--sand-deep);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  overflow-y: auto;
  margin-bottom: 14px;
}
.program-hint {
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 14px;
  margin: auto;
  text-align: center;
  max-width: 220px;
}
.block {
  --c: var(--sea);
  position: relative;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--c);
  box-shadow: 0 4px 0 rgba(0,0,0,.18);
  display: grid; place-items: center;
  cursor: pointer;
  animation: pop .22s cubic-bezier(.34,1.5,.5,1);
}
.block[data-cmd="forward"] { --c: var(--sea); }
.block[data-cmd="left"]    { --c: var(--grape); }
.block[data-cmd="right"]   { --c: var(--coral); }
.block .cmd-ico { width: 26px; height: 26px; }
.block .step-num {
  position: absolute; top: -6px; left: -6px;
  width: 20px; height: 20px;
  background: var(--paper); color: var(--ink);
  border-radius: 50%;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 2px 0 rgba(0,0,0,.15);
}
.block .remove {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px;
  background: #fff; color: var(--coral-deep);
  border-radius: 50%; border: none;
  font-size: 14px; font-weight: 800; line-height: 1;
  display: grid; place-items: center;
  box-shadow: 0 2px 0 rgba(0,0,0,.15);
  opacity: 0; transition: opacity .15s; cursor: pointer;
}
.block:hover .remove { opacity: 1; }
.block.running {
  outline: 4px solid var(--sun);
  outline-offset: 2px;
  transform: scale(1.12);
}
.block.done { opacity: .45; }
.block { touch-action: none; cursor: grab; }
.loop-block { touch-action: none; }
.drag-clone {
  position: fixed; left: 0; top: 0; z-index: 200;
  pointer-events: none; opacity: .92;
  box-shadow: 0 10px 20px rgba(0,0,0,.28);
  cursor: grabbing;
}
.drag-ph {
  flex: none;
  border: 3px dashed var(--sea);
  border-radius: 14px;
  background: rgba(56,182,201,.15);
}
@keyframes pop {
  from { transform: scale(.3); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---- Bloc "répéter" ---- */
.loop-block {
  background: #fff6e0;
  border: 3px solid #f3cf78;
  border-radius: 16px;
  padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
  cursor: pointer;
  animation: pop .22s cubic-bezier(.34,1.5,.5,1);
}
.loop-block.active { border-color: var(--sun); box-shadow: 0 0 0 3px rgba(255,201,77,.55); }
.loop-block.loop-running { box-shadow: 0 0 0 4px var(--sun); }
.loop-header { display: flex; align-items: center; gap: 6px; }
.loop-ico {
  width: 22px; height: 22px; flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c8860a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9a5 5 0 0 1 5-5h8M17 4l3 3-3 3'/%3E%3Cpath d='M20 15a5 5 0 0 1-5 5H7M7 20l-3-3 3-3'/%3E%3C/svg%3E") center/contain no-repeat;
}
.loop-minus, .loop-plus {
  width: 26px; height: 26px; flex: none;
  border: none; cursor: pointer;
  border-radius: 9px;
  background: var(--sun); color: #7a5200;
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 18px; line-height: 1;
  box-shadow: 0 3px 0 #e0a82e;
}
.loop-minus:active, .loop-plus:active { transform: translateY(2px); box-shadow: 0 1px 0 #e0a82e; }
.loop-count {
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 18px;
  color: #b5760a; min-width: 34px; text-align: center;
}
.loop-remove {
  margin-left: auto; flex: none;
  width: 24px; height: 24px;
  border: none; cursor: pointer;
  border-radius: 50%;
  background: #fff; color: var(--coral-deep);
  font-size: 16px; font-weight: 800; line-height: 1;
  box-shadow: 0 2px 0 rgba(0,0,0,.15);
}
.loop-body {
  display: flex; flex-wrap: wrap; gap: 8px;
  min-height: 58px;
  background: rgba(255,255,255,.65);
  border: 2px dashed #f3cf78;
  border-radius: 12px;
  padding: 8px;
  align-content: flex-start;
}
.loop-hint { color: #b5760a; font-size: 12px; font-weight: 600; margin: auto; }

/* Palette */
.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.cmd-card {
  border: none; cursor: pointer;
  background: #fff;
  border-radius: 16px;
  padding: 12px 6px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 5px 0 rgba(0,0,0,.12), inset 0 0 0 2px #f0e9d6;
  transition: transform .08s;
}
.cmd-card:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.12), inset 0 0 0 2px #f0e9d6; }
.cmd-card[data-cmd="forward"] .cmd-ico-wrap { background: var(--sea); }
.cmd-card .cmd-ico {
  width: 30px; height: 30px;
  display: grid; place-items: center;
}
.cmd-label { font-weight: 600; font-size: 14px; color: var(--ink); }
.cmd-card[data-cmd="forward"] .cmd-label { color: var(--sea-deep); }
.cmd-card[data-cmd="left"]    .cmd-label { color: var(--grape); }
.cmd-card[data-cmd="right"]   .cmd-label { color: var(--coral-deep); }
.cmd-card[data-cmd="loop"]    .cmd-label { color: #c8860a; }

/* Command icons (arrows) */
.cmd-ico { background-repeat: no-repeat; background-position: center; background-size: contain; }
.cmd-forward { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2338b6c9' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20V5M5 11l7-7 7 7'/%3E%3C/svg%3E"); }
.cmd-left    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237c5cff' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 14L4 9l5-5'/%3E%3Cpath d='M20 20v-7a4 4 0 0 0-4-4H4'/%3E%3C/svg%3E"); }
.cmd-right   { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ff7a59' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 14l5-5-5-5'/%3E%3Cpath d='M4 20v-7a4 4 0 0 1 4-4h12'/%3E%3C/svg%3E"); }
.cmd-loop    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e0a82e' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9a5 5 0 0 1 5-5h8M17 4l3 3-3 3'/%3E%3Cpath d='M20 15a5 5 0 0 1-5 5H7M7 20l-3-3 3-3'/%3E%3C/svg%3E"); }
.block .cmd-forward { filter: brightness(0) invert(1); }
.block .cmd-left    { filter: brightness(0) invert(1); }
.block .cmd-right   { filter: brightness(0) invert(1); }

/* ---------- Controls ---------- */
.controls { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; }
.btn {
  border: none; cursor: pointer;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700; font-size: 16px;
  border-radius: 16px;
  padding: 13px 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .08s;
  white-space: nowrap;
}
.btn:active { transform: translateY(4px) !important; }
.btn-play {
  background: var(--coral); color: #fff;
  box-shadow: 0 5px 0 var(--coral-deep);
}
.btn-secondary {
  background: var(--sun); color: #7a5200;
  box-shadow: 0 5px 0 #e0a82e;
}
.btn-ghost {
  background: #f0e9d6; color: var(--ink-soft);
  box-shadow: 0 5px 0 #ddd2b6;
}
.btn:active { box-shadow: 0 1px 0 rgba(0,0,0,.2) !important; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* small inline icons */
.ico { width: 18px; height: 18px; display: inline-block; background-repeat: no-repeat; background-position: center; background-size: contain; }
.ico-play  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M7 4v16l13-8z'/%3E%3C/svg%3E"); }
.ico-step  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%237a5200'%3E%3Cpath d='M6 4v16l9-8zM17 4h2v16h-2z'/%3E%3C/svg%3E"); }
.ico-trash { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a767d' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14'/%3E%3C/svg%3E"); }
.ico-next  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14M13 6l6 6-6 6'/%3E%3C/svg%3E"); }
.ico-home  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f8fa3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11l9-8 9 8M5 10v10h14V10'/%3E%3C/svg%3E"); }
.ico-grid  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a767d' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='3' y='14' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='14' width='7' height='7' rx='1.5'/%3E%3C/svg%3E"); }
.ico-sound { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f8fa3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9v6h4l5 4V5L8 9zM16 9a3 3 0 0 1 0 6M19 7a7 7 0 0 1 0 10'/%3E%3C/svg%3E"); }
.ico-fullscreen { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f8fa3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M3 16v3a2 2 0 0 0 2 2h3M16 21h3a2 2 0 0 0 2-2v-3'/%3E%3C/svg%3E"); }
:fullscreen .ico-fullscreen,
:-webkit-full-screen .ico-fullscreen,
.fullscreen-active .ico-fullscreen { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f8fa3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 3v3a2 2 0 0 1-2 2H3M21 8h-3a2 2 0 0 1-2-2V3M3 16h3a2 2 0 0 1 2 2v3M16 21v-3a2 2 0 0 1 2-2h3'/%3E%3C/svg%3E"); }

.muted .ico-sound { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b08' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9v6h4l5 4V5L8 9zM17 9l4 6M21 9l-4 6' stroke='%23ec5c3a'/%3E%3C/svg%3E"); }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,50,58,.55);
  display: grid; place-items: center;
  z-index: 100;
  animation: fade .2s ease;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--paper);
  border-radius: 28px;
  padding: 28px 28px 24px;
  text-align: center;
  max-width: 380px; width: 100%;
  box-shadow: 0 14px 0 rgba(0,0,0,.2);
  animation: drop .35s cubic-bezier(.34,1.4,.5,1);
}
@keyframes drop { from { transform: translateY(-40px) scale(.9); opacity: 0; } }
.modal h2 {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800; font-size: 30px; color: var(--coral);
}
.modal p { color: var(--ink-soft); font-weight: 500; margin-top: 6px; }
.modal-gecko { width: 110px; height: 110px; margin: 0 auto 4px; }
.modal-gecko svg { width: 100%; height: 100%; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

.modal-help { text-align: center; max-width: 400px; }
.modal-help h2 { color: var(--sea-deep); }

.help-cmds { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 14px; }
.help-cmd-card {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--surface); border-radius: 14px; padding: 12px 8px 10px;
  border: 2px solid var(--border);
}
.help-ico { width: 32px; height: 32px; flex: none; }
.help-cmd-name { font-weight: 700; font-size: 14px; color: var(--ink); }
.help-cmd-desc { font-size: 12px; color: var(--ink-soft); font-weight: 500; }

.help-run-hint { font-size: 14px; font-weight: 500; color: var(--ink-soft); margin: 0 0 14px; }
.help-run-hint b { color: var(--ink); }

.help-targets { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 4px; }
.help-target { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.help-target-ico { width: 48px; height: 48px; }
.help-target-ico svg { width: 100%; height: 100%; }
.help-target span { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.help-target span b { color: var(--ink); }
.help-target-sep { font-size: 22px; font-weight: 700; color: var(--ink-soft); padding-bottom: 20px; }

.modal-levels h2 { color: var(--sea-deep); }
.level-progress {
  text-align: center;
  font-weight: 500; font-size: 14px; color: var(--ink-soft);
  margin-top: 6px;
}
.level-progress b { color: var(--ink); font-weight: 700; }
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 12px;
  margin: 16px 0 4px;
  max-height: 56vh;
  overflow-y: auto;
  padding: 2px 4px;
}
/* Header de monde */
.world-header {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 8px;
  background: var(--world-bg, #f6efdd);
  border-left: 4px solid var(--world-color, #ccc);
  border-radius: 10px;
  padding: 6px 12px;
  margin-top: 6px;
}
.world-header:first-child { margin-top: 0; }
.world-emoji { font-size: 18px; }
.world-name {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800; font-size: 15px;
  color: var(--world-color, #555);
  flex: 1;
}
.world-progress {
  font-size: 12px; font-weight: 700;
  color: var(--ink-soft);
  background: rgba(0,0,0,.06);
  padding: 2px 8px; border-radius: 999px;
}
.level-card {
  position: relative;
  border: none; cursor: pointer;
  background: #f6efdd;
  border-radius: 16px;
  padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: 0 4px 0 rgba(0,0,0,.1);
  transition: transform .08s;
  overflow: hidden;
}
.level-card:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.level-card .num {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800; font-size: 22px; color: var(--sea-deep); line-height: 1;
}
.level-card .lvl-name {
  font-size: 10px; font-weight: 600; color: var(--ink-soft);
  line-height: 1.1; text-align: center;
  height: 22px; display: flex; align-items: center;
}
.level-card .badge {
  position: absolute; top: 5px; right: 5px;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 12px; font-weight: 800; color: #fff;
  display: grid; place-items: center;
}
.level-card.completed { background: #e6f6e2; }
.level-card.completed .badge { background: var(--leaf); }
.level-card.completed .num { color: var(--leaf-deep); }
.level-card.current { box-shadow: 0 0 0 3px var(--coral), 0 4px 0 rgba(0,0,0,.1); }
.level-card.current .num { color: var(--coral); }
.level-card.completed .badge { background: var(--world-color, var(--leaf)); }
.level-card.completed .num   { color: var(--world-color, var(--leaf-deep)); }

@media (max-width: 460px) {
  .level-grid { grid-template-columns: repeat(3, 1fr); }
}

.credits {
  text-align: center;
  margin-top: clamp(8px, 1.6vh, 16px);
  padding: 4px 0 2px;
  font-size: clamp(11px, 1.5vw, 13px);
  font-weight: 500;
  color: #d6f5fa;
}
.credits b { font-weight: 700; color: var(--paper); }

/* ---- Modale joueurs ---- */
.modal-users h2, .modal-profile h2 { color: var(--sea-deep); text-align: center; }
.users-list { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.user-row {
  display: flex; align-items: center; gap: 8px;
}
.user-pick {
  flex: 1;
  border: none; cursor: pointer;
  background: #f6efdd;
  border-radius: 16px;
  padding: 8px 14px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,.1);
  transition: transform .08s;
}
.user-pick:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.user-row.active .user-pick { box-shadow: 0 0 0 3px var(--leaf), 0 4px 0 rgba(0,0,0,.1); background: #e6f6e2; }
.user-name { font-weight: 700; font-size: 16px; color: var(--ink); flex: 1; text-align: left; }
.user-current { color: var(--leaf-deep); font-weight: 800; font-size: 18px; }
.user-del {
  border: none; cursor: pointer;
  width: 38px; height: 38px; flex: none;
  background: #f0e9d6;
  border-radius: 12px;
  font-size: 16px;
  box-shadow: 0 4px 0 #ddd2b6;
  transition: transform .08s;
}
.user-del:active { transform: translateY(3px); box-shadow: 0 1px 0 #ddd2b6; }
.add-user { width: 100%; margin-bottom: 4px; }
.add-user .plus { font-size: 20px; font-weight: 800; }

/* ---- Modale création ---- */
.modal-profile p { margin-top: 10px; }
.modal-profile .gender-q { margin-top: 16px; font-weight: 600; }
.name-input {
  width: 100%;
  margin-top: 10px;
  border: 3px solid var(--sand-deep);
  border-radius: 14px;
  padding: 12px 16px;
  font-family: 'Fredoka', sans-serif;
  font-size: 18px; font-weight: 600;
  color: var(--ink);
  text-align: center;
  background: #fffdf6;
  outline: none;
}
.name-input:focus { border-color: var(--sea); }
.name-input.shake { animation: shake .4s; }
@keyframes shake {
  0%,100%{transform:translateX(0);} 20%,60%{transform:translateX(-7px);} 40%,80%{transform:translateX(7px);}
}
.gender-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.gender-btn {
  border: 3px solid #f0e9d6; cursor: pointer;
  background: #fff;
  border-radius: 16px;
  padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-family: 'Fredoka', sans-serif;
  font-weight: 600; font-size: 15px; color: var(--ink);
  box-shadow: 0 4px 0 rgba(0,0,0,.1);
  transition: transform .08s;
}
.gender-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.gender-emoji { font-size: 30px; }
.gender-btn[data-gender="f"].selected { border-color: #ff7ab0; background: #ffe6f0; }
.gender-btn[data-gender="g"].selected { border-color: #4aa3e8; background: #e2f1ff; }
.gender-choice.missing .gender-btn { border-color: var(--coral); animation: shake .4s; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

/* =========================================================
   Tutoriel animé
   ========================================================= */
#tutorialOverlay {
  position: fixed; inset: 0;
  z-index: 80;
  pointer-events: none;
  transition: opacity .4s;
}
#tutorialOverlay.fading { opacity: 0; }
/* Les étapes flottent au-dessus des éléments concernés */
.tuto-step {
  position: absolute;
  background: var(--ink);
  color: #fff;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700; font-size: 15px;
  padding: 10px 16px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .3s, transform .3s;
  white-space: nowrap;
  pointer-events: auto;
}
.tuto-step.visible { opacity: 1; transform: translateY(0); }
.tuto-step::after {
  content: "";
  position: absolute;
  bottom: -10px; left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--ink);
  border-bottom: none;
}
/* Étape 1 : au-dessus de la palette */
#tutoStep1 {
  bottom: calc(100% - 56px);
  left: 50%; transform: translateX(-50%) translateY(6px);
}
#tutoStep1.visible { transform: translateX(-50%) translateY(0); }
/* Étape 2 : au-dessus du bouton Lancer */
#tutoStep2 {
  bottom: 20%;
  right: 18px;
}
#tutoStep2::after {
  left: auto; right: 24px; transform: none;
}

/* Anneau pulsant sur l'élément mis en avant */
.tuto-highlight {
  position: relative;
  animation: tuto-glow .7s ease-in-out infinite alternate !important;
  z-index: 10;
}
@keyframes tuto-glow {
  from { box-shadow: 0 0 0 0 rgba(255, 122, 89, .7); }
  to   { box-shadow: 0 0 0 10px rgba(255, 122, 89, 0); }
}
.tuto-hand {
  font-size: 28px;
  display: inline-block;
  margin-right: 6px;
  animation: tuto-tap .6s ease-in-out infinite alternate;
}
@keyframes tuto-tap {
  from { transform: translateY(0); }
  to   { transform: translateY(5px); }
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  body { overflow-x: hidden; overflow-y: auto; }
  #app { height: auto; min-height: 100%; width: 100%; }
  .play-area { grid-template-columns: minmax(0, 1fr); }
  .board { width: min(100%, 64vh); max-width: 100%; }
  .board-frame { overflow: hidden; }
}

@media (max-width: 520px) {
  .brand-badge { width: 46px; height: 46px; }
  .brand-text { display: none; }
  .profile-chip { padding: 5px 10px 5px 5px; gap: 6px; max-width: 110px; }
  .profile-name { font-size: 13px; }
  .level-pill { padding: 6px 10px 6px 10px; gap: 5px; }
  .level-pill-label { display: none; }
  .level-pill-num { font-size: 18px; }
  .icon-btn { width: 38px; height: 38px; font-size: 16px; }
  .topbar { gap: 6px; }
  .topbar-right { gap: 6px; }

  .controls { grid-template-columns: 1fr 1fr 1fr; }
  .btn { padding: 11px 10px; font-size: 14px; gap: 5px; }
  .ico { width: 15px; height: 15px; }
  .code-panel { padding: 12px; }
  .palette { gap: 6px; margin-bottom: 10px; }
  .cmd-card { padding: 10px 4px 8px; gap: 4px; border-radius: 14px; }
  .cmd-label { font-size: 12px; }
}
