body {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-align: center;
  padding: 10px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

/* Two-column layout: rules left, game right */
.page-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 30px;
  max-width: 860px;
  margin: 0 auto;
  padding: 10px 10px 20px;
  flex-wrap: wrap;
}

.game-container {
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
}

#board {
  width: 400px;
  height: 400px;
  border: 10px solid darkgray;
  background-color: lightgray;
  display: flex;
  flex-wrap: wrap;
}

.controls {
  display: flex;
  flex-direction: column;
  margin-left: 10px;
}

#board div {
  width: 48px;
  height: 48px;
  border: 1px solid whitesmoke;
  font-size: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.tile-clicked {
  background-color: darkgrey;
}

.x1 { color: blue; }
.x2 { color: green; }
.x3 { color: red; }
.x4 { color: navy; }
.x5 { color: brown; }
.x6 { color: teal; }
.x7 { color: black; }
.x8 { color: gray; }

#flag-button, #refresh-button {
  width: 50px;
  height: 50px;
  font-size: 25px;
  background-color: lightgray;
  border: 2px solid darkgray;
  border-radius: 5px;
  margin-bottom: 10px;
  cursor: pointer;
}

#refresh-button {
  margin-top: 300px;
}

#flag-button:hover, #refresh-button:hover {
  background-color: #c0c0c0;
}

.dialog {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.dialog-content {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  min-width: 300px;
  text-align: center;
}

#dialog-message {
  font-size: 18px;
  margin-bottom: 15px;
}

#dialog-close {
  padding: 8px 16px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

#dialog-close:hover {
  background-color: #45a049;
}

.rules-container {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
  text-align: left;
  border: 2px solid darkgray;
  border-radius: 5px;
  padding: 10px 20px;
  background-color: #f5f5f5;
  align-self: stretch;
}

.rules-container h2 {
  text-align: center;
  margin-top: 10px;
  color: #333;
}

.rules-container ul {
  padding-left: 20px;
}

.rules-container li {
  margin-bottom: 8px;
  font-weight: normal;
}

@media (max-width: 480px) {
  body {
    padding: 8px;
  }

  .page-layout {
    gap: 16px;
    padding: 8px;
  }

  /* Stack controls below the board so nothing overflows horizontally */
  .game-container {
    flex-direction: column;
    align-items: center;
  }

  #board {
    width: 296px;
    height: 296px;
  }

  #board div {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .controls {
    flex-direction: row;
    margin-left: 0;
    margin-top: 10px;
    gap: 12px;
  }

  #flag-button,
  #refresh-button {
    width: 56px;
    height: 56px;
    font-size: 26px;
  }

  #refresh-button {
    margin-top: 0;
  }

  .rules-container {
    max-width: 100%;
    min-width: unset;
    width: 296px;
  }
}
