* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  display: flex;
  background: #ffffff;
  font-family: sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  width: 100%;
  padding: 16px;
  margin: auto;
}

.header-slot {
  width: 100%;
  max-width: 594px;
}

.topbar {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar-agents {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 24px;
}

.agent-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
}

.agent-select {
  padding: 8px 10px;
  font-size: 14px;
  border-radius: 6px;
  border: 1px solid #ccc;
}

.footer-slot {
  grid-area: footer;
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn {
  border: none;
  border-radius: 8px;
  background: #4e4e4e;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 20px;
  cursor: pointer;
}

.btn:hover {
  background: #000000;
}

.content {
  width: 100%;
  max-width: 1250px;
  display: grid;
  grid-template-columns: minmax(0, 280px) minmax(0, 594px) minmax(0, 280px);
  grid-template-areas:
    "panelx board panelo"
    "footer footer footer";
  align-items: center;
  justify-content: center;
  gap: 32px;
}

.board {
  grid-area: board;
  position: relative;
  width: 100%;
  aspect-ratio: 594 / 588;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  background-image: url("../img/board.png");
  background-size: 100% 100%;
  image-rendering: pixelated;
  cursor: pointer;
}

.probs-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.probs-panel.side-left {
  grid-area: panelx;
}

.probs-panel.side-right {
  grid-area: panelo;
}

.probs-label {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
}

.probs-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-image: linear-gradient(rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.6)),
    url("../img/board.png");
  background-size: 100% 100%;
  image-rendering: pixelated;
  border-radius: 4px;
}

.probs-count {
  font-size: 16px;
  font-weight: 600;
  color: #2b2b2b;
  text-align: center;
}

/* positions mirror .piece's measured tile centers (see note above) so text
   lands on the same visual tile centers regardless of panel size */
.prob-cell {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 400;
  color: #2b2b2b;
}

.prob-cell-max {
  font-weight: 600;
}

.prob-cell[data-idx="0"] { left: 18.1818%; top: 17.8571%; }
.prob-cell[data-idx="1"] { left: 50.5051%; top: 17.8571%; }
.prob-cell[data-idx="2"] { left: 82.8283%; top: 17.8571%; }
.prob-cell[data-idx="3"] { left: 18.1818%; top: 49.4898%; }
.prob-cell[data-idx="4"] { left: 50.5051%; top: 49.4898%; }
.prob-cell[data-idx="5"] { left: 82.8283%; top: 49.4898%; }
.prob-cell[data-idx="6"] { left: 18.1818%; top: 81.1224%; }
.prob-cell[data-idx="7"] { left: 50.5051%; top: 81.1224%; }
.prob-cell[data-idx="8"] { left: 82.8283%; top: 81.1224%; }

.board.disabled {
  cursor: default;
  opacity: 0.35;
}

.board.locked {
  cursor: default;
}

.overlay-title {
  width: 100%;
  min-height: 64px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 40px;
  font-weight: 700;
  color: #000000;
  text-align: center;
}

.overlay-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}

.hidden {
  display: none;
}

.btn-play-again {
  padding: 16px 32px;
  font-size: 18px;
}

.cell {
  /* transparent click target only; visual tile lives in the board.png background */
}

/*
 * board.png's baked-in tiles are not exact equal thirds (5px left / 4px right
 * margin out of 99px; 5px top / 6px bottom out of 98px), so pieces are placed
 * at the tile's measured position instead of the naive grid center.
 */
.piece {
  position: absolute;
  object-fit: contain;
  pointer-events: none;
  image-rendering: pixelated;
}

.piece[data-idx="0"] { left: 5.0505%;  top: 5.1020%;  width: 26.2626%; height: 25.5102%; }
.piece[data-idx="1"] { left: 37.3737%; top: 5.1020%;  width: 26.2626%; height: 25.5102%; }
.piece[data-idx="2"] { left: 69.6970%; top: 5.1020%;  width: 26.2626%; height: 25.5102%; }
.piece[data-idx="3"] { left: 5.0505%;  top: 36.7347%; width: 26.2626%; height: 25.5102%; }
.piece[data-idx="4"] { left: 37.3737%; top: 36.7347%; width: 26.2626%; height: 25.5102%; }
.piece[data-idx="5"] { left: 69.6970%; top: 36.7347%; width: 26.2626%; height: 25.5102%; }
.piece[data-idx="6"] { left: 5.0505%;  top: 68.3673%; width: 26.2626%; height: 25.5102%; }
.piece[data-idx="7"] { left: 37.3737%; top: 68.3673%; width: 26.2626%; height: 25.5102%; }
.piece[data-idx="8"] { left: 69.6970%; top: 68.3673%; width: 26.2626%; height: 25.5102%; }

@media (max-width: 1250px) {
  .content {
    grid-template-columns: minmax(0, 594px);
    grid-template-areas:
      "board"
      "footer"
      "panelx"
      "panelo";
  }

  .board,
  .probs-panel {
    max-width: 594px;
  }
}

@media (max-width: 560px) {
  .topbar {
    justify-content: center;
  }

  .topbar-agents {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .app {
    gap: 20px;
  }

  .topbar-agents {
    gap: 12px;
  }

  .agent-icon {
    width: 24px;
    height: 24px;
  }

  .agent-select {
    font-size: 12px;
    padding: 6px 8px;
  }

  .btn {
    font-size: 14px;
    padding: 10px 16px;
  }

  .overlay-title {
    font-size: 28px;
  }
}
