.mesa-grid {
  --grid-blue: #2446ed;
  width: min(100%, 700px, var(--grid-fit-width, 700px));
  margin: auto;
  position: relative;
  color: #252321;
}

.mesa-grid-board {
  box-sizing: border-box;
  position: relative;
  aspect-ratio: var(--grid-ratio);
  padding: clamp(5px, 1.1vw, 12px);
  border: 2px solid #1835b9;
  border-radius: clamp(16px, 3vw, 28px);
  background: var(--grid-blue);
  box-shadow:
    0 8px 0 #1835b9,
    0 14px 26px #25232120;
}

.mesa-grid-cells,
.mesa-grid-targets,
.mesa-grid-decorations,
.mesa-grid-preview-layer,
.mesa-grid-animation-layer {
  position: absolute;
  inset: clamp(5px, 1.1vw, 12px);
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows), minmax(0, 1fr));
  gap: clamp(3px, 0.7vw, 8px);
}

.mesa-grid-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 6%;
  border-radius: 50%;
  background: #fff8e6;
  box-shadow: inset 0 3px 6px #25232124;
}

.mesa-grid-piece {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: clamp(2px, 0.4vw, 4px) solid #25232147;
  border-radius: 50%;
  background: var(--grid-piece);
  box-shadow:
    inset 0 4px 0 #ffffff55,
    inset 0 -5px 0 #25232122,
    0 2px 3px #25232120;
  color: var(--grid-piece-ink, #252321);
  font: 800 clamp(12px, 2vw, 24px)/1 var(--font-body, sans-serif);
}

.mesa-grid-piece-label {
  max-width: 90%;
  padding: 0.12em 0.22em;
  border-radius: 0.35em;
  background: #fff8e6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mesa-grid-piece.piece-square {
  border-radius: 18%;
}

.mesa-grid-piece.piece-token {
  border-radius: 42% 42% 30% 30%;
}

.mesa-grid-cell.is-arriving > .mesa-grid-piece {
  visibility: hidden;
}

.mesa-grid-preview-layer,
.mesa-grid-decorations,
.mesa-grid-animation-layer {
  pointer-events: none;
}

.mesa-grid-ghost,
.mesa-grid-animation-slot {
  display: grid;
  place-items: center;
  padding: 6%;
}

.mesa-grid-ghost {
  opacity: 0.65;
  filter: drop-shadow(0 0 4px #fff8e6);
}

.mesa-grid-target {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 16px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.mesa-grid-target:hover,
.mesa-grid-target[aria-pressed="true"] {
  background: #fff8e61a;
}

.mesa-grid-target:focus-visible {
  outline: 3px solid #ffd64f;
  outline-offset: -3px;
  background: #fff8e61a;
}

.mesa-grid-target:disabled {
  cursor: wait;
}

.mesa-grid-decoration {
  margin: 3%;
  border-radius: 50%;
  border: 4px solid transparent;
}

.mesa-grid-decoration.tone-winning {
  border-color: #fff8e6;
  box-shadow:
    0 0 0 3px #ffd64f,
    0 0 14px #ffd64f;
}

.mesa-grid-decoration.tone-recent {
  border-color: #fff8e6;
}

.mesa-grid-decoration.tone-muted {
  background: #25232130;
}

.mesa-grid-animation-slot {
  overflow: visible;
}

.mesa-grid-piece.is-playing {
  animation: mesa-grid-drop 480ms cubic-bezier(0.3, 0.1, 0.6, 1) both;
}

@keyframes mesa-grid-drop {
  from {
    transform: translateY(calc(var(--grid-travel) * 114%));
  }
  75% {
    transform: translateY(4%);
  }
  to {
    transform: translateY(0);
  }
}

.mesa-grid-confirmation {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 18px;
  background: #fff8e6ee;
  box-shadow: 0 3px 12px #25232116;
}

.mesa-grid-confirmation[hidden] {
  display: none;
}

.mesa-grid-confirmation > span {
  flex-basis: 100%;
  text-align: center;
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  .mesa-grid-piece.is-playing {
    animation: none;
  }
}

/* Contiguous surfaces and neutral pieces are presentation opt-ins. */
.mesa-grid.layout-squares .mesa-grid-cells,
.mesa-grid.layout-squares .mesa-grid-targets,
.mesa-grid.layout-squares .mesa-grid-decorations,
.mesa-grid.layout-squares .mesa-grid-preview-layer,
.mesa-grid.layout-squares .mesa-grid-animation-layer {
  gap: 0;
}
.mesa-grid.layout-squares .mesa-grid-cell {
  border-radius: 0;
  box-shadow: none;
  padding: 11%;
}
.mesa-grid.layout-squares .mesa-grid-target {
  border-radius: 6px;
}
.mesa-grid-cell.surface-light {
  background: #fff1cf;
}
.mesa-grid-cell.surface-dark {
  background: #4964b0;
}
.mesa-grid-piece.face-light {
  --grid-piece: #fff8e6;
  --grid-piece-ink: #39342b;
  background: #fff8e6;
  border-color: #c9b68b;
  color: #39342b;
}
.mesa-grid-piece.face-dark {
  --grid-piece: #39342b;
  --grid-piece-ink: #fff8e6;
  background: #39342b;
  border-color: #181d32;
  color: #fff8e6;
}
.mesa-grid-crown {
  width: 62%;
  height: 62%;
  display: block;
  filter: drop-shadow(0 1px 0 #0002);
}
.mesa-grid-decoration.tone-selected {
  border-color: #ffd64f;
  box-shadow:
    0 0 0 2px #fff8e6,
    0 0 10px #ffd64f88;
}
.mesa-grid-decoration.tone-path {
  border-color: #fff8e6;
  background: #ffd64f55;
  box-shadow: inset 0 0 0 2px #39342b55;
}

/* A path marks a square; it must not resemble an additional playing piece. */
.mesa-grid.layout-squares .mesa-grid-decoration.tone-path {
  margin: 12%;
  border: 2px dashed #ffd64f;
  border-radius: 18%;
  background: transparent;
  box-shadow: 0 0 0 1px #39342b66;
}
