.gem-play { --game-play-width: 460px; }

.gem-controls, .gem-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.gem-controls, .gem-stats, .gem-status {
  color: var(--game-secondary);
  font-size: 14px;
  line-height: 1.6;
}
.gem-controls select { min-width: 0; max-width: 100%; }
.gem-stats {
  gap: 0 8px;
  margin: 12px auto 8px;
  font-variant-numeric: tabular-nums;
}
.gem-goal { display: inline-flex; align-items: center; gap: 3px; }
.gem-goal svg { width: 19px; height: 19px; }
.gem-moves { margin-inline-start: 8px; }
.gem-stats strong { color: var(--game-ink); white-space: nowrap; }
.gem-actions { margin-top: 12px; }
.gem-status { min-height: 1.6em; margin: 8px 0 0; text-align: center; }
.gem-status[data-error] { color: #aa473f; }
html[data-theme=dark] .gem-status[data-error] { color: #ffc2b5; }

.gem-board {
  --gem-gap: clamp(3px, 1.2vw, 6px);
  display: grid;
  grid-template-columns: repeat(var(--gem-columns, 5), minmax(0, 1fr));
  gap: var(--gem-gap);
  box-sizing: border-box;
  width: min(100%, 365px);
  margin-inline: auto;
  padding: clamp(5px, 1.5vw, 9px);
  border: 1px solid #3e5656;
  border-radius: 15px;
  background:
    repeating-linear-gradient(134deg, transparent 0 11px, #649a8512 11px 12px, transparent 12px 18px),
    #263b3e;
  box-shadow: 0 3px 8px #1a2b3614, inset 0 1px #e6fff228;
}
html[data-theme=dark] .gem-board { background-color: #172c2f; }
.gem-cell {
  position: relative;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #758f8e5e;
  border-radius: clamp(5px, 1.7vw, 8px);
  background: #162d3185;
  box-shadow: inset 0 1px 3px #12202566;
  cursor: pointer;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.gem-cell[aria-disabled=true] { cursor: default; }
.gem-cell:focus-visible { outline: 2px solid #f6ebb6; outline-offset: 2px; z-index: 1; }
.gem-cell svg {
  width: 74%;
  height: 74%;
  filter: drop-shadow(0 2px 1px #111d2470);
  pointer-events: none;
}
.gem-cell[aria-pressed=true], .gem-cell[data-hinted] { border: 2px solid #ffe4a4; background: #62654f; }
.gem-cell[data-hinted] { border-style: dashed; }
.gem-cell[data-error] { border: 2px solid #f0a79f; background: #634e4d; }
@media (hover: hover) {
  .gem-cell:hover:not([aria-disabled=true]) svg { filter: drop-shadow(0 2px 1px #111d2470) brightness(1.16); }
}
.gem-cell[data-hit] { border-color: #d9fce2; background: #5a7e69; }
.gem-cell[data-hit] svg { animation: gem-hit 148ms ease-in both; }
.gem-cell[data-fall] { overflow: hidden; }
.gem-cell[data-fall] svg { animation: gem-fall 165ms cubic-bezier(.25,.65,.4,1) both; }
@keyframes gem-hit {
  28% { transform: scale(1.15); filter: drop-shadow(0 0 5px #fffbc9); }
  100% { opacity: .12; transform: scale(.36); }
}
@keyframes gem-fall {
  from { opacity: .34; transform: translateY(calc(var(--gem-drop, 0) * -72%)); }
}
#show-victory[hidden], #retry-result[hidden], #next-level[hidden] { display: none; }

.gem-result {
  box-sizing: border-box;
  width: min(410px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--game-line);
  border-radius: 15px;
  background: var(--game-surface);
  color: var(--game-secondary);
  box-shadow: 0 18px 54px #14243840;
  overscroll-behavior: contain;
}
.gem-result[open] { animation: gem-result-in 180ms ease-out; }
.gem-result::backdrop { background: #1427319c; }
.gem-result-body { padding: 24px clamp(16px, 6vw, 32px); text-align: center; }
.gem-result h2 { margin: 0; color: var(--game-accent); font-size: 22px; }
.gem-result p { margin: 9px 0 16px; line-height: 1.65; }
@keyframes gem-result-in { from { opacity: .35; transform: scale(.97); } }

@media (max-width: 420px) {
  body[data-fourhao-game=gem-match] .gem-controls .game-page-button { padding-inline: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .gem-cell[data-hit] svg, .gem-cell[data-fall] svg, .gem-result[open] { animation: none; }
}
