:root {
  color-scheme: light;
  --primary: #ff66aa;
  --primary-dark: #d94b87;
  --bg: linear-gradient(180deg, #ffe3f2 0%, #fff7fb 100%);
  --text: rgba(39, 33, 60, 0.78);
  --panel-bg: rgba(255, 255, 255, 0.85);
  --border: rgba(255, 102, 170, 0.25);
}

html,
body {
  /* Empêche le pull-to-refresh et les gestuelles de navigation lors des drags */
  overscroll-behavior: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 0; /* Explicitly set padding to 0 */
  min-height: 100vh;
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

.auth-shell {
  width: min(100%, 480px);
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 8vw, 3.4rem);
  font-family: "Pacifico", cursive;
}

.brand p {
  margin: 0.5rem 0 0;
}

p {
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
  font-size: 1rem;
  margin: 0;
}

.auth-panel {
  background: var(--panel-bg);
  padding: clamp(1rem, 4vw, 2rem);
  border-radius: 20px;
  box-shadow: 0 16px 40px -20px rgba(210, 80, 160, 0.7);
  backdrop-filter: blur(8px);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.75rem;
  border: none;
  border-radius: 14px;
  background: rgba(255, 102, 170, 0.15);
  color: var(--text);
  font-weight: 600;
  cursor: grab;
  transition: background 0.2s ease, transform 0.2s ease;
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.tab:focus-visible {
  outline: 3px solid rgba(255, 102, 170, 0.5);
  outline-offset: 2px;
}

.auth-form {
  display: grid;
  gap: 0.75rem;
}

.auth-form[hidden] {
  display: none;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
}

input {
  width: 100%;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background-color: rgba(255, 255, 255, 0.9);
}

input:focus {
  outline: 3px solid rgba(255, 102, 170, 0.35);
  border-color: transparent;
}

.password-input-wrapper {
  position: relative;
  width: 100%;
}

.password-input-wrapper input {
  padding-right: 3rem; /* Make room for the toggle button */
}

.password-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.25rem;
  opacity: 0.6;
  transition: opacity 0.2s ease, background 0.2s ease;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
}

.password-toggle:hover {
  opacity: 1;
  background: rgba(255, 102, 170, 0.1);
}

.password-toggle:focus-visible {
  outline: 2px solid rgba(255, 102, 170, 0.5);
  outline-offset: 2px;
  opacity: 1;
}

.password-toggle[aria-pressed="true"] {
  opacity: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.75rem;
  background: linear-gradient(120deg, var(--primary) 0%, var(--primary-dark) 100%);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 16px 35px -20px rgba(210, 80, 160, 0.9);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 40px -22px rgba(210, 80, 160, 1);
}

.btn:focus-visible {
  outline: 3px solid rgba(255, 102, 170, 0.35);
  outline-offset: 2px;
}

.btn--full {
  width: 100%;
}

.btn--stretch {
  align-self: stretch;
  justify-content: center;
  width: 100%;
}

.btn--wide {
  padding-inline: 2.5rem;
}

.btn--center {
  justify-self: center;
}

.auth-form .btn {
  width: 100%;
  margin-top: 0.5rem;
}

.feedback {
  min-height: 1.25rem;
  margin: 0;
  font-size: 0.85rem;
  color: var(--primary-dark);
}

.album-body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: var(--bg);
}

.album-shell {
  width: min(100%, 620px);
  padding: clamp(1.5rem, 4vw, 3rem);
  display: grid;
  gap: clamp(1.25rem, 4vw, 2rem);
  justify-items: center;
  text-align: center;
  margin: 0 auto;
}

.album-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}

