.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  align-items: start;
  gap: 18px;
}

.board-wrap {
  position: relative;
  width: min(100%, calc(100svh - 150px));
  max-width: 720px;
  margin: 0 auto;
  aspect-ratio: 1;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(31, 35, 40, 0.18);
  border-radius: 8px;
  background: rgba(31, 35, 40, 0.13);
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(31, 35, 40, 0.18);
  touch-action: none;
}

.tile {
  position: absolute;
  width: calc(100% / var(--size));
  height: calc(100% / var(--size));
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 6px;
  background-image: var(--image);
  background-size: calc(var(--size) * 100%) calc(var(--size) * 100%);
  cursor: pointer;
  transition:
    transform 150ms ease,
    filter 150ms ease,
    box-shadow 150ms ease;
  will-change: transform;
}

.tile::after {
  content: attr(data-label);
  position: absolute;
  right: 8px;
  bottom: 7px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.82);
  color: rgba(31, 35, 40, 0.72);
  font-size: clamp(0.7rem, 2.3vw, 0.88rem);
  font-weight: 800;
}

.tile:active {
  filter: brightness(1.05);
  box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.12);
}

.tile.selected {
  z-index: 2;
  box-shadow:
    inset 0 0 0 4px var(--warn),
    0 10px 24px rgba(31, 35, 40, 0.22);
  filter: saturate(1.08) brightness(1.04);
}

.tile.dragging {
  z-index: 3;
  box-shadow: 0 18px 36px rgba(31, 35, 40, 0.3);
  filter: saturate(1.1) brightness(1.06);
  transition:
    filter 120ms ease,
    box-shadow 120ms ease;
}

.board.swap-mode {
  background: rgba(255, 255, 255, 0.38);
}

.complete {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(246, 241, 232, 0.78);
  backdrop-filter: blur(8px);
  text-align: center;
}

.complete div {
  width: min(320px, 82%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.complete strong,
.complete span {
  display: block;
}

.complete strong {
  font-size: 2rem;
}

.complete span {
  margin-top: 6px;
  color: var(--muted);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.preview canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

.controls {
  display: grid;
  gap: 14px;
}

.control-row {
  display: grid;
  gap: 8px;
}

.control-row > span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.55);
}

.mode-segments {
  grid-template-columns: repeat(2, 1fr);
}

.segment {
  min-height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

#imageInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 820px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    width: min(100%, calc(100svh - 230px));
    max-width: 680px;
  }

  .panel {
    display: grid;
    grid-template-columns: 116px 1fr;
    align-items: start;
  }
}

@media (max-width: 560px) {
  .board-wrap {
    width: min(100%, calc(100svh - 292px));
  }

  .panel {
    grid-template-columns: 92px 1fr;
    gap: 10px;
  }

  .tile::after {
    right: 5px;
    bottom: 5px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
  }
}
