/* ========================== RESET ========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --c0: #ff5470;
  --c1: #ffb43d;
  --c2: #ffe14a;
  --c3: #5cd6a0;
  --c4: #5db9ff;
}
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: radial-gradient(ellipse at top, #1a2147 0%, #0f1424 60%, #060818 100%);
  color: #e8eaff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

/* ========================== SCREENS ========================== */
.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* ========================== HOME ========================== */
#home { align-items: center; justify-content: flex-start; padding: 16px 20px; overflow-y: auto; height: 100vh; }
.home-inner { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; padding: 8px 0 80px; }
.logo { text-align: center; }
.logo-octopus { font-size: 48px; display: block; line-height: 1; filter: drop-shadow(0 4px 12px rgba(255,100,180,0.4)); }
.logo h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #ff6ba6 0%, #ffa76b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-top: 4px;
}
.tagline { color: #8b93b8; font-size: 13px; margin-top: 4px; }

.card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lbl { font-size: 12px; color: #8b93b8; text-transform: uppercase; letter-spacing: 1px; }

/* ============== Player list ============== */
.player-list { display: flex; flex-direction: column; gap: 6px; }
.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.player-row:hover { background: rgba(255,255,255,0.05); }
.player-row.current {
  border-color: #ff6ba6;
  background: rgba(255, 107, 166, 0.08);
}
.player-row .name { font-weight: 600; font-size: 15px; }
.player-row .badge {
  font-size: 11px;
  color: #ffa76b;
  background: rgba(255,167,107,0.15);
  padding: 2px 8px;
  border-radius: 8px;
}
.player-row .del {
  background: transparent;
  border: none;
  color: #8b93b8;
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
  margin-left: 4px;
}
.player-row .del:hover { color: #ff5470; }

/* ============== Stats ============== */
.stats-row { display: flex; gap: 10px; }
.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  padding: 10px 6px;
  gap: 2px;
}
.stat-val { font-size: 22px; font-weight: 800; color: #ffa76b; }
.stat-lbl { font-size: 11px; color: #8b93b8; text-align: center; }

/* ============== Levels list ============== */
.levels-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}
.level-tile {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
  position: relative;
  min-height: 64px;
}
.level-tile.more {
  background: rgba(255,167,107,0.08);
  border-color: rgba(255,167,107,0.25);
  color: #ffa76b;
}
.level-tile.more .lvl-num {
  font-size: 22px;
  font-weight: 800;
}
.level-tile:hover:not(.locked) { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.15); }
.level-tile:active:not(.locked) { transform: scale(0.95); }
.level-tile.locked { opacity: 0.3; cursor: not-allowed; }
.level-tile .lvl-num { font-size: 18px; font-weight: 800; color: #e8eaff; }
.level-tile .lvl-score {
  font-size: 11px;
  color: #ffa76b;
  background: rgba(255,167,107,0.12);
  padding: 1px 6px;
  border-radius: 6px;
}
.level-tile .lvl-done {
  position: absolute;
  top: 4px; right: 4px;
  color: #5cd6a0;
  font-size: 14px;
  font-weight: 700;
}
.level-tile.next { border-color: #ff6ba6; box-shadow: 0 0 0 2px rgba(255,107,166,0.2); }

/* ============== Buttons ============== */
.btn {
  border: none; border-radius: 12px; padding: 14px 18px;
  font-size: 16px; font-weight: 700;
  transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #ff6ba6 0%, #ffa76b 100%); color: #1a0a14; }
.btn.ghost { background: transparent; color: #8b93b8; border: 1px solid rgba(255,255,255,0.1); }
.btn.ghost.small { padding: 8px 12px; font-size: 13px; align-self: flex-start; }
.btn.ghost.small:hover { color: #e8eaff; border-color: rgba(255,255,255,0.25); }

/* ============== How-to ============== */
.how-to {
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: #b8bee0;
}
.how-to summary {
  cursor: pointer;
  font-weight: 600;
  color: #ffa76b;
  padding: 2px 0;
  user-select: none;
}
.how-to summary:hover { color: #ff6ba6; }
.how-to ol { padding-left: 20px; margin-top: 8px; }
.how-to li { margin-bottom: 3px; }
.how-to b { color: #ffa76b; }

/* ========================== GAME ========================== */
#game { background: linear-gradient(180deg, #0f1424 0%, #1a2147 100%); overflow-y: auto; }
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  font-size: 15px;
}
.icon-btn, .hud-restart {
  background: rgba(255,255,255,0.08);
  border: none;
  color: #e8eaff;
  width: 36px; height: 36px;
  border-radius: 10px;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.hud-lvl { font-weight: 700; font-size: 17px; color: #ffa76b; }

.board {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 0;
}
.grid {
  display: grid;
  width: 100%;
  max-width: 280px;
  aspect-ratio: 7 / 9;
  gap: 2px;
  background: rgba(0,0,0,0.25);
  border: 2px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 5px;
  position: relative;
  z-index: 1;
}
.cell {
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  transition: background 0.2s, transform 0.25s, opacity 0.25s;
}
.cell.has-block {
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25), 0 2px 6px rgba(0,0,0,0.3);
}
.cell.popping {
  transform: scale(1.3);
  opacity: 0;
  transition: transform 0.2s ease-out, opacity 0.2s ease-in;
}
.cell.just-popped {
  animation: popBurst 0.22s ease-out;
}
.cell.falling { transition: transform 0.25s ease-in; }
@keyframes popBurst {
  0%   { transform: scale(1); filter: brightness(1.6); }
  60%  { transform: scale(1.25); filter: brightness(2); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Couleurs des blocs (6 couleurs mesurées sur la vidéo Octo Crush) */
.cell.c0 { background: #ff5470; }   /* rouge */
.cell.c1 { background: #ff9933; }   /* orange */
.cell.c2 { background: #ffd93d; }   /* jaune */
.cell.c3 { background: #5cd6a0; }   /* vert */
.cell.c4 { background: #5b8cff; }   /* bleu */
.cell.c5 { background: #9b59ff; }   /* violet */
.cell.c6 { background: #ff6b9d; }   /* rose */

/* Shots layer = effets visuels par-dessus la grille */
.shots-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.shots-layer-inner {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 7 / 9;
  position: relative;
}
.shot {
  position: absolute;
  width: 14%;
  height: 6%;
  border-radius: 50%;
  filter: blur(2px);
  animation: shootUp 0.4s ease-out forwards;
}
@keyframes shootUp {
  0%   { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-1500%) scale(0.3); opacity: 0; }
}
/* Traînées de tir entre zone et bloc */
.shot-trail {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  width: 8px;
  height: 40px;
  border-radius: 50%;
  filter: blur(4px);
  animation: trailUp 0.35s ease-out forwards;
}
@keyframes trailUp {
  0%   { opacity: 1; transform: translateY(0) scaleY(1); }
  100% { opacity: 0; transform: translateY(-80px) scaleY(0.3); }
}
.splash {
  position: absolute;
  width: 22%;
  height: 18%;
  border-radius: 50%;
  animation: splash 0.3s ease-out forwards;
  pointer-events: none;
}
@keyframes splash {
  0%   { transform: scale(0.5); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ========================== SLOTS (zone de tir) ========================== */
.slots-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  padding: 6px 16px;
  max-width: 280px;
  margin: 0 auto;
  width: 100%;
}
.slot {
  aspect-ratio: 1;
  background: rgba(255,255,255,0.04);
  border: 2px dashed rgba(255,255,255,0.18);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  transition: all 0.2s;
  position: relative;
}
.slot.empty::before {
  content: '+';
  color: rgba(255,255,255,0.2);
  font-size: 24px;
  font-weight: 300;
}
.slot.filled {
  background: rgba(255,255,255,0.08);
  border-style: solid;
  border-color: rgba(255,255,255,0.15);
  position: relative;
}
.slot.filled::after {
  content: attr(data-ammo);
  position: absolute;
  bottom: 2px; right: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.5);
  padding: 1px 5px;
  border-radius: 6px;
}
.slot.firing .octopus-svg { animation: recoil 0.2s ease-out; }
.slot.available {
  border-color: rgba(255, 107, 166, 0.5);
  background: rgba(255, 107, 166, 0.05);
  cursor: pointer;
  animation: slotPulse 1.5s infinite ease-in-out;
}
.slot.available:active { transform: scale(0.95); }
@keyframes slotPulse {
  0%, 100% { border-color: rgba(255, 107, 166, 0.3); }
  50% { border-color: rgba(255, 107, 166, 0.8); }
}
@keyframes recoil {
  0% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
  100% { transform: translateY(0); }
}

/* ========================== STOCK ========================== */
.stock-wrap {
  padding: 6px 16px 16px;
  max-width: 280px;
  margin: 0 auto;
  width: 100%;
}
.stock-label {
  font-size: 12px;
  color: #8b93b8;
  margin-bottom: 6px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.stock {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 3px;
  background: rgba(0,0,0,0.3);
  border-radius: 12px;
  padding: 5px;
  min-height: 90px;
  align-items: center;
}
.octopus-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  position: relative;
}
.octopus-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.octopus-wrap.stock-slot {
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
  background: rgba(255,255,255,0.04);
}
.octopus-wrap.stock-slot:not(.empty):hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.octopus-wrap.stock-slot:not(.empty):active {
  transform: translateY(0) scale(0.95);
}
.octopus-wrap.stock-slot.empty {
  opacity: 0.15;
  cursor: default;
  border: 2px dashed rgba(255,255,255,0.1);
  background: transparent;
}
.octopus-wrap.stock-slot.flash-error {
  animation: stockShake 0.4s;
}
@keyframes stockShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
/* Compteur munitions sur la pieuvre du stock */
.octopus-ammo {
  position: absolute;
  bottom: -2px; right: -2px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  background: rgba(0,0,0,0.85);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid rgba(255,255,255,0.3);
  line-height: 1;
}
.octopus-wrap.locked { opacity: 0.25; filter: grayscale(0.8); }
.octopus-wrap.next { animation: pulse 1.2s infinite ease-in-out; cursor: default; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ========================== WIN ========================== */
#win { align-items: center; justify-content: center; padding: 24px; }
.win-inner { text-align: center; max-width: 360px; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.win-burst { font-size: 72px; animation: bounce 0.6s ease-out; }
@keyframes bounce {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}
#win h2 { font-size: 26px; color: #ffa76b; }
#win-msg { color: #b8bee0; font-size: 15px; }
.score-display {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: rgba(255, 167, 107, 0.12);
  border: 1px solid rgba(255, 167, 107, 0.3);
  border-radius: 14px;
  padding: 12px 20px;
}
.score-val { font-size: 36px; font-weight: 800; color: #ffa76b; }
.score-lbl { font-size: 14px; color: #b8bee0; text-transform: uppercase; letter-spacing: 1px; }

/* ========================== OVERLAY ========================== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.overlay-inner {
  background: #1a2147;
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}

/* ========================== Responsive ========================== */
@media (max-height: 700px) {
  .logo-octopus { font-size: 48px; }
  .logo h1 { font-size: 32px; }
  .how-to { display: none; }
}