@media (min-width: 768px) {
  /* iPad/tablettes: alléger les effets pour limiter les freezes GPU */
  @supports (-webkit-touch-callout: none) {
    .tile {
      filter: drop-shadow(0 6px 8px rgba(39, 33, 60, 0.1));
      transition: transform 0.1s ease;
    }
    .board {
      box-shadow: 0 20px 40px -32px rgba(210, 80, 160, 0.6);
    }
    .board-overlay { backdrop-filter: none; }
    .tile--syrup::after { backdrop-filter: none; }
  }
  .album-actions {
    flex-direction: row;
    justify-content: center;
  }
}

.album-note {
  margin: 0;
  margin-top: 0.75rem;
  max-width: 36ch;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.5;
}

.album-header p {
  margin: 0.75rem auto 0;
  max-width: 32ch;
}

.play-link {
  display: inline-flex;
  justify-content: center;
  width: auto;
  text-decoration: none;
}

.play-link:hover,
.play-link:focus {
  text-decoration: none;
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: clamp(1rem, 4vw, 1.25rem);
  width: 100%;
  justify-content: center;
  justify-items: center;
}

.album-grid figure {
  margin: 0;
  padding: 1.25rem 0.75rem;
  border-radius: 18px;
  border: 1px solid rgba(255, 102, 170, 0.25);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  width: min(100%, 160px);
  margin-inline: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.album-grid figure:focus,
.album-grid figure:focus-visible,
.album-grid figure:active {
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.album-grid figure::after {
  content: attr(data-progress);
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: rgba(39, 33, 60, 0.75);
}

.album-grid figure:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 32px -24px rgba(210, 80, 160, 0.7);
}

.album-grid img {
  width: min(100%, 120px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  filter: grayscale(100%);
  opacity: 0.75;
}

.album-grid figcaption {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.album-grid figure.unlocked img {
  filter: none;
  opacity: 1;
}

.album-footer {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: clamp(1.5rem, 5vw, 2.5rem);
}

.game-body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: var(--bg);
}

.game-shell {
  width: 100%; /* Use full width on mobile */
  max-width: none; /* Remove max-width restriction on mobile */
  padding: clamp(0.5rem, 1.5vw, 1rem); /* Minimal padding for mobile */
  display: flex;
  flex-direction: column;
  gap: clamp(0.75rem, 2vw, 1.5rem); /* Reduced gap for mobile */
  margin: 0 auto;
  /* Évite les rebonds/gestes de scroll au sein du conteneur */
  overscroll-behavior: contain;
}

@media (min-width: 768px) {
  .game-shell {
    width: min(100%, 1080px);
    max-width: 1080px;
    padding: clamp(0.75rem, 2vw, 1.5rem);
    gap: clamp(1rem, 3vw, 2rem);
  }
}

.game-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  text-align: center;
  position: relative;
}

.game-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  position: relative;
}

.btn--rules,
.btn--music,
.btn--install {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  min-width: auto;
}

.btn--music {
  font-size: 1.2rem;
  padding: 0.5rem 0.75rem;
}

.btn--install {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn--install:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn--install.show {
  display: block !important;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-shell .btn--install {
  width: 100%;
  margin-bottom: 1rem;
}

.game-identity p {
  margin: 0.5rem 0 0;
  max-width: 42ch;
  font-size: 1.05rem;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 3vw, 1.5rem); /* Reduced gap */
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}





.hud-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  padding: 0.75rem 0.85rem; /* Reduced padding */
  box-shadow: 0 12px 24px -20px rgba(210, 80, 160, 0.6);
  display: grid;
  gap: 0.25rem;
  text-align: center;
  max-width: 100%; /* Ensure it doesn't overflow */
  box-sizing: border-box;
}

.hud-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.board-wrapper {
  grid-area: board;
  position: relative;
  width: min(100%, calc(100vw)); /* Use almost full viewport width with small padding */
  max-width: none; /* Remove max-width restriction on mobile */
  margin: 0 auto;
  overscroll-behavior: contain;
}

@media (min-width: 768px) {
  .board-wrapper {
    width: min(100%, 85vw); /* Use viewport width on tablet */
    max-width: 900px; /* Increased from 750px for better tablet experience */
  }
}

