.number-match-shell {
  width: min(100%, 640px);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(8px, 1.6cqh, 14px);
  align-self: stretch;
}

.number-match-scroll {
  width: 100%;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: clamp(4px, 1.2vw, 10px);
  border: 1px solid color-mix(in srgb, var(--game-accent) 24%, var(--line));
  border-radius: 18px;
  background:
    radial-gradient(circle at 18% 8%, color-mix(in srgb, var(--game-accent) 9%, transparent), transparent 34%),
    color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: inset 0 1px 0 color-mix(in srgb, white 5%, transparent);
}

.number-match-scroll:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--game-accent) 65%, white);
  outline-offset: 2px;
}

.number-match-board {
  --number-match-cell-cap: 58px;
  width: min(100%, 540px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: clamp(2px, .8vw, 6px);
  align-content: start;
  justify-content: center;
}

.number-match-cell {
  min-width: 0;
  direction: ltr;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: clamp(7px, 1.6vw, 12px);
  font: inherit;
}

button.number-match-cell {
  border: 1px solid color-mix(in srgb, var(--game-accent) 22%, var(--line));
  background: color-mix(in srgb, var(--surface-strong) 94%, var(--game-accent) 6%);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, border-color .12s ease, background .12s ease, box-shadow .12s ease;
}

button.number-match-cell > span {
  font-size: clamp(1rem, 3.7cqw, 1.55rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

button.number-match-cell:hover {
  border-color: color-mix(in srgb, var(--game-accent) 58%, var(--line));
  transform: translateY(-1px);
}

button.number-match-cell:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--game-accent) 72%, white);
  outline-offset: 1px;
  z-index: 1;
}

button.number-match-cell.is-selected {
  border-color: var(--game-accent);
  background: color-mix(in srgb, var(--game-accent) 20%, var(--surface-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--game-accent) 18%, transparent);
  transform: scale(.94);
}

button.number-match-cell.is-hint {
  border-color: var(--game-accent-2);
  background: color-mix(in srgb, var(--game-accent-2) 24%, var(--surface-strong));
  animation: number-match-hint .72s ease-in-out infinite alternate;
}

.number-match-cell.is-cleared {
  border: 1px dashed color-mix(in srgb, var(--line) 48%, transparent);
  background: color-mix(in srgb, var(--surface) 35%, transparent);
  opacity: .34;
}

.number-match-instructions {
  margin: 0;
  padding-inline: 4px;
  color: var(--muted);
  font-size: clamp(.76rem, 2.6vw, .9rem);
  line-height: 1.45;
  text-align: center;
}

.number-match-shell.is-complete .number-match-scroll {
  border-color: color-mix(in srgb, var(--game-accent) 56%, var(--line));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--game-accent) 12%, transparent), var(--shadow-soft);
}

@keyframes number-match-hint {
  from { transform: scale(.94); box-shadow: 0 0 0 2px color-mix(in srgb, var(--game-accent-2) 12%, transparent); }
  to { transform: scale(1); box-shadow: 0 0 0 5px color-mix(in srgb, var(--game-accent-2) 22%, transparent); }
}

/* The logical board always keeps nine columns. Only its presentation is
   transposed, so the same saved cells and the same matching topology survive
   a viewport change without regenerating or rewriting the puzzle. */
@media (max-width: 700px) {
  .number-match-scroll {
    padding: 4px;
    border-radius: 14px;
    scrollbar-gutter: auto;
  }

  .number-match-board {
    gap: 2px;
  }

  .number-match-board.is-logically-wide {
    width: min(100%, var(--number-match-transposed-width));
    grid-template-columns: repeat(var(--number-match-rows), minmax(0, 1fr));
    grid-template-rows: repeat(9, minmax(0, 1fr));
    grid-auto-flow: column;
    direction: rtl;
  }

  .number-match-cell {
    border-radius: 7px;
  }

  button.number-match-cell > span {
    font-size: clamp(.92rem, 5.2vw, 1.25rem);
  }
}

@media (min-width: 701px) {
  .number-match-board.is-logically-tall {
    width: min(100%, var(--number-match-transposed-width));
    grid-template-columns: repeat(var(--number-match-rows), minmax(0, 1fr));
    grid-template-rows: repeat(9, minmax(0, 1fr));
    grid-auto-flow: column;
    direction: rtl;
  }
}

@media (prefers-reduced-motion: reduce) {
  button.number-match-cell {
    transition: none;
  }

  button.number-match-cell.is-hint {
    animation: none;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--game-accent-2) 18%, transparent);
  }
}
