.boxes-game {
  --blue: #27546b;
  --rust: #9c412d;
  --board-ink: #3d4439;
  --notebook: #fff9e8;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(235px, .85fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "paper score" "paper setup";
  column-gap: clamp(20px, 4vw, 56px);
  row-gap: clamp(15px, 2.1vw, 24px);
  align-items: start;
  max-width: 930px;
  margin-top: 25px;
  padding: clamp(14px, 3vw, 34px);
  border: 1px solid #ded9c3;
  border-radius: 13px;
  background: #eeebdb;
}

.boxes-paper {
  grid-area: paper;
  padding: 2px;
  border: 1px solid #c9bf9e;
  border-radius: 5px 12px 8px 5px;
  background: var(--notebook);
  box-shadow: 2px 3px 0 #ece2c4, 4px 5px 0 #bdaf8a, 5px 10px 18px #634d2a22;
}

.boxes-board {
  --move-ink: var(--blue);
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px 10px 7px 3px;
  overflow: clip;
  background:
    repeating-linear-gradient(0deg, transparent 0 23px, #778b7e24 23px 24px),
    linear-gradient(90deg, #d18a7355 0 1px, transparent 1px) 3.1% 0 / 96.9% 100% no-repeat,
    linear-gradient(112deg, #fdf5de, #fff9ea 65%, #faf0d8);
  isolation: isolate;
}

.boxes-board[data-turn="2"] {
  --move-ink: var(--rust);
}

.boxes-dot,
.boxes-mark,
.boxes-edge {
  position: absolute;
  transform: translate(-50%, -50%);
}

.boxes-dot {
  z-index: 2;
  width: clamp(7px, 2.25%, 11px);
  aspect-ratio: 1;
  border-radius: 49% 48% 40% 43%;
  background: var(--board-ink);
  box-shadow: 0 1px 1px #3d44394a;
  pointer-events: none;
}

.boxes-edge {
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--box-step);
  height: var(--box-step);
  border: 0;
  padding: 0;
  border-radius: 0;
  outline-offset: 0;
  background: transparent;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.boxes-edge::before {
  content: "";
  width: 89%;
  height: 0;
  border-top: 2px dotted #756d52;
  pointer-events: none;
}

.boxes-edge[data-direction="vertical"]::before {
  width: 0;
  height: 89%;
  border: 0;
  border-left: 2px dotted #756d52;
}

.boxes-edge[data-owner="1"],
.boxes-mark[data-owner="1"],
.boxes-player[data-player="1"] {
  --owner-ink: var(--blue);
  --wash: #dce9e9;
  --hash: #2b68851c;
}

.boxes-edge[data-owner="2"],
.boxes-mark[data-owner="2"],
.boxes-player[data-player="2"] {
  --owner-ink: var(--rust);
  --wash: #f3dfd2;
  --hash: #b354351f;
}

.boxes-edge:not([data-owner="0"]) {
  pointer-events: none;
}

.boxes-edge:not([data-owner="0"])::before {
  width: 100%;
  height: clamp(3px, 6.5%, 7px);
  border: none;
  border-radius: 40% 10% 32% 18% / 30% 36% 15% 30%;
  background: var(--owner-ink);
  opacity: .77;
}

.boxes-edge:not([data-owner="0"])[data-direction="vertical"]::before {
  width: clamp(3px, 6.5%, 7px);
  height: 100%;
}

.boxes-edge[data-last="true"]::before {
  opacity: 1;
}

@media (hover: hover) {
  .boxes-edge[aria-disabled="false"]:hover {
    background: color-mix(in srgb, var(--move-ink) 11%, transparent);
  }

  .boxes-edge[aria-disabled="false"]:hover::before {
    border-color: var(--move-ink);
  }
}

.boxes-edge:focus-visible {
  z-index: 3;
  outline: none;
  background: color-mix(in srgb, var(--move-ink) 18%, transparent);
}

.boxes-edge:focus-visible::before {
  border-color: var(--move-ink);
  box-shadow: 0 0 0 3px var(--move-ink);
}

.boxes-mark {
  display: grid;
  place-items: center;
  width: calc(var(--box-step) * .87);
  aspect-ratio: 1;
  color: var(--owner-ink);
  font: italic 600 clamp(1.05rem, 4.5vw, 2.8rem)/1 var(--serif);
  pointer-events: none;
}

.boxes-mark:not([data-owner="0"]) {
  background: repeating-linear-gradient(132deg, transparent 0 5px, var(--hash) 5px 6px), var(--wash);
}

.boxes-scorecard {
  grid-area: score;
  display: grid;
  align-items: start;
  gap: 20px;
  padding-top: 5px;
}

.boxes-scores {
  display: grid;
  gap: 8px;
}

.boxes-player {
  display: grid;
  grid-template-columns: 29px 1fr auto;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 8px 11px;
  border: 1px solid #cfc6ae;
  border-radius: 6px;
  color: var(--owner-ink);
  background: #fbf7eb;
  font-weight: 700;
  font-size: .9rem;
}

.boxes-player[data-turn="true"] {
  border-color: var(--owner-ink);
  background: var(--wash);
  box-shadow: inset 3px 0 0 var(--owner-ink);
}

.boxes-player strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.boxes-initial {
  display: grid;
  place-items: center;
  width: 27px;
  aspect-ratio: 1;
  border: 1px solid var(--owner-ink);
  border-radius: 3px 5px 3px 5px;
  background: repeating-linear-gradient(132deg, transparent 0 4px, var(--hash) 4px 5px), #fff9ef;
  font: italic 600 1.05rem/1 var(--serif);
}

.boxes-status {
  min-height: 94px;
}

.boxes-status h2 {
  font-size: clamp(1.85rem, 3.8vw, 2.85rem);
}

.boxes-status h2:focus-visible {
  outline: 3px solid #ce7620;
  outline-offset: 3px;
  border-radius: 3px;
}

.boxes-status p {
  margin-top: 7px;
  color: #485046;
}

.boxes-setup {
  grid-area: setup;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
  max-width: 345px;
  padding-top: 14px;
  border-top: 1px solid #cfc6ae;
}

.boxes-setup label {
  display: grid;
  gap: 4px;
  font-size: .86rem;
  font-weight: 750;
}

.boxes-setup select {
  width: 100%;
  min-height: 44px;
  padding: 6px;
  border: 1px solid #a8a293;
  border-radius: 6px;
  color: var(--ink);
  background: #fffdf4;
}

.boxes-setup .btn {
  justify-self: start;
  min-height: 44px;
  grid-column: 1 / -1;
}

.boxes-a11y {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.boxes-rules {
  max-width: 75ch;
  margin-top: 20px;
  padding: 15px 18px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffdf6;
}

.boxes-rules summary {
  width: fit-content;
  font-weight: 750;
  cursor: pointer;
}

.boxes-rules ul {
  padding-left: 1.2em;
}

.boxes-rules li + li {
  margin-top: 6px;
}

@media (max-width: 680px) {
  .boxes-game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "score" "paper" "setup";
    max-width: 540px;
    padding: clamp(9px, 3vw, 18px);
  }

  .boxes-scorecard {
    gap: 9px;
    padding-top: 0;
  }

  .boxes-scores {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .boxes-player {
    grid-template-columns: 23px 1fr auto;
    gap: 6px;
    padding: 6px;
    font-size: .8rem;
  }

  .boxes-initial {
    width: 22px;
    font-size: .95rem;
  }

  .boxes-status {
    min-height: 70px;
  }

  .boxes-status h2 {
    font-size: clamp(1.6rem, 6vw, 2.1rem);
  }

  .boxes-status p {
    margin-top: 3px;
    font-size: .9rem;
  }

  .boxes-setup {
    max-width: none;
    border-top: 0;
    padding-top: 3px;
  }
}

@media (forced-colors: active) {
  .boxes-dot,
  .boxes-edge:not([data-owner="0"])::before {
    background: CanvasText;
    forced-color-adjust: none;
  }

  .boxes-edge:focus-visible {
    background: Highlight;
    forced-color-adjust: none;
  }

  .boxes-edge:focus-visible::before {
    border-color: HighlightText;
  }
}