@media (min-width: 1024px) {
  .board-wrapper {
    width: min(100%, 800px);
    max-width: 900px; /* Increased from 800px for better desktop experience */
  }
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: clamp(14px, 4vw, 26px);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 30px 60px -35px rgba(210, 80, 160, 0.9);
  overflow: hidden;
  touch-action: none; /* Bloque les gestes de scroll pendant un drag sur le plateau */
}

.board canvas {
  width: 100%;
  height: 100% !important;
  display: block;
  border-radius: clamp(12px, 3.2vw, 20px);
  margin: 0 !important;
  touch-action: none;
}

.tile {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background-color: transparent;
  background-size: 85%; /* Slightly smaller to show background color border */
  background-repeat: no-repeat;
  background-position: center;
  border: none;
  outline: none;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  filter: drop-shadow(0 10px 14px rgba(39, 33, 60, 0.18));
  /* Optimizations for mobile animations */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform, background-image; /* Hint browser about transform changes */
  /* Prevent unnecessary repaints */
  contain: layout style paint;
  /* iOS flicker mitigations */
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.skip-animations .board,
.skip-animations .board canvas {
  box-shadow: none;
}

.skip-animations .tile {
  transition: none !important;
  filter: none !important;
  box-shadow: none !important;
}

@media (max-width: 767px) {
  .tile {
    /* Reduce expensive effects on mobile */
    filter: drop-shadow(0 6px 8px rgba(39, 33, 60, 0.12));
    transition: transform 0.12s ease; /* Faster transitions on mobile */
  }
}

/* Further optimizations for very low-end devices */
@media (max-width: 480px) {
  .tile {
    /* Minimal effects for very small screens */
    filter: drop-shadow(0 4px 6px rgba(39, 33, 60, 0.1));
    transition: transform 0.1s ease;
  }

  .board {
    /* Keep reasonable padding and gaps even on very small screens */
    gap: clamp(0.2rem, 1vw, 0.3rem);
    padding: 0.2rem;
  }
}

.tile:focus-visible {
  outline: 2px solid rgba(255, 102, 170, 0.6);
  outline-offset: 2px;
}

.tile--dragging {
  cursor: grabbing;
  z-index: 2;
}

.tile--matched {
  animation: sparkle 0.4s ease forwards;
}

.tile--hint {
  box-shadow: 0 0 20px rgba(255, 102, 170, 0.8), 0 0 40px rgba(255, 102, 170, 0.6);
  animation: hintPulse 0.6s ease-in-out infinite;
  z-index: 3;
}

@keyframes hintPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 20px rgba(255, 102, 170, 0.8), 0 0 40px rgba(255, 102, 170, 0.6);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 102, 170, 1), 0 0 60px rgba(255, 102, 170, 0.8);
  }
}

@media (max-width: 767px) {
  .tile--hint {
    /* Simpler animation on mobile for better performance */
    animation: hintPulse 0.8s ease-in-out infinite;
  }
  
  @keyframes hintPulse {
    0%, 100% {
      transform: scale(1);
      box-shadow: 0 0 15px rgba(255, 102, 170, 0.7);
    }
    50% {
      transform: scale(1.03);
      box-shadow: 0 0 25px rgba(255, 102, 170, 0.9);
    }
  }
}

.tile--empty {
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.tile--blocked {
  cursor: not-allowed;
  filter: grayscale(100%);
  opacity: 0.5;
}

/* Tiles with ice cannot be dragged */
.tile--icing,
.tile--double-icing {
  cursor: not-allowed;
}

.tile--icing:has(.tile--dragging),
.tile--double-icing:has(.tile--dragging) {
  pointer-events: none;
}

.tile--icing::after,
.tile--double-icing::after,
.tile--syrup::after,
.tile--jelly::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.tile--icing::after {
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 0 0 2px rgba(193, 220, 255, 0.8);
}

.tile--double-icing::after {
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.75), rgba(210, 220, 255, 0.95));
  box-shadow: inset 0 0 0 3px rgba(139, 170, 255, 0.8);
}

