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

body {
  background: #e0e5ec;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: #4a5568;
  user-select: none;
  overflow-x: hidden;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #5a6478;
  margin-bottom: 24px;
  text-shadow: 2px 2px 4px #ffffff, -1px -1px 3px #b8bec7;
}

.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* Neumorphic card */
.neo {
  background: #e0e5ec;
  border-radius: 16px;
  box-shadow: 6px 6px 14px #b8bec7, -6px -6px 14px #ffffff;
  padding: 20px;
}

/* Inset panel */
.neo-inset {
  background: #e0e5ec;
  border-radius: 12px;
  box-shadow: inset 4px 4px 10px #b8bec7, inset -4px -4px 10px #ffffff;
}

/* ── Board canvas ── */
#board {
  display: block;
  border-radius: 10px;
  box-shadow: inset 4px 4px 12px #b8bec7, inset -4px -4px 12px #ffffff;
  touch-action: none; /* Android : désactive le scroll natif sur le canvas */
}

/* ── Side panel ── */
.side {
  width: 170px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-block {
  padding: 0;
}

/* Sections internes séparées par un trait */
.panel-section {
  padding: 12px 14px;
}

.panel-section + .panel-section {
  border-top: 1px solid rgba(184,190,199,0.4);
}

.panel-section h3,
.side-block.controls h3 {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8a95a3;
  margin-bottom: 10px;
}

/* Stats : Score / Lignes / Niveau */
.stats-block {
  display: flex;
  flex-direction: column;
}

.stats-block .stat {
  padding: 4px 0;
}

.stats-block .stat + .stat {
  border-top: 1px solid rgba(184,190,199,0.25);
}

.value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #5a6478;
  text-shadow: 1px 1px 2px #ffffff, -1px -1px 2px #b8bec7;
}

.value.small {
  font-size: 1.1rem;
}

#preview-canvas {
  display: block;
  margin: 0 auto;
  border-radius: 8px;
  box-shadow: inset 3px 3px 8px #b8bec7, inset -3px -3px 8px #ffffff;
}

/* ── Buttons ── */
.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

button {
  background: #e0e5ec;
  border: none;
  border-radius: 10px;
  box-shadow: 4px 4px 10px #b8bec7, -4px -4px 10px #ffffff;
  color: #5a6478;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 10px 0;
  width: 100%;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}

button:hover {
  box-shadow: 5px 5px 12px #b8bec7, -5px -5px 12px #ffffff;
}

button:active {
  box-shadow: inset 3px 3px 8px #b8bec7, inset -3px -3px 8px #ffffff;
  transform: scale(0.98);
}

button.active-pause {
  box-shadow: inset 3px 3px 8px #b8bec7, inset -3px -3px 8px #ffffff;
  color: #7c8fa3;
}

/* ── Controls legend ── */
.controls {
  font-size: 0.68rem;
  color: #8a95a3;
  line-height: 1.9;
  padding: 12px 14px;
}

.controls span {
  display: inline-block;
  background: #e0e5ec;
  border-radius: 5px;
  box-shadow: 2px 2px 5px #b8bec7, -2px -2px 5px #ffffff;
  padding: 1px 6px;
  font-size: 0.65rem;
  color: #5a6478;
  font-weight: 600;
  margin-right: 4px;
}

/* ── Overlay ── */
#overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(224, 229, 236, 0.88);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#overlay h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: #5a6478;
}

#overlay p {
  font-size: 0.8rem;
  color: #8a95a3;
}

.board-wrap {
  position: relative;
}

/* ── High scores ── */
#highscores-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.72rem;
  color: #5a6478;
  line-height: 2;
}

#highscores-list li {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

#highscores-list li .hs-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

#highscores-list li .hs-score {
  font-weight: 700;
  color: #7c8fa3;
  flex-shrink: 0;
}

#highscores-list:empty::after {
  content: "Aucun score";
  font-size: 0.68rem;
  color: #a0aab4;
}

/* ── Name form inside overlay ── */
#name-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

#name-warning {
  font-size: 0.72rem;
  color: #c0392b;
  text-align: center;
  margin: 0;
}

#player-name {
  background: #e0e5ec;
  border: none;
  border-radius: 8px;
  box-shadow: inset 3px 3px 7px #b8bec7, inset -3px -3px 7px #ffffff;
  color: #5a6478;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  width: 140px;
  text-align: center;
  outline: none;
}

#player-name::placeholder { color: #a0aab4; font-weight: 400; }

#btn-save-score {
  width: 140px;
  padding: 8px 0;
}

#btn-reset-scores {
  margin-top: 8px;
  width: 100%;
  padding: 5px 0;
  font-size: 0.65rem;
  color: #a0aab4;
  box-shadow: 3px 3px 7px #b8bec7, -3px -3px 7px #ffffff;
}

/* ── Admin ── */
#admin-status {
  font-size: 0.65rem;
  color: #8a95a3;
  margin-top: 4px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Touch controls (hidden on desktop) ── */
#touch-controls {
  display: none;
}

/* ── Mobile layout ── */
@media (max-width: 700px) {
  h1 {
    font-size: 1.4rem;
    margin-bottom: 14px;
  }

  .layout {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 0 10px;
  }

  /* Sur mobile : panneau gauche en haut, panneau droit en bas, board au milieu */
  .layout { order: 0; }
  .side:first-child  { order: 1; width: 100%; max-width: 340px; }
  .board-wrap        { order: 2; }
  .side:last-child   { order: 3; width: 100%; max-width: 340px; }

  /* Les deux panneaux côte à côte sur mobile */
  .layout > .side {
    width: 100%;
    max-width: 340px;
  }

  /* Reorganise : panneau gauche en haut en ligne */
  .side {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    max-width: 340px;
    gap: 10px;
  }

  .side-block {
    flex: 1 1 140px;
  }

  /* Boutons tactiles */
  #touch-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 340px;
    padding: 10px 0 4px;
  }

  .touch-row {
    display: flex;
    gap: 12px;
    justify-content: center;
  }

  .touch-btn {
    width: 72px;
    height: 72px;
    font-size: 1.5rem;
    border-radius: 16px;
    background: #e0e5ec;
    border: none;
    box-shadow: 4px 4px 10px #b8bec7, -4px -4px 10px #ffffff;
    color: #5a6478;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; /* Android : désactive TOUT scroll/zoom sur ces boutons */
    transition: box-shadow 0.1s, transform 0.08s;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
  }

  .touch-btn:active {
    box-shadow: inset 3px 3px 8px #b8bec7, inset -3px -3px 8px #ffffff;
    transform: scale(0.93);
  }

  .touch-btn.small-btn {
    width: 72px;
    height: 50px;
    font-size: 1.1rem;
  }
}
