.stone-viewport {
  justify-self: center;
  width: min(100%, 33rem);
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border-radius: 9px;
  scrollbar-width: thin;
}

.table-game .stone-board {
  box-sizing: border-box;
  position: relative;
  isolation: isolate;
  width: 100%;
  grid-template-rows: repeat(var(--cols), minmax(0, 1fr));
  gap: 0;
  padding: 0;
  border: 6px solid;
  border-radius: 9px;
  user-select: none;
}

.table-game .stone-gomoku {
  min-width: 372px; /* Fifteen full 24px intersections and the 6px frame. */
  border-color: #a16b36;
  background:
    repeating-linear-gradient(3deg, transparent 0 5px, #ae6f2310 6px, transparent 7px 13px),
    linear-gradient(108deg, #e5ae65, #efc688 46%, #e3ae6e);
  box-shadow: inset 0 0 0 1px #77461c55;
}

.stone-gomoku::before {
  content: "";
  position: absolute;
  inset: calc(50% / 15);
  background:
    linear-gradient(to right, #77522c 1px, transparent 1px) 0 0 / calc(100% / 14) 100%,
    linear-gradient(to bottom, #77522c 1px, transparent 1px) 0 0 / 100% calc(100% / 14);
  box-shadow: inset -1px -1px #77522c;
  pointer-events: none;
}

.table-game .stone-reversi {
  border-color: #213930;
  background: linear-gradient(120deg, #397b59, #246348 75%);
}

.table-game .stone-board > button,
.table-game .stone-board > button:hover:enabled {
  position: relative;
  z-index: 1;
  padding: 0;
  min-height: 0;
  min-width: 0;
  background: transparent;
  color: transparent;
  border: 0;
  border-radius: 0;
  font-size: 0;
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.table-game .stone-board > button[aria-disabled="true"] { cursor: default; }
.table-game .stone-reversi > button { box-shadow: inset 1px 1px #163f30; }

.stone-board button::before,
.stone-board button::after {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  box-sizing: border-box;
  border-radius: 50%;
  pointer-events: none;
}

.stone-gomoku .stone-star::before {
  content: "";
  width: 16%;
  aspect-ratio: 1;
  background: #694420;
}

.stone-board [data-stone]::before {
  content: "";
  width: 86%;
  aspect-ratio: 1;
  border: 1px solid #181b1c;
  background: radial-gradient(ellipse at 32% 24%, #575c5d, #222628 48%, #101315 85%);
  box-shadow: 0 1px 2px #15181670, inset 0 -1px 1px #0006;
}

.stone-board [data-stone="white"]::before {
  border-color: #74746a;
  background: radial-gradient(ellipse at 30% 23%, #fff, #f3f2ed 52%, #cccac1 93%);
}

.stone-board .stone-last::after {
  content: "";
  width: 24%;
  aspect-ratio: 1;
  border: 2px solid #f7f7ec;
}
.stone-board [data-stone="white"].stone-last::after { border-color: #282c2c; }
.stone-reversi .stone-open::before {
  content: "";
  width: 29%;
  aspect-ratio: 1;
  border: 2px solid #d3e9c0;
}

@media (hover: hover) {
  .table-game .stone-board > .stone-open:hover { background-color: #ffffff2b; }
}

.table-game .stone-board > button:focus-visible {
  z-index: 2;
  outline: 2px solid #f9fcff;
  outline-offset: -3px;
  box-shadow: inset 0 0 0 4px #245598;
  border-radius: 4px;
}

@media (max-width: 31rem) {
  /* Let the full board fit typical phones. Smaller viewports pan only the board itself. */
  .table-game[data-game="gomoku"] { margin-inline: calc(-1rem + 4px); }
  .table-game[data-game="gomoku"] > .gt-stack { padding-inline: 3px; }
  .table-game[data-game="gomoku"] > .gt-stack > p,
  .table-game[data-game="gomoku"] .gt-stack > [role="status"] { padding-inline: .7rem; }
  .table-game[data-game="gomoku"] > .gt-stack > button { margin-inline: .7rem; }
}

@media (forced-colors: active) {
  .table-game .stone-board { forced-color-adjust: none; }
}