.tile--syrup::after {
  background: rgba(255, 120, 80, 0.25);
  box-shadow: inset 0 0 0 2px rgba(255, 120, 80, 0.5);
  backdrop-filter: blur(2px);
}

.tile--jelly::after {
  background: rgba(255, 102, 170, 0.18);
  box-shadow: inset 0 0 0 2px rgba(255, 102, 170, 0.35);
}

.tile--power::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: inherit;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  animation: pulse 1.2s linear infinite;
}

.tile--ray::before {
  background: linear-gradient(120deg, rgba(255, 102, 170, 0.65), rgba(255, 210, 250, 0.45));
}

.tile--bomb::before {
  background: radial-gradient(circle, rgba(255, 102, 170, 0.8), rgba(217, 75, 135, 0.9));
}

.board-overlay {
  position: absolute;
  inset: 0;
  border-radius: 26px;
  background: rgba(255, 247, 251, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  backdrop-filter: blur(4px);
}

.overlay-content {
  display: grid;
  gap: 0.75rem;
}

.overlay-content h3 {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-family: "Pacifico", cursive;
}

.overlay-content p {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
}

.board-panel {
  display: grid;
  gap: clamp(1rem, 3vw, 1.5rem);
  grid-template-columns: 1fr;
  width: min(100%, calc(100vw - 1rem)); /* Use almost full viewport width with minimal padding */
  max-width: none; /* Remove max-width restriction on mobile */
  margin: 0 auto;
  grid-template-areas:
    "board"
    "hud"
    "objectives"
    "message"
    "actions";
}

.hud {
  grid-area: hud;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); /* Reduced min-width from 140px */
  gap: 0.75rem;
  width: 100%;
  max-width: 100%; /* Ensure it doesn't overflow */
}

.objectives-panel {
  grid-area: objectives;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  padding: 1rem; /* Reduced from 1.25rem */
  box-shadow: 0 12px 24px -20px rgba(210, 80, 160, 0.6);
  display: grid;
  gap: 0.75rem; /* Reduced from 1rem */
  max-width: 100%; /* Ensure it doesn't overflow */
  box-sizing: border-box;
}

.objectives-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
}

.objectives-list {
  display: grid;
  gap: 1rem;
}

.objective-item {
  display: grid;
  gap: 0.5rem;
}

.objective-text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.objective-icon {
  font-size: 1.2rem;
}

.objective-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.objective-value {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

.objective-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 102, 170, 0.15);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.objective-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: 999px;
  transition: width 0.3s ease;
  min-width: 0;
}

.level-message {
  grid-area: message;
  margin: 0.5rem 0 0;
  min-height: 1.5rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

@keyframes sparkle {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.5;
  }
  100% {
    transform: scale(0.8);
    opacity: 0;
  }
}

@keyframes pulse {
  0% {
    opacity: 0.9;
  }
  50% {
    opacity: 0.4;
  }
  100% {
    opacity: 0.9;
  }
}

@keyframes rayPulse {
  0% {
    transform: scale(1);
    opacity: 0.85;
  }
  60% {
    transform: scale(1.1);
    opacity: 0.35;
  }
  100% {
    transform: scale(1.2);
    opacity: 0.05;
  }
}

@keyframes bombPulse {
  0% {
    transform: scale(0.8);
    opacity: 0.9;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.4;
  }
  100% {
    transform: scale(1.45);
    opacity: 0;
  }
}

