:root {
  --accent: #2f6fed;
  /* Côté de la grille : le plus grand carré qui tient dans la fenêtre. */
  --board: max(280px, min(100vw - 32px, 100vh - 160px, 1100px));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #26272b;
  color: #ececec;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 20px;
  padding: 14px 16px;
}

.toolbar h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.size {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-buttons {
  display: flex;
  gap: 12px;
}

button,
select {
  font: inherit;
  color: inherit;
  background: #3a3c42;
  border: 1px solid #55575e;
  border-radius: 6px;
  padding: 6px 12px;
}

button:enabled,
select:enabled {
  cursor: pointer;
}

button:disabled,
select:disabled {
  opacity: 0.45;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Mobile : barre d'outils alignée sur la grille, le sélecteur sur toute la
   largeur restante et deux boutons égaux, assez hauts pour le doigt. */
@media (max-width: 600px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    width: min(100% - 32px, var(--board));
    margin: 0 auto;
    padding-inline: 0;
  }

  .toolbar h1 {
    justify-content: center;
  }

  .size select {
    flex: 1;
    min-width: 0;
  }

  .toolbar-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .toolbar select,
  .toolbar button {
    min-height: 44px;
    padding-inline: 8px;
  }
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 16px;
}

/* La marge extérieure et les écarts valent 1/60 du côté, comme à l'export. */
.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  flex: none;
  width: var(--board);
  height: var(--board);
  gap: calc(var(--board) / 60);
  padding: calc(var(--board) / 60);
  background: #fff;
}

.cell {
  position: relative;
  overflow: hidden;
}

.pick {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #e4e5e8;
  color: #6b6e76;
  user-select: none;
}

.pick:hover {
  background: #d8dae0;
}

.pick:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.pick img {
  position: absolute;
  max-width: none;
  pointer-events: none;
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 8px;
  font-size: 13px;
}

.placeholder b {
  font-size: 40px;
  font-weight: 300;
  line-height: 1;
}

.filled .placeholder {
  display: none;
}

.filled .pick {
  cursor: grab;
  touch-action: none;
}

.filled .pick:active {
  cursor: grabbing;
}

.handle,
.zoom {
  position: absolute;
  opacity: 0;
  transition: opacity 0.15s;
  touch-action: none;
}

.handle {
  top: 6px;
  left: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: #fff;
  background: rgb(0 0 0 / 0.6);
  border: 0;
}

.handle:enabled {
  cursor: move;
}

.zoom {
  bottom: 8px;
  left: 10%;
  width: 80%;
  margin: 0;
  accent-color: var(--accent);
  filter: drop-shadow(0 0 3px rgb(0 0 0 / 0.7));
  cursor: pointer;
}

.cell:not(.filled) .handle,
.cell:not(.filled) .zoom {
  display: none;
}

.cell:hover .handle,
.cell:hover .zoom,
.cell:focus-within .handle,
.cell:focus-within .zoom {
  opacity: 1;
}

/* Écran tactile : pas de survol, les commandes restent visibles. */
@media (hover: none) {
  .handle,
  .zoom {
    opacity: 1;
  }
}

.cell.loading::before {
  content: "Chargement…";
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: rgb(255 255 255 / 0.75);
  color: #333;
  pointer-events: none;
}

.cell.target::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border: 4px solid var(--accent);
  background: rgb(47 111 237 / 0.25);
  pointer-events: none;
}

.cell.source {
  opacity: 0.4;
}

.ghost {
  position: fixed;
  z-index: 10;
  overflow: hidden;
  opacity: 0.85;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.5);
  pointer-events: none;
}

.ghost img {
  position: absolute;
  max-width: none;
}

.hint {
  max-width: var(--board);
  margin: 12px 0 0;
  color: #a9abb2;
  font-size: 13px;
  text-align: center;
  text-wrap: balance;
}

.hint-touch {
  display: none;
}

/* Même critère que pour les commandes des cases : un écran sans survol. */
@media (hover: none) {
  .hint-mouse {
    display: none;
  }

  .hint-touch {
    display: block;
  }
}

.message {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: #111;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.4);
}

.message.error {
  background: #8f1d1d;
}

dialog {
  max-width: 360px;
  padding: 20px;
  border: 1px solid #55575e;
  border-radius: 10px;
  background: #2f3035;
  color: inherit;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}

dialog p {
  margin: 0 0 18px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