@media (min-width: 768px) {
  body {
    align-items: center;
  }

  .auth-shell {
    padding: 2.5rem 3rem;
  }

  .auth-panel {
    border-radius: 28px;
  }

  .btn--stretch {
    width: auto;
    align-self: center;
    padding-inline: 1.75rem;
  }

  .board-wrapper {
    width: min(100%, 85vw); /* Use viewport width on tablet */
    max-width: 900px; /* Increased from 750px */
  }

  .board {
    padding: clamp(0.4rem, 1vw, 1.1rem);
  }

  .board-panel {
    width: 100%; /* Further reduced from 90vw */
    max-width: 1100px; /* Further reduced from 1200px */
    grid-template-columns: minmax(500px, 1.5fr) minmax(220px, 0.5fr); /* Right column even smaller - 220px min */
    grid-template-areas:
      "board hud"
      "board objectives"
      "board message"
      "board actions";
    align-items: start;
  }

  .level-message {
    text-align: left;
    align-self: center;
  }

  .exit-btn {
    justify-self: flex-start;
  }
}

@media (min-width: 1024px) {
  .board-wrapper {
    width: min(100%, 900px); /* Increased from 800px */
    max-width: 950px; /* Increased from 900px */
  }

  .board-panel {
    width: min(100%, 1300px); /* Further reduced from 1400px */
    grid-template-columns: minmax(600px, 1.6fr) minmax(250px, 0.4fr); /* Right column even smaller - 250px min */
  }
}

.exit-btn {
  grid-area: actions;
  justify-self: center;
  margin-top: 0.5rem;
}

/* Modal des règles */
.rules-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.rules-modal[hidden] {
  display: none;
}

.rules-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(39, 33, 60, 0.75);
  backdrop-filter: blur(4px);
}

.rules-modal-content {
  position: relative;
  background: var(--panel-bg);
  border-radius: 24px;
  padding: 2rem;
  max-width: min(100%, 600px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px -20px rgba(210, 80, 160, 0.9);
  z-index: 1;
  display: grid;
  gap: 1.5rem;
}

.rules-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: rgba(255, 102, 170, 0.15);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
}

.rules-modal-close:hover {
  background: rgba(255, 102, 170, 0.25);
  transform: scale(1.1);
}

.rules-modal-close:focus-visible {
  outline: 3px solid rgba(255, 102, 170, 0.5);
  outline-offset: 2px;
}

.rules-title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-family: "Pacifico", cursive;
  text-align: center;
  color: var(--primary);
}

.rules-section {
  display: grid;
  gap: 0.75rem;
}

.rules-section h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.rules-section p {
  margin: 0;
  line-height: 1.6;
}

.rules-list {
  margin: 0;
  padding-left: 1.5rem;
  display: grid;
  gap: 0.5rem;
}

.rules-list li {
  line-height: 1.6;
}

.rules-power,
.rules-obstacle {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  background: rgba(255, 102, 170, 0.08);
  border-radius: 12px;
  border: 1px solid rgba(255, 102, 170, 0.2);
}

.rules-power-visual,
.rules-obstacle-visual {
  display: flex;
  align-items: center;
  justify-content: center;
}

.rules-power-text,
.rules-obstacle-text {
  line-height: 1.6;
}

.rules-power-text strong,
.rules-obstacle-text strong {
  color: var(--primary-dark);
}

/* Visuels de démonstration des tiles */
.tile-demo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: #fff;
  position: relative;
  box-shadow: 0 6px 18px rgba(210, 80, 160, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.tile-demo img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  position: relative;
  z-index: 2;
}

.tile-demo--power[data-tile="ray-row"] {
  background: linear-gradient(135deg, #e9f2ff 0%, #f6fbff 100%);
  box-shadow: 0 8px 18px rgba(100, 180, 255, 0.35);
}

.tile-demo--power[data-tile="ray-row"]::before,
.tile-demo--power[data-tile="ray-row"]::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 2px solid rgba(100, 180, 255, 0.9);
  box-shadow: 0 0 12px rgba(100, 180, 255, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  animation: rayPulse 1.4s ease-in-out infinite;
  z-index: 1;
}

.tile-demo--power[data-tile="ray-row"]::after {
  border-style: solid;
  border-width: 2px 0;
  border-color: rgba(255, 255, 255, 0.7);
  inset: 21px 10px;
  animation: none;
  opacity: 0.75;
}

.tile-demo--power[data-tile="bomb"] {
  background: linear-gradient(135deg, #ffe5f2 0%, #ffd7eb 100%);
  box-shadow: 0 8px 18px rgba(255, 90, 122, 0.3);
}

.tile-demo--power[data-tile="bomb"]::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 122, 170, 0.6);
  box-shadow: 0 0 18px rgba(255, 122, 170, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  animation: bombPulse 1.2s ease-in-out infinite;
  z-index: 1;
}

.tile-demo--power[data-tile="bomb"]::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
  z-index: 3;
}

.tile-demo--power[data-tile="cross"] {
  background: linear-gradient(135deg, #e8f7ed 0%, #f4fff7 100%);
  box-shadow: 0 8px 18px rgba(51, 184, 100, 0.28);
}

.tile-demo--power[data-tile="cross"]::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 12px;
  border: 2px dashed rgba(51, 184, 100, 0.9);
  box-shadow: 0 0 14px rgba(51, 184, 100, 0.35);
  background: linear-gradient(
      0deg,
      transparent 47%,
      rgba(51, 184, 100, 0.35) 47%,
      rgba(51, 184, 100, 0.35) 53%,
      transparent 53%
    ),
    linear-gradient(
      90deg,
      transparent 47%,
      rgba(51, 184, 100, 0.35) 47%,
      rgba(51, 184, 100, 0.35) 53%,
      transparent 53%
    );
  z-index: 1;
}

.tile-demo--power[data-tile="splash"] {
  background: linear-gradient(135deg, #fff3e3 0%, #fff8ed 100%);
  box-shadow: 0 8px 18px rgba(255, 179, 71, 0.3);
}

.tile-demo--power[data-tile="splash"]::before {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 14px;
  border: 2px dashed rgba(255, 179, 71, 0.9);
  box-shadow: 0 0 14px rgba(255, 179, 71, 0.35);
  background: radial-gradient(circle at 40% 40%, rgba(255, 232, 166, 0.55), transparent 50%),
    radial-gradient(circle at 65% 65%, rgba(255, 179, 71, 0.4), transparent 55%),
    radial-gradient(circle at 30% 70%, rgba(255, 215, 130, 0.4), transparent 50%);
  z-index: 1;
}

.tile-demo--jelly::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 102, 170, 0.18);
  box-shadow: inset 0 0 0 2px rgba(255, 102, 170, 0.35);
}

.tile-demo--icing::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 0 0 2px rgba(193, 220, 255, 0.8);
}

.tile-demo--double-icing::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.75), rgba(210, 220, 255, 0.95));
  box-shadow: inset 0 0 0 3px rgba(139, 170, 255, 0.8);
}

.tile-demo--syrup::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 120, 80, 0.25);
  box-shadow: inset 0 0 0 2px rgba(255, 120, 80, 0.5);
  backdrop-filter: blur(2px);
}

@media (max-width: 767px) {
  .rules-modal-content {
    padding: 1.5rem;
    max-height: 95vh;
  }

  .rules-title {
    font-size: 1.6rem;
  }

  .rules-power,
  .rules-obstacle {
    grid-template-columns: 1fr;
    text-align: center;
  }
  
  .game-header-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }
  
  .btn--rules,
  .btn--music,
  .btn--install {
    position: static;
    margin-top: 0.5rem;
    width: 100%;
  }

  .tile-demo {
    width: 50px;
    height: 50px;
  }

  .btn--rules {
    position: static;
    margin-top: 0.5rem;
  }
}

/* Modal pour afficher les stickers en grand */
.sticker-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.sticker-modal[hidden] {
  display: none;
}

.sticker-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(39, 33, 60, 0.85);
  backdrop-filter: blur(6px);
}

.sticker-modal-content {
  position: relative;
  background: var(--panel-bg);
  border-radius: 28px;
  padding: 2.5rem;
  max-width: min(100%, 500px);
  box-shadow: 0 32px 64px -20px rgba(210, 80, 160, 1);
  z-index: 1;
  display: grid;
  gap: 1.5rem;
  text-align: center;
  align-items: center;
}

.sticker-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: rgba(255, 102, 170, 0.15);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
}

.sticker-modal-close:hover {
  background: rgba(255, 102, 170, 0.25);
  transform: scale(1.1);
}

.sticker-modal-close:focus-visible {
  outline: 3px solid rgba(255, 102, 170, 0.5);
  outline-offset: 2px;
}

.sticker-modal-image {
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 20px;
  margin: 0 auto;
  box-shadow: 0 16px 40px -20px rgba(210, 80, 160, 0.6);
}

.sticker-modal-title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-family: "Pacifico", cursive;
  color: var(--primary);
}

.sticker-modal-progress {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
  opacity: 0.8;
}

@media (max-width: 767px) {
  .sticker-modal-content {
    padding: 2rem 1.5rem;
  }

  .sticker-modal-title {
    font-size: 1.6rem;
  }
}

/* Modal pour le classement */
.leaderboard-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.leaderboard-modal[hidden] {
  display: none;
}

.leaderboard-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(39, 33, 60, 0.85);
  backdrop-filter: blur(6px);
}

.leaderboard-modal-content {
  position: relative;
  background: var(--panel-bg);
  border-radius: 24px;
  padding: 2rem;
  max-width: min(100%, 600px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px -20px rgba(210, 80, 160, 0.9);
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.leaderboard-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: rgba(255, 102, 170, 0.15);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
}

.leaderboard-modal-close:hover {
  background: rgba(255, 102, 170, 0.25);
  transform: scale(1.1);
}

.leaderboard-modal-close:focus-visible {
  outline: 3px solid rgba(255, 102, 170, 0.5);
  outline-offset: 2px;
}

.leaderboard-modal-title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-family: "Pacifico", cursive;
  color: var(--primary);
  text-align: center;
}

.leaderboard-loading {
  text-align: center;
  padding: 2rem;
  color: var(--text);
  opacity: 0.7;
}

.leaderboard-empty {
  text-align: center;
  padding: 2rem;
  color: var(--text);
  opacity: 0.7;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  border: 2px solid transparent;
  transition: all 0.2s ease;
}

.leaderboard-item:hover {
  background: rgba(255, 255, 255, 0.7);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 102, 170, 0.2);
}

.leaderboard-item--current {
  background: rgba(255, 102, 170, 0.15);
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(255, 102, 170, 0.3);
}

.leaderboard-rank {
  font-size: 1.5rem;
  font-weight: bold;
  min-width: 3rem;
  text-align: center;
  color: var(--primary);
}

.leaderboard-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-username {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text);
}

.leaderboard-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text);
  opacity: 0.8;
}

.leaderboard-stat {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.btn--leaderboard {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  color: #333;
  border: none;
  font-weight: 600;
}

.btn--leaderboard:hover {
  background: linear-gradient(135deg, #ffed4e 0%, #ffd700 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

@media (max-width: 767px) {
  .leaderboard-modal-content {
    padding: 1.5rem;
    max-height: 95vh;
    width: 100%;
  }

  .leaderboard-modal-title {
    font-size: 1.6rem;
  }

  .leaderboard-item {
    padding: 0.75rem;
  }

  .leaderboard-rank {
    font-size: 1.2rem;
    min-width: 2.5rem;
  }

  .leaderboard-stats {
    flex-direction: column;
    gap: 0.5rem;
  }
}